Skip to content

Commit

Permalink
Add test for DateOnly
Browse files Browse the repository at this point in the history
Add test for domaindrivendev#2771 for `DateOnly` values.
  • Loading branch information
martincostello committed May 8, 2024
1 parent 8d66e39 commit c8596df
Showing 1 changed file with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
using System.Globalization;
using System.Linq;
using System.Net.Http;
#if NET8_0_OR_GREATER
using System.Net.Http.Json;
#endif
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
Expand Down Expand Up @@ -119,11 +122,43 @@ public async Task SwaggerEndpoint_ReturnsCorrectPriceExample_ForDifferentCulture
await SwaggerEndpointReturnsValidSwaggerJson<Program>(swaggerRequestUri);
}

[Fact]
public async Task TypesAreRenderedCorrectly()
{
using var application = new TestApplication<Program>();
using var client = application.CreateDefaultClient();

using var swaggerResponse = await client.GetFromJsonAsync<JsonDocument>("/swagger/v1/swagger.json");

var weatherForecase = swaggerResponse.RootElement
.GetProperty("components")
.GetProperty("schemas")
.GetProperty("WeatherForecast");

Assert.Equal("object", weatherForecase.GetProperty("type").GetString());

var properties = weatherForecase.GetProperty("properties");
Assert.Equal(4, properties.EnumerateObject().Count());

Assert.Equal("string", properties.GetProperty("date").GetProperty("type").GetString());
Assert.Equal("date", properties.GetProperty("date").GetProperty("format").GetString());

Assert.Equal("integer", properties.GetProperty("temperatureC").GetProperty("type").GetString());
Assert.Equal("int32", properties.GetProperty("temperatureC").GetProperty("format").GetString());

Assert.Equal("string", properties.GetProperty("summary").GetProperty("type").GetString());
Assert.True(properties.GetProperty("summary").GetProperty("nullable").GetBoolean());

Assert.Equal("integer", properties.GetProperty("temperatureF").GetProperty("type").GetString());
Assert.Equal("int32", properties.GetProperty("temperatureF").GetProperty("format").GetString());
Assert.True(properties.GetProperty("temperatureF").GetProperty("readOnly").GetBoolean());
}

private async Task SwaggerEndpointReturnsValidSwaggerJson<TEntryPoint>(string swaggerRequestUri)
where TEntryPoint : class
{
var application = new TestApplication<TEntryPoint>();
var client = application.CreateDefaultClient();
using var application = new TestApplication<TEntryPoint>();
using var client = application.CreateDefaultClient();

await AssertValidSwaggerJson(client, swaggerRequestUri);
}
Expand Down

3 comments on commit c8596df

@vierlijner
Copy link

Choose a reason for hiding this comment

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

Please also add test for TimeOnly!

@martincostello
Copy link
Owner Author

Choose a reason for hiding this comment

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

domaindrivendev#2804 added tests for TimeOnly. This test was specific to the referenced issue.

@vierlijner
Copy link

Choose a reason for hiding this comment

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

Yes, but it would be nice if it will also be added in this intergration test with the weatherforecase example. But you have to implement it, because microsoft hasn't done this.

Please sign in to comment.