Skip to content

Commit 02f397f

Browse files
committed
Add test to demonstrate hash validation
1 parent 2ad6cf4 commit 02f397f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/SIL.Harmony.Tests/DataModelIntegrityTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,21 @@ public async Task CanAddTheSameCommitMultipleTimesVisSync()
2929
var entry = await DataModel.GetLatest<Word>(entity1Id);
3030
entry!.Text.Should().Be("entity1.1");
3131
}
32+
33+
[Fact]
34+
public async Task InvalidCommitHashesResultInException()
35+
{
36+
// arrange
37+
var addedCommit = await WriteNextChange(SetWord(Guid.NewGuid(), "word"));
38+
39+
// act - break the hash
40+
addedCommit.SetParentHash("BBAADD");
41+
DbContext.SaveChanges();
42+
43+
// act - add another commit to trigger validation
44+
Func<Task> act = async () => await WriteNextChange(SetWord(Guid.NewGuid(), "word"));
45+
46+
// assert - validation detects the broken hash
47+
await act.Should().ThrowAsync<CommitValidationException>().WithMessage("*does not match expected hash*");
48+
}
3249
}

0 commit comments

Comments
 (0)