Skip to content

Commit 540b2dc

Browse files
Add test for DateOnly
Add test for #2771 for `DateOnly` values.
1 parent 455b780 commit 540b2dc

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

test/Swashbuckle.AspNetCore.IntegrationTests/SwaggerIntegrationTests.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
using System.Globalization;
33
using System.Linq;
44
using System.Net.Http;
5+
#if NET8_0_OR_GREATER
6+
using System.Net.Http.Json;
7+
#endif
58
using System.Text;
69
using System.Text.Json;
710
using System.Threading.Tasks;
@@ -118,11 +121,43 @@ public async Task SwaggerEndpoint_ReturnsValidSwaggerJson_For_WebApi(
118121
await SwaggerEndpointReturnsValidSwaggerJson<Program>(swaggerRequestUri);
119122
}
120123

124+
[Fact]
125+
public async Task TypesAreRenderedCorrectly()
126+
{
127+
using var application = new TestApplication<Program>();
128+
using var client = application.CreateDefaultClient();
129+
130+
using var swaggerResponse = await client.GetFromJsonAsync<JsonDocument>("/swagger/v1/swagger.json");
131+
132+
var weatherForecase = swaggerResponse.RootElement
133+
.GetProperty("components")
134+
.GetProperty("schemas")
135+
.GetProperty("WeatherForecast");
136+
137+
Assert.Equal("object", weatherForecase.GetProperty("type").GetString());
138+
139+
var properties = weatherForecase.GetProperty("properties");
140+
Assert.Equal(4, properties.EnumerateObject().Count());
141+
142+
Assert.Equal("string", properties.GetProperty("date").GetProperty("type").GetString());
143+
Assert.Equal("date", properties.GetProperty("date").GetProperty("format").GetString());
144+
145+
Assert.Equal("integer", properties.GetProperty("temperatureC").GetProperty("type").GetString());
146+
Assert.Equal("int32", properties.GetProperty("temperatureC").GetProperty("format").GetString());
147+
148+
Assert.Equal("string", properties.GetProperty("summary").GetProperty("type").GetString());
149+
Assert.True(properties.GetProperty("summary").GetProperty("nullable").GetBoolean());
150+
151+
Assert.Equal("integer", properties.GetProperty("temperatureF").GetProperty("type").GetString());
152+
Assert.Equal("int32", properties.GetProperty("temperatureF").GetProperty("format").GetString());
153+
Assert.True(properties.GetProperty("temperatureF").GetProperty("readOnly").GetBoolean());
154+
}
155+
121156
private async Task SwaggerEndpointReturnsValidSwaggerJson<TEntryPoint>(string swaggerRequestUri)
122157
where TEntryPoint : class
123158
{
124-
var application = new TestApplication<TEntryPoint>();
125-
var client = application.CreateDefaultClient();
159+
using var application = new TestApplication<TEntryPoint>();
160+
using var client = application.CreateDefaultClient();
126161

127162
await AssertValidSwaggerJson(client, swaggerRequestUri);
128163
}

0 commit comments

Comments
 (0)