Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jezzsantos committed Oct 15, 2023
1 parent 3031088 commit dbee3bf
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public async Task WhenGetThrowsException_ThenReturnsServerError()
result.Content.Error.Instance.Should().Be("http://localhost/testingonly/errors/throws");
result.Content.Error.Exception.Should().StartWith("System.InvalidOperationException: amessage");
result.Content.Error.Errors.Should().BeNull();

}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ public async Task WhenGetWithNoRequestId_ThenReturnsGeneratedResponseHeader()
[Fact]
public async Task WhenGetWithRequestId_ThenReturnsSameResponseHeader()
{
var result = await Api.GetAsync(new RequestCorrelationsTestingOnlyRequest(), message =>
{
message.Headers.Add("Request-ID", "acorrelationid");
});

var result = await Api.GetAsync(new RequestCorrelationsTestingOnlyRequest(),
message => { message.Headers.Add("Request-ID", "acorrelationid"); });

result.StatusCode.Should().Be(HttpStatusCode.OK);
result.Headers.GetValues(HttpHeaders.RequestId).FirstOrDefault().Should()
.Be("acorrelationid");
Expand All @@ -45,10 +43,8 @@ public async Task WhenGetWithRequestId_ThenReturnsSameResponseHeader()
[Fact]
public async Task WhenGetWithXRequestId_ThenReturnsSameResponseHeader()
{
var result = await Api.GetAsync(new RequestCorrelationsTestingOnlyRequest(), message =>
{
message.Headers.Add("X-Request-ID", "acorrelationid");
});
var result = await Api.GetAsync(new RequestCorrelationsTestingOnlyRequest(),
message => { message.Headers.Add("X-Request-ID", "acorrelationid"); });

result.StatusCode.Should().Be(HttpStatusCode.OK);
result.Headers.GetValues(HttpHeaders.RequestId).FirstOrDefault().Should()
Expand All @@ -58,10 +54,8 @@ public async Task WhenGetWithXRequestId_ThenReturnsSameResponseHeader()
[Fact]
public async Task WhenGetWithXCorrelationId_ThenReturnsSameResponseHeader()
{
var result = await Api.GetAsync(new RequestCorrelationsTestingOnlyRequest(), message =>
{
message.Headers.Add("X-Correlation-ID", "acorrelationid");
});
var result = await Api.GetAsync(new RequestCorrelationsTestingOnlyRequest(),
message => { message.Headers.Add("X-Correlation-ID", "acorrelationid"); });

result.StatusCode.Should().Be(HttpStatusCode.OK);
result.Headers.GetValues(HttpHeaders.RequestId).FirstOrDefault().Should()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public async Task WhenGetValidatedRequestWithPartialInvalidFields_ThenReturnsVal
new() { Rule = "NotEmptyValidator", Reason = "'Field2' must not be empty.", Value = null }
});
}

[Fact]
public async Task WhenGetValidatedRequestWithValidId_ThenReturnsResponse()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public class TestRequest : IWebRequest<TestResponse>
{
public int ANumberProperty { get; set; }

public string AStringProperty { get; set; }
public string? AStringProperty { get; set; }

public string Id { get; set; }
public string? Id { get; set; }
}

public class TestResponse : IWebResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ Task<JsonResponse<TResponse>> PutAsync<TResponse>(IWebRequest<TResponse> request

Task<JsonResponse> PutAsync(IWebRequest request,
Action<HttpRequestMessage>? requestFilter = null, CancellationToken? cancellationToken = default);
}
}
2 changes: 1 addition & 1 deletion src/Infrastructure.WebApi.Common/Clients/JsonClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private async Task<HttpResponseMessage> SendRequestAsync(HttpMethod method, IWeb
{
var requestUri = request.GetRequestInfo().Route;
var content = new StringContent(request.ToJson()!, new MediaTypeHeaderValue(HttpContentTypes.Json));

return await SendRequestAsync(method, requestUri, content, requestFilter, cancellationToken);
}

Expand Down
10 changes: 5 additions & 5 deletions src/Infrastructure.WebApi.Common/HttpConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ namespace Infrastructure.WebApi.Common;
/// </summary>
public static class HttpContentTypes
{
public const string JsonProblem = "application/problem+json";
public const string FormData = "multipart/form-data";
public const string FormUrlEncoded = "application/x-www-form-urlencoded";
public const string FormUrlEncodedWithCharset = "application/x-www-form-urlencoded; charset=utf-8";
public const string Json = "application/json";
public const string JsonProblem = "application/problem+json";
public const string JsonWithCharset = "application/json; charset=utf-8";
public const string OctetStream = "application/octet-stream";
public const string XmlProblem = "application/problem+xml";
public const string Xml = "application/xml";
public const string XmlProblem = "application/problem+xml";
public const string XmlWithCharset = "application/xml; charset=utf-8";
public const string FormUrlEncoded = "application/x-www-form-urlencoded";
public const string FormUrlEncodedWithCharset = "application/x-www-form-urlencoded; charset=utf-8";
public const string FormData = "multipart/form-data";
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion src/Infrastructure.WebApi.Common/Resources.resx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>

<root>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="root"
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
id="root"
xmlns="">
<xsd:element name="root" msdata:IsDataSet="true">

Expand Down
4 changes: 2 additions & 2 deletions src/Infrastructure.WebApi.Common/ValidatorProblem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ namespace Infrastructure.WebApi.Common;
/// </summary>
public class ValidatorProblem
{
public required string Rule { get; set; }

public required string Reason { get; set; }

public required string Rule { get; set; }

public object? Value { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ namespace Infrastructure.WebApi.Interfaces.Operations.TestingOnly;
public class ContentNegotiationsTestingOnlyRequest : IWebRequest<StringMessageTestingOnlyResponse>
{
public string? Format { get; set; }

}
#endif
2 changes: 2 additions & 0 deletions src/SaaStack.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=DE31F486_002DAE81_002D49C0_002DBA00_002D3A6A325B7C42_002Ff_003AAnalyzerReleases_002EShipped_002Emd/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=DE31F486_002DAE81_002D49C0_002DBA00_002D3A6A325B7C42_002Ff_003AAnalyzerReleases_002EUnshipped_002Emd/@EntryIndexedValue">ExplicitlyExcluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/GeneratedFilesAndFolders/=7AB39FD6_002D660F_002D4400_002D9955_002DB92684378492_002Fd_003AReference/@EntryIndexedValue">7AB39FD6-660F-4400-9955-B92684378492/d:Reference</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/GeneratedFilesAndFolders/=DE31F486_002DAE81_002D49C0_002DBA00_002D3A6A325B7C42_002Fd_003AReference/@EntryIndexedValue">DE31F486-AE81-49C0-BA00-3A6A325B7C42/d:Reference</s:String>


<s:String x:Key="/Default/CodeInspection/Highlighting/InspectionSeverities/=ArrangeNamespaceBody/@EntryIndexedValue">WARNING</s:String>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,6 @@ public ApiEmptyResult AMethod(TestNoneRequest request)

await Verify.DiagnosticExists<WebApiClassAnalyzer>(input, (WebApiClassAnalyzer.Sas013, 10, 27, "AMethod"),
(WebApiClassAnalyzer.Sas017, 10, 35, "TestNoneRequest"));

}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static void ReportDiagnostic(this SyntaxNodeAnalysisContext context, Diag
var diagnostic = Diagnostic.Create(descriptor, identifier.GetLocation(), arguments.ToArray());
context.ReportDiagnostic(diagnostic);
}

public static void ReportDiagnostic(this SyntaxNodeAnalysisContext context, DiagnosticDescriptor descriptor,
MethodDeclarationSyntax methodDeclarationSyntax, params object?[]? messageArgs)
{
Expand Down
5 changes: 3 additions & 2 deletions src/Tools.Generators.WebApi/WebApiAssemblyVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace Tools.Generators.WebApi;
/// 2. They return type that is not void
/// 3. They have a request DTO type derived from <see cref="_webRequestInterfaceSymbol" /> as their first parameter
/// 4. They may have a <see cref="CancellationToken" /> as their second parameter, but no other parameters
/// 5. Their request DTO type is decorated with the <see cref="_routeAttributeSymbol" /> attribute, and have both a route and operation
/// 5. Their request DTO type is decorated with the <see cref="_routeAttributeSymbol" /> attribute, and have both a
/// route and operation
/// </summary>
public class WebApiAssemblyVisitor : SymbolVisitor
{
Expand All @@ -24,11 +25,11 @@ public class WebApiAssemblyVisitor : SymbolVisitor

private readonly CancellationToken _cancellationToken;
private readonly INamedTypeSymbol _cancellationTokenSymbol;
private readonly INamedTypeSymbol _routeAttributeSymbol;
private readonly INamedTypeSymbol _serviceInterfaceSymbol;
private readonly INamedTypeSymbol _voidSymbol;
private readonly INamedTypeSymbol _webRequestInterfaceSymbol;
private readonly INamedTypeSymbol _webRequestResponseInterfaceSymbol;
private readonly INamedTypeSymbol _routeAttributeSymbol;

public WebApiAssemblyVisitor(CancellationToken cancellationToken, Compilation compilation)
{
Expand Down
Binary file modified tools/nuget/SaaStack.Tools.Analyzers.Core.1.0.0.nupkg
Binary file not shown.

0 comments on commit dbee3bf

Please sign in to comment.