Skip to content

Commit

Permalink
expose change and object types on config
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Jan 30, 2025
1 parent 5d62145 commit 451a997
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/SIL.Harmony.Tests/ConfigTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using SIL.Harmony.Sample.Changes;
using SIL.Harmony.Sample.Models;
using SIL.Harmony.Tests.Adapter;

namespace SIL.Harmony.Tests;

public class ConfigTests
{
[Fact]
public void CanGetEntityTypes()
{
var config = new CrdtConfig();
config.ObjectTypeListBuilder.DefaultAdapter()
.Add<Word>()
.Add<Definition>();
config.ObjectTypeListBuilder
.CustomAdapter<CustomObjectAdapterTests.IMyCustomInterface, CustomObjectAdapterTests.MyClassAdapter>()
.Add<CustomObjectAdapterTests.MyClass>();
var types = config.ObjectTypes.ToArray();
types.Should().BeEquivalentTo([typeof(Word), typeof(Definition), typeof(CustomObjectAdapterTests.MyClass)]);
}

[Fact]
public void CanGetChangeTypes()
{
var config = new CrdtConfig();
config.ChangeTypeListBuilder.Add<NewDefinitionChange>();
config.ChangeTypeListBuilder.Add<SetWordTextChange>();
var types = config.ChangeTypes.ToArray();
types.Should().BeEquivalentTo([typeof(NewDefinitionChange), typeof(SetWordTextChange)]);
}
}
2 changes: 2 additions & 0 deletions src/SIL.Harmony/CrdtConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public class CrdtConfig
/// </summary>
public bool AlwaysValidateCommits { get; set; } = true;
public ChangeTypeListBuilder ChangeTypeListBuilder { get; } = new();
public IEnumerable<Type> ChangeTypes => ChangeTypeListBuilder.Types.Select(t => t.DerivedType);
public ObjectTypeListBuilder ObjectTypeListBuilder { get; } = new();
public IEnumerable<Type> ObjectTypes => ObjectTypeListBuilder.AdapterProviders.SelectMany(p => p.GetRegistrations().Select(r => r.ObjectDbType));
public JsonSerializerOptions JsonSerializerOptions => _lazyJsonSerializerOptions.Value;
private readonly Lazy<JsonSerializerOptions> _lazyJsonSerializerOptions;

Expand Down

0 comments on commit 451a997

Please sign in to comment.