Skip to content

Commit cca7daa

Browse files
committed
Add support for Fluent Assertsion v8
1 parent 990a202 commit cca7daa

22 files changed

+192
-1722
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageVersion Include="FluentAssertions" Version="6.5.1" />
9+
<PackageVersion Include="FluentAssertions" Version="8.0.0" />
1010
<PackageVersion Include="Microsoft.AspNet.WebApi.Client" Version="6.0.0" />
1111
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
1212
<PackageVersion Include="System.Text.Json" Version="8.0.5" />

appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ image: Visual Studio 2022
33
branches:
44
only:
55
- master
6+
- master-fluent-assertions-v8
67
- /\d+\.\d+\.\d+/
78
pull_requests:
89
do_not_increment_build_number: false
@@ -70,7 +71,7 @@ artifacts:
7071
deploy:
7172
- provider: NuGet
7273
api_key:
73-
secure: aHT1IlqkfTAZm236Pkjt84NdjfEIrPJqJt4IwO5QNvH0LpIWqx/L3oFRewdCwCQs
74+
secure: vSWvi7ciU2pZZmpcXGvvR0APUpesgZBAScxNcBUttDHuWhgEAFS5fEeEiFFl5wl6
7475
skip_symbols: true
7576
artifact: /.*\.nupkg/
7677
on:

src/FluentAssertions.Web.Serializers.NewtonsoftJson/FluentAssertions.Web.Serializers.NewtonsoftJson.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4+
<PackageId>FluentAssertions.Web.v8.Serializers.NewtonsoftJson</PackageId>
45
<PackageDescription>
56
NewtonsoftJson based serializer for FluentAssertions.Web
67
</PackageDescription>

src/FluentAssertions.Web/BadRequestAssertions.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ public class BadRequestAssertions : HttpResponseMessageAssertions
1212
/// class.
1313
/// </summary>
1414
/// <param name="value">The subject value to be asserted.</param>
15-
public BadRequestAssertions(HttpResponseMessage value) : base(value)
15+
/// <param name="assertionChain">The assertion chain to build and manage assertions.</param>
16+
public BadRequestAssertions(HttpResponseMessage value, AssertionChain assertionChain) : base(value, assertionChain)
1617
{
1718
}
1819

@@ -56,7 +57,7 @@ public AndConstraint<BadRequestAssertions> HaveError(string expectedErrorField,
5657
var allFields = json.GetChildrenNames("");
5758
var fields = hasErrorsProperty ? fieldsOfErrorsProperty : allFields;
5859

59-
Execute.Assertion
60+
CurrentAssertionChain
6061
.BecauseOf(because, becauseArgs)
6162
.ForCondition(fields.Any(field => string.Equals(field, expectedErrorField, StringComparison.OrdinalIgnoreCase)))
6263
.FailWith("Expected {context:response} " +
@@ -72,7 +73,7 @@ public AndConstraint<BadRequestAssertions> HaveError(string expectedErrorField,
7273
return !scope.Discard().Any();
7374
});
7475

75-
Execute.Assertion
76+
CurrentAssertionChain
7677
.BecauseOf(because, becauseArgs)
7778
.ForCondition(matchFound)
7879
.FailWith("Expected {context:response} to contain " +
@@ -122,7 +123,7 @@ public AndConstraint<BadRequestAssertions> OnlyHaveError(string expectedErrorFie
122123
var allFields = json.GetChildrenNames("");
123124
var fields = hasErrorsProperty ? fieldsOfErrorsProperty : allFields;
124125

125-
Execute.Assertion
126+
CurrentAssertionChain
126127
.BecauseOf(because, becauseArgs)
127128
.ForCondition(fields.Any(field => string.Equals(field, expectedErrorField, StringComparison.OrdinalIgnoreCase)))
128129
.FailWith("Expected {context:response} " +
@@ -133,7 +134,7 @@ public AndConstraint<BadRequestAssertions> OnlyHaveError(string expectedErrorFie
133134
var parent = hasErrorsProperty ? ErrorsPropertyName : json.GetParentKey(expectedErrorField);
134135
var children = json.GetChildrenNames(parent);
135136

136-
Execute.Assertion
137+
CurrentAssertionChain
137138
.BecauseOf(because, becauseArgs)
138139
.ForCondition(children.Count() == 1)
139140
.FailWith("Expected {context:response} " +
@@ -149,7 +150,7 @@ public AndConstraint<BadRequestAssertions> OnlyHaveError(string expectedErrorFie
149150
return !scope.Discard().Any();
150151
});
151152

152-
Execute.Assertion
153+
CurrentAssertionChain
153154
.BecauseOf(because, becauseArgs)
154155
.ForCondition(expectedWildcardErrorMessageMatchFound)
155156
.FailWith("Expected {context:response} to contain " +
@@ -160,7 +161,7 @@ public AndConstraint<BadRequestAssertions> OnlyHaveError(string expectedErrorFie
160161
expectedErrorField,
161162
Subject);
162163

163-
Execute.Assertion
164+
CurrentAssertionChain
164165
.BecauseOf(because, becauseArgs)
165166
.ForCondition(values.Count() == 1)
166167
.FailWith("Expected {context:response} " +
@@ -202,7 +203,7 @@ public AndConstraint<BadRequestAssertions> NotHaveError(string expectedErrorFiel
202203
var allFields = json.GetChildrenNames("");
203204
var fields = hasErrorsProperty ? fieldsOfErrorsProperty : allFields;
204205

205-
Execute.Assertion
206+
CurrentAssertionChain
206207
.BecauseOf(because, becauseArgs)
207208
.ForCondition(!fields.Any(c => string.Equals(c, expectedErrorField, StringComparison.OrdinalIgnoreCase)))
208209
.FailWith("Expected {context:response} " +
@@ -247,7 +248,7 @@ public AndConstraint<BadRequestAssertions> HaveErrorMessage(string expectedWildc
247248
return !scope.Discard().Any();
248249
});
249250

250-
Execute.Assertion
251+
CurrentAssertionChain
251252
.BecauseOf(because, becauseArgs)
252253
.ForCondition(matchFound)
253254
.FailWith("Expected {context:response} to contain " +

src/FluentAssertions.Web/BadRequestAssertionsExtensions.cs

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

src/FluentAssertions.Web/FluentAssertions.Web.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<PackageDescription>
5-
This is a FluentAssertions extension over the HttpResponseMessage object. It provides assertions specific to HTTP responses and outputs rich erros messages when the tests fail, so less time with debugging is spent.
6-
</PackageDescription>
4+
<PackageId>FluentAssertions.Web.v8</PackageId>
5+
<PackageDescription>
6+
This is a FluentAssertions extension over the HttpResponseMessage object. It provides assertions specific to HTTP responses and outputs rich erros messages when the tests fail, so less time with debugging is spent.
7+
</PackageDescription>
78
</PropertyGroup>
89

910
<ItemGroup>

src/FluentAssertions.Web/HaveHeaderAssertions.cs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public class HeadersAssertions : HttpResponseMessageAssertions
1313
/// </summary>
1414
/// <param name="value">The subject value to be asserted.</param>
1515
/// <param name="header">The HTTP header name to be asserted.</param>
16-
public HeadersAssertions(HttpResponseMessage value, string header) : base(value) => _header = header;
16+
/// <param name="assertionChain">The assertion chain to build and manage assertions.</param>
17+
public HeadersAssertions(HttpResponseMessage value, string header, AssertionChain assertionChain) : base(value, assertionChain) => _header = header;
1718

1819
/// <summary>
1920
/// Asserts that an existing HTTP header in a HTTP response contains at least a value that matches a wildcard pattern.
@@ -37,7 +38,7 @@ public AndConstraint<HeadersAssertions> Match(string expectedWildcardValue, stri
3738
{
3839
Guard.ThrowIfArgumentIsNull(expectedWildcardValue, nameof(expectedWildcardValue), "Cannot verify a HTTP header to be a value against a <null> value. Use And.BeEmpty to test if the HTTP header has no values.");
3940

40-
Execute.Assertion
41+
CurrentAssertionChain
4142
.ForCondition(Subject is not null)
4243
.BecauseOf(because, becauseArgs)
4344
.FailWith("Expected a {context:response} to assert{reason}, but found <null>.");
@@ -51,7 +52,7 @@ public AndConstraint<HeadersAssertions> Match(string expectedWildcardValue, stri
5152
return !scope.Discard().Any();
5253
});
5354

54-
Execute.Assertion
55+
CurrentAssertionChain
5556
.BecauseOf(because, becauseArgs)
5657
.ForCondition(matchFound)
5758
.FailWith("Expected {context:response} to contain " +
@@ -78,7 +79,7 @@ public AndConstraint<HeadersAssertions> BeEmpty(string because = "", params obje
7879
{
7980
var headerValues = Subject.GetHeaderValues(_header);
8081

81-
Execute.Assertion
82+
CurrentAssertionChain
8283
.BecauseOf(because, becauseArgs)
8384
.ForCondition(!headerValues.Any())
8485
.FailWith("Expected {context:response} to contain " +
@@ -105,7 +106,7 @@ public AndConstraint<HeadersAssertions> NotBeEmpty(string because = "", params o
105106
{
106107
var headerValues = Subject.GetHeaderValues(_header);
107108

108-
Execute.Assertion
109+
CurrentAssertionChain
109110
.BecauseOf(because, becauseArgs)
110111
.ForCondition(headerValues.Any())
111112
.FailWith("Expected {context:response} to contain " +
@@ -151,7 +152,7 @@ public AndConstraint<HeadersAssertions> BeValues(IEnumerable<string> expectedVal
151152
failures = scope.Discard();
152153
}
153154

154-
Execute.Assertion
155+
CurrentAssertionChain
155156
.BecauseOf(because, becauseArgs)
156157
.ForCondition(failures.Length == 0)
157158
.FailWith("Expected {context:response} to contain " +
@@ -182,7 +183,7 @@ public AndConstraint<HeadersAssertions> BeValue(string expectedValue,
182183
{
183184
Guard.ThrowIfArgumentIsNullOrEmpty(expectedValue, nameof(expectedValue), "Cannot verify a HTTP header to be a value against a <null> or empty value. Use And.BeEmpty to test if the HTTP header has no value.");
184185

185-
Execute.Assertion
186+
CurrentAssertionChain
186187
.BecauseOf(because, becauseArgs)
187188
.ForCondition(Subject.GetHeaderValues(_header).Count() == 1)
188189
.FailWith($$"""
@@ -200,7 +201,7 @@ public AndConstraint<HeadersAssertions> BeValue(string expectedValue,
200201
failures = scope.Discard();
201202
}
202203

203-
Execute.Assertion
204+
CurrentAssertionChain
204205
.BecauseOf(because, becauseArgs)
205206
.ForCondition(failures.Length == 0)
206207
.FailWith($$"""
@@ -237,15 +238,15 @@ public AndConstraint<HeadersAssertions> HaveHeader(string expectedHeader,
237238
{
238239
Guard.ThrowIfArgumentIsNull(expectedHeader, nameof(expectedHeader), "Cannot verify having a header against a <null> header.");
239240

240-
Execute.Assertion
241+
CurrentAssertionChain
241242
.BecauseOf(because, becauseArgs)
242243
.ForCondition(IsHeaderPresent(expectedHeader))
243244
.FailWith("Expected {context:response} to contain " +
244245
"the HTTP header {0}, but no such header was found in the actual response{reason}.{1}",
245246
expectedHeader,
246247
Subject);
247248

248-
return new AndConstraint<HeadersAssertions>(new HeadersAssertions(Subject, expectedHeader));
249+
return new AndConstraint<HeadersAssertions>(new HeadersAssertions(Subject, expectedHeader, CurrentAssertionChain));
249250
}
250251

251252
/// <summary>
@@ -267,7 +268,7 @@ public AndConstraint<HttpResponseMessageAssertions> NotHaveHeader(string expecte
267268
{
268269
Guard.ThrowIfArgumentIsNull(expectedHeader, nameof(expectedHeader), "Cannot verify not having a header against a <null> header.");
269270

270-
Execute.Assertion
271+
CurrentAssertionChain
271272
.BecauseOf(because, becauseArgs)
272273
.ForCondition(!IsHeaderPresent(expectedHeader))
273274
.FailWith("Expected {context:response} to not to contain " +

src/FluentAssertions.Web/HaveHeaderAssertionsExtensions.cs

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

0 commit comments

Comments
 (0)