-
-
Notifications
You must be signed in to change notification settings - Fork 466
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
querying child collections impacts each other
- Loading branch information
1 parent
3344754
commit 47d1896
Showing
1 changed file
with
160 additions
and
0 deletions.
There are no files selected for viewing
160 changes: 160 additions & 0 deletions
160
src/DocumentDbTests/Bugs/querying_child_collections_impact_each_other.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,160 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Marten; | ||
using Marten.Testing.Harness; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace DocumentDbTests.Bugs; | ||
|
||
public class querying_child_collections_impact_each_other: IntegrationContext | ||
{ | ||
public querying_child_collections_impact_each_other(DefaultStoreFixture fixture): base(fixture) { } | ||
|
||
[Fact] | ||
public async Task query_collection_property_before_querying_against_collection_of_values() | ||
{ | ||
StoreOptions(_ => | ||
{ | ||
_.Schema.For<One>(); | ||
_.Schema.For<Two>(); | ||
}); | ||
|
||
var guid1 = Guid.NewGuid(); | ||
|
||
theSession.Store(new One { Id = Guid.NewGuid(), Guids = new List<Guid>() { guid1, new Guid() } }); | ||
theSession.Store(new One { Id = Guid.NewGuid(), Guids = new List<Guid>() { guid1, new Guid() } }); | ||
theSession.Store(new Two { Id = guid1 }); | ||
theSession.Store(new Two { Id = Guid.NewGuid() }); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
await using (var query = theStore.LightweightSession()) | ||
{ | ||
var result = await query.Query<One>() | ||
.Where(x => x.Guids.Contains(guid1)) | ||
.ToListAsync(); | ||
|
||
result.Count.ShouldBe(2); | ||
} | ||
|
||
await using (var query = theStore.LightweightSession()) | ||
{ | ||
var guids = new List<Guid> { guid1, new Guid() }; | ||
var result = await query.Query<Two>() | ||
.Where(x => guids.Contains(x.Id)) | ||
.ToListAsync(); | ||
|
||
result.Count.ShouldBe(1); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task query_collection_of_values_before_querying_against_collection_property() | ||
{ | ||
StoreOptions(_ => | ||
{ | ||
_.Schema.For<One>(); | ||
_.Schema.For<Two>(); | ||
}); | ||
|
||
var guid1 = Guid.NewGuid(); | ||
|
||
theSession.Store(new One { Id = Guid.NewGuid(), Guids = new List<Guid>() { guid1, new Guid() } }); | ||
theSession.Store(new One { Id = Guid.NewGuid(), Guids = new List<Guid>() { guid1, new Guid() } }); | ||
theSession.Store(new Two { Id = guid1 }); | ||
theSession.Store(new Two { Id = Guid.NewGuid() }); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
await using (var query = theStore.LightweightSession()) | ||
{ | ||
var guids = new List<Guid> { guid1, new Guid() }; | ||
var result = await query.Query<Two>() | ||
.Where(x => guids.Contains(x.Id)) | ||
.ToListAsync(); | ||
|
||
result.Count.ShouldBe(1); | ||
} | ||
|
||
await using (var query = theStore.LightweightSession()) | ||
{ | ||
var result = await query.Query<One>() | ||
.Where(x => x.Guids.Contains(guid1)) | ||
.ToListAsync(); | ||
|
||
result.Count.ShouldBe(2); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task query_collection_of_values_works_on_its_own() | ||
{ | ||
StoreOptions(_ => | ||
{ | ||
_.Schema.For<One>(); | ||
_.Schema.For<Two>(); | ||
}); | ||
|
||
var guid1 = Guid.NewGuid(); | ||
|
||
theSession.Store(new One { Id = Guid.NewGuid(), Guids = new List<Guid>() { guid1, new Guid() } }); | ||
theSession.Store(new One { Id = Guid.NewGuid(), Guids = new List<Guid>() { guid1, new Guid() } }); | ||
theSession.Store(new Two { Id = guid1 }); | ||
theSession.Store(new Two { Id = Guid.NewGuid() }); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
await using (var query = theStore.LightweightSession()) | ||
{ | ||
var guids = new List<Guid> { guid1, new Guid() }; | ||
var result = await query.Query<Two>() | ||
.Where(x => guids.Contains(x.Id)) | ||
.ToListAsync(); | ||
|
||
result.Count.ShouldBe(1); | ||
} | ||
} | ||
|
||
[Fact] | ||
public async Task query_collection_property_works_on_its_own() | ||
{ | ||
StoreOptions(_ => | ||
{ | ||
_.Schema.For<One>(); | ||
_.Schema.For<Two>(); | ||
}); | ||
|
||
var guid1 = Guid.NewGuid(); | ||
|
||
theSession.Store(new One { Id = Guid.NewGuid(), Guids = new List<Guid>() { guid1, new Guid() } }); | ||
theSession.Store(new One { Id = Guid.NewGuid(), Guids = new List<Guid>() { guid1, new Guid() } }); | ||
theSession.Store(new Two { Id = guid1 }); | ||
theSession.Store(new Two { Id = Guid.NewGuid() }); | ||
|
||
await theSession.SaveChangesAsync(); | ||
|
||
await using (var query = theStore.LightweightSession()) | ||
{ | ||
var result = await query.Query<One>() | ||
.Where(x => x.Guids.Contains(guid1)) | ||
.ToListAsync(); | ||
|
||
result.Count.ShouldBe(2); | ||
} | ||
} | ||
|
||
public class One | ||
{ | ||
public Guid Id { get; set; } | ||
|
||
public List<Guid> Guids { get; set; } = new(); | ||
} | ||
|
||
public class Two | ||
{ | ||
public Guid Id { get; set; } | ||
} | ||
} |