diff --git a/src/SIL.Harmony.Tests/DefinitionTests.cs b/src/SIL.Harmony.Tests/DefinitionTests.cs index 5281548..e21e9c9 100644 --- a/src/SIL.Harmony.Tests/DefinitionTests.cs +++ b/src/SIL.Harmony.Tests/DefinitionTests.cs @@ -14,7 +14,7 @@ public async Task CanAddADefinitionToAWord() await WriteNextChange(NewDefinition(wordId, "a greeting", "verb")); var snapshot = await DataModel.GetProjectSnapshot(); var definitionSnapshot = snapshot.Snapshots.Values.Single(s => s.IsType()); - var definition = (Definition)await DataModel.GetBySnapshotId(definitionSnapshot.Id); + var definition = await DataModel.GetBySnapshotId(definitionSnapshot.Id); definition.Text.Should().Be("a greeting"); definition.WordId.Should().Be(wordId); } diff --git a/src/SIL.Harmony.Tests/ExampleSentenceTests.cs b/src/SIL.Harmony.Tests/ExampleSentenceTests.cs index fa6128c..aba4a6c 100644 --- a/src/SIL.Harmony.Tests/ExampleSentenceTests.cs +++ b/src/SIL.Harmony.Tests/ExampleSentenceTests.cs @@ -21,7 +21,7 @@ public async Task CanAddAnExampleSentenceToAWord() await WriteNextChange(NewExampleSentence(definitionId, "Hello, world!")); var snapshot = await DataModel.GetProjectSnapshot(); var exampleSentenceSnapshot = snapshot.Snapshots.Values.Single(s => s.IsType()); - var exampleSentence = (Example)await DataModel.GetBySnapshotId(exampleSentenceSnapshot.Id); + var exampleSentence = await DataModel.GetBySnapshotId(exampleSentenceSnapshot.Id); exampleSentence.Text.Should().Be("Hello, world!"); exampleSentence.DefinitionId.Should().Be(definitionId); } diff --git a/src/SIL.Harmony.Tests/ModelSnapshotTests.cs b/src/SIL.Harmony.Tests/ModelSnapshotTests.cs index 8700460..90bed26 100644 --- a/src/SIL.Harmony.Tests/ModelSnapshotTests.cs +++ b/src/SIL.Harmony.Tests/ModelSnapshotTests.cs @@ -28,7 +28,7 @@ public async Task ModelSnapshotShowsMultipleChanges() var secondChange = await WriteNextChange(SetWord(entityId, "second")); var snapshot = await DataModel.GetProjectSnapshot(); var simpleSnapshot = snapshot.Snapshots.Values.First(); - var entry = (Word) await DataModel.GetBySnapshotId(simpleSnapshot.Id); + var entry = await DataModel.GetBySnapshotId(simpleSnapshot.Id); entry.Text.Should().Be("second"); snapshot.LastChange.Should().Be(secondChange.DateTime); } diff --git a/src/SIL.Harmony.Tests/SyncTests.cs b/src/SIL.Harmony.Tests/SyncTests.cs index 221f04f..4e3f0c0 100644 --- a/src/SIL.Harmony.Tests/SyncTests.cs +++ b/src/SIL.Harmony.Tests/SyncTests.cs @@ -45,9 +45,9 @@ public async Task CanSyncSimpleChange() var client1Snapshot = await _client1.DataModel.GetProjectSnapshot(); var client2Snapshot = await _client2.DataModel.GetProjectSnapshot(); client1Snapshot.LastCommitHash.Should().Be(client2Snapshot.LastCommitHash); - var client2Entity1 = (Word) await _client2.DataModel.GetBySnapshotId(client2Snapshot.Snapshots[entity1Id].Id); + var client2Entity1 = await _client2.DataModel.GetBySnapshotId(client2Snapshot.Snapshots[entity1Id].Id); client2Entity1.Text.Should().Be("entity1"); - var client1Entity2 = (Word) await _client1.DataModel.GetBySnapshotId(client1Snapshot.Snapshots[entity2Id].Id); + var client1Entity2 = await _client1.DataModel.GetBySnapshotId(client1Snapshot.Snapshots[entity2Id].Id); client1Entity2.Text.Should().Be("entity2"); } @@ -93,12 +93,12 @@ public async Task SyncMultipleClientChanges(int clientCount) serverSnapshot.Snapshots.Should().HaveCount(clientCount + 1); foreach (var entitySnapshot in serverSnapshot.Snapshots.Values) { - var serverEntity = (Word) await _client1.DataModel.GetBySnapshotId(entitySnapshot.Id); + var serverEntity = await _client1.DataModel.GetBySnapshotId(entitySnapshot.Id); foreach (var client in clients) { var clientSnapshot = await client.DataModel.GetProjectSnapshot(); var simpleSnapshot = clientSnapshot.Snapshots.Should().ContainKey(entitySnapshot.EntityId).WhoseValue; - var entity = (Word) await client.DataModel.GetBySnapshotId(simpleSnapshot.Id); + var entity = await client.DataModel.GetBySnapshotId(simpleSnapshot.Id); entity.Should().BeEquivalentTo(serverEntity); } } diff --git a/src/SIL.Harmony/DataModel.cs b/src/SIL.Harmony/DataModel.cs index 176bb7a..a0e0292 100644 --- a/src/SIL.Harmony/DataModel.cs +++ b/src/SIL.Harmony/DataModel.cs @@ -219,9 +219,9 @@ public IQueryable GetLatestObjects() where T : class return q; } - public async Task GetBySnapshotId(Guid snapshotId) + public async Task GetBySnapshotId(Guid snapshotId) { - return await _crdtRepository.GetObjectBySnapshotId(snapshotId); + return await _crdtRepository.GetObjectBySnapshotId(snapshotId); } public async Task> GetSnapshotsAt(DateTimeOffset dateTime) diff --git a/src/SIL.Harmony/Db/CrdtRepository.cs b/src/SIL.Harmony/Db/CrdtRepository.cs index 2a4ea39..bb94e70 100644 --- a/src/SIL.Harmony/Db/CrdtRepository.cs +++ b/src/SIL.Harmony/Db/CrdtRepository.cs @@ -158,14 +158,14 @@ public async Task GetCommitsAfter(Commit? commit) .LastOrDefaultAsync(s => s.EntityId == objectId && (ignoreChangesAfter == null || s.Commit.DateTime <= ignoreChangesAfter)); } - public async Task GetObjectBySnapshotId(Guid snapshotId) + public async Task GetObjectBySnapshotId(Guid snapshotId) { var entity = await Snapshots .Where(s => s.Id == snapshotId) .Select(s => s.Entity) .SingleOrDefaultAsync() ?? throw new ArgumentException($"unable to find snapshot with id {snapshotId}"); - return entity; + return (T) entity; } public async Task GetCurrent(Guid objectId) where T: class