Skip to content

Commit 24df130

Browse files
committed
add Rule.WhenPost
1 parent c3c5445 commit 24df130

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/TestServer/Rule.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ public Rule WhenGet()
4949
return this;
5050
}
5151

52+
/// <summary>
53+
/// Add a rule that the HttpRequest.Method is POST
54+
/// </summary>
55+
public Rule WhenPost()
56+
{
57+
Predictions.Add((request) =>
58+
{
59+
return request.Method == "POST";
60+
});
61+
return this;
62+
}
63+
5264
/// <summary>
5365
/// Add a rule that the request url matches a regex expression
5466
/// </summary>

test/TestServer.Tests/TestServerTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,23 @@ public async Task WhenPredictGet_GetAsync_ShouldSucceed()
8383
AssertOkResponse(actual);
8484
}
8585

86+
[Test]
87+
public async Task WhenPredictPost_PostAsync_ShouldSucceed()
88+
{
89+
// Arrange
90+
_server.CurrentRuleSet
91+
.AddRule()
92+
.WhenPost()
93+
.SetOkResponse(_okResponse);
94+
var client = _server.CreateClient();
95+
96+
// Act
97+
var actual = await client.PostAsync("/", new StringContent("dummy"));
98+
99+
// Assert
100+
AssertOkResponse(actual);
101+
}
102+
86103
[Test]
87104
public async Task WhenPredictGet_PostAsync_ShouldFail()
88105
{

0 commit comments

Comments
 (0)