Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate everything from Shouldly to FluentAssertions #1262

Merged
merged 5 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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="Microsoft.Extensions.Logging.Debug" Version="8.0.1"/>
<PackageReference Include="FluentAssertions" Version="6.12.0"/>
<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
29 changes: 15 additions & 14 deletions backend/FwLite/FwDataMiniLcmBridge.Tests/UpdateComplexFormsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FwDataMiniLcmBridge.Tests.Fixtures;
using MiniLcm;
using MiniLcm.Models;
using Testing;

namespace FwDataMiniLcmBridge.Tests;
//these tests were not moved because they need to be rewritten once we have the new update api for MiniLcm
Expand Down Expand Up @@ -33,7 +34,7 @@ await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Add(e => e.Components,
ComplexFormComponent.FromEntries(complexForm, component)));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry.ShouldNotBeNull();
entry!.Components.Should()
.ContainSingle(c => c.ComponentEntryId == component.Id && c.ComplexFormEntryId == complexForm.Id);
}
Expand Down Expand Up @@ -62,7 +63,7 @@ public async Task CanRemoveComponentFromExistingEntry()
await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Remove(e => e.Components, 0));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry.ShouldNotBeNull();
entry!.Components.Should().BeEmpty();
}

Expand Down Expand Up @@ -91,7 +92,7 @@ public async Task CanChangeComponentId()
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();
entry.ShouldNotBeNull();
var complexFormComponent = entry!.Components.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(component2.Id);
}
Expand Down Expand Up @@ -126,7 +127,7 @@ public async Task CanChangeComponentSenseId()
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();
entry.ShouldNotBeNull();
var complexFormComponent = entry!.Components.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(component2.Id);
complexFormComponent.ComponentSenseId.Should().Be(component2SenseId);
Expand Down Expand Up @@ -162,7 +163,7 @@ public async Task CanChangeComponentSenseIdToNull()
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.ShouldNotBeNull();
entry!.Components.Should()
.ContainSingle(c => c.ComponentEntryId == component2.Id && c.ComponentSenseId == null);
}
Expand Down Expand Up @@ -192,7 +193,7 @@ public async Task CanChangeComplexFormId()
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();
entry.ShouldNotBeNull();
var complexFormComponent = entry!.Components.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(component1.Id);
}
Expand All @@ -207,7 +208,7 @@ await _api.UpdateEntry(component.Id,
new UpdateObjectInput<Entry>().Add(e => e.ComplexForms,
ComplexFormComponent.FromEntries(complexForm, component)));
var entry = await _api.GetEntry(component.Id);
entry.Should().NotBeNull();
entry.ShouldNotBeNull();
entry!.ComplexForms.Should()
.ContainSingle(c => c.ComponentEntryId == component.Id && c.ComplexFormEntryId == complexForm.Id);
}
Expand Down Expand Up @@ -236,7 +237,7 @@ await _api.CreateEntry(new()
await _api.UpdateEntry(component.Id,
new UpdateObjectInput<Entry>().Remove(e => e.ComplexForms, 0));
var entry = await _api.GetEntry(component.Id);
entry.Should().NotBeNull();
entry.ShouldNotBeNull();
entry!.ComplexForms.Should().BeEmpty();
}

Expand Down Expand Up @@ -265,7 +266,7 @@ await _api.CreateEntry(new()
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();
entry.ShouldNotBeNull();
var complexFormComponent = entry!.ComplexForms.Should().ContainSingle().Subject;
complexFormComponent.ComplexFormEntryId.Should().Be(complexForm2.Id);
}
Expand Down Expand Up @@ -295,7 +296,7 @@ await _api.CreateEntry(new()
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();
entry.ShouldNotBeNull();
var complexFormComponent = entry!.ComplexForms.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(component2.Id);
complexFormComponent.ComplexFormEntryId.Should().Be(complexFormId);
Expand Down Expand Up @@ -337,7 +338,7 @@ await _api.CreateEntry(new()
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();
entry.ShouldNotBeNull();
var complexFormComponent = entry!.ComplexForms.Should().ContainSingle().Subject;
complexFormComponent.ComponentEntryId.Should().Be(componentId1);
complexFormComponent.ComponentSenseId.Should().Be(component1SenseId2);
Expand All @@ -352,7 +353,7 @@ public async Task CanAddComplexFormType()
await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Add(e => e.ComplexFormTypes, complexFormType));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry.ShouldNotBeNull();
entry!.ComplexFormTypes.Should().ContainSingle(c => c.Id == complexFormType.Id);
}

Expand All @@ -368,7 +369,7 @@ public async Task CanRemoveComplexFormType()
await _api.UpdateEntry(complexForm.Id,
new UpdateObjectInput<Entry>().Remove(e => e.ComplexFormTypes, 0));
var entry = await _api.GetEntry(complexForm.Id);
entry.Should().NotBeNull();
entry.ShouldNotBeNull();
entry!.ComplexFormTypes.Should().BeEmpty();
}

Expand All @@ -381,7 +382,7 @@ public async Task CanChangeComplexFormType()
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.ShouldNotBeNull();
entry!.ComplexFormTypes.Should().ContainSingle().Which.Id.Should().Be(complexFormType2.Id);
}
}
13 changes: 7 additions & 6 deletions backend/FwLite/FwLiteProjectSync.Tests/EntrySyncTests.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
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;
using Testing;

namespace FwLiteProjectSync.Tests;

Expand All @@ -24,7 +25,7 @@ public async Task CanSyncRandomEntries()
var after = await AutoFaker.EntryReadyForCreation(_fixture.CrdtApi, entryId: createdEntry.Id);
await EntrySync.Sync(after, createdEntry, _fixture.CrdtApi);
var actual = await _fixture.CrdtApi.GetEntry(after.Id);
actual.Should().NotBeNull();
actual.ShouldNotBeNull();
actual.Should().BeEquivalentTo(after, options => options);
}

Expand Down Expand Up @@ -56,7 +57,7 @@ public async Task CanChangeComplexFormVisSync_Components()
await EntrySync.Sync(after, complexForm, _fixture.CrdtApi);

var actual = await _fixture.CrdtApi.GetEntry(after.Id);
actual.Should().NotBeNull();
actual.ShouldNotBeNull();
actual.Should().BeEquivalentTo(after, options => options);
}

Expand Down Expand Up @@ -88,7 +89,7 @@ public async Task CanChangeComplexFormViaSync_ComplexForms()
await EntrySync.Sync(after, component, _fixture.CrdtApi);

var actual = await _fixture.CrdtApi.GetEntry(after.Id);
actual.Should().NotBeNull();
actual.ShouldNotBeNull();
actual.Should().BeEquivalentTo(after, options => options);
}

Expand All @@ -102,7 +103,7 @@ public async Task CanChangeComplexFormTypeViaSync()
await EntrySync.Sync(after, entry, _fixture.CrdtApi);

var actual = await _fixture.CrdtApi.GetEntry(after.Id);
actual.Should().NotBeNull();
actual.ShouldNotBeNull();
actual.Should().BeEquivalentTo(after, options => options);
}
}
15 changes: 8 additions & 7 deletions backend/FwLite/LcmCrdt.Tests/Changes/ComplexFormTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using LcmCrdt.Objects;
using MiniLcm.Models;
using SIL.Harmony.Changes;
using Testing;
using ComplexFormType = MiniLcm.Models.ComplexFormType;

namespace LcmCrdt.Tests.Changes;
Expand All @@ -17,7 +18,7 @@ public async Task AddComplexFormType()
var change = new AddComplexFormTypeChange(complexEntry.Id,complexFormType);
await fixture.DataModel.AddChange(Guid.NewGuid(), change);
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
complexEntry.ShouldNotBeNull();
complexEntry!.ComplexFormTypes.Should().ContainSingle().Which.Id.Should().Be(change.ComplexFormType.Id);
}

Expand All @@ -32,14 +33,14 @@ await fixture.DataModel.AddChange(
new AddComplexFormTypeChange(complexEntry.Id, complexFormType)
);
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
complexEntry.ShouldNotBeNull();
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.ShouldNotBeNull();
complexEntry!.ComplexFormTypes.Should().BeEmpty();
}

Expand All @@ -54,12 +55,12 @@ public async Task AddEntryComponent()
await fixture.DataModel.AddChange(Guid.NewGuid(), new AddEntryComponentChange(ComplexFormComponent.FromEntries(complexEntry, coatEntry)));
await fixture.DataModel.AddChange(Guid.NewGuid(), new AddEntryComponentChange(ComplexFormComponent.FromEntries(complexEntry, rackEntry)));
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
complexEntry.ShouldNotBeNull();
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.ShouldNotBeNull();
coatEntry!.ComplexForms.Should().ContainSingle(e => e.ComplexFormEntryId == complexEntry.Id);
}

Expand All @@ -73,12 +74,12 @@ public async Task DeleteEntryComponent()
await fixture.DataModel.AddChange(Guid.NewGuid(), new AddEntryComponentChange(ComplexFormComponent.FromEntries(complexEntry, coatEntry)));
await fixture.DataModel.AddChange(Guid.NewGuid(), new AddEntryComponentChange(ComplexFormComponent.FromEntries(complexEntry, rackEntry)));
complexEntry = await fixture.Api.GetEntry(complexEntry.Id);
complexEntry.Should().NotBeNull();
complexEntry.ShouldNotBeNull();
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.ShouldNotBeNull();
complexEntry!.Components.Should().NotContain(c => c.Id == component.Id);
}
}
3 changes: 2 additions & 1 deletion backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using SIL.Harmony.Entities;
using Soenneker.Utils.AutoBogus;
using Soenneker.Utils.AutoBogus.Config;
using Testing;

namespace LcmCrdt.Tests;

Expand Down Expand Up @@ -89,7 +90,7 @@ public void VerifyIObjectWithIdsMatchAdapterGetObjectTypeName()
{
foreach (var jsonDerivedType in types)
{
var typeDiscriminator = jsonDerivedType.TypeDiscriminator.Should().BeOfType<string>().Subject;
var typeDiscriminator = jsonDerivedType.TypeDiscriminator.ShouldBeOfType<string>();
var obj = Faker.Generate(jsonDerivedType.DerivedType);
new MiniLcmCrdtAdapter((IObjectWithId)obj).GetObjectTypeName().Should().Be(typeDiscriminator);
}
Expand Down
7 changes: 4 additions & 3 deletions backend/FwLite/LcmCrdt.Tests/JsonPatchEntryRewriteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using LcmCrdt.Objects;
using SIL.Harmony.Changes;
using SystemTextJsonPatch;
using Testing;

namespace LcmCrdt.Tests;

Expand All @@ -17,7 +18,7 @@ public void ChangesFromJsonPatch_AddComponentMakesAddEntryComponentChange()
patch.Add(entry => entry.Components, ComplexFormComponent.FromEntries(_entry, componentEntry));
var changes = _entry.ToChanges(patch);
var addEntryComponentChange =
changes.Should().ContainSingle().Which.Should().BeOfType<AddEntryComponentChange>().Subject;
changes.Should().ContainSingle().Which.ShouldBeOfType<AddEntryComponentChange>();
addEntryComponentChange.ComplexFormEntryId.Should().Be(_entry.Id);
addEntryComponentChange.ComponentEntryId.Should().Be(componentEntry.Id);
addEntryComponentChange.ComponentHeadword.Should().Be(componentEntry.Headword());
Expand Down Expand Up @@ -81,7 +82,7 @@ public void ChangesFromJsonPatch_AddComplexFormMakesAddEntryComponentChange()
patch.Add(entry => entry.ComplexForms, ComplexFormComponent.FromEntries(_entry, componentEntry));
var changes = componentEntry.ToChanges(patch);
var addEntryComponentChange =
changes.Should().ContainSingle().Which.Should().BeOfType<AddEntryComponentChange>().Subject;
changes.Should().ContainSingle().Which.ShouldBeOfType<AddEntryComponentChange>();
addEntryComponentChange.ComplexFormEntryId.Should().Be(_entry.Id);
addEntryComponentChange.ComponentEntryId.Should().Be(componentEntry.Id);
addEntryComponentChange.ComponentHeadword.Should().Be(componentEntry.Headword());
Expand Down Expand Up @@ -145,7 +146,7 @@ public void ChangesFromJsonPatch_AddComplexFormTypeMakesAddComplexFormTypeChange
patch.Add(entry => entry.ComplexFormTypes, complexFormType);
var changes = _entry.ToChanges(patch);
var addComplexFormTypeChange =
changes.Should().ContainSingle().Which.Should().BeOfType<AddComplexFormTypeChange>().Subject;
changes.Should().ContainSingle().Which.ShouldBeOfType<AddComplexFormTypeChange>();
addComplexFormTypeChange.EntityId.Should().Be(_entry.Id);
addComplexFormTypeChange.ComplexFormType.Should().Be(complexFormType);
}
Expand Down
3 changes: 2 additions & 1 deletion backend/FwLite/LcmCrdt.Tests/JsonPatchSenseRewriteTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using MiniLcm.Models;
using SystemTextJsonPatch;
using SystemTextJsonPatch.Operations;
using Testing;

namespace LcmCrdt.Tests;

Expand Down Expand Up @@ -47,7 +48,7 @@ public void JsonPatchChangeRewriteDoesNotReturnEmptyPatchChanges()
var changes = _sense.ToChanges(_patchDocument).ToArray();

var setPartOfSpeechChange = changes.Should().ContainSingle()
.Subject.Should().BeOfType<SetPartOfSpeechChange>().Subject;
.Subject.ShouldBeOfType<SetPartOfSpeechChange>();
setPartOfSpeechChange.EntityId.Should().Be(_sense.Id);
setPartOfSpeechChange.PartOfSpeechId.Should().Be(newPartOfSpeechId);
}
Expand Down
3 changes: 2 additions & 1 deletion backend/FwLite/LcmCrdt.Tests/SerializationTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Text.Json;
using MiniLcm.Models;
using Testing;
using Xunit.Abstractions;

namespace LcmCrdt.Tests;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void CanDeserializeMultiString()
Values = { { "en", "test" } }
};
var actualMs = JsonSerializer.Deserialize<MultiString>(json);
actualMs.Should().NotBeNull();
actualMs.ShouldNotBeNull();
actualMs!.Values.Should().ContainKey("en");
actualMs.Should().BeEquivalentTo(expectedMs);
}
Expand Down
8 changes: 5 additions & 3 deletions backend/FwLite/MiniLcm.Tests/BasicApiTestsBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace MiniLcm.Tests;
using Testing;

namespace MiniLcm.Tests;

public abstract class BasicApiTestsBase : MiniLcmTestBase
{
Expand Down Expand Up @@ -201,7 +203,7 @@ public async Task SearchEntries_MatchesGloss()
public async Task GetEntry()
{
var entry = await Api.GetEntry(Entry1Id);
entry.Should().NotBeNull();
entry.ShouldNotBeNull();
entry!.LexemeForm.Values.Should().NotBeEmpty();
var sense = entry.Senses.Should()
.NotBeEmpty($"because '{entry.LexemeForm.Values.First().Value}' should have a sense").And.Subject.First();
Expand Down Expand Up @@ -275,7 +277,7 @@ public async Task CreateEntry()
}
]
});
entry.Should().NotBeNull();
entry.ShouldNotBeNull();
entry.LexemeForm.Values["en"].Should().Be("Kevin");
entry.LiteralMeaning.Values["en"].Should().Be("Kevin");
entry.CitationForm.Values["en"].Should().Be("Kevin");
Expand Down
Loading
Loading