-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into feat/1246-allow-re…
…ordering-senses-example-sentences-complex-forms-and-components
- Loading branch information
Showing
18 changed files
with
138 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
backend/FwLite/LcmCrdt.Tests/Changes/ChangeSerializationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
using System.Reflection; | ||
using System.Text.Json; | ||
using FluentAssertions.Execution; | ||
using LcmCrdt.Changes; | ||
using LcmCrdt.Changes.Entries; | ||
using MiniLcm.Tests.AutoFakerHelpers; | ||
using SIL.Harmony.Changes; | ||
using Soenneker.Utils.AutoBogus; | ||
using SystemTextJsonPatch; | ||
|
||
namespace LcmCrdt.Tests.Changes; | ||
|
||
public class ChangeSerializationTests | ||
{ | ||
private static readonly AutoFaker Faker = new() | ||
{ | ||
Config = | ||
{ | ||
Overrides = [new WritingSystemIdOverride()] | ||
} | ||
}; | ||
|
||
public static IEnumerable<object[]> Changes() | ||
{ | ||
foreach (var type in LcmCrdtKernel.AllChangeTypes()) | ||
{ | ||
//can't generate this type because there's no public constructor, so its specified below | ||
if (type == typeof(SetComplexFormComponentChange)) continue; | ||
|
||
object change; | ||
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(JsonPatchChange<>)) | ||
{ | ||
change = PatchMethod.MakeGenericMethod(type.GenericTypeArguments[0]).Invoke(null, null)!; | ||
} | ||
else | ||
{ | ||
change = Faker.Generate(type); | ||
} | ||
change.Should().NotBeNull($"change type {type.Name} should have been generated"); | ||
yield return [change]; | ||
} | ||
yield return [SetComplexFormComponentChange.NewComplexForm(Guid.NewGuid(), Guid.NewGuid())]; | ||
yield return [SetComplexFormComponentChange.NewComponent(Guid.NewGuid(), Guid.NewGuid())]; | ||
yield return [SetComplexFormComponentChange.NewComponentSense(Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid())]; | ||
} | ||
|
||
private static readonly MethodInfo PatchMethod = new Func<IChange>(Patch<Entry>).Method.GetGenericMethodDefinition(); | ||
|
||
private static IChange Patch<T>() where T : class | ||
{ | ||
return new JsonPatchChange<T>(Guid.NewGuid(), new JsonPatchDocument<T>()); | ||
} | ||
|
||
[Theory] | ||
[MemberData(nameof(Changes))] | ||
public void CanRoundTripChanges(IChange change) | ||
{ | ||
var config = new CrdtConfig(); | ||
LcmCrdtKernel.ConfigureCrdt(config); | ||
//commit id is not serialized | ||
change.CommitId = Guid.Empty; | ||
var type = change.GetType(); | ||
var json = JsonSerializer.Serialize(change, config.JsonSerializerOptions); | ||
var newChange = JsonSerializer.Deserialize(json, type, config.JsonSerializerOptions); | ||
newChange.Should().BeEquivalentTo(change); | ||
} | ||
|
||
[Fact] | ||
public void ChangesIncludesAllValidChangeTypes() | ||
{ | ||
var allChangeTypes = LcmCrdtKernel.AllChangeTypes(); | ||
allChangeTypes.Should().NotBeEmpty(); | ||
var testedTypes = Changes().Select(c => c[0].GetType()).ToArray(); | ||
using (new AssertionScope()) | ||
{ | ||
foreach (var allChangeType in allChangeTypes) | ||
{ | ||
testedTypes.Should().Contain(allChangeType); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule harmony
updated
3 files
+1 −1 | src/SIL.Harmony.Core/QueryHelpers.cs | |
+1 −1 | src/SIL.Harmony.Tests/DbContextTests.VerifyModel.verified.txt | |
+1 −1 | src/SIL.Harmony/Db/CrdtRepository.cs |