Skip to content

Commit 881987d

Browse files
authored
(#346) Swapped FluentAssertions for AwesomeAssertions (#357)
1 parent 429db6d commit 881987d

File tree

14 files changed

+91
-160
lines changed

14 files changed

+91
-160
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
</PropertyGroup>
66
<ItemGroup>
77
<PackageVersion Include="AutoMapper" Version="13.0.1" />
8+
<PackageVersion Include="AwesomeAssertions" Version="8.2.0" />
89
<PackageVersion Include="Azure.Identity" Version="1.13.1" />
9-
<PackageVersion Include="FluentAssertions" Version="7.1.0" />
1010
<PackageVersion Include="FluentAssertions.Web" Version="1.8.0" />
1111
<PackageVersion Include="LiteDB" Version="5.0.21" />
1212
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.4" />

tests/CommunityToolkit.Datasync.Client.Test/Authentication/GenericAuthenticationProvider_Tests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public async Task SendAsync_AddsHeader_BearerAuth()
289289
response.Should().NotBeNull();
290290

291291
handler.Requests.Should().ContainSingle();
292-
handler.Requests[0].Should().HaveHeader("Authorization", $"Bearer {ValidAuthenticationToken.Token}");
292+
handler.Requests[0].Headers.Should().ContainSingle(x => x.Key == "Authorization" && x.Value.First() == $"Bearer {ValidAuthenticationToken.Token}");
293293
}
294294

295295
[Fact]
@@ -308,7 +308,7 @@ public async Task SendAsync_NoHeader_WhenExpired()
308308
response.Should().NotBeNull();
309309

310310
handler.Requests.Should().ContainSingle();
311-
handler.Requests[0].Should().NotHaveHeader("Authorization");
311+
handler.Requests[0].Headers.Should().NotContain(x => x.Key == "Authorization");
312312
}
313313

314314
[Fact]
@@ -328,7 +328,7 @@ public async Task SendAsync_RemoveHeader_WhenExpired()
328328
response.Should().NotBeNull();
329329

330330
handler.Requests.Should().ContainSingle();
331-
handler.Requests[0].Should().NotHaveHeader("Authorization");
331+
handler.Requests[0].Headers.Should().NotContain(x => x.Key == "Authorization");
332332
}
333333

334334
[Fact]
@@ -348,7 +348,7 @@ public async Task SendAsync_OverwritesHeader_WhenNotExpired()
348348
response.Should().NotBeNull();
349349

350350
handler.Requests.Should().ContainSingle();
351-
handler.Requests[0].Should().HaveHeader("Authorization", $"Bearer {ValidAuthenticationToken.Token}");
351+
handler.Requests[0].Headers.Should().ContainSingle(x => x.Key == "Authorization" && x.Value.First() == $"Bearer {ValidAuthenticationToken.Token}");
352352
}
353353

354354
/// <summary>

tests/CommunityToolkit.Datasync.Client.Test/Live/SampleServerTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public async Task Metadata_GetsSetByServer()
2424
TodoItem source = new() { Title = "Test item" };
2525
HttpResponseMessage response = await client.PostAsJsonAsync($"{this.serviceEndpoint}/tables/TodoItem", source);
2626

27-
response.Should().HaveHttpStatusCode(HttpStatusCode.Created);
27+
response.StatusCode.Should().Be(HttpStatusCode.Created);
2828

2929
TodoItem result = await response.Content.ReadFromJsonAsync<TodoItem>();
3030
result.Id.Should().NotBeNullOrEmpty();

tests/CommunityToolkit.Datasync.Client.Test/Offline/Operations/DeleteOperation_Tests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public async Task DeleteOperation_ExecuteAsync()
2121
{
2222
MockDelegatingHandler handler = new();
2323
HttpClient client = new(handler) { BaseAddress = new Uri("https://test.zumo.net") };
24-
string itemJson = """{"id":"123"}""";
24+
const string itemJson = """{"id":"123"}""";
2525
DatasyncOperation op = new()
2626
{
2727
Id = Guid.NewGuid().ToString(),
@@ -52,7 +52,7 @@ public async Task DeleteOperation_ExecuteAsync()
5252
request.Should().NotBeNull();
5353
request.Method.Should().Be(HttpMethod.Delete);
5454
request.RequestUri.ToString().Should().Be("https://test.zumo.net/tables/movies/123");
55-
request.Should().NotHaveHeader("If-Match");
55+
request.Headers.Should().NotContain(x => x.Key == "If-Match");
5656

5757
response.Should().NotBeNull();
5858
response.HasContent.Should().BeFalse();
@@ -67,7 +67,7 @@ public async Task DeleteOperation_ExecuteAsync_WithVersion()
6767
{
6868
MockDelegatingHandler handler = new();
6969
HttpClient client = new(handler) { BaseAddress = new Uri("https://test.zumo.net") };
70-
string itemJson = """{"id":"123"}""";
70+
const string itemJson = """{"id":"123"}""";
7171
DatasyncOperation op = new()
7272
{
7373
Id = Guid.NewGuid().ToString(),
@@ -98,7 +98,7 @@ public async Task DeleteOperation_ExecuteAsync_WithVersion()
9898
request.Should().NotBeNull();
9999
request.Method.Should().Be(HttpMethod.Delete);
100100
request.RequestUri.ToString().Should().Be("https://test.zumo.net/tables/movies/123");
101-
request.Should().HaveHeader("If-Match", "\"abcdefg\"");
101+
request.Headers.Should().Contain(x => x.Key == "If-Match" && x.Value.First() == "\"abcdefg\"");
102102

103103
response.Should().NotBeNull();
104104
response.HasContent.Should().BeFalse();

tests/CommunityToolkit.Datasync.Client.Test/Offline/Operations/ReplaceOperation_Tests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@ namespace CommunityToolkit.Datasync.Client.Test.Offline.Operations;
1717
[ExcludeFromCodeCoverage]
1818
public class ReplaceOperation_Tests
1919
{
20-
2120
[Fact]
2221
public async Task ReplaceOperation_ExecuteAsync()
2322
{
2423
MockDelegatingHandler handler = new();
2524
HttpClient client = new(handler) { BaseAddress = new Uri("https://test.zumo.net") };
26-
string itemJson = """{"id":"123"}""";
25+
const string itemJson = """{"id":"123"}""";
2726
DatasyncOperation op = new()
2827
{
2928
Id = Guid.NewGuid().ToString(),
@@ -55,7 +54,7 @@ public async Task ReplaceOperation_ExecuteAsync()
5554
request.Should().NotBeNull();
5655
request.Method.Should().Be(HttpMethod.Put);
5756
request.RequestUri.ToString().Should().Be("https://test.zumo.net/tables/movies/123");
58-
request.Should().NotHaveHeader("If-Match");
57+
request.Headers.Should().NotContain(x => x.Key == "If-Match");
5958
(await request.Content.ReadAsStringAsync()).Should().Be(itemJson);
6059

6160
response.Should().NotBeNull();
@@ -73,7 +72,7 @@ public async Task ReplaceOperation_ExecuteAsync_WithVersion()
7372
{
7473
MockDelegatingHandler handler = new();
7574
HttpClient client = new(handler) { BaseAddress = new Uri("https://test.zumo.net") };
76-
string itemJson = """{"id":"123"}""";
75+
const string itemJson = """{"id":"123"}""";
7776
DatasyncOperation op = new()
7877
{
7978
Id = Guid.NewGuid().ToString(),
@@ -105,7 +104,7 @@ public async Task ReplaceOperation_ExecuteAsync_WithVersion()
105104
request.Should().NotBeNull();
106105
request.Method.Should().Be(HttpMethod.Put);
107106
request.RequestUri.ToString().Should().Be("https://test.zumo.net/tables/movies/123");
108-
request.Should().HaveHeader("If-Match", "\"abcdefg\"");
107+
request.Headers.Should().Contain(x => x.Key == "If-Match" && x.Value.First() == "\"abcdefg\"");
109108
(await request.Content.ReadAsStringAsync()).Should().Be(itemJson);
110109

111110
response.Should().NotBeNull();

tests/CommunityToolkit.Datasync.Client.Test/Service/DatasyncServiceClient_Tests.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal class NamedSelectClass
5656
/// <summary>
5757
/// A test evaluator that ensures DateTimeOffset, DateTime, and TimeOnly values are msec resolution.
5858
/// </summary>
59-
private readonly Func<EquivalencyAssertionOptions<ClientKitchenSink>, EquivalencyAssertionOptions<ClientKitchenSink>> entityEquivalentOptions = (options) =>
59+
private readonly Func<EquivalencyOptions<ClientKitchenSink>, EquivalencyOptions<ClientKitchenSink>> entityEquivalentOptions = (options) =>
6060
{
6161
options.Using<DateTimeOffset>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, 1.Milliseconds())).WhenTypeIs<DateTimeOffset>();
6262
options.Using<DateTime>(ctx => ctx.Subject.Should().BeCloseTo(ctx.Expectation, 1.Milliseconds())).WhenTypeIs<DateTime>();
@@ -267,7 +267,7 @@ public async Task AddAsync_Conflict(HttpStatusCode code)
267267
{
268268
this.mockHandler.Responses.Add(GetSuccessfulResponse(this.successfulKitchenSink, code));
269269
ClientKitchenSink entity = new() { Id = "1", StringValue = "abc" };
270-
string expected = """{"stringValue":"abc","id":"1"}""";
270+
const string expected = """{"stringValue":"abc","id":"1"}""";
271271
DatasyncServiceClient<ClientKitchenSink> client = GetMockClient<ClientKitchenSink>();
272272

273273
Func<Task> act = async () => _ = await client.AddAsync(entity, new DatasyncServiceOptions());
@@ -1204,7 +1204,7 @@ public async Task Query_OnePageOfItems()
12041204
[Fact]
12051205
public async Task Query_TwoPagesOfItems()
12061206
{
1207-
Page<ClientKitchenSink>
1207+
Page<ClientKitchenSink>
12081208
page1 = CreatePage(5, null, "$skip=5"),
12091209
page2 = CreatePage(5);
12101210

@@ -1436,7 +1436,7 @@ public async Task RemoveAsync_SetsVersion()
14361436
request.Should().NotBeNull();
14371437
request.Method.Should().Be(HttpMethod.Delete);
14381438
request.RequestUri.ToString().Should().Be($"http://localhost/tables/kitchensink/{id}");
1439-
request.Should().HaveHeader("If-Match", "\"abcdefg1234\"");
1439+
request.Headers.Should().Contain(x => x.Key == "If-Match" && x.Value.First() == "\"abcdefg1234\"");
14401440

14411441
response.Should().NotBeNull();
14421442
response.HasContent.Should().BeFalse();
@@ -1458,7 +1458,7 @@ public async Task RemoveAsync_Extn_Unforced_SetsVersion()
14581458
request.Should().NotBeNull();
14591459
request.Method.Should().Be(HttpMethod.Delete);
14601460
request.RequestUri.ToString().Should().Be($"http://localhost/tables/kitchensink/{entity.Id}");
1461-
request.Should().HaveHeader("If-Match", "\"abcdefg1234\"");
1461+
request.Headers.Should().Contain(x => x.Key == "If-Match" && x.Value.First() == "\"abcdefg1234\"");
14621462

14631463
response.Should().NotBeNull();
14641464
response.HasContent.Should().BeFalse();
@@ -1480,7 +1480,7 @@ public async Task RemoveAsync_Extn2_SetsVersion()
14801480
request.Should().NotBeNull();
14811481
request.Method.Should().Be(HttpMethod.Delete);
14821482
request.RequestUri.ToString().Should().Be($"http://localhost/tables/kitchensink/{entity.Id}");
1483-
request.Should().HaveHeader("If-Match", "\"abcdefg1234\"");
1483+
request.Headers.Should().Contain(x => x.Key == "If-Match" && x.Value.First() == "\"abcdefg1234\"");
14841484

14851485
response.Should().NotBeNull();
14861486
response.HasContent.Should().BeFalse();
@@ -1502,7 +1502,7 @@ public async Task RemoveAsync_Extn_Forced_SetsVersion()
15021502
request.Should().NotBeNull();
15031503
request.Method.Should().Be(HttpMethod.Delete);
15041504
request.RequestUri.ToString().Should().Be($"http://localhost/tables/kitchensink/{entity.Id}");
1505-
request.Should().NotHaveHeader("If-Match");
1505+
request.Headers.Should().NotContain(x => x.Key == "If-Match");
15061506

15071507
response.Should().NotBeNull();
15081508
response.HasContent.Should().BeFalse();
@@ -1745,7 +1745,7 @@ public async Task ReplaceAsync_SetsVersion()
17451745
request.Should().NotBeNull();
17461746
request.Method.Should().Be(HttpMethod.Put);
17471747
request.RequestUri.ToString().Should().Be($"http://localhost/tables/kitchensink/{entity.Id}");
1748-
request.Should().HaveHeader("If-Match", "\"abcdefg1234\"");
1748+
request.Headers.Should().Contain(x => x.Key == "If-Match" && x.Value.First() == "\"abcdefg1234\"");
17491749
(await request.Content.ReadAsStringAsync()).Should().Be(expected);
17501750

17511751
response.Should().NotBeNull();
@@ -1771,7 +1771,7 @@ public async Task ReplaceAsync_Extn_Forced_SetsVersion()
17711771
request.Should().NotBeNull();
17721772
request.Method.Should().Be(HttpMethod.Put);
17731773
request.RequestUri.ToString().Should().Be($"http://localhost/tables/kitchensink/{entity.Id}");
1774-
request.Should().NotHaveHeader("If-Match");
1774+
request.Headers.Should().NotContain(x => x.Key == "If-Match");
17751775
(await request.Content.ReadAsStringAsync()).Should().Be(expected);
17761776

17771777
response.Should().NotBeNull();
@@ -1797,7 +1797,7 @@ public async Task ReplaceAsync_Extn_Unforced_SetsVersion()
17971797
request.Should().NotBeNull();
17981798
request.Method.Should().Be(HttpMethod.Put);
17991799
request.RequestUri.ToString().Should().Be($"http://localhost/tables/kitchensink/{entity.Id}");
1800-
request.Should().HaveHeader("If-Match", "\"abcdefg1234\"");
1800+
request.Headers.Should().Contain(x => x.Key == "If-Match" && x.Value.First() == "\"abcdefg1234\"");
18011801
(await request.Content.ReadAsStringAsync()).Should().Be(expected);
18021802

18031803
response.Should().NotBeNull();
@@ -1823,7 +1823,7 @@ public async Task ReplaceAsync_Extn_Default_SetsVersion()
18231823
request.Should().NotBeNull();
18241824
request.Method.Should().Be(HttpMethod.Put);
18251825
request.RequestUri.ToString().Should().Be($"http://localhost/tables/kitchensink/{entity.Id}");
1826-
request.Should().HaveHeader("If-Match", "\"abcdefg1234\"");
1826+
request.Headers.Should().Contain(x => x.Key == "If-Match" && x.Value.First() == "\"abcdefg1234\"");
18271827
(await request.Content.ReadAsStringAsync()).Should().Be(expected);
18281828

18291829
response.Should().NotBeNull();
@@ -3561,10 +3561,12 @@ public void Linq_Where_String_Contains()
35613561
[Fact]
35623562
public void Linq_Where_EndsWith_ToUpper()
35633563
{
3564+
#pragma warning disable RCS1155 // Use StringComparison when comparing strings
35643565
ExecuteQueryTest(
35653566
x => x.Where(m => m.StringValue.ToUpperInvariant() == "ER"),
35663567
"$filter=(toupper(stringValue) eq 'ER')"
35673568
);
3569+
#pragma warning restore RCS1155 // Use StringComparison when comparing strings
35683570
}
35693571

35703572
[Fact]

tests/CommunityToolkit.Datasync.Server.Test/Service/Create_Tests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task Create_WithValidInput_Returns201(string id)
2525
ClientMovie source = new(TestData.Movies.BlackPanther) { Id = id };
2626

2727
HttpResponseMessage response = await this.client.PostAsJsonAsync(this.factory.MovieEndpoint, source, this.serializerOptions);
28-
response.Should().HaveStatusCode(HttpStatusCode.Created);
28+
response.StatusCode.Should().Be(HttpStatusCode.Created);
2929

3030
ClientMovie clientMovie = await response.Content.ReadFromJsonAsync<ClientMovie>(this.serializerOptions);
3131
clientMovie.Should().NotBeNull().And.HaveChangedMetadata(id, this.StartTime).And.BeEquivalentTo<IMovie>(source);
@@ -44,7 +44,7 @@ public async Task Create_ExistingId_Returns409()
4444
ClientMovie source = new(TestData.Movies.BlackPanther) { Id = existingMovie.Id };
4545

4646
HttpResponseMessage response = await this.client.PostAsJsonAsync(this.factory.MovieEndpoint, source, this.serializerOptions);
47-
response.Should().HaveStatusCode(HttpStatusCode.Conflict);
47+
response.StatusCode.Should().Be(HttpStatusCode.Conflict);
4848

4949
ClientMovie clientMovie = await response.Content.ReadFromJsonAsync<ClientMovie>(this.serializerOptions);
5050
clientMovie.Should().NotBeNull().And.HaveEquivalentMetadataTo(existingMovie).And.BeEquivalentTo<IMovie>(existingMovie);
@@ -60,7 +60,7 @@ public async Task Create_SoftDeleted_Returns409()
6060
ClientMovie source = new(TestData.Movies.BlackPanther) { Id = existingMovie.Id };
6161

6262
HttpResponseMessage response = await this.client.PostAsJsonAsync(this.factory.MovieEndpoint, source, this.serializerOptions);
63-
response.Should().HaveStatusCode(HttpStatusCode.Conflict);
63+
response.StatusCode.Should().Be(HttpStatusCode.Conflict);
6464

6565
ClientMovie clientMovie = await response.Content.ReadFromJsonAsync<ClientMovie>(this.serializerOptions);
6666
clientMovie.Should().NotBeNull().And.HaveEquivalentMetadataTo(existingMovie).And.BeEquivalentTo<IMovie>(existingMovie);
@@ -83,7 +83,7 @@ public async Task Create_CanRoundtrip_Types()
8383
};
8484

8585
HttpResponseMessage response = await this.client.PostAsJsonAsync(this.factory.KitchenSinkEndpoint, source, this.serializerOptions);
86-
response.Should().HaveStatusCode(HttpStatusCode.Created);
86+
response.StatusCode.Should().Be(HttpStatusCode.Created);
8787

8888
ClientKitchenSink clientKitchenSink = await response.Content.ReadFromJsonAsync<ClientKitchenSink>(this.serializerOptions);
8989
clientKitchenSink.Should().NotBeNull().And.HaveChangedMetadata(id, this.StartTime).And.BeEquivalentTo<IKitchenSink>(source);
@@ -97,7 +97,7 @@ public async Task Create_NonJsonData_Returns415()
9797
{
9898
const string content = "<html><body><h1>Not JSON</h1></body></html>";
9999
HttpResponseMessage response = await this.client.PostAsync(this.factory.MovieEndpoint, new StringContent(content, Encoding.UTF8, "text/html"));
100-
response.Should().HaveStatusCode(HttpStatusCode.UnsupportedMediaType);
100+
response.StatusCode.Should().Be(HttpStatusCode.UnsupportedMediaType);
101101
}
102102

103103
[Theory]
@@ -134,6 +134,6 @@ public async Task Create_ValidationError_Returns400(string propName, object prop
134134
}
135135

136136
HttpResponseMessage response = await this.client.PostAsJsonAsync(this.factory.MovieEndpoint, source, this.serializerOptions);
137-
response.Should().HaveStatusCode(HttpStatusCode.BadRequest);
137+
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
138138
}
139139
}

tests/CommunityToolkit.Datasync.Server.Test/Service/Delete_Tests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public async Task Delete_ById_Returns204()
1919
InMemoryMovie existingMovie = this.factory.GetRandomMovie();
2020

2121
HttpResponseMessage response = await this.client.DeleteAsync($"{this.factory.MovieEndpoint}/{existingMovie.Id}");
22-
response.Should().HaveStatusCode(HttpStatusCode.NoContent);
22+
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
2323

2424
InMemoryMovie serverEntity = this.factory.GetServerEntityById<InMemoryMovie>(existingMovie.Id);
2525
serverEntity.Should().BeNull();
@@ -39,7 +39,7 @@ public async Task Delete_WithVersioning_Works(string headerName, string value, H
3939
request.Headers.Add(headerName, etag);
4040

4141
HttpResponseMessage response = await this.client.SendAsync(request);
42-
response.Should().HaveStatusCode(expectedStatusCode);
42+
response.StatusCode.Should().Be(expectedStatusCode);
4343

4444
if (expectedStatusCode == HttpStatusCode.PreconditionFailed)
4545
{
@@ -53,7 +53,7 @@ public async Task Delete_WithVersioning_Works(string headerName, string value, H
5353
public async Task Delete_MissingId_Returns404()
5454
{
5555
HttpResponseMessage response = await this.client.DeleteAsync($"{this.factory.MovieEndpoint}/missing");
56-
response.Should().HaveStatusCode(HttpStatusCode.NotFound);
56+
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
5757
}
5858

5959
[Fact]
@@ -64,7 +64,7 @@ public async Task Delete_NotSoftDeleted_Returns204()
6464
DateTimeOffset existingUpdatedAt = (DateTimeOffset)existingMovie.UpdatedAt;
6565

6666
HttpResponseMessage response = await this.client.DeleteAsync($"{this.factory.SoftDeletedMovieEndpoint}/{existingMovie.Id}");
67-
response.Should().HaveStatusCode(HttpStatusCode.NoContent);
67+
response.StatusCode.Should().Be(HttpStatusCode.NoContent);
6868

6969
InMemoryMovie serverEntity = this.factory.GetServerEntityById<InMemoryMovie>(existingMovie.Id);
7070
serverEntity.Should().NotBeNull();
@@ -80,7 +80,7 @@ public async Task Delete_SoftDeletedId_Returns410()
8080
this.factory.SoftDelete(existingMovie);
8181

8282
HttpResponseMessage response = await this.client.DeleteAsync($"{this.factory.SoftDeletedMovieEndpoint}/{existingMovie.Id}");
83-
response.Should().HaveStatusCode(HttpStatusCode.Gone);
83+
response.StatusCode.Should().Be(HttpStatusCode.Gone);
8484

8585
InMemoryMovie serverEntity = this.factory.GetServerEntityById<InMemoryMovie>(existingMovie.Id);
8686
serverEntity.Should().NotBeNull();

0 commit comments

Comments
 (0)