-
-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
making IDocumentSession.Delete() operations purge pending operations …
…involving that same document. Closes GH-2660
- Loading branch information
1 parent
3c0520a
commit b6efdc2
Showing
6 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
src/DocumentDbTests/Bugs/Bug_2660_deletes_in_complex_order.cs
This file contains 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,79 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Marten; | ||
using Marten.Testing.Harness; | ||
using Xunit; | ||
using Shouldly; | ||
|
||
namespace DocumentDbTests.Bugs; | ||
|
||
public class Bug_2660_deletes_in_complex_order : BugIntegrationContext | ||
{ | ||
// works | ||
[Fact] | ||
public async Task Deleting_Single_DocType_In_One_Session_Works() | ||
{ | ||
// store & delete within same session | ||
await using var session = theStore.IdentitySession(); | ||
var id = Guid.NewGuid(); | ||
session.Store(new FooModel() { Id = id }); | ||
session.Delete<FooModel>(id); | ||
await session.SaveChangesAsync(); | ||
|
||
await using var session2 = theStore.IdentitySession(); | ||
var model = await session.LoadAsync<FooModel>(id); | ||
model.ShouldBeNull(); | ||
} | ||
|
||
// fails | ||
[Fact] | ||
public async Task Deleting_Multiple_DocTypes_In_One_Session_Works() | ||
{ | ||
// store & delete within same session | ||
await using var session = theStore.IdentitySession(); | ||
var id = Guid.NewGuid(); | ||
session.Store(new FooModel() { Id = id }); | ||
session.Store(new BarModel() { Id = id }); | ||
session.Delete<FooModel>(id); | ||
session.Delete<BarModel>(id); | ||
|
||
session.PendingChanges.Operations().Count().ShouldBe(2); | ||
session.PendingChanges.Deletions().Count().ShouldBe(2); | ||
|
||
await session.SaveChangesAsync(); | ||
|
||
await using var session2 = theStore.IdentitySession(); | ||
var model = await session.LoadAsync<FooModel>(id); | ||
model.ShouldBeNull(); | ||
} | ||
|
||
// also fails | ||
[Fact] | ||
public async Task Delete_Where_Within_Same_Session_Doesnt_Affect_Actual_Delete() | ||
{ | ||
// store & delete in the same session | ||
using var session = theStore.IdentitySession(); | ||
var id = Guid.NewGuid(); | ||
session.Store(new FooModel() { Id = id }); | ||
session.Store(new BarModel() { Id = Guid.NewGuid(), RelGuid = id }); | ||
session.Delete<FooModel>(id); | ||
session.DeleteWhere<BarModel>(x => x.RelGuid == id); | ||
await session.SaveChangesAsync(); | ||
|
||
await using var session2 = theStore.IdentitySession(); | ||
var model = await session.LoadAsync<FooModel>(id); | ||
model.ShouldBeNull(); | ||
} | ||
} | ||
|
||
public class FooModel | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
|
||
public class BarModel | ||
{ | ||
public Guid Id { get; set; } | ||
public Guid RelGuid { get; set; } | ||
} |
This file contains 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 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 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 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 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