-
-
Notifications
You must be signed in to change notification settings - Fork 163
Expand file tree
/
Copy pathQueryStringTests.cs
More file actions
91 lines (79 loc) · 3.72 KB
/
QueryStringTests.cs
File metadata and controls
91 lines (79 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using System.Text.Json;
using FluentAssertions;
using TestBuildingBlocks;
using Xunit;
using Xunit.Abstractions;
namespace OpenApiTests.QueryStrings;
public sealed class QueryStringTests : IClassFixture<OpenApiTestContext<OpenApiStartup<QueryStringDbContext>, QueryStringDbContext>>
{
private readonly OpenApiTestContext<OpenApiStartup<QueryStringDbContext>, QueryStringDbContext> _testContext;
public QueryStringTests(OpenApiTestContext<OpenApiStartup<QueryStringDbContext>, QueryStringDbContext> testContext, ITestOutputHelper testOutputHelper)
{
_testContext = testContext;
testContext.UseController<NodesController>();
testContext.UseController<NameValuePairsController>();
testContext.SetTestOutputHelper(testOutputHelper);
testContext.SwaggerDocumentOutputDirectory = $"{GetType().Namespace!.Replace('.', '/')}/GeneratedSwagger";
}
[Theory]
[InlineData("/nodes.get")]
[InlineData("/nodes.head")]
[InlineData("/nodes.post")]
[InlineData("/nodes/{id}.get")]
[InlineData("/nodes/{id}.head")]
[InlineData("/nodes/{id}.patch")]
[InlineData("/nodes/{id}/parent.get")]
[InlineData("/nodes/{id}/parent.head")]
[InlineData("/nodes/{id}/relationships/parent.get")]
[InlineData("/nodes/{id}/relationships/parent.head")]
[InlineData("/nodes/{id}/children.get")]
[InlineData("/nodes/{id}/children.head")]
[InlineData("/nodes/{id}/relationships/children.get")]
[InlineData("/nodes/{id}/relationships/children.head")]
public async Task Endpoints_have_query_string_parameter(string endpointPath)
{
// Act
JsonElement document = await _testContext.GetSwaggerDocumentAsync();
// Assert
document.Should().ContainPath($"paths.{endpointPath}").With(verbElement =>
{
verbElement.Should().ContainPath("parameters").With(parametersElement =>
{
parametersElement.EnumerateArray().Should().ContainSingle(element => element.GetProperty("in").ValueEquals("query")).Subject
.With(parameterElement =>
{
parameterElement.Should().HaveProperty("name", "query");
parameterElement.Should().ContainPath("schema").With(schemaElement =>
{
schemaElement.Should().HaveProperty("type", "object");
schemaElement.Should().ContainPath("additionalProperties").With(propertiesElement =>
{
propertiesElement.Should().HaveProperty("type", "string");
propertiesElement.Should().HaveProperty("nullable", true);
});
schemaElement.Should().HaveProperty("example", string.Empty);
});
});
});
});
}
[Theory]
[InlineData("/nodes/{id}.delete")]
[InlineData("/nodes/{id}/relationships/parent.patch")]
[InlineData("/nodes/{id}/relationships/children.post")]
[InlineData("/nodes/{id}/relationships/children.patch")]
[InlineData("/nodes/{id}/relationships/children.delete")]
public async Task Endpoints_do_not_have_query_string_parameter(string endpointPath)
{
// Act
JsonElement document = await _testContext.GetSwaggerDocumentAsync();
// Assert
document.Should().ContainPath($"paths.{endpointPath}").With(verbElement =>
{
verbElement.Should().ContainPath("parameters").With(parametersElement =>
{
parametersElement.EnumerateArray().Should().NotContain(element => element.GetProperty("in").ValueEquals("query"));
});
});
}
}