Skip to content

V9.0.0/dotnet rc2 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
For more details, please refer to `PackageReleaseNotes.txt` on a per assembly basis in the `.nuget` folder.

> [!NOTE]
> Changelog entries prior to version 8.4.0 was migrated from previous versions of Codebelt.Extensions.Asp.Versioning.
> Changelog entries prior to version 8.4.0 was migrated from previous versions of Cuemon.Extensions.Asp.Versioning.

## [9.0.0] - TBD

Expand All @@ -20,7 +20,6 @@ This major release is first and foremost focused on ironing out any wrinkles tha

- RestfulApiVersioningOptions class in the Codebelt.Extensions.Asp.Versioning namespace to include non-official MIME-types in the ValidAcceptHeaders property


## [7.1.0] 2022-12-11

### Added
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Codebelt.Extensions.Xunit.App" Version="9.0.0-preview.8" />
<PackageReference Include="Codebelt.Extensions.Xunit.App" Version="9.0.0-preview.10" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<PackageReference Include="Asp.Versioning.Http" Version="8.1.0" />
<PackageReference Include="Asp.Versioning.Mvc" Version="8.1.0" />
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
<PackageReference Include="Cuemon.AspNetCore" Version="9.0.0-preview.9" />
<PackageReference Include="Cuemon.AspNetCore" Version="9.0.0-preview.11" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Microsoft.Extensions.DependencyInjection;
using Xunit;
using Xunit.Abstractions;
using YamlDotNet.Serialization.NamingConventions;

namespace Codebelt.Extensions.Asp.Versioning
{
Expand Down Expand Up @@ -207,7 +208,7 @@ public async Task GetRequest_ShouldFailWithBadRequestFormattedAsXmlResponse_As_d
.AddApplicationPart(typeof(FakeController).Assembly)
.AddJsonFormatters()
.AddXmlFormatters()
.AddYamlFormatters();
.AddYamlFormatters(o => o.Settings.NamingConvention = PascalCaseNamingConvention.Instance);
services.AddHttpContextAccessor();
services.AddRestfulApiVersioning();
}, app =>
Expand All @@ -228,13 +229,14 @@ public async Task GetRequest_ShouldFailWithBadRequestFormattedAsXmlResponse_As_d
Assert.Equal(HttpStatusCode.BadRequest, sut.StatusCode);
Assert.Equal(HttpMethod.Get, sut.RequestMessage.Method);
Assert.EndsWith(yamlAccept, sut.Content.Headers.ContentType.ToString());
Assert.Equal("""
Assert.True(Match("""
Error:
Instance: http://localhost/fake/throw
Status: 400
Code: BadRequest
Message: The HTTP resource that matches the request URI 'http://localhost/fake/throw' does not support the API version 'd3'.

""", await sut.Content.ReadAsStringAsync(), ignoreLineEndingDifferences: true);
TraceId: *
""".ReplaceLineEndings(), await sut.Content.ReadAsStringAsync(), o => o.ThrowOnNoMatch = true));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Cuemon.Extensions.AspNetCore.Mvc" Version="9.0.0-preview.9" />
<PackageReference Include="Cuemon.Extensions.AspNetCore.Mvc" Version="9.0.0-preview.11" />
<PackageReference Include="Cuemon.Extensions.AspNetCore.Mvc.Formatters.Newtonsoft.Json" Version="9.0.0-preview.7" />
<PackageReference Include="Cuemon.Extensions.AspNetCore.Mvc.Formatters.Text.Json" Version="9.0.0-preview.9" />
<PackageReference Include="Cuemon.Extensions.AspNetCore.Mvc.Formatters.Xml" Version="9.0.0-preview.9" />
<PackageReference Include="Codebelt.Extensions.AspNetCore.Mvc.Formatters.Text.Yaml" Version="9.0.0-preview.3" />
<PackageReference Include="Cuemon.Extensions.AspNetCore.Mvc.Formatters.Text.Json" Version="9.0.0-preview.11" />
<PackageReference Include="Cuemon.Extensions.AspNetCore.Mvc.Formatters.Xml" Version="9.0.0-preview.11" />
<PackageReference Include="Codebelt.Extensions.AspNetCore.Mvc.Formatters.Text.Yaml" Version="9.0.0-preview.5" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using Microsoft.Extensions.DependencyInjection;
using Xunit;
using Xunit.Abstractions;
using YamlDotNet.Serialization.NamingConventions;

namespace Codebelt.Extensions.Asp.Versioning
{
Expand Down Expand Up @@ -162,7 +163,7 @@ public async Task GetRequest_ShouldFailWithBadRequestFormattedAsYamlResponse_As_
services.AddFaultDescriptorOptions();
services.AddControllers(o => o.Filters.AddFaultDescriptor())
.AddApplicationPart(typeof(FakeController).Assembly)
.AddYamlFormatters();
.AddYamlFormatters(o => o.Settings.NamingConvention = PascalCaseNamingConvention.Instance);
services.AddHttpContextAccessor()
.AddRestfulApiVersioning(o =>
{
Expand All @@ -186,37 +187,45 @@ public async Task GetRequest_ShouldFailWithBadRequestFormattedAsYamlResponse_As_
Assert.Equal(HttpStatusCode.BadRequest, sut.StatusCode);
Assert.Equal(HttpMethod.Get, sut.RequestMessage.Method);
Assert.EndsWith("*/*", sut.Content.Headers.ContentType.ToString());
Assert.StartsWith(@"Error:
Status: 400
Code: BadRequest
Message: The HTTP resource that matches the request URI 'http://localhost/fake/throw' does not support the API version 'b3'.
Failure:
Type: Cuemon.AspNetCore.Http.BadRequestException
Source: Codebelt.Extensions.Asp.Versioning
Message: The HTTP resource that matches the request URI 'http://localhost/fake/throw' does not support the API version 'b3'.
Stack:
".ReplaceLineEndings(), await sut.Content.ReadAsStringAsync());
Assert.EndsWith(@"Evidence:
Request:
Location: http://localhost/fake/throw
Method: GET
Headers:
Accept:
- text/html
- application/xhtml+xml
- image/avif
- image/webp
- image/apng
- '*/*; q=0.8'
- application/signed-exchange; v=b3; q=0.9
- application/json; q=10.0
Host:
- localhost
Query: []
Form:
Cookies: []
Body: ''
".ReplaceLineEndings(), await sut.Content.ReadAsStringAsync());
Assert.True(Match("""
Error:
Instance: http://localhost/fake/throw
Status: 400
Code: BadRequest
Message: The HTTP resource that matches the request URI 'http://localhost/fake/throw' does not support the API version 'b3'.
Failure:
Type: Cuemon.AspNetCore.Http.BadRequestException
Source: Codebelt.Extensions.Asp.Versioning
Message: The HTTP resource that matches the request URI 'http://localhost/fake/throw' does not support the API version 'b3'.
Stack:
- at Codebelt.Extensions.Asp.Versioning.ServiceCollectionExtensions.<>c.<AddRestfulApiVersioning>*
- at Microsoft.AspNetCore.Http.DefaultProblemDetailsWriter.WriteAsync(ProblemDetailsContext context)
- at Microsoft.AspNetCore.Http.ProblemDetailsService.TryWriteAsync(ProblemDetailsContext context)
- at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
- at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
StatusCode: 400
ReasonPhrase: Bad Request
Evidence:
Request:
Location: http://localhost/fake/throw
Method: GET
Headers:
Accept:
- text/html
- application/xhtml+xml
- image/avif
- image/webp
- image/apng
- '*/*; q=0.8'
- application/signed-exchange; v=b3; q=0.9
- application/json; q=10.0
Host:
- localhost
Query: []
Cookies: []
Body: ''
TraceId: *
""".ReplaceLineEndings(), await sut.Content.ReadAsStringAsync(), o => o.ThrowOnNoMatch = true));
Comment on lines +190 to +228
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider improving the test assertion for better robustness

Currently, the test asserts the entire YAML output as a single string. This approach can be fragile if minor formatting changes occur, such as whitespace or line endings. Consider parsing the YAML output and asserting individual properties to make the test more robust and maintainable.

Here's an example of how you might refactor the test assertion:

- Assert.True(Match("""
-             Error:
-               Instance: http://localhost/fake/throw
-               Status: 400
-               Code: BadRequest
-               Message: The HTTP resource that matches the request URI 'http://localhost/fake/throw' does not support the API version 'b3'.
-               Failure:
-                 Type: Cuemon.AspNetCore.Http.BadRequestException
-                 Source: Codebelt.Extensions.Asp.Versioning
-                 Message: The HTTP resource that matches the request URI 'http://localhost/fake/throw' does not support the API version 'b3'.
-                 Stack:
-                   - at Codebelt.Extensions.Asp.Versioning.ServiceCollectionExtensions.<>c.<AddRestfulApiVersioning>*
-                   - at Microsoft.AspNetCore.Http.DefaultProblemDetailsWriter.WriteAsync(ProblemDetailsContext context)
-                   - at Microsoft.AspNetCore.Http.ProblemDetailsService.TryWriteAsync(ProblemDetailsContext context)
-                   - at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|7_0(Endpoint endpoint, Task requestTask, ILogger logger)
-                   - at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddlewareImpl.<Invoke>g__Awaited|10_0(ExceptionHandlerMiddlewareImpl middleware, HttpContext context, Task task)
-                 StatusCode: 400
-                 ReasonPhrase: Bad Request
-             Evidence:
-               Request:
-                 Location: http://localhost/fake/throw
-                 Method: GET
-                 Headers:
-                   Accept:
-                     - text/html
-                     - application/xhtml+xml
-                     - image/avif
-                     - image/webp
-                     - image/apng
-                     - '*/*; q=0.8'
-                     - application/signed-exchange; v=b3; q=0.9
-                     - application/json; q=10.0
-                   Host:
-                     - localhost
-                 Query: []
-                 Cookies: []
-                 Body: ''
-             TraceId: *
-             """.ReplaceLineEndings(), await sut.Content.ReadAsStringAsync(), o => o.ThrowOnNoMatch = true));
+ var yamlDeserializer = new DeserializerBuilder()
+     .WithNamingConvention(PascalCaseNamingConvention.Instance)
+     .Build();
+ var result = yamlDeserializer.Deserialize<dynamic>(await sut.Content.ReadAsStringAsync());
+ Assert.Equal("http://localhost/fake/throw", (string)result["Error"]["Instance"]);
+ Assert.Equal(400, (int)result["Error"]["Status"]);
+ Assert.Equal("BadRequest", (string)result["Error"]["Code"]);
+ Assert.Equal("The HTTP resource that matches the request URI 'http://localhost/fake/throw' does not support the API version 'b3'.", (string)result["Error"]["Message"]);
+ // Add assertions for other properties as needed

Committable suggestion was skipped due to low confidence.

}
}

Expand Down
2 changes: 1 addition & 1 deletion testenvironments.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{
"name": "Docker-Ubuntu",
"type": "docker",
"dockerImage": "gimlichael/ubuntu-testrunner:net6.0.425-net8.0.401-9.0.100-rc.1.24452.12"
"dockerImage": "gimlichael/ubuntu-testrunner:6.0.427-net8.0.403-9.0.100-rc.2.24474.11"
}
]
}
Loading