Skip to content

Commit 99ff1ed

Browse files
authored
CSHARP-5512: Convert LINQ-related tests to use fixtures (#1710)
1 parent f2a92e7 commit 99ff1ed

File tree

68 files changed

+1833
-1715
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1833
-1715
lines changed

tests/MongoDB.Driver.TestHelpers/IntegrationTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
using System;
1717
using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
18-
using MongoDB.TestHelpers.XunitExtensions;
1918
using Xunit;
2019

2120
namespace MongoDB.Driver.Tests

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@
1818
using FluentAssertions;
1919
using MongoDB.Bson;
2020
using MongoDB.Bson.Serialization.Attributes;
21+
using MongoDB.Driver.TestHelpers;
2122
using Xunit;
2223

2324
namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira
2425
{
25-
public class CSharp1326Tests : Linq3IntegrationTest
26+
public class CSharp1326Tests : LinqIntegrationTest<CSharp1326Tests.ClassFixture>
2627
{
28+
public CSharp1326Tests(ClassFixture fixture)
29+
: base(fixture)
30+
{
31+
}
32+
2733
[Fact]
2834
public void Projection_of_ArrayOfDocuments_dictionary_keys_and_values_should_work()
2935
{
30-
var collection = CreateCollection();
36+
var collection = Fixture.Collection;
3137
var parentIds = new int[] { 1, 2, 3 };
3238
var childrenFilter =
3339
Builders<Child>.Filter.In(c => c.ParentId, parentIds) &
@@ -52,21 +58,6 @@ public void Projection_of_ArrayOfDocuments_dictionary_keys_and_values_should_wor
5258
results[1].Value.Select(x => x.Id).Should().BeEquivalentTo(4);
5359
}
5460

55-
private IMongoCollection<Child> CreateCollection()
56-
{
57-
var collection = GetCollection<Child>("Children");
58-
59-
CreateCollection(
60-
collection,
61-
new Child { Id = 1, ParentId = 1, Gender = Gender.Male },
62-
new Child { Id = 2, ParentId = 1, Gender = Gender.Male },
63-
new Child { Id = 3, ParentId = 1, Gender = Gender.Female },
64-
new Child { Id = 4, ParentId = 2, Gender = Gender.Male },
65-
new Child { Id = 5, ParentId = 4, Gender = Gender.Male });
66-
67-
return collection;
68-
}
69-
7061
public class Parent
7162
{
7263
public int Id { get; set; }
@@ -83,5 +74,17 @@ public class Child
8374
}
8475

8576
public enum Gender { Male, Female };
77+
78+
public sealed class ClassFixture : MongoCollectionFixture<Child>
79+
{
80+
protected override IEnumerable<Child> InitialData =>
81+
[
82+
new Child { Id = 1, ParentId = 1, Gender = Gender.Male },
83+
new Child { Id = 2, ParentId = 1, Gender = Gender.Male },
84+
new Child { Id = 3, ParentId = 1, Gender = Gender.Female },
85+
new Child { Id = 4, ParentId = 2, Gender = Gender.Male },
86+
new Child { Id = 5, ParentId = 4, Gender = Gender.Male }
87+
];
88+
}
8689
}
8790
}

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,26 @@
1313
* limitations under the License.
1414
*/
1515

16+
using System.Collections.Generic;
1617
using System.Linq;
1718
using FluentAssertions;
1819
using MongoDB.Bson.Serialization.Attributes;
20+
using MongoDB.Driver.TestHelpers;
1921
using Xunit;
2022

2123
namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira
2224
{
23-
public class CSharp1555Tests : Linq3IntegrationTest
25+
public class CSharp1555Tests : LinqIntegrationTest<CSharp1555Tests.ClassFixture>
2426
{
27+
public CSharp1555Tests(ClassFixture fixture)
28+
: base(fixture)
29+
{
30+
}
31+
2532
[Fact]
2633
public void Queryable_should_work()
2734
{
28-
var collection = CreatePeopleCollection();
35+
var collection = Fixture.Collection;
2936
var queryable = collection.AsQueryable();
3037

3138
var stages = Translate(collection, queryable);
@@ -38,7 +45,7 @@ public void Queryable_should_work()
3845
[Fact]
3946
public void Select_new_Person_should_work()
4047
{
41-
var collection = CreatePeopleCollection();
48+
var collection = Fixture.Collection;
4249
var queryable = collection.AsQueryable()
4350
.Select(p => new Person { Id = p.Id, Name = p.Name });
4451

@@ -52,7 +59,7 @@ public void Select_new_Person_should_work()
5259
[Fact]
5360
public void Select_new_Person_without_Name_should_work()
5461
{
55-
var collection = CreatePeopleCollection();
62+
var collection = Fixture.Collection;
5663
var queryable = collection.AsQueryable()
5764
.Select(p => new Person { Id = p.Id });
5865

@@ -66,7 +73,7 @@ public void Select_new_Person_without_Name_should_work()
6673
[Fact]
6774
public void Select_new_Person_without_Id_should_work()
6875
{
69-
var collection = CreatePeopleCollection();
76+
var collection = Fixture.Collection;
7077
var queryable = collection.AsQueryable()
7178
.Select(p => new Person { Name = p.Name });
7279

@@ -77,25 +84,20 @@ public void Select_new_Person_without_Id_should_work()
7784
result.ShouldBeEquivalentTo(new Person { Id = 0, Name = "A" });
7885
}
7986

80-
private IMongoCollection<Person> CreatePeopleCollection()
81-
{
82-
var collection = GetCollection<Person>();
83-
84-
var documents = new[]
85-
{
86-
new Person { Id = 1, Name = "A" }
87-
};
88-
CreateCollection(collection, documents);
89-
90-
return collection;
91-
}
92-
93-
private class Person
87+
public class Person
9488
{
9589
[BsonIgnoreIfNull]
9690
public int Id { get; set; }
9791
[BsonIgnoreIfNull]
9892
public string Name { get; set; }
9993
}
94+
95+
public sealed class ClassFixture : MongoCollectionFixture<Person>
96+
{
97+
protected override IEnumerable<Person> InitialData =>
98+
[
99+
new Person { Id = 1, Name = "A" }
100+
];
101+
}
100102
}
101103
}

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,25 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
16+
using System.Collections.Generic;
1717
using System.Linq;
1818
using FluentAssertions;
19+
using MongoDB.Driver.TestHelpers;
1920
using Xunit;
2021

2122
namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira
2223
{
23-
public class CSharp1754Tests : Linq3IntegrationTest
24+
public class CSharp1754Tests : LinqIntegrationTest<CSharp1754Tests.ClassFixture>
2425
{
26+
public CSharp1754Tests(ClassFixture fixture)
27+
: base(fixture)
28+
{
29+
}
30+
2531
[Fact]
2632
public void Test()
2733
{
28-
var collection = CreateCollection();
34+
var collection = Fixture.Collection;
2935
var requiredMeta = new[] { "a", "b" };
3036

3137
var queryable = collection.AsQueryable()
@@ -38,20 +44,6 @@ public void Test()
3844
results.Select(r => r.Id).Should().Equal(2);
3945
}
4046

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-
5547
public class C
5648
{
5749
public int Id { get; set; }
@@ -62,5 +54,14 @@ public class Occurrence
6254
{
6355
public string[] Meta { get; set; }
6456
}
57+
58+
public sealed class ClassFixture : MongoCollectionFixture<C>
59+
{
60+
protected override IEnumerable<C> InitialData =>
61+
[
62+
new C { Id = 1, Occurrences = new[] { new Occurrence { Meta = new[] { "a" } } } },
63+
new C { Id = 2, Occurrences = new[] { new Occurrence { Meta = new[] { "a" } }, new Occurrence { Meta = new[] { "a", "b" } } } }
64+
];
65+
}
6566
}
6667
}

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

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,27 @@
1313
* limitations under the License.
1414
*/
1515

16-
using System;
16+
using System.Collections.Generic;
1717
using System.Linq;
1818
using System.Text.RegularExpressions;
1919
using FluentAssertions;
2020
using MongoDB.Driver.Linq;
21+
using MongoDB.Driver.TestHelpers;
2122
using Xunit;
2223

2324
namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira
2425
{
25-
public class CSharp1906Tests : Linq3IntegrationTest
26+
public class CSharp1906Tests : LinqIntegrationTest<CSharp1906Tests.ClassFixture>
2627
{
28+
public CSharp1906Tests(ClassFixture fixture)
29+
: base(fixture)
30+
{
31+
}
32+
2733
[Fact]
2834
public void Using_ToLower_should_work()
2935
{
30-
var collection = CreateCollection();
36+
var collection = Fixture.Collection;
3137
var lowerCaseValues = new[] { "abc", "def" }; // ensure all are lower case at compile time
3238
var queryable = collection.AsQueryable()
3339
.Where(c => lowerCaseValues.Contains(c.S.ToLower()));
@@ -42,7 +48,7 @@ public void Using_ToLower_should_work()
4248
[Fact]
4349
public void Using_regular_expression_should_work()
4450
{
45-
var collection = CreateCollection();
51+
var collection = Fixture.Collection;
4652
var regularExpresssion = new StringOrRegularExpression[] { new Regex("ABC", RegexOptions.IgnoreCase), new Regex("DEF", RegexOptions.IgnoreCase) };
4753
var queryable = collection.AsQueryable()
4854
.Where(c => c.S.StringIn(regularExpresssion));
@@ -54,25 +60,20 @@ public void Using_regular_expression_should_work()
5460
results.Select(x => x.Id).Should().Equal(1, 2);
5561
}
5662

57-
private IMongoCollection<C> CreateCollection()
63+
public class C
5864
{
59-
var collection = GetCollection<C>();
65+
public int Id { get; set; }
66+
public string S { get; set; }
67+
}
6068

61-
var documents = new[]
62-
{
69+
public sealed class ClassFixture : MongoCollectionFixture<C>
70+
{
71+
protected override IEnumerable<C> InitialData =>
72+
[
6373
new C { Id = 1, S = "aBc" },
6474
new C { Id = 2, S = "dEf" },
6575
new C { Id = 3, S = "gHi" }
66-
};
67-
CreateCollection(collection, documents);
68-
69-
return collection;
70-
}
71-
72-
public class C
73-
{
74-
public int Id { get; set; }
75-
public string S { get; set; }
76+
];
7677
}
7778
}
7879
}

0 commit comments

Comments
 (0)