Skip to content

Commit 985e39d

Browse files
committed
CSHARP-4447: Standardize on how tests are run against both LINQ providers.
1 parent 1330dc5 commit 985e39d

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

tests/MongoDB.Driver.Tests/IMongoCollectionExtensionsTests.cs

+5-12
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ public void Aggregate_should_return_expected_result(
5959
[ParameterAttributeData]
6060
public void AsQueryable_should_return_expected_result(
6161
[Values(false, true)] bool withSession,
62-
[Values(2, 3)] int linqVersion)
62+
[Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider)
6363
{
64-
var collection = CreateMockCollection(linqVersion).Object;
64+
var collection = CreateMockCollection(linqProvider).Object;
6565
var session = withSession ? Mock.Of<IClientSessionHandle>() : null;
6666
var options = new AggregateOptions();
6767

@@ -75,16 +75,15 @@ public void AsQueryable_should_return_expected_result(
7575
result = collection.AsQueryable(options);
7676
}
7777

78-
if (linqVersion == 2)
78+
if (linqProvider == LinqProvider.V2)
7979
{
8080
var queryable = result.Should().BeOfType<Driver.Linq.Linq2Implementation.MongoQueryableImpl<Person, Person>>().Subject;
8181
var provider = queryable.Provider.Should().BeOfType<Driver.Linq.Linq2Implementation.MongoQueryProviderImpl<Person>>().Subject;
8282
provider._collection().Should().BeSameAs(collection);
8383
provider._options().Should().BeSameAs(options);
8484
provider._session().Should().BeSameAs(session);
8585
}
86-
87-
if (linqVersion == 3)
86+
else
8887
{
8988
var queryable = result.Should().BeOfType<Driver.Linq.Linq3Implementation.MongoQuery<Person, Person>>().Subject;
9089
var provider = queryable.Provider.Should().BeOfType<Driver.Linq.Linq3Implementation.MongoQueryProvider<Person>>().Subject;
@@ -1234,15 +1233,9 @@ public void Watch_should_call_collection_with_expected_arguments(
12341233
}
12351234
}
12361235

1237-
private Mock<IMongoCollection<Person>> CreateMockCollection(int linqVersion = 2)
1236+
private Mock<IMongoCollection<Person>> CreateMockCollection(LinqProvider linqProvider = LinqProvider.V2)
12381237
{
12391238
var mockClient = new Mock<IMongoClient>();
1240-
var linqProvider = linqVersion switch
1241-
{
1242-
2 => LinqProvider.V2,
1243-
3 => LinqProvider.V3,
1244-
_ => throw new ArgumentException($"Invalid linqVersion: {linqVersion}.", nameof(linqVersion))
1245-
};
12461239
var clientSettings = new MongoClientSettings { LinqProvider = linqProvider };
12471240
mockClient.SetupGet(c => c.Settings).Returns(clientSettings);
12481241

tests/MongoDB.Driver.Tests/Jira/CSharp4172Tests.cs

+7-6
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
using MongoDB.Bson.Serialization.Serializers;
2323
using MongoDB.Driver.Linq;
2424
using MongoDB.Driver.Tests.Linq.Linq3ImplementationTests;
25+
using MongoDB.TestHelpers.XunitExtensions;
2526
using Xunit;
2627

2728
namespace MongoDB.Driver.Tests.Jira
2829
{
2930
public class CSharp4172Tests : Linq3IntegrationTest
3031
{
3132
[Theory]
32-
[InlineData(LinqProvider.V2)]
33-
[InlineData(LinqProvider.V3)]
34-
public void Find_uses_the_expected_serializer(LinqProvider linqProvider)
33+
[ParameterAttributeData]
34+
public void Find_uses_the_expected_serializer(
35+
[Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider)
3536
{
3637
var collection = GetCollection<Order>(null, null, linqProvider);
3738

@@ -43,9 +44,9 @@ public void Find_uses_the_expected_serializer(LinqProvider linqProvider)
4344
}
4445

4546
[Theory]
46-
[InlineData(LinqProvider.V2)]
47-
[InlineData(LinqProvider.V3)]
48-
public void Aggregate_uses_the_expected_serializer(LinqProvider linqProvider)
47+
[ParameterAttributeData]
48+
public void Aggregate_uses_the_expected_serializer(
49+
[Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider)
4950
{
5051
var collection = GetCollection<Order>(null, null, linqProvider);
5152

tests/MongoDB.Driver.Tests/Linq/Linq3ImplementationTests/Jira/CSharp4079Tests.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@ public class CSharp4079Tests : Linq3IntegrationTest
2828
[Theory]
2929
[ParameterAttributeData]
3030
public void Positional_operator_with_negative_one_array_index_should_work_or_throw_depending_on_Linq_provider(
31-
[Values(false, true)] bool useLinq2)
31+
[Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider)
3232
{
33-
var linqProvider = useLinq2 ? LinqProvider.V2 : LinqProvider.V3;
3433
var collection = GetCollection<C>();
3534

3635
var negativeOne = -1;
3736
var update = Builders<C>.Update.Set(x => x.A[negativeOne], 0); // using -1 constant is a compile time error
3837

39-
if (useLinq2)
38+
if (linqProvider == LinqProvider.V2)
4039
{
4140
var rendered = Render(update, linqProvider);
4241
rendered.Should().Be("{ $set : { 'A.$' : 0 } }");
@@ -51,14 +50,13 @@ public void Positional_operator_with_negative_one_array_index_should_work_or_thr
5150
[Theory]
5251
[ParameterAttributeData]
5352
public void Positional_operator_with_negative_one_ElementAt_should_work_or_throw_depending_on_Linq_provider(
54-
[Values(false, true)] bool useLinq2)
53+
[Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider)
5554
{
56-
var linqProvider = useLinq2 ? LinqProvider.V2 : LinqProvider.V3;
5755
var collection = GetCollection<C>();
5856

5957
var update = Builders<C>.Update.Set(x => x.A.ElementAt(-1), 0);
6058

61-
if (useLinq2)
59+
if (linqProvider == LinqProvider.V2)
6260
{
6361
var rendered = Render(update, linqProvider);
6462
rendered.Should().Be("{ $set : { 'A.$' : 0 } }");

tests/MongoDB.Driver.Tests/Samples/AggregationSample.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ public async Task States_with_pops_over_20000_queryable_method(
105105

106106
#if !MONO
107107
[Theory]
108-
[InlineData(LinqProvider.V2)]
109-
[InlineData(LinqProvider.V3)]
110-
public void States_with_pops_over_20000_queryable_syntax(LinqProvider linqProvider)
108+
[ParameterAttributeData]
109+
public void States_with_pops_over_20000_queryable_syntax(
110+
[Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider)
111111
{
112112
var client = DriverTestConfiguration.GetLinqClient(linqProvider);
113113
var database = client.GetDatabase(__collection.CollectionNamespace.DatabaseNamespace.DatabaseName);

0 commit comments

Comments
 (0)