Skip to content

Commit 5bfab02

Browse files
committed
Update FluentAssertions to 6.4.0
Fix the conflicts between FA 'Should' extension and FA.Web 'Should' extension Add a test to maintain the sync between FA.Web assertions and Primitives.HttpResponseMessageAssertions Closes #72
1 parent 5a39559 commit 5bfab02

12 files changed

+1451
-26
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
using FluentAssertions.Web;
2+
using System.Diagnostics;
3+
4+
// ReSharper disable once CheckNamespace
5+
namespace FluentAssertions
6+
{
7+
/// <summary>
8+
/// Contains extension methods for custom assertions in unit tests related to <see cref="BadRequestAssertions"/>.
9+
/// </summary>
10+
[DebuggerNonUserCode]
11+
public static class BadRequestAssertionsExtensions
12+
{
13+
/// <summary>
14+
/// Asserts that a Bad Request HTTP response content contains an error message identifiable by an expected field name and a wildcard error text.
15+
/// </summary>
16+
/// <remarks>
17+
/// This assertion considers the HTTP response content a JSON generated by the ASP.NET Core 3.0 framework or less
18+
/// </remarks>
19+
/// <param name="expectedErrorField">
20+
/// The expected field name.
21+
/// </param>
22+
/// <param name="expectedWildcardErrorMessage">
23+
/// The wildcard pattern with which the error field associated error message is matched, where * and ? have special meanings.
24+
/// </param>
25+
/// <param name="because">
26+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
27+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
28+
/// </param>
29+
/// <param name="becauseArgs">
30+
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
31+
/// </param>
32+
public static AndConstraint<BadRequestAssertions> HaveError(
33+
#pragma warning disable 1573
34+
this Primitives.HttpResponseMessageAssertions<Primitives.HttpResponseMessageAssertions> parent,
35+
#pragma warning restore 1573
36+
string expectedErrorField, string expectedWildcardErrorMessage,
37+
string because = "", params object[] becauseArgs)
38+
=> new BadRequestAssertions(parent.Subject).HaveError(expectedErrorField, expectedWildcardErrorMessage, because, becauseArgs);
39+
40+
/// <summary>
41+
/// Asserts that a Bad Request HTTP response content contains only a single error message identifiable by an expected field name and a wildcard error text.
42+
/// </summary>
43+
/// <remarks>
44+
/// This assertion considers the HTTP response content a JSON generated by the ASP.NET Core 3.0 framework or less
45+
/// </remarks>
46+
/// <param name="expectedErrorField">
47+
/// The expected field name.
48+
/// </param>
49+
/// <param name="expectedWildcardErrorMessage">
50+
/// The wildcard pattern with which the error field associated error message is matched, where * and ? have special meanings.
51+
/// </param>
52+
/// <param name="because">
53+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
54+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
55+
/// </param>
56+
/// <param name="becauseArgs">
57+
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
58+
/// </param>
59+
public static AndConstraint<BadRequestAssertions> OnlyHaveError(
60+
#pragma warning disable 1573
61+
this Primitives.HttpResponseMessageAssertions<Primitives.HttpResponseMessageAssertions> parent,
62+
#pragma warning restore 1573
63+
string expectedErrorField, string expectedWildcardErrorMessage,
64+
string because = "", params object[] becauseArgs)
65+
=> new BadRequestAssertions(parent.Subject).OnlyHaveError(expectedErrorField, expectedWildcardErrorMessage, because, becauseArgs);
66+
67+
/// <summary>
68+
/// Asserts that a Bad Request HTTP response content does not contain an error message identifiable by an expected field name.
69+
/// </summary>
70+
/// <remarks>
71+
/// This assertion considers the HTTP response content a JSON generated by the ASP.NET Core 3.0 framework or less
72+
/// </remarks>
73+
/// <param name="expectedErrorField">
74+
/// The expected field name.
75+
/// </param>
76+
/// <param name="because">
77+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
78+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
79+
/// </param>
80+
/// <param name="becauseArgs">
81+
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
82+
/// </param>
83+
public static AndConstraint<BadRequestAssertions> NotHaveError(
84+
#pragma warning disable 1573
85+
this Primitives.HttpResponseMessageAssertions<Primitives.HttpResponseMessageAssertions> parent,
86+
#pragma warning restore 1573
87+
string expectedErrorField, string because = "", params object[] becauseArgs)
88+
=> new BadRequestAssertions(parent.Subject).NotHaveError(expectedErrorField, because, becauseArgs);
89+
90+
/// <summary>
91+
/// Asserts that a Bad Request HTTP response content contains an error message identifiable by an wildcard error text.
92+
/// </summary>
93+
/// <param name="expectedWildcardErrorMessage">
94+
/// The wildcard pattern with which the error field associated error message is matched, where * and ? have special meanings.
95+
/// </param>
96+
/// <param name="because">
97+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
98+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
99+
/// </param>
100+
/// <param name="becauseArgs">
101+
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
102+
/// </param>
103+
public static AndConstraint<BadRequestAssertions> HaveErrorMessage(
104+
#pragma warning disable 1573
105+
this Primitives.HttpResponseMessageAssertions<Primitives.HttpResponseMessageAssertions> parent,
106+
#pragma warning restore 1573
107+
string expectedWildcardErrorMessage,
108+
string because = "", params object[] becauseArgs)
109+
=> new BadRequestAssertions(parent.Subject).HaveErrorMessage(expectedWildcardErrorMessage, because, becauseArgs);
110+
}
111+
}

src/FluentAssertions.Web/FluentAssertions.Web.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</PropertyGroup>
2424

2525
<ItemGroup>
26-
<PackageReference Include="FluentAssertions" Version="6.1.0" />
26+
<PackageReference Include="FluentAssertions" Version="6.4.0" />
2727
<PackageReference Include="System.Text.Json" Version="5.0.1" />
2828
</ItemGroup>
2929
</Project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using FluentAssertions.Web;
2+
using System.Diagnostics;
3+
4+
namespace FluentAssertions
5+
{
6+
/// <summary>
7+
/// Contains extension methods for custom assertions in unit tests related to <see cref="HeadersAssertions"/>.
8+
/// </summary>
9+
[DebuggerNonUserCode]
10+
public static class HeadersAssertionsExtensions
11+
{
12+
/// <summary>
13+
/// Asserts that an HTTP response has a named header.
14+
/// </summary>
15+
/// <param name="expectedHeader">
16+
/// The expected header with which the HTTP headers list is matched.
17+
/// </param>
18+
/// <param name="because">
19+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
20+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
21+
/// </param>
22+
/// <param name="becauseArgs">
23+
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
24+
/// </param>
25+
public static AndConstraint<HeadersAssertions> HaveHeader(
26+
#pragma warning disable 1573
27+
this Primitives.HttpResponseMessageAssertions<Primitives.HttpResponseMessageAssertions> parent,
28+
#pragma warning restore 1573
29+
string expectedHeader,
30+
string because = "", params object[] becauseArgs)
31+
=> new HttpResponseMessageAssertions(parent.Subject).HaveHeader(expectedHeader, because, becauseArgs);
32+
33+
/// <summary>
34+
/// Asserts that an HTTP response does not have a named header.
35+
/// </summary>
36+
/// <param name="expectedHeader">
37+
/// The expected header with which the HTTP headers list is matched.
38+
/// </param>
39+
/// <param name="because">
40+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
41+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
42+
/// </param>
43+
/// <param name="becauseArgs">
44+
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
45+
/// </param>
46+
public static AndConstraint<HttpResponseMessageAssertions> NotHaveHeader(
47+
#pragma warning disable 1573
48+
this Primitives.HttpResponseMessageAssertions<Primitives.HttpResponseMessageAssertions> parent,
49+
#pragma warning restore 1573
50+
string expectedHeader,
51+
string because = "", params object[] becauseArgs)
52+
=> new HttpResponseMessageAssertions(parent.Subject).NotHaveHeader(expectedHeader, because, becauseArgs);
53+
}
54+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using FluentAssertions.Web;
2+
using System.Diagnostics;
3+
4+
namespace FluentAssertions
5+
{
6+
/// <summary>
7+
/// Contains extension methods for custom assertions in unit tests related to Http Response Content Assertions
8+
/// </summary>
9+
[DebuggerNonUserCode]
10+
public static class HttpResponseContentAssertionsExtensions
11+
{
12+
/// <summary>
13+
/// Asserts that HTTP response content can be an equivalent representation of the expected model.
14+
/// </summary>
15+
/// <param name="expectedModel">
16+
/// The expected model.
17+
/// </param>
18+
/// <param name="because">
19+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
20+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
21+
/// </param>
22+
/// <param name="becauseArgs">
23+
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
24+
/// </param>
25+
public static AndConstraint<HttpResponseMessageAssertions> BeAs<TModel>(
26+
#pragma warning disable 1573
27+
this Primitives.HttpResponseMessageAssertions<Primitives.HttpResponseMessageAssertions> parent,
28+
#pragma warning restore 1573
29+
TModel expectedModel, string because = "", params object[] becauseArgs)
30+
=> new HttpResponseMessageAssertions(parent.Subject).BeAs(expectedModel, because, becauseArgs);
31+
32+
/// <summary>
33+
/// Asserts that HTTP response has content that matches a wildcard pattern.
34+
/// </summary>
35+
/// <param name="expectedWildcardText">
36+
/// The wildcard pattern with which the subject is matched, where * and ? have special meanings.
37+
/// </param>
38+
/// <param name="because">
39+
/// A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
40+
/// is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
41+
/// </param>
42+
/// <param name="becauseArgs">
43+
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
44+
/// </param>
45+
public static AndConstraint<HttpResponseMessageAssertions> MatchInContent(
46+
#pragma warning disable 1573
47+
this Primitives.HttpResponseMessageAssertions<Primitives.HttpResponseMessageAssertions> parent,
48+
#pragma warning restore 1573,
49+
string expectedWildcardText, string because = "", params object[] becauseArgs)
50+
=> new HttpResponseMessageAssertions(parent.Subject).MatchInContent(expectedWildcardText, because, becauseArgs);
51+
}
52+
}

src/FluentAssertions.Web/HttpResponseMessageFluentAssertionsExtensions.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/FluentAssertions.Web/HttpStatusCodeAssertions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public partial class HttpResponseMessageAssertions
1717
/// <param name="becauseArgs">
1818
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
1919
/// </param>
20+
// ReSharper disable once InconsistentNaming
2021
public AndConstraint<HttpResponseMessageAssertions> Be1XXInformational(string because = "", params object[] becauseArgs)
2122
{
2223
ExecuteSubjectNotNull(because, becauseArgs);
@@ -43,6 +44,7 @@ public AndConstraint<HttpResponseMessageAssertions> Be1XXInformational(string be
4344
/// <param name="becauseArgs">
4445
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
4546
/// </param>
47+
// ReSharper disable once InconsistentNaming
4648
public AndConstraint<HttpResponseMessageAssertions> Be2XXSuccessful(string because = "", params object[] becauseArgs)
4749
{
4850
ExecuteSubjectNotNull(because, becauseArgs);
@@ -69,6 +71,7 @@ public AndConstraint<HttpResponseMessageAssertions> Be2XXSuccessful(string becau
6971
/// <param name="becauseArgs">
7072
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
7173
/// </param>
74+
// ReSharper disable once InconsistentNaming
7275
public AndConstraint<HttpResponseMessageAssertions> Be3XXRedirection(string because = "", params object[] becauseArgs)
7376
{
7477
ExecuteSubjectNotNull(because, becauseArgs);
@@ -95,6 +98,7 @@ public AndConstraint<HttpResponseMessageAssertions> Be3XXRedirection(string beca
9598
/// <param name="becauseArgs">
9699
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
97100
/// </param>
101+
// ReSharper disable once InconsistentNaming
98102
public AndConstraint<HttpResponseMessageAssertions> Be4XXClientError(string because = "", params object[] becauseArgs)
99103
{
100104
ExecuteSubjectNotNull(because, becauseArgs);
@@ -121,6 +125,7 @@ public AndConstraint<HttpResponseMessageAssertions> Be4XXClientError(string beca
121125
/// <param name="becauseArgs">
122126
/// Zero or more objects to format using the placeholders in <see paramref="because" />.
123127
/// </param>
128+
// ReSharper disable once InconsistentNaming
124129
public AndConstraint<HttpResponseMessageAssertions> Be5XXServerError(string because = "", params object[] becauseArgs)
125130
{
126131
ExecuteSubjectNotNull(because, becauseArgs);

0 commit comments

Comments
 (0)