Skip to content

Commit 08117e8

Browse files
authored
Add AtPath and AtAbsolutePath to Assertions projects (#1349)
* Add AtPath and AtAbsolutePath to Assertions projects * tst
1 parent ddb181c commit 08117e8

13 files changed

+278
-12
lines changed

src/WireMock.Net.AwesomeAssertions/Assertions/WireMockANumberOfCallsAssertions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
using WireMock.Server;
55

66
// ReSharper disable once CheckNamespace
7-
namespace WireMock.FluentAssertions;
7+
namespace WireMock.AwesomeAssertions;
88

99
/// <summary>
1010
/// Provides assertion methods to verify the number of calls made to a WireMock server.
11-
/// This class is used in the context of FluentAssertions.
11+
/// This class is used in the context of AwesomeAssertions.
1212
/// </summary>
1313
public class WireMockANumberOfCallsAssertions
1414
{
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright © WireMock.Net
2+
3+
using WireMock.Extensions;
4+
using WireMock.Matchers;
5+
6+
// ReSharper disable once CheckNamespace
7+
namespace WireMock.AwesomeAssertions;
8+
9+
#pragma warning disable CS1591
10+
public partial class WireMockAssertions
11+
{
12+
[CustomAssertion]
13+
public AndWhichConstraint<WireMockAssertions, string> AtAbsolutePath(string absolutePath, string because = "", params object[] becauseArgs)
14+
{
15+
_ = AtAbsolutePath(new ExactMatcher(true, absolutePath), because, becauseArgs);
16+
17+
return new AndWhichConstraint<WireMockAssertions, string>(this, absolutePath);
18+
}
19+
20+
[CustomAssertion]
21+
public AndWhichConstraint<WireMockAssertions, IStringMatcher> AtAbsolutePath(IStringMatcher absolutePathMatcher, string because = "", params object[] becauseArgs)
22+
{
23+
var (filter, condition) = BuildFilterAndCondition(request => absolutePathMatcher.IsPerfectMatch(request.AbsolutePath));
24+
25+
var absolutePath = absolutePathMatcher.GetPatterns().FirstOrDefault().GetPattern();
26+
27+
_chain
28+
.BecauseOf(because, becauseArgs)
29+
.Given(() => RequestMessages)
30+
.ForCondition(requests => CallsCount == 0 || requests.Any())
31+
.FailWith(
32+
"Expected {context:wiremockserver} to have been called at address matching the absolute path {0}{reason}, but no calls were made.",
33+
absolutePath
34+
)
35+
.Then
36+
.ForCondition(condition)
37+
.FailWith(
38+
"Expected {context:wiremockserver} to have been called at address matching the absolute path {0}{reason}, but didn't find it among the calls to {1}.",
39+
_ => absolutePath,
40+
requests => requests.Select(request => request.AbsolutePath)
41+
);
42+
43+
FilterRequestMessages(filter);
44+
45+
return new AndWhichConstraint<WireMockAssertions, IStringMatcher>(this, absolutePathMatcher);
46+
}
47+
48+
[CustomAssertion]
49+
public AndWhichConstraint<WireMockAssertions, string> AtPath(string path, string because = "", params object[] becauseArgs)
50+
{
51+
_ = AtPath(new ExactMatcher(true, path), because, becauseArgs);
52+
53+
return new AndWhichConstraint<WireMockAssertions, string>(this, path);
54+
}
55+
56+
[CustomAssertion]
57+
public AndWhichConstraint<WireMockAssertions, IStringMatcher> AtPath(IStringMatcher pathMatcher, string because = "", params object[] becauseArgs)
58+
{
59+
var (filter, condition) = BuildFilterAndCondition(request => pathMatcher.IsPerfectMatch(request.Path));
60+
61+
var path = pathMatcher.GetPatterns().FirstOrDefault().GetPattern();
62+
63+
_chain
64+
.BecauseOf(because, becauseArgs)
65+
.Given(() => RequestMessages)
66+
.ForCondition(requests => CallsCount == 0 || requests.Any())
67+
.FailWith(
68+
"Expected {context:wiremockserver} to have been called at address matching the path {0}{reason}, but no calls were made.",
69+
path
70+
)
71+
.Then
72+
.ForCondition(condition)
73+
.FailWith(
74+
"Expected {context:wiremockserver} to have been called at address matching the path {0}{reason}, but didn't find it among the calls to {1}.",
75+
_ => path,
76+
requests => requests.Select(request => request.Path)
77+
);
78+
79+
FilterRequestMessages(filter);
80+
81+
return new AndWhichConstraint<WireMockAssertions, IStringMatcher>(this, pathMatcher);
82+
}
83+
}

src/WireMock.Net.AwesomeAssertions/Assertions/WireMockAssertions.AtUrl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using WireMock.Matchers;
55

66
// ReSharper disable once CheckNamespace
7-
namespace WireMock.FluentAssertions;
7+
namespace WireMock.AwesomeAssertions;
88

99
#pragma warning disable CS1591
1010
public partial class WireMockAssertions

src/WireMock.Net.AwesomeAssertions/Assertions/WireMockAssertions.FromClientIP.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System;
55

66
// ReSharper disable once CheckNamespace
7-
namespace WireMock.FluentAssertions;
7+
namespace WireMock.AwesomeAssertions;
88

99
public partial class WireMockAssertions
1010
{

src/WireMock.Net.AwesomeAssertions/Assertions/WireMockAssertions.UsingMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using WireMock.Constants;
66

77
// ReSharper disable once CheckNamespace
8-
namespace WireMock.FluentAssertions;
8+
namespace WireMock.AwesomeAssertions;
99

1010
public partial class WireMockAssertions
1111
{

src/WireMock.Net.AwesomeAssertions/Assertions/WireMockAssertions.WithBody.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using WireMock.Models;
1212

1313
// ReSharper disable once CheckNamespace
14-
namespace WireMock.FluentAssertions;
14+
namespace WireMock.AwesomeAssertions;
1515

1616
public partial class WireMockAssertions
1717
{

src/WireMock.Net.AwesomeAssertions/Assertions/WireMockAssertions.WithHeader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#pragma warning disable CS1591
44

55
// ReSharper disable once CheckNamespace
6-
namespace WireMock.FluentAssertions;
6+
namespace WireMock.AwesomeAssertions;
77

88
public partial class WireMockAssertions
99
{

src/WireMock.Net.AwesomeAssertions/Assertions/WireMockAssertions.WithProxy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using System;
55

66
// ReSharper disable once CheckNamespace
7-
namespace WireMock.FluentAssertions;
7+
namespace WireMock.AwesomeAssertions;
88

99
public partial class WireMockAssertions
1010
{

src/WireMock.Net.AwesomeAssertions/Assertions/WireMockAssertions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using WireMock.Server;
88

99
// ReSharper disable once CheckNamespace
10-
namespace WireMock.FluentAssertions;
10+
namespace WireMock.AwesomeAssertions;
1111

1212
public partial class WireMockAssertions
1313
{

src/WireMock.Net.AwesomeAssertions/Assertions/WireMockReceivedAssertions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using WireMock.Server;
55

66
// ReSharper disable once CheckNamespace
7-
namespace WireMock.FluentAssertions;
7+
namespace WireMock.AwesomeAssertions;
88

99
/// <summary>
1010
/// Contains a number of methods to assert that the <see cref="IWireMockServer"/> is in the expected state.

0 commit comments

Comments
 (0)