Skip to content

Commit

Permalink
Migrate everything from Shouldly to FluentAssertions (#1262)
Browse files Browse the repository at this point in the history
* Migrate everything from Shouldly to FluentAssertions

* Don't reference Testing.csproj from MiniLcm.Tests

* Address feedback

* Upgrade to FluentAssertions 7-prerelease

* Fix assertion that's now case-sensitive

---------

Co-authored-by: Robin Munn <[email protected]>
  • Loading branch information
myieye and rmunn authored Nov 25, 2024
1 parent d816858 commit a525563
Show file tree
Hide file tree
Showing 47 changed files with 352 additions and 349 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1"/>
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5"/>
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
28 changes: 14 additions & 14 deletions backend/FwLite/FwDataMiniLcmBridge.Tests/UpdateComplexFormsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ await _api.UpdateEntry(complexForm.Id,
ComplexFormComponent.FromEntries(complexForm, component)));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry!.Components.Should()
entry.Components.Should()
.ContainSingle(c => c.ComponentEntryId == component.Id && c.ComplexFormEntryId == complexForm.Id);
}

Expand Down Expand Up @@ -63,7 +63,7 @@ await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Remove(e => e.Components, 0));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry!.Components.Should().BeEmpty();
entry.Components.Should().BeEmpty();
}

[Fact]
Expand Down Expand Up @@ -92,7 +92,7 @@ await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Set(e => e.Components[0].ComponentEntryId, component2.Id));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
var complexFormComponent = entry!.Components.Should().ContainSingle().Subject;
var complexFormComponent = entry.Components.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(component2.Id);
}

Expand Down Expand Up @@ -127,7 +127,7 @@ await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Set(e => e.Components[0].ComponentSenseId, component2SenseId));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
var complexFormComponent = entry!.Components.Should().ContainSingle().Subject;
var complexFormComponent = entry.Components.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(component2.Id);
complexFormComponent.ComponentSenseId.Should().Be(component2SenseId);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Set(e => e.Components[0].ComponentSenseId, null));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry!.Components.Should()
entry.Components.Should()
.ContainSingle(c => c.ComponentEntryId == component2.Id && c.ComponentSenseId == null);
}

Expand Down Expand Up @@ -193,7 +193,7 @@ await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Set(e => e.Components[0].ComplexFormEntryId, complexForm2.Id));
var entry = await _api.GetEntry(complexForm2.Id);
entry.Should().NotBeNull();
var complexFormComponent = entry!.Components.Should().ContainSingle().Subject;
var complexFormComponent = entry.Components.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(component1.Id);
}

Expand All @@ -208,7 +208,7 @@ await _api.UpdateEntry(component.Id,
ComplexFormComponent.FromEntries(complexForm, component)));
var entry = await _api.GetEntry(component.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should()
entry.ComplexForms.Should()
.ContainSingle(c => c.ComponentEntryId == component.Id && c.ComplexFormEntryId == complexForm.Id);
}

Expand Down Expand Up @@ -237,7 +237,7 @@ await _api.UpdateEntry(component.Id,
new UpdateObjectInput<Entry>().Remove(e => e.ComplexForms, 0));
var entry = await _api.GetEntry(component.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should().BeEmpty();
entry.ComplexForms.Should().BeEmpty();
}

[Fact]
Expand Down Expand Up @@ -266,7 +266,7 @@ await _api.UpdateEntry(component1.Id,
new UpdateObjectInput<Entry>().Set(e => e.ComplexForms[0].ComplexFormEntryId, complexForm2.Id));
var entry = await _api.GetEntry(component1.Id);
entry.Should().NotBeNull();
var complexFormComponent = entry!.ComplexForms.Should().ContainSingle().Subject;
var complexFormComponent = entry.ComplexForms.Should().ContainSingle().Subject;
complexFormComponent.ComplexFormEntryId.Should().Be(complexForm2.Id);
}

Expand Down Expand Up @@ -296,7 +296,7 @@ await _api.UpdateEntry(component1.Id,
new UpdateObjectInput<Entry>().Set(e => e.ComplexForms[0].ComponentEntryId, component2.Id));
var entry = await _api.GetEntry(component2.Id);
entry.Should().NotBeNull();
var complexFormComponent = entry!.ComplexForms.Should().ContainSingle().Subject;
var complexFormComponent = entry.ComplexForms.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(component2.Id);
complexFormComponent.ComplexFormEntryId.Should().Be(complexFormId);
}
Expand Down Expand Up @@ -338,7 +338,7 @@ await _api.UpdateEntry(component1.Id,
new UpdateObjectInput<Entry>().Set(e => e.ComplexForms[0].ComponentSenseId, component1SenseId2));
var entry = await _api.GetEntry(component1.Id);
entry.Should().NotBeNull();
var complexFormComponent = entry!.ComplexForms.Should().ContainSingle().Subject;
var complexFormComponent = entry.ComplexForms.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(componentId1);
complexFormComponent.ComponentSenseId.Should().Be(component1SenseId2);
}
Expand All @@ -353,7 +353,7 @@ await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Add(e => e.ComplexFormTypes, complexFormType));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry!.ComplexFormTypes.Should().ContainSingle(c => c.Id == complexFormType.Id);
entry.ComplexFormTypes.Should().ContainSingle(c => c.Id == complexFormType.Id);
}

[Fact]
Expand All @@ -369,7 +369,7 @@ await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Remove(e => e.ComplexFormTypes, 0));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry!.ComplexFormTypes.Should().BeEmpty();
entry.ComplexFormTypes.Should().BeEmpty();
}

[Fact]
Expand All @@ -382,6 +382,6 @@ await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Set(e => e.ComplexFormTypes[0].Id, complexFormType2.Id));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry!.ComplexFormTypes.Should().ContainSingle().Which.Id.Should().Be(complexFormType2.Id);
entry.ComplexFormTypes.Should().ContainSingle().Which.Id.Should().Be(complexFormType2.Id);
}
}
4 changes: 2 additions & 2 deletions backend/FwLite/FwLiteProjectSync.Tests/EntrySyncTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using FluentAssertions.Equivalency;
using FwLiteProjectSync.Tests.Fixtures;
using FwLiteProjectSync.Tests.Fixtures;
using MiniLcm.Models;
using MiniLcm.SyncHelpers;
using MiniLcm.Tests;
using MiniLcm.Tests.AutoFakerHelpers;
using Soenneker.Utils.AutoBogus;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1"/>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5"/>
<PackageReference Include="Soenneker.Utils.AutoBogus" Version="3.0.410" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
Expand Down
14 changes: 7 additions & 7 deletions backend/FwLite/LcmCrdt.Tests/Changes/ComplexFormTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task AddComplexFormType()
await fixture.DataModel.AddChange(Guid.NewGuid(), change);
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
complexEntry!.ComplexFormTypes.Should().ContainSingle().Which.Id.Should().Be(change.ComplexFormType.Id);
complexEntry.ComplexFormTypes.Should().ContainSingle().Which.Id.Should().Be(change.ComplexFormType.Id);
}

[Fact]
Expand All @@ -33,14 +33,14 @@ await fixture.DataModel.AddChange(
);
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
complexEntry!.ComplexFormTypes.Should().ContainSingle().Which.Id.Should().Be(complexFormType.Id);
complexEntry.ComplexFormTypes.Should().ContainSingle().Which.Id.Should().Be(complexFormType.Id);
await fixture.DataModel.AddChange(
Guid.NewGuid(),
new RemoveComplexFormTypeChange(complexEntry.Id, complexFormType.Id)
);
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
complexEntry!.ComplexFormTypes.Should().BeEmpty();
complexEntry.ComplexFormTypes.Should().BeEmpty();
}

[Fact]
Expand All @@ -55,12 +55,12 @@ public async Task AddEntryComponent()
await fixture.DataModel.AddChange(Guid.NewGuid(), new AddEntryComponentChange(ComplexFormComponent.FromEntries(complexEntry, rackEntry)));
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
complexEntry!.Components.Should().ContainSingle(e => e.ComponentEntryId == coatEntry.Id);
complexEntry.Components.Should().ContainSingle(e => e.ComponentEntryId == coatEntry.Id);
complexEntry.Components.Should().ContainSingle(e => e.ComponentEntryId == rackEntry.Id);

coatEntry = await fixture.Api.GetEntry(coatEntry.Id);
coatEntry.Should().NotBeNull();
coatEntry!.ComplexForms.Should().ContainSingle(e => e.ComplexFormEntryId == complexEntry.Id);
coatEntry.ComplexForms.Should().ContainSingle(e => e.ComplexFormEntryId == complexEntry.Id);
}

[Fact]
Expand All @@ -74,11 +74,11 @@ public async Task DeleteEntryComponent()
await fixture.DataModel.AddChange(Guid.NewGuid(), new AddEntryComponentChange(ComplexFormComponent.FromEntries(complexEntry, rackEntry)));
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
var component = complexEntry!.Components.First();
var component = complexEntry.Components.First();

await fixture.DataModel.AddChange(Guid.NewGuid(), new DeleteChange<ComplexFormComponent>(component.Id));
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
complexEntry!.Components.Should().NotContain(c => c.Id == component.Id);
complexEntry.Components.Should().NotContain(c => c.Id == component.Id);
}
}
2 changes: 1 addition & 1 deletion backend/FwLite/LcmCrdt.Tests/LcmCrdt.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5"/>
<PackageReference Include="Soenneker.Utils.AutoBogus" Version="3.0.410" />
<PackageReference Include="Verify.Xunit" Version="27.0.1" />
<PackageReference Include="xunit" Version="2.9.2" />
Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/LcmCrdt.Tests/SerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void CanDeserializeMultiString()
};
var actualMs = JsonSerializer.Deserialize<MultiString>(json);
actualMs.Should().NotBeNull();
actualMs!.Values.Should().ContainKey("en");
actualMs.Values.Should().ContainKey("en");
actualMs.Should().BeEquivalentTo(expectedMs);
}

Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/MiniLcm.Tests/BasicApiTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public async Task GetEntry()
{
var entry = await Api.GetEntry(Entry1Id);
entry.Should().NotBeNull();
entry!.LexemeForm.Values.Should().NotBeEmpty();
entry.LexemeForm.Values.Should().NotBeEmpty();
var sense = entry.Senses.Should()
.NotBeEmpty($"because '{entry.LexemeForm.Values.First().Value}' should have a sense").And.Subject.First();
sense.Gloss.Values.Should().NotBeEmpty();
Expand Down
12 changes: 6 additions & 6 deletions backend/FwLite/MiniLcm.Tests/CreateEntryTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public async Task CanCreateEntry()
{
var entry = await Api.CreateEntry(new() { LexemeForm = { { "en", "test" } } });
entry.Should().NotBeNull();
entry!.LexemeForm.Values.Should().ContainKey("en");
entry.LexemeForm.Values.Should().ContainKey("en");
entry.LexemeForm.Values["en"].Should().Be("test");
}

Expand Down Expand Up @@ -53,7 +53,7 @@ public async Task CanCreate_WithComponentsProperty()
});
entry = await Api.GetEntry(entry.Id);
entry.Should().NotBeNull();
entry!.Components.Should().ContainSingle(c => c.ComponentEntryId == component.Id);
entry.Components.Should().ContainSingle(c => c.ComponentEntryId == component.Id);
}

[Fact]
Expand All @@ -78,7 +78,7 @@ public async Task CanCreate_WithComplexFormsProperty()
});
entry = await Api.GetEntry(entry.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should().ContainSingle(c => c.ComplexFormEntryId == complexForm.Id);
entry.ComplexForms.Should().ContainSingle(c => c.ComplexFormEntryId == complexForm.Id);
}

[Fact]
Expand Down Expand Up @@ -110,11 +110,11 @@ await Api.CreateEntry(new()

var entry = await Api.GetEntry(component.Id);
entry.Should().NotBeNull();
entry!.ComplexForms.Should().ContainSingle().Which.ComponentSenseId.Should().Be(componentSenseId);
entry.ComplexForms.Should().ContainSingle().Which.ComponentSenseId.Should().Be(componentSenseId);

entry = await Api.GetEntry(complexFormEntryId);
entry.Should().NotBeNull();
entry!.Components.Should().ContainSingle(c =>
entry.Components.Should().ContainSingle(c =>
c.ComplexFormEntryId == complexFormEntryId && c.ComponentEntryId == component.Id &&
c.ComponentSenseId == componentSenseId);
}
Expand All @@ -133,6 +133,6 @@ public async Task CanCreate_WithComplexFormTypesProperty()
});
entry = await Api.GetEntry(entry.Id);
entry.Should().NotBeNull();
entry!.ComplexFormTypes.Should().ContainSingle(c => c.Id == complexFormType.Id);
entry.ComplexFormTypes.Should().ContainSingle(c => c.Id == complexFormType.Id);
}
}
6 changes: 3 additions & 3 deletions backend/FwLite/MiniLcm.Tests/MiniLcm.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
<PackageReference Include="Meziantou.Extensions.Logging.Xunit" Version="1.0.7" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.5.3"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0"/>
<PackageReference Include="xunit" Version="2.9.0"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3"/>
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<PackageReference Include="FluentAssertions" Version="7.0.0-alpha.5"/>
<PackageReference Include="Soenneker.Utils.AutoBogus" Version="3.0.410" />
<PackageReference Include="System.Linq.Async" Version="6.0.1"/>
</ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions backend/FwLite/MiniLcm.Tests/SemanticDomainTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ await Api.CreateEntry(new Entry()
});
}

private Task<Entry> GetEntry()
private async Task<Entry> GetEntry()
{
var entry = Api.GetEntry(_entryId);
var entry = await Api.GetEntry(_entryId);
entry.Should().NotBeNull();
return entry!;
return entry;
}

[Fact]
Expand All @@ -55,7 +55,7 @@ public async Task Sense_HasSemanticDomains()
{
var entry = await GetEntry();
entry.Should().NotBeNull();
var sense = entry!.Senses.First(s => s.SemanticDomains.Any());
var sense = entry.Senses.First(s => s.SemanticDomains.Any());
sense.SemanticDomains.Should().NotBeEmpty();
sense.SemanticDomains.Should().AllSatisfy(sd =>
{
Expand Down
8 changes: 3 additions & 5 deletions backend/FwLite/MiniLcm.Tests/WritingSystemIdTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using MiniLcm.Models;

namespace MiniLcm.Tests;
namespace MiniLcm.Tests;

public class WritingSystemIdTests
{
Expand All @@ -11,7 +9,7 @@ public class WritingSystemIdTests
public void ValidWritingSystemId_ShouldNotThrow(string code)
{
var ws = new WritingSystemId(code);
ws.Should().NotBeNull();
ws.Should().NotBe(default);
}

[Theory]
Expand All @@ -29,6 +27,6 @@ public void InvalidWritingSystemId_ShouldThrow(string code)
public void DefaultWritingSystemId_IsValid()
{
var ws = new WritingSystemId("default");
ws.Should().NotBeNull();
ws.Should().NotBe(default);
}
}
4 changes: 2 additions & 2 deletions backend/LexBoxApi/GraphQL/ProjectMutations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public enum CreateProjectResult
Requested
}

public record CreateProjectResponse(Guid? Id, CreateProjectResult Result);
public record CreateProjectResponse(Guid Id, CreateProjectResult Result);
[Error<DbError>]
[Error<AlreadyExistsException>]
[Error<ProjectCreatorsMustHaveEmail>]
[UseMutationConvention]
[RefreshJwt]
[VerifiedEmailRequired]
public async Task<CreateProjectResponse?> CreateProject(
public async Task<CreateProjectResponse> CreateProject(
LoggedInContext loggedInContext,
IPermissionService permissionService,
CreateProjectInput input,
Expand Down
Loading

0 comments on commit a525563

Please sign in to comment.