-
Couldn't load subscription status.
- Fork 1
Make NewEntry override deleted #54
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
Merged
+319
−25
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
0fe7a07
Make NewEntity override deleted
myieye 00bd310
Save changes even if no snapshots were created
myieye 6755b88
Restore save-changes in loop
myieye d4d2126
Fix projecting deleted and undeleted snapshots of same entity
myieye 5986c56
Test no-op NewEntity
myieye 0fde24a
Add note explaining redundant try/catch
myieye 277fc2d
Fix insufficient commit ordering
myieye 5bbf018
Add debug assert for what is now an unexpected code path.
myieye 4f0ce0a
Add comments/docs
myieye File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,215 @@ | ||
| using Microsoft.EntityFrameworkCore; | ||
| using SIL.Harmony.Changes; | ||
| using SIL.Harmony.Sample.Changes; | ||
| using SIL.Harmony.Sample.Models; | ||
|
|
||
| namespace SIL.Harmony.Tests; | ||
|
|
||
| public class DeleteAndCreateTests : DataModelTestBase | ||
| { | ||
| [Fact] | ||
| public async Task DeleteAndUndeleteInSameCommitWorks() | ||
| { | ||
| var wordId = Guid.NewGuid(); | ||
|
|
||
| await WriteNextChange(new NewWordChange(wordId, "original")); | ||
|
|
||
| await WriteNextChange( | ||
| [ | ||
| new DeleteChange<Word>(wordId), | ||
| new NewWordChange(wordId, "Undeleted"), | ||
| ]); | ||
|
|
||
| var word = await DataModel.GetLatest<Word>(wordId); | ||
| word.Should().NotBeNull(); | ||
| word.DeletedAt.Should().BeNull(); | ||
| word.Text.Should().Be("Undeleted"); | ||
|
|
||
| var entityWord = await DataModel.QueryLatest<Word>().Where(w => w.Id == wordId).SingleOrDefaultAsync(); | ||
| entityWord.Should().NotBeNull(); | ||
| entityWord.DeletedAt.Should().BeNull(); | ||
| entityWord.Text.Should().Be("Undeleted"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task DeleteAndUndeleteInSameSyncWorks() | ||
| { | ||
| var wordId = Guid.NewGuid(); | ||
|
|
||
| await WriteNextChange(new NewWordChange(wordId, "original")); | ||
|
|
||
| await AddCommitsViaSync([ | ||
| await WriteNextChange(new DeleteChange<Word>(wordId), add: false), | ||
| await WriteNextChange(new NewWordChange(wordId, "Undeleted"), add: false), | ||
| ]); | ||
|
|
||
| var word = await DataModel.GetLatest<Word>(wordId); | ||
| word.Should().NotBeNull(); | ||
| word.DeletedAt.Should().BeNull(); | ||
| word.Text.Should().Be("Undeleted"); | ||
|
|
||
| var entityWord = await DataModel.QueryLatest<Word>().Where(w => w.Id == wordId).SingleOrDefaultAsync(); | ||
| entityWord.Should().NotBeNull(); | ||
| entityWord.DeletedAt.Should().BeNull(); | ||
| entityWord.Text.Should().Be("Undeleted"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task UpdateAndUndeleteInSameCommitWorks() | ||
| { | ||
| var wordId = Guid.NewGuid(); | ||
|
|
||
| await WriteNextChange(new NewWordChange(wordId, "original")); | ||
| await WriteNextChange(new DeleteChange<Word>(wordId)); | ||
|
|
||
| await WriteNextChange([ | ||
| new SetWordNoteChange(wordId, "overridden-note"), | ||
| new NewWordChange(wordId, "Undeleted"), | ||
| ]); | ||
|
|
||
| var word = await DataModel.GetLatest<Word>(wordId); | ||
| word.Should().NotBeNull(); | ||
| word.DeletedAt.Should().BeNull(); | ||
| word.Text.Should().Be("Undeleted"); | ||
|
|
||
| var entityWord = await DataModel.QueryLatest<Word>().Where(w => w.Id == wordId).SingleOrDefaultAsync(); | ||
| entityWord.Should().NotBeNull(); | ||
| entityWord.DeletedAt.Should().BeNull(); | ||
| entityWord.Text.Should().Be("Undeleted"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task UpdateAndUndeleteInSameSyncWorks() | ||
| { | ||
| var wordId = Guid.NewGuid(); | ||
|
|
||
| await WriteNextChange(new NewWordChange(wordId, "original")); | ||
| await WriteNextChange(new DeleteChange<Word>(wordId)); | ||
|
|
||
| await AddCommitsViaSync([ | ||
| await WriteNextChange(new SetWordNoteChange(wordId, "overridden-note"), add: false), | ||
| await WriteNextChange(new NewWordChange(wordId, "Undeleted"), add: false), | ||
| ]); | ||
|
|
||
| var word = await DataModel.GetLatest<Word>(wordId); | ||
| word.Should().NotBeNull(); | ||
| word.DeletedAt.Should().BeNull(); | ||
| word.Text.Should().Be("Undeleted"); | ||
|
|
||
| var entityWord = await DataModel.QueryLatest<Word>().Where(w => w.Id == wordId).SingleOrDefaultAsync(); | ||
| entityWord.Should().NotBeNull(); | ||
| entityWord.DeletedAt.Should().BeNull(); | ||
| entityWord.Text.Should().Be("Undeleted"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateDeleteAndUndeleteInSameCommitWorks() | ||
| { | ||
| var wordId = Guid.NewGuid(); | ||
|
|
||
| await WriteNextChange( | ||
| [ | ||
| new NewWordChange(wordId, "original"), | ||
| new DeleteChange<Word>(wordId), | ||
| new NewWordChange(wordId, "Undeleted"), | ||
| ]); | ||
|
|
||
| var word = await DataModel.GetLatest<Word>(wordId); | ||
| word.Should().NotBeNull(); | ||
| word.DeletedAt.Should().BeNull(); | ||
| word.Text.Should().Be("Undeleted"); | ||
|
|
||
| var entityWord = await DataModel.QueryLatest<Word>().Where(w => w.Id == wordId).SingleOrDefaultAsync(); | ||
| entityWord.Should().NotBeNull(); | ||
| entityWord.DeletedAt.Should().BeNull(); | ||
| entityWord.Text.Should().Be("Undeleted"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateDeleteAndUndeleteInSameSyncWorks() | ||
| { | ||
| var wordId = Guid.NewGuid(); | ||
|
|
||
| await AddCommitsViaSync([ | ||
| await WriteNextChange(new NewWordChange(wordId, "original"), add: false), | ||
| await WriteNextChange(new DeleteChange<Word>(wordId), add: false), | ||
| await WriteNextChange(new NewWordChange(wordId, "Undeleted"), add: false), | ||
| ]); | ||
|
|
||
| var word = await DataModel.GetLatest<Word>(wordId); | ||
| word.Should().NotBeNull(); | ||
| word.DeletedAt.Should().BeNull(); | ||
| word.Text.Should().Be("Undeleted"); | ||
|
|
||
| var entityWord = await DataModel.QueryLatest<Word>().Where(w => w.Id == wordId).SingleOrDefaultAsync(); | ||
| entityWord.Should().NotBeNull(); | ||
| entityWord.DeletedAt.Should().BeNull(); | ||
| entityWord.Text.Should().Be("Undeleted"); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateAndDeleteInSameCommitWorks() | ||
| { | ||
| var wordId = Guid.NewGuid(); | ||
|
|
||
| await WriteNextChange( | ||
| [ | ||
| new NewWordChange(wordId, "original"), | ||
| new DeleteChange<Word>(wordId), | ||
| ]); | ||
|
|
||
| var word = await DataModel.GetLatest<Word>(wordId); | ||
| word.Should().NotBeNull(); | ||
| word.DeletedAt.Should().NotBeNull(); | ||
| word.Text.Should().Be("original"); | ||
|
|
||
| var entityWord = await DataModel.QueryLatest<Word>().Where(w => w.Id == wordId).SingleOrDefaultAsync(); | ||
| entityWord.Should().BeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task CreateAndDeleteInSameSyncWorks() | ||
| { | ||
| var wordId = Guid.NewGuid(); | ||
|
|
||
| await AddCommitsViaSync([ | ||
| await WriteNextChange(new NewWordChange(wordId, "original"), add: false), | ||
| await WriteNextChange(new DeleteChange<Word>(wordId), add: false), | ||
| ]); | ||
|
|
||
| var word = await DataModel.GetLatest<Word>(wordId); | ||
| word.Should().NotBeNull(); | ||
| word.DeletedAt.Should().NotBeNull(); | ||
| word.Text.Should().Be("original"); | ||
|
|
||
| var entityWord = await DataModel.QueryLatest<Word>().Where(w => w.Id == wordId).SingleOrDefaultAsync(); | ||
| entityWord.Should().BeNull(); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task NewEntityOnExistingEntityIsNoOp() | ||
| { | ||
| var wordId = Guid.NewGuid(); | ||
|
|
||
| await WriteNextChange(new NewWordChange(wordId, "original")); | ||
| var snapshotsBefore = await DbContext.Snapshots.Where(s => s.EntityId == wordId).ToArrayAsync(); | ||
|
|
||
| await WriteNextChange( | ||
| [ | ||
| new NewWordChange(wordId, "Undeleted"), | ||
| ]); | ||
|
|
||
| var word = await DataModel.GetLatest<Word>(wordId); | ||
| word.Should().NotBeNull(); | ||
| word.DeletedAt.Should().BeNull(); | ||
| word.Text.Should().Be("original"); | ||
|
|
||
| var entityWord = await DataModel.QueryLatest<Word>().Where(w => w.Id == wordId).SingleOrDefaultAsync(); | ||
| entityWord.Should().NotBeNull(); | ||
| entityWord.DeletedAt.Should().BeNull(); | ||
| entityWord.Text.Should().Be("original"); | ||
|
|
||
| var snapshotsAfter = await DbContext.Snapshots.Where(s => s.EntityId == wordId).ToArrayAsync(); | ||
| snapshotsAfter.Select(s => s.Id).Should().BeEquivalentTo(snapshotsBefore.Select(s => s.Id)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.