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

History apis #18

Merged
merged 10 commits into from
Nov 7, 2024
Prev Previous commit
Next Next commit
add explicit tests for CurrentSnapshots from a scoped repo
hahn-kev committed Oct 31, 2024
commit a11c91d266bbb82cf38b7f92b2bb83ba3820e39c
51 changes: 50 additions & 1 deletion src/SIL.Harmony.Tests/RepositoryTests.cs
Original file line number Diff line number Diff line change
@@ -211,6 +211,55 @@ await _repository.AddSnapshots([
snapshots.Should().ContainSingle().Which.Commit.HybridDateTime.Should().BeEquivalentTo(commit1Time);
}

[Fact]
public async Task ScopedRepo_CurrentSnapshots_FiltersByCounter()
{
var entityId = Guid.NewGuid();
//not sorting as we want to order based on the hybrid date time counter
Guid[] commitIds = [Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()];
var snapshot1 = Snapshot(entityId, commitIds[0], Time(1, 0));
var snapshot2 = Snapshot(entityId, commitIds[1], Time(2, 0));
var snapshot3 = Snapshot(entityId, commitIds[2], Time(2, 1));
await _repository.AddSnapshots([
snapshot3,
snapshot1,
snapshot2,
]);

var snapshots = await _repository.CurrentSnapshots().Include(s => s.Commit).ToArrayAsync();
var commit = snapshots.Should().ContainSingle().Subject.Commit;
commit.Id.Should().Be(commitIds[2]);

snapshots = await _repository.GetScopedRepository(snapshot2.Commit).CurrentSnapshots().Include(s => s.Commit)
.ToArrayAsync();
commit = snapshots.Should().ContainSingle().Subject.Commit;
commit.Id.Should().Be(commitIds[1], $"commit order: [{string.Join(", ", commitIds)}]");
}

[Fact]
public async Task ScopedRepo_CurrentSnapshots_FiltersByCommitId()
{
var entityId = Guid.NewGuid();
Guid[] commitIds = [Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()];
Array.Sort(commitIds);
var snapshot1 = Snapshot(entityId, commitIds[0], Time(1, 0));
var snapshot2 = Snapshot(entityId, commitIds[1], Time(2, 0));
var snapshot3 = Snapshot(entityId, commitIds[2], Time(2, 0));
await _repository.AddSnapshots([
snapshot3,
snapshot1,
snapshot2,
]);

var snapshots = await _repository.CurrentSnapshots().Include(s => s.Commit).ToArrayAsync();
var commit = snapshots.Should().ContainSingle().Subject.Commit;
commit.Id.Should().Be(commitIds[2]);

snapshots = await _repository.GetScopedRepository(snapshot2.Commit).CurrentSnapshots().Include(s => s.Commit).ToArrayAsync();
commit = snapshots.Should().ContainSingle().Subject.Commit;
commit.Id.Should().Be(commitIds[1], $"commit order: [{string.Join(", ", commitIds)}]");
}

[Fact]
public async Task DeleteStaleSnapshots_Works()
{
@@ -283,7 +332,7 @@ 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)