Skip to content

Commit ee34ba7

Browse files
committed
CSHARP-1754: Verify that issue is not present in LINQ3.
1 parent 6b29843 commit ee34ba7

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/* Copyright 2010-present MongoDB Inc.
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
using System;
17+
using System.Linq;
18+
using FluentAssertions;
19+
using Xunit;
20+
21+
namespace MongoDB.Driver.Tests.Linq.Linq3ImplementationTests.Jira
22+
{
23+
public class CSharp1754Tests : Linq3IntegrationTest
24+
{
25+
[Fact]
26+
public void Test()
27+
{
28+
var collection = CreateCollection();
29+
var requiredMeta = new[] { "a", "b" };
30+
31+
var queryable = collection.AsQueryable()
32+
.Where(x => x.Occurrences.Any(o => requiredMeta.All(i => o.Meta.Contains(i))));
33+
34+
var stages = Translate(collection, queryable);
35+
AssertStages(stages, "{ $match : { Occurrences : { $elemMatch : { Meta : { $all : ['a', 'b'] } } } } }");
36+
37+
var results = queryable.ToList();
38+
results.Select(r => r.Id).Should().Equal(2);
39+
}
40+
41+
private IMongoCollection<C> CreateCollection()
42+
{
43+
var collection = GetCollection<C>();
44+
45+
var documents = new[]
46+
{
47+
new C { Id = 1, Occurrences = new[] { new Occurrence { Meta = new[] { "a" } } } },
48+
new C { Id = 2, Occurrences = new[] { new Occurrence { Meta = new[] { "a" } }, new Occurrence { Meta = new[] { "a", "b" } } } }
49+
};
50+
CreateCollection(collection, documents);
51+
52+
return collection;
53+
}
54+
55+
public class C
56+
{
57+
public int Id { get; set; }
58+
public Occurrence[] Occurrences { get; set; }
59+
}
60+
61+
public class Occurrence
62+
{
63+
public string[] Meta { get; set; }
64+
}
65+
}
66+
}

0 commit comments

Comments
 (0)