-
-
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.
Test to verify Linq bug on sub collection queries was fixed. Closed G…
- Loading branch information
1 parent
132ecf1
commit 861f255
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/LinqTests/Bugs/Bug_2563_sub_collection_queries_and_OR.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,58 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Marten; | ||
using Marten.Testing.Harness; | ||
using Shouldly; | ||
using Xunit.Abstractions; | ||
|
||
namespace LinqTests.Bugs; | ||
|
||
public class Bug_2563_sub_collection_queries_and_OR : BugIntegrationContext | ||
{ | ||
private readonly ITestOutputHelper _output; | ||
|
||
public Bug_2563_sub_collection_queries_and_OR(ITestOutputHelper output) | ||
{ | ||
_output = output; | ||
} | ||
|
||
[Fact] | ||
public async Task get_distinct_number() | ||
{ | ||
theStore.Options.Schema.For<Target>() | ||
.Duplicate(x => x.UserIds); | ||
|
||
theSession.Store(new Target {Id = 1, IsPublic = false, UserIds = new [] { 1, 2, 3, 4, 5, 6 }}); | ||
theSession.Store(new Target {Id = 2, IsPublic = false, UserIds = new int[] { }}); | ||
theSession.Store(new Target {Id = 3, IsPublic = true, UserIds = new [] { 1, 2, 3 }}); | ||
theSession.Store(new Target {Id = 4, IsPublic = true, UserIds = new [] { 1, 2, 6 }}); | ||
theSession.Store(new Target {Id = 5, IsPublic = false, UserIds = new [] { 4, 5, 6 }}); | ||
theSession.Store(new Target {Id = 6, IsPublic = true, UserIds = new [] { 10 }}); | ||
|
||
await theSession.SaveChangesAsync(); | ||
theSession.Logger = new TestOutputMartenLogger(_output); | ||
|
||
|
||
var result1 = await theSession.Query<Target>() | ||
.Where(x => x.IsPublic == false || x.UserIds.Contains(10)) | ||
.ToListAsync(); | ||
|
||
result1.Count.ShouldBeEquivalentTo(4); | ||
|
||
// This should pass without any error as the query will return results | ||
var result2 = await theSession.Query<Target>().Where(x => x.IsPublic || x.UserIds.Contains(5)).ToListAsync(); | ||
|
||
result2.ShouldContain(x => x.Id == 1); | ||
result2.ShouldContain(x => x.Id == 5); | ||
} | ||
|
||
public class Target | ||
{ | ||
public int Id { get; set; } | ||
|
||
public bool IsPublic { get; set; } | ||
|
||
public int[] UserIds { get; set; } | ||
} | ||
} | ||
|