Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7e07193

Browse files
committedNov 6, 2024··
Add unit tests
1 parent 98083a1 commit 7e07193

File tree

1 file changed

+51
-2
lines changed

1 file changed

+51
-2
lines changed
 

‎test/Ocelot.UnitTests/Configuration/AggregatesCreatorTests.cs

+51-2
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,58 @@ public void Create_TwoAggregateRoutes_HappyPath()
100100
AssertResultByIndex(1);
101101
}
102102

103-
private void AssertResultByIndex(int i)
103+
[Theory]
104+
[Trait("Feat", "1389")]
105+
[InlineData(nameof(HttpMethod.Get))]
106+
[InlineData(nameof(HttpMethod.Post))]
107+
public void SetUpAggregateRoute_NoUpstreamHttpMethod_DefaultVerbIsAssigned(string httpVerb)
104108
{
105-
_result[i].UpstreamHttpMethod.ShouldContain(x => x == HttpMethod.Get);
109+
// Arrange
110+
_fileConfiguration = new FileConfiguration
111+
{
112+
Aggregates = new List<FileAggregateRoute>
113+
{
114+
new()
115+
{
116+
RouteKeys = new List<string>{"key1", "key2"},
117+
},
118+
new()
119+
{
120+
RouteKeys = new List<string>{"key3", "key4"},
121+
UpstreamHttpMethod = new() { httpVerb }, // wanted verb
122+
},
123+
},
124+
};
125+
_routes = new List<Route>
126+
{
127+
new RouteBuilder().WithDownstreamRoute(new DownstreamRouteBuilder().WithKey("key1").Build()).Build(),
128+
new RouteBuilder().WithDownstreamRoute(new DownstreamRouteBuilder().WithKey("key2").Build()).Build(),
129+
new RouteBuilder().WithDownstreamRoute(new DownstreamRouteBuilder().WithKey("key3").Build()).Build(),
130+
new RouteBuilder().WithDownstreamRoute(new DownstreamRouteBuilder().WithKey("key4").Build()).Build(),
131+
};
132+
GivenTheUtpCreatorReturns();
133+
GivenTheUhtpCreatorReturns();
134+
135+
// Act
136+
_result = _creator.Create(_fileConfiguration, _routes);
137+
138+
// Assert
139+
ThenTheUtpCreatorIsCalledCorrectly();
140+
_result.ShouldNotBeNull().Count.ShouldBe(2);
141+
AssertRoute(0, FileAggregateRoute.DefaultHttpMethod); // default verb scenario
142+
AssertRoute(1, new HttpMethod(httpVerb)); // // wanted verb scenario
143+
}
144+
145+
private void AssertRoute(int i, HttpMethod expected)
146+
{
147+
_result[i].UpstreamHttpMethod.ShouldContain(x => x == expected);
148+
AssertResultByIndex(i, expected);
149+
}
150+
151+
private void AssertResultByIndex(int i, HttpMethod method = null)
152+
{
153+
method ??= FileAggregateRoute.DefaultHttpMethod;
154+
_result[i].UpstreamHttpMethod.ShouldContain(x => x == method);
106155
_result[i].UpstreamHost.ShouldBe(_fileConfiguration.Aggregates[i].UpstreamHost);
107156
_result[i].UpstreamTemplatePattern.ShouldBe(_aggregateUtp[i]);
108157
_result[i].UpstreamHeaderTemplates.ShouldBe(_headerTemplates[i]);

0 commit comments

Comments
 (0)
Please sign in to comment.