Skip to content

Commit

Permalink
add test to ensure changes are round tripped through the db properly
Browse files Browse the repository at this point in the history
  • Loading branch information
hahn-kev committed Sep 2, 2024
1 parent 93a14ff commit fedce8a
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions src/SIL.Harmony.Tests/RepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using SIL.Harmony.Tests.Mocks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using SIL.Harmony.Changes;
using SIL.Harmony.Sample.Changes;

namespace SIL.Harmony.Tests;

Expand Down Expand Up @@ -36,8 +38,23 @@ public async Task DisposeAsync()
await _services.DisposeAsync();
}

private Commit Commit(Guid id, HybridDateTime hybridDateTime) =>
new(id) { ClientId = Guid.Empty, HybridDateTime = hybridDateTime };
private Commit Commit(Guid id, HybridDateTime hybridDateTime)
{
var entityId = Guid.NewGuid();
return new Commit(id)
{
ClientId = Guid.Empty, HybridDateTime = hybridDateTime, ChangeEntities =
[
new ChangeEntity<IChange>()
{
Change = new SetWordTextChange(entityId, "test"),
CommitId = id,
EntityId = entityId,
Index = 0
}
]
};
}

private ObjectSnapshot Snapshot(Guid entityId, Guid commitId, HybridDateTime time)
{
Expand Down Expand Up @@ -257,4 +274,17 @@ await _repository.AddCommits([
}));
changes.MissingFromClient.Select(c => c.DateTime.ToUnixTimeMilliseconds()).Should().ContainSingle("because {0} is only before the last commit", commit2Time.DateTime.ToUnixTimeMilliseconds());
}

[Fact]
public async Task AddCommit_RoundTripsData()
{
var commit = Commit(Guid.NewGuid(), Time(1, 0));
await _repository.AddCommit(commit);

var queriedCommit = _repository.CurrentCommits()
.AsNoTracking()//ensures that the commit which is tracked above is not returned
.Include(c => c.ChangeEntities)
.Should().ContainSingle().Subject;
queriedCommit.Should().NotBeSameAs(commit).And.BeEquivalentTo(commit);
}
}

0 comments on commit fedce8a

Please sign in to comment.