From dde589bf46ee4c59a9509259f66975ffe3979a26 Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Tue, 19 Nov 2024 09:33:34 +0700 Subject: [PATCH] upgrade autofaker and make all instances static --- backend/FwLite/FwLiteProjectSync.Tests/EntrySyncTests.cs | 6 +++--- .../FwLiteProjectSync.Tests.csproj | 2 +- backend/FwLite/FwLiteProjectSync.Tests/UpdateDiffTests.cs | 8 ++++---- backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.cs | 4 ++-- backend/FwLite/LcmCrdt.Tests/EntityCopyMethodTests.cs | 4 ++-- backend/FwLite/LcmCrdt.Tests/LcmCrdt.Tests.csproj | 2 +- backend/FwLite/MiniLcm.Tests/MiniLcm.Tests.csproj | 2 +- backend/FwLite/MiniLcm.Tests/MiniLcmTestBase.cs | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/backend/FwLite/FwLiteProjectSync.Tests/EntrySyncTests.cs b/backend/FwLite/FwLiteProjectSync.Tests/EntrySyncTests.cs index 523f73526..d1b264839 100644 --- a/backend/FwLite/FwLiteProjectSync.Tests/EntrySyncTests.cs +++ b/backend/FwLite/FwLiteProjectSync.Tests/EntrySyncTests.cs @@ -9,7 +9,7 @@ namespace FwLiteProjectSync.Tests; public class EntrySyncTests : IClassFixture { - private readonly AutoFaker _autoFaker = new(builder => builder.WithOverride(new MultiStringOverride()).WithOverride(new ObjectWithIdOverride())); + private static readonly AutoFaker AutoFaker = new(builder => builder.WithOverride(new MultiStringOverride()).WithOverride(new ObjectWithIdOverride())); public EntrySyncTests(SyncFixture fixture) { _fixture = fixture; @@ -20,8 +20,8 @@ public EntrySyncTests(SyncFixture fixture) [Fact] public async Task CanSyncRandomEntries() { - var createdEntry = await _fixture.CrdtApi.CreateEntry(await _autoFaker.EntryReadyForCreation(_fixture.CrdtApi)); - var after = await _autoFaker.EntryReadyForCreation(_fixture.CrdtApi, entryId: createdEntry.Id); + var createdEntry = await _fixture.CrdtApi.CreateEntry(await AutoFaker.EntryReadyForCreation(_fixture.CrdtApi)); + 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(); diff --git a/backend/FwLite/FwLiteProjectSync.Tests/FwLiteProjectSync.Tests.csproj b/backend/FwLite/FwLiteProjectSync.Tests/FwLiteProjectSync.Tests.csproj index ea6572e46..1ae1063f4 100644 --- a/backend/FwLite/FwLiteProjectSync.Tests/FwLiteProjectSync.Tests.csproj +++ b/backend/FwLite/FwLiteProjectSync.Tests/FwLiteProjectSync.Tests.csproj @@ -21,7 +21,7 @@ - + all diff --git a/backend/FwLite/FwLiteProjectSync.Tests/UpdateDiffTests.cs b/backend/FwLite/FwLiteProjectSync.Tests/UpdateDiffTests.cs index 9d1feffa2..2d1eb2058 100644 --- a/backend/FwLite/FwLiteProjectSync.Tests/UpdateDiffTests.cs +++ b/backend/FwLite/FwLiteProjectSync.Tests/UpdateDiffTests.cs @@ -9,7 +9,7 @@ namespace FwLiteProjectSync.Tests; public class UpdateDiffTests { - private readonly AutoFaker _autoFaker = new(new AutoFakerConfig() + private static readonly AutoFaker AutoFaker = new(new AutoFakerConfig() { Overrides = [new MultiStringOverride(), new WritingSystemIdOverride()] }); @@ -18,7 +18,7 @@ public class UpdateDiffTests public void EntryDiffShouldUpdateAllFields() { var before = new Entry(); - var after = _autoFaker.Generate(); + var after = AutoFaker.Generate(); var entryDiffToUpdate = EntrySync.EntryDiffToUpdate(before, after); ArgumentNullException.ThrowIfNull(entryDiffToUpdate); entryDiffToUpdate.Apply(before); @@ -33,7 +33,7 @@ public void EntryDiffShouldUpdateAllFields() public async Task SenseDiffShouldUpdateAllFields() { var before = new Sense(); - var after = _autoFaker.Generate(); + var after = AutoFaker.Generate(); var senseDiffToUpdate = await SenseSync.SenseDiffToUpdate(before, after); ArgumentNullException.ThrowIfNull(senseDiffToUpdate); senseDiffToUpdate.Apply(before); @@ -44,7 +44,7 @@ public async Task SenseDiffShouldUpdateAllFields() public void ExampleSentenceDiffShouldUpdateAllFields() { var before = new ExampleSentence(); - var after = _autoFaker.Generate(); + var after = AutoFaker.Generate(); var exampleSentenceDiffToUpdate = ExampleSentenceSync.DiffToUpdate(before, after); ArgumentNullException.ThrowIfNull(exampleSentenceDiffToUpdate); exampleSentenceDiffToUpdate.Apply(before); diff --git a/backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.cs b/backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.cs index c08c3812c..359edff20 100644 --- a/backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.cs +++ b/backend/FwLite/LcmCrdt.Tests/DataModelSnapshotTests.cs @@ -17,7 +17,7 @@ namespace LcmCrdt.Tests; public class DataModelSnapshotTests : IAsyncLifetime { - private static AutoFaker _faker = new AutoFaker(new AutoFakerConfig() + private static readonly AutoFaker Faker = new AutoFaker(new AutoFakerConfig() { Overrides = [new MultiStringOverride(), new WritingSystemIdOverride()] }); @@ -90,7 +90,7 @@ public void VerifyIObjectWithIdsMatchAdapterGetObjectTypeName() foreach (var jsonDerivedType in types) { var typeDiscriminator = jsonDerivedType.TypeDiscriminator.Should().BeOfType().Subject; - var obj = _faker.Generate(jsonDerivedType.DerivedType); + var obj = Faker.Generate(jsonDerivedType.DerivedType); new MiniLcmCrdtAdapter((IObjectWithId)obj).GetObjectTypeName().Should().Be(typeDiscriminator); } } diff --git a/backend/FwLite/LcmCrdt.Tests/EntityCopyMethodTests.cs b/backend/FwLite/LcmCrdt.Tests/EntityCopyMethodTests.cs index 395615d46..3caf45d35 100644 --- a/backend/FwLite/LcmCrdt.Tests/EntityCopyMethodTests.cs +++ b/backend/FwLite/LcmCrdt.Tests/EntityCopyMethodTests.cs @@ -9,7 +9,7 @@ namespace LcmCrdt.Tests; public class EntityCopyMethodTests { - private readonly AutoFaker _autoFaker = new(new AutoFakerConfig() + private static readonly AutoFaker AutoFaker = new(new AutoFakerConfig() { Overrides = [new MultiStringOverride(), new WritingSystemIdOverride()] }); @@ -35,7 +35,7 @@ public static IEnumerable GetEntityTypes() public void EntityCopyMethodShouldCopyAllFields(Type type) { type.IsAssignableTo(typeof(IObjectWithId)).Should().BeTrue(); - var entity = (IObjectWithId) _autoFaker.Generate(type); + var entity = (IObjectWithId) AutoFaker.Generate(type); var copy = entity.Copy(); copy.Should().BeEquivalentTo(entity, options => options.IncludingAllRuntimeProperties()); } diff --git a/backend/FwLite/LcmCrdt.Tests/LcmCrdt.Tests.csproj b/backend/FwLite/LcmCrdt.Tests/LcmCrdt.Tests.csproj index 2b9260c62..d955b734a 100644 --- a/backend/FwLite/LcmCrdt.Tests/LcmCrdt.Tests.csproj +++ b/backend/FwLite/LcmCrdt.Tests/LcmCrdt.Tests.csproj @@ -17,7 +17,7 @@ - + diff --git a/backend/FwLite/MiniLcm.Tests/MiniLcm.Tests.csproj b/backend/FwLite/MiniLcm.Tests/MiniLcm.Tests.csproj index 86bcc41df..83030857f 100644 --- a/backend/FwLite/MiniLcm.Tests/MiniLcm.Tests.csproj +++ b/backend/FwLite/MiniLcm.Tests/MiniLcm.Tests.csproj @@ -20,7 +20,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/backend/FwLite/MiniLcm.Tests/MiniLcmTestBase.cs b/backend/FwLite/MiniLcm.Tests/MiniLcmTestBase.cs index f4ee8de99..1b5601be2 100644 --- a/backend/FwLite/MiniLcm.Tests/MiniLcmTestBase.cs +++ b/backend/FwLite/MiniLcm.Tests/MiniLcmTestBase.cs @@ -6,7 +6,7 @@ namespace MiniLcm.Tests; public abstract class MiniLcmTestBase : IAsyncLifetime { - protected readonly AutoFaker AutoFaker = new(builder => + protected static readonly AutoFaker AutoFaker = new(builder => builder.WithOverride(new MultiStringOverride(["en"])) .WithOverride(new ObjectWithIdOverride()) );