Skip to content

Commit 27d21ba

Browse files
committed
CSHARP-1913: Added tests for nested SelectMany.
1 parent 2cf31c2 commit 27d21ba

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1913Tests.cs

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,67 @@ public CSharp1913Tests(ClassFixture fixture)
3131
}
3232

3333
[Fact]
34-
public void SelectMany_with_ArrayOfArrays_representation_should_work()
34+
public void Nested__SelectMany_with_ArrayOfArrays_representation_should_work()
35+
{
36+
var collection = Fixture.Collection;
37+
38+
var queryable = collection.AsQueryable()
39+
.OfType<C>()
40+
.Where( to => to.Name == "TestName" )
41+
.Select( to => to.DictionaryWithArrayOfArraysRepresentation.SelectMany(kvp => new KeyValuePair<string, string>[] { kvp }) );
42+
43+
var stages = Translate(collection, queryable);
44+
AssertStages(
45+
stages,
46+
"{ $match : { Name : 'TestName' } }",
47+
"{ $project : { _v : { $reduce : { input : { $map : { input : '$DictionaryWithArrayOfArraysRepresentation', as : 'kvp', in : ['$$kvp'] } }, initialValue : [], in : { $concatArrays : ['$$value', '$$this'] } } }, _id : 0 } }");
48+
49+
var result = queryable.Single();
50+
result.Select(kvp => kvp.Key).Should().Equal("A", "B", "C");
51+
}
52+
53+
[Fact]
54+
public void Nested__SelectMany_with_ArrayOfDocuments_representation_should_work()
55+
{
56+
var collection = Fixture.Collection;
57+
58+
var queryable = collection.AsQueryable()
59+
.OfType<C>()
60+
.Where( to => to.Name == "TestName" )
61+
.Select( to => to.DictionaryWithArrayOfDocumentsRepresentation.SelectMany(kvp => new KeyValuePair<string, string>[] { kvp }) );
62+
63+
var stages = Translate(collection, queryable);
64+
AssertStages(
65+
stages,
66+
"{ $match : { Name : 'TestName' } }",
67+
"{ $project : { _v : { $reduce : { input : { $map : { input : '$DictionaryWithArrayOfDocumentsRepresentation', as : 'kvp', in : ['$$kvp'] } }, initialValue : [], in : { $concatArrays : ['$$value', '$$this'] } } }, _id : 0 } }");
68+
69+
var result = queryable.Single();
70+
result.Select(kvp => kvp.Key).Should().Equal("A", "B", "C");
71+
}
72+
73+
[Fact]
74+
public void Nested_SelectMany_with_Document_representation_should_work()
75+
{
76+
var collection = Fixture.Collection;
77+
78+
var queryable = collection.AsQueryable()
79+
.OfType<C>()
80+
.Where( to => to.Name == "TestName" )
81+
.Select( to => to.DictionaryWithDocumentRepresentation.SelectMany(kvp => new KeyValuePair<string, string>[] { kvp }) );
82+
83+
var stages = Translate(collection, queryable);
84+
AssertStages(
85+
stages,
86+
"{ $match : { Name : 'TestName' } }",
87+
"{ $project : { _v : { $reduce : { input : { $map : { input : { $objectToArray : '$DictionaryWithDocumentRepresentation' }, as : 'kvp', in : ['$$kvp'] } }, initialValue : [], in : { $concatArrays : ['$$value', '$$this'] } } }, _id : 0 } }");
88+
89+
var result = queryable.Single();
90+
result.Select(kvp => kvp.Key).Should().Equal("A", "B", "C");
91+
}
92+
93+
[Fact]
94+
public void Top_level_SelectMany_with_ArrayOfArrays_representation_should_work()
3595
{
3696
var collection = Fixture.Collection;
3797

@@ -58,7 +118,7 @@ public void SelectMany_with_ArrayOfArrays_representation_should_work()
58118
}
59119

60120
[Fact]
61-
public void SelectMany_with_ArrayOfDocuments_representation_should_work()
121+
public void Top_level_SelectMany_with_ArrayOfDocuments_representation_should_work()
62122
{
63123
var collection = Fixture.Collection;
64124

@@ -85,7 +145,7 @@ public void SelectMany_with_ArrayOfDocuments_representation_should_work()
85145
}
86146

87147
[Fact]
88-
public void SelectMany_with_Document_representation_should_work()
148+
public void Top_level_SelectMany_with_Document_representation_should_work()
89149
{
90150
var collection = Fixture.Collection;
91151

0 commit comments

Comments
 (0)