diff --git a/tests/MongoDB.Driver.TestHelpers/IntegrationTest.cs b/tests/MongoDB.Driver.TestHelpers/IntegrationTest.cs index f373a4d897e..a1408959b6c 100644 --- a/tests/MongoDB.Driver.TestHelpers/IntegrationTest.cs +++ b/tests/MongoDB.Driver.TestHelpers/IntegrationTest.cs @@ -15,7 +15,6 @@ using System; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; -using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1326Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1326Tests.cs index f641013292b..4d30844b780 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1326Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1326Tests.cs @@ -18,16 +18,22 @@ using FluentAssertions; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp1326Tests : Linq3IntegrationTest + public class CSharp1326Tests : LinqIntegrationTest { + public CSharp1326Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Projection_of_ArrayOfDocuments_dictionary_keys_and_values_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var parentIds = new int[] { 1, 2, 3 }; var childrenFilter = Builders.Filter.In(c => c.ParentId, parentIds) & @@ -52,21 +58,6 @@ public void Projection_of_ArrayOfDocuments_dictionary_keys_and_values_should_wor results[1].Value.Select(x => x.Id).Should().BeEquivalentTo(4); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("Children"); - - CreateCollection( - collection, - new Child { Id = 1, ParentId = 1, Gender = Gender.Male }, - new Child { Id = 2, ParentId = 1, Gender = Gender.Male }, - new Child { Id = 3, ParentId = 1, Gender = Gender.Female }, - new Child { Id = 4, ParentId = 2, Gender = Gender.Male }, - new Child { Id = 5, ParentId = 4, Gender = Gender.Male }); - - return collection; - } - public class Parent { public int Id { get; set; } @@ -83,5 +74,17 @@ public class Child } public enum Gender { Male, Female }; + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Child { Id = 1, ParentId = 1, Gender = Gender.Male }, + new Child { Id = 2, ParentId = 1, Gender = Gender.Male }, + new Child { Id = 3, ParentId = 1, Gender = Gender.Female }, + new Child { Id = 4, ParentId = 2, Gender = Gender.Male }, + new Child { Id = 5, ParentId = 4, Gender = Gender.Male } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1555Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1555Tests.cs index 6260eec71d5..ad0cb8fdc47 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1555Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1555Tests.cs @@ -13,19 +13,26 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp1555Tests : Linq3IntegrationTest + public class CSharp1555Tests : LinqIntegrationTest { + public CSharp1555Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Queryable_should_work() { - var collection = CreatePeopleCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable(); var stages = Translate(collection, queryable); @@ -38,7 +45,7 @@ public void Queryable_should_work() [Fact] public void Select_new_Person_should_work() { - var collection = CreatePeopleCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(p => new Person { Id = p.Id, Name = p.Name }); @@ -52,7 +59,7 @@ public void Select_new_Person_should_work() [Fact] public void Select_new_Person_without_Name_should_work() { - var collection = CreatePeopleCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(p => new Person { Id = p.Id }); @@ -66,7 +73,7 @@ public void Select_new_Person_without_Name_should_work() [Fact] public void Select_new_Person_without_Id_should_work() { - var collection = CreatePeopleCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(p => new Person { Name = p.Name }); @@ -77,25 +84,20 @@ public void Select_new_Person_without_Id_should_work() result.ShouldBeEquivalentTo(new Person { Id = 0, Name = "A" }); } - private IMongoCollection CreatePeopleCollection() - { - var collection = GetCollection(); - - var documents = new[] - { - new Person { Id = 1, Name = "A" } - }; - CreateCollection(collection, documents); - - return collection; - } - - private class Person + public class Person { [BsonIgnoreIfNull] public int Id { get; set; } [BsonIgnoreIfNull] public string Name { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Person { Id = 1, Name = "A" } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1754Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1754Tests.cs index 363079b1652..26a8c6c0c02 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1754Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1754Tests.cs @@ -13,19 +13,25 @@ * limitations under the License. */ -using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp1754Tests : Linq3IntegrationTest + public class CSharp1754Tests : LinqIntegrationTest { + public CSharp1754Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Test() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var requiredMeta = new[] { "a", "b" }; var queryable = collection.AsQueryable() @@ -38,20 +44,6 @@ public void Test() results.Select(r => r.Id).Should().Equal(2); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - - var documents = new[] - { - new C { Id = 1, Occurrences = new[] { new Occurrence { Meta = new[] { "a" } } } }, - new C { Id = 2, Occurrences = new[] { new Occurrence { Meta = new[] { "a" } }, new Occurrence { Meta = new[] { "a", "b" } } } } - }; - CreateCollection(collection, documents); - - return collection; - } - public class C { public int Id { get; set; } @@ -62,5 +54,14 @@ public class Occurrence { public string[] Meta { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, Occurrences = new[] { new Occurrence { Meta = new[] { "a" } } } }, + new C { Id = 2, Occurrences = new[] { new Occurrence { Meta = new[] { "a" } }, new Occurrence { Meta = new[] { "a", "b" } } } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1906Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1906Tests.cs index dba72f7fb13..534cca49414 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1906Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp1906Tests.cs @@ -13,21 +13,27 @@ * limitations under the License. */ -using System; +using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using FluentAssertions; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp1906Tests : Linq3IntegrationTest + public class CSharp1906Tests : LinqIntegrationTest { + public CSharp1906Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Using_ToLower_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var lowerCaseValues = new[] { "abc", "def" }; // ensure all are lower case at compile time var queryable = collection.AsQueryable() .Where(c => lowerCaseValues.Contains(c.S.ToLower())); @@ -42,7 +48,7 @@ public void Using_ToLower_should_work() [Fact] public void Using_regular_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var regularExpresssion = new StringOrRegularExpression[] { new Regex("ABC", RegexOptions.IgnoreCase), new Regex("DEF", RegexOptions.IgnoreCase) }; var queryable = collection.AsQueryable() .Where(c => c.S.StringIn(regularExpresssion)); @@ -54,25 +60,20 @@ public void Using_regular_expression_should_work() results.Select(x => x.Id).Should().Equal(1, 2); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection(); + public int Id { get; set; } + public string S { get; set; } + } - var documents = new[] - { + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new C { Id = 1, S = "aBc" }, new C { Id = 2, S = "dEf" }, new C { Id = 3, S = "gHi" } - }; - CreateCollection(collection, documents); - - return collection; - } - - public class C - { - public int Id { get; set; } - public string S { get; set; } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2003Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2003Tests.cs index 075436de3b1..c68696c8285 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2003Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2003Tests.cs @@ -14,18 +14,25 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp2003Tests : Linq3IntegrationTest + public class CSharp2003Tests : LinqIntegrationTest { + public CSharp2003Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Find_BitsAllClear_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var mask = E.E2 | E.E4; var find = collection.Find(x => (x.E & mask) == 0); @@ -39,7 +46,7 @@ public void Find_BitsAllClear_should_work() [Fact] public void Find_BitsAllSet_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var mask = E.E2 | E.E4; var find = collection.Find(x => (x.E & mask) == mask); @@ -53,7 +60,7 @@ public void Find_BitsAllSet_should_work() [Fact] public void Find_BitsAnyClear_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var mask = E.E2 | E.E4; var find = collection.Find(x => (x.E & mask) != mask); @@ -67,7 +74,7 @@ public void Find_BitsAnyClear_should_work() [Fact] public void Find_BitsAnySet_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var mask = E.E2 | E.E4; var find = collection.Find(x => (x.E & mask) != 0); @@ -81,7 +88,7 @@ public void Find_BitsAnySet_should_work() [Fact] public void Where_BitsAllClear_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var mask = E.E2 | E.E4; var queryable = collection.AsQueryable().Where(x => (x.E & mask) == 0); @@ -95,7 +102,7 @@ public void Where_BitsAllClear_should_work() [Fact] public void Where_BitsAllSet_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var mask = E.E2 | E.E4; var queryable = collection.AsQueryable().Where(x => (x.E & mask) == mask); @@ -109,7 +116,7 @@ public void Where_BitsAllSet_should_work() [Fact] public void Where_BitsAnyClear_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var mask = E.E2 | E.E4; var queryable = collection.AsQueryable().Where(x => (x.E & mask) != mask); @@ -123,7 +130,7 @@ public void Where_BitsAnyClear_should_work() [Fact] public void Where_BitsAnySet_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var mask = E.E2 | E.E4; var queryable = collection.AsQueryable().Where(x => (x.E & mask) != 0); @@ -134,25 +141,10 @@ public void Where_BitsAnySet_should_work() results.Select(x => x.Id).Should().Equal(2, 4, 6); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - - var documents = new[] - { - new C { Id = 1, E = E.E1 }, - new C { Id = 2, E = E.E2 }, - new C { Id = 4, E = E.E4 }, - new C { Id = 6, E = E.E2 | E.E4 }, - new C { Id = 8, E = E.E8 } - }; - CreateCollection(collection, documents); - - return collection; - } - [Flags] - private enum E +#pragma warning disable CA1714 + public enum E +#pragma warning restore CA1714 { E1 = 1, E2 = 2, @@ -160,10 +152,22 @@ private enum E E8 = 8 } - private class C + public class C { public int Id { get; set; } public E E; } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, E = E.E1 }, + new C { Id = 2, E = E.E2 }, + new C { Id = 4, E = E.E4 }, + new C { Id = 6, E = E.E2 | E.E4 }, + new C { Id = 8, E = E.E8 } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2107Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2107Tests.cs index 9c5b2180dbf..98f330ff623 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2107Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2107Tests.cs @@ -13,21 +13,29 @@ * limitations under the License. */ +using System; using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Driver.Core.TestHelpers.XunitExtensions; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp2107Tests : Linq3IntegrationTest + public class CSharp2107Tests : LinqIntegrationTest { + public CSharp2107Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Aggregate_Project_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .Project(doc => new @@ -46,7 +54,7 @@ public void Aggregate_Project_should_work() [Fact] public void Queryable_Select_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(doc => new @@ -62,49 +70,44 @@ public void Queryable_Select_should_work() results[0].UserIsCustomer.Select(u => u.UserId).Should().Equal(1); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - - var documents = new[] - { - new Customer - { - Id = 1, - Users = new[] - { - new User { UserId = 1, Identity = new Identity { IdentityType = IdentityType.Type1 } }, - new User { UserId = 2, Identity = new Identity { IdentityType = IdentityType.Type2 } } - } - } - }; - CreateCollection(collection, documents); - - return collection; - } - - private class Customer + public class Customer { public int Id { get; set; } public IEnumerable Users { get; set; } } - private class User + public class User { public int UserId { get; set; } public Identity Identity { get; set; } } - private class Identity + public class Identity { [BsonRepresentation(BsonType.String)] public IdentityType IdentityType { get; set; } } - private enum IdentityType + public enum IdentityType { Type1, Type2 } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Customer + { + Id = 1, + Users = new[] + { + new User { UserId = 1, Identity = new Identity { IdentityType = IdentityType.Type1 } }, + new User { UserId = 2, Identity = new Identity { IdentityType = IdentityType.Type2 } } + } + } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2108Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2108Tests.cs index 03a98dc8e29..2b8ee28de3b 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2108Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2108Tests.cs @@ -14,23 +14,29 @@ */ using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using FluentAssertions; using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp2108Tests : Linq3IntegrationTest + public class CSharp2108Tests : LinqIntegrationTest { + public CSharp2108Tests(ClassFixture fixture) + : base(fixture, server => server.Supports(Feature.DateOperatorsNewIn50)) + { + } + [Fact] public void Aggregate_Project_should_work() { - RequireServer.Check().Supports(Feature.DateOperatorsNewIn50); - var collection = CreateCollection(); + var collection = Fixture.Collection; var endDate = DateTime.Parse("2020-01-03Z", null, DateTimeStyles.AdjustToUniversal); var queryable = collection.Aggregate() @@ -52,8 +58,7 @@ public void Aggregate_Project_should_work() [Fact] public void Queryable_Select_should_work() { - RequireServer.Check().Supports(Feature.DateOperatorsNewIn50); - var collection = CreateCollection(); + var collection = Fixture.Collection; var endDate = DateTime.Parse("2020-01-03Z", null, DateTimeStyles.AdjustToUniversal); var queryable = collection.AsQueryable() @@ -72,24 +77,19 @@ public void Queryable_Select_should_work() results[1].ShouldBeEquivalentTo(new { Days = 1 }); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection(); - - var documents = new[] - { - new C { Id = 1, StartDate = DateTime.Parse("2020-01-01Z", null, DateTimeStyles.AdjustToUniversal) }, - new C { Id = 2, StartDate = DateTime.Parse("2020-01-02Z", null, DateTimeStyles.AdjustToUniversal) } - }; - CreateCollection(collection, documents); - - return collection; + public int Id { get; set; } + public DateTime StartDate { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public DateTime StartDate { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 1, StartDate = DateTime.Parse("2020-01-01Z", null, DateTimeStyles.AdjustToUniversal) }, + new C { Id = 2, StartDate = DateTime.Parse("2020-01-02Z", null, DateTimeStyles.AdjustToUniversal) } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2195Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2195Tests.cs index e8d5f764d92..03163607bc0 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2195Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2195Tests.cs @@ -13,21 +13,27 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; using MongoDB.Bson.Serialization; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp2195Tests : Linq3IntegrationTest + public class CSharp2195Tests : LinqIntegrationTest { + public CSharp2195Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Filter_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var builder = Builders.Filter; var filter = builder.Eq(x => x["life"], 42); @@ -43,7 +49,7 @@ public void Filter_should_work() [Fact] public void Where_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -58,16 +64,13 @@ public void Where_should_work() results.Select(x => x["_id"].AsInt32).Should().Equal(2); } - private IMongoCollection CreateCollection() + public sealed class ClassFixture : MongoCollectionFixture { - var collection = GetCollection(); - - CreateCollection( - collection, + protected override IEnumerable InitialData => + [ new BsonDocument { { "_id", 1 }, { "life", 41 } }, - new BsonDocument { { "_id", 2 }, { "life", 42 } }); - - return GetCollection(); + new BsonDocument { { "_id", 2 }, { "life", 42 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2308Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2308Tests.cs index 0aee509d5ea..071d8a6a6c9 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2308Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2308Tests.cs @@ -17,42 +17,33 @@ using System.Linq; using FluentAssertions; using MongoDB.Bson; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { [Trait("Category", "Integration")] - public class CSharp2308Tests + public class CSharp2308Tests : LinqIntegrationTest { + public CSharp2308Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Nested_Select_should_work() { - var client = DriverTestConfiguration.Client; - var database = client.GetDatabase("FooBar"); - var collection = database.GetCollection("Foos"); - - database.DropCollection("Foos"); - - collection.InsertOne( - new FooNest - { - Name = "Parent", - NestedCollection = new[] { - new FooNest { - Name = "Child" - } - } - }); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(top => top.NestedCollection.Select(child => new { ParentName = top.Name, child.Name })); - var stages = Linq3TestHelpers.Translate(collection, queryable); + var stages = Translate(collection, queryable); var expectedStages = new[] { "{ $project : { _v : { $map : { input : '$NestedCollection', as : 'child', in : { ParentName : '$Name', Name : '$$child.Name' } } }, _id : 0 } }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); + AssertStages(stages, expectedStages); var pipelineDefinition = new BsonDocumentStagePipelineDefinition(stages); var resultAsDocument = collection.Aggregate(pipelineDefinition).ToList().Single(); @@ -69,5 +60,21 @@ public class FooNest public string Name; public IEnumerable NestedCollection; } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new FooNest + { + Name = "Parent", + NestedCollection = new[] { + new FooNest { + Name = "Child" + } + } + } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2348Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2348Tests.cs index fb61ec89f85..9f3c0b2b1c7 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2348Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2348Tests.cs @@ -13,20 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; -using MongoDB.Driver.Tests.Linq.Linq3Implementation; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3ImplementationTests.Jira { - public class CSharp2348Tests : Linq3IntegrationTest + public class CSharp2348Tests : LinqIntegrationTest { + public CSharp2348Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Any_with_equals_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var find = collection.Find(x => x.A.Any(v => v == 2)); @@ -40,7 +45,7 @@ public void Any_with_equals_should_work() [Fact] public void Any_with_or_of_equals_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var find = collection.Find(x => x.A.Any(v => v == 2 || v == 3)); @@ -54,7 +59,7 @@ public void Any_with_or_of_equals_should_work() [Fact] public void Any_with_or_of_equals_and_greater_than_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var find = collection.Find(x => x.A.Any(v => v == 2 || v > 3)); @@ -68,18 +73,6 @@ public void Any_with_or_of_equals_and_greater_than_should_work() results.Select(x => x.Id).Should().Equal(2, 4); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new User { Id = 1, A = new[] { 1 } }, - new User { Id = 2, A = new[] { 1, 2 } }, - new User { Id = 3, A = new[] { 1, 3 } }, - new User { Id = 4, A = new[] { 1, 4 } }); - return collection; - } - public class User { public int Id { get; set; } @@ -91,5 +84,16 @@ public enum Role Admin = 1, Editor = 2 } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new User { Id = 1, A = new[] { 1 } }, + new User { Id = 2, A = new[] { 1, 2 } }, + new User { Id = 3, A = new[] { 1, 3 } }, + new User { Id = 4, A = new[] { 1, 4 } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2472Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2472Tests.cs index 1ae5fc6f93b..035bba42f7e 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2472Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2472Tests.cs @@ -14,22 +14,26 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Driver.Core.Misc; -using MongoDB.Driver.Core.TestHelpers.XunitExtensions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp2472Tests : Linq3IntegrationTest + public class CSharp2472Tests : LinqIntegrationTest { + public CSharp2472Tests(ClassFixture fixture) + : base(fixture, server => server.Supports(Feature.ToConversionOperators)) + { + } + [Fact] public void Numeric_casts_should_work() { - RequireServer.Check().Supports(Feature.ToConversionOperators); - var collection = CreateCollection(); + var collection = Fixture.Collection; var equipmentId = 1; var startDate = new DateTime(2022, 01, 01, 0, 0, 0, DateTimeKind.Utc); var endDate = new DateTime(2022, 01, 02, 0, 0, 0, DateTimeKind.Utc); @@ -64,18 +68,7 @@ public void Numeric_casts_should_work() result.sqrt_calc.Should().Be(2M); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("C"); - - CreateCollection( - collection, - new C { Id = 1, equipment_id = 1, timestamp = new DateTime(2022, 01, 01, 12, 0, 0, DateTimeKind.Utc), my_decimal_value = 4M }); - - return collection; - } - - private class C + public class C { public int Id { get; set; } public int equipment_id { get; set; } @@ -88,5 +81,13 @@ private class MyDTO public DateTime timestamp { get; set; } public decimal sqrt_calc { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, equipment_id = 1, timestamp = new DateTime(2022, 01, 01, 12, 0, 0, DateTimeKind.Utc), my_decimal_value = 4M } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2509Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2509Tests.cs index 720218b4f83..b64e62ed650 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2509Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2509Tests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System; using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson.Serialization.Attributes; using MongoDB.Bson.Serialization.Options; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp2509Tests : Linq3IntegrationTest + public class CSharp2509Tests : LinqIntegrationTest { + public CSharp2509Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Where_ContainsValue_should_work_when_representation_is_Dictionary() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(x => x.D1.ContainsValue(1)); @@ -43,7 +49,7 @@ public void Where_ContainsValue_should_work_when_representation_is_Dictionary() [Fact] public void Where_ContainsValue_should_work_when_representation_is_ArrayOfArrays() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(x => x.D2.ContainsValue(1)); @@ -58,7 +64,7 @@ public void Where_ContainsValue_should_work_when_representation_is_ArrayOfArrays [Fact] public void Where_ContainsValue_should_work_when_representation_is_ArrayOfDocuments() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(x => x.D3.ContainsValue(1)); @@ -73,7 +79,7 @@ public void Where_ContainsValue_should_work_when_representation_is_ArrayOfDocume [Fact] public void Select_ContainsValue_should_work_when_representation_is_Dictionary() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => x.D1.ContainsValue(1)); @@ -88,7 +94,7 @@ public void Select_ContainsValue_should_work_when_representation_is_Dictionary() [Fact] public void Select_ContainsValue_should_work_when_representation_is_ArrayOfArrays() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => x.D2.ContainsValue(1)); @@ -103,7 +109,7 @@ public void Select_ContainsValue_should_work_when_representation_is_ArrayOfArray [Fact] public void Select_ContainsValue_should_work_when_representation_is_ArrayOfDocuments() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => x.D3.ContainsValue(1)); @@ -115,11 +121,21 @@ public void Select_ContainsValue_should_work_when_representation_is_ArrayOfDocum results.Should().Equal(true, true, false); } - private IMongoCollection GetCollection() + public class User { - var collection = GetCollection("test"); - CreateCollection( - collection, + public int Id { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.Document)] + public Dictionary D1 { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] + public Dictionary D2 { get; set; } + [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] + public Dictionary D3 { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new User { Id = 1, @@ -140,19 +156,8 @@ private IMongoCollection GetCollection() D1 = new() { { "A", 2 }, { "B", 3 } }, D2 = new() { { "A", 2 }, { "B", 3 } }, D3 = new() { { "A", 2 }, { "B", 3 } } - }); - return collection; - } - - private class User - { - public int Id { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.Document)] - public Dictionary D1 { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfArrays)] - public Dictionary D2 { get; set; } - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] - public Dictionary D3 { get; set; } + } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2727Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2727Tests.cs index db6254700f8..160cfc8fa85 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2727Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp2727Tests.cs @@ -14,24 +14,30 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; using MongoDB.Bson.Serialization; using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp2727Tests : Linq3IntegrationTest + public class CSharp2727Tests : LinqIntegrationTest { + public CSharp2727Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Find_with_predicate_on_Body_should_work() { RequireServer.Check().Supports(Feature.AggregateToString); - var collection = CreateCollection(); + var collection = Fixture.Collection; var filter = new ExpressionFilterDefinition(x => new[] { "Test1", "Test2" }.Contains((string)x.Body["name"])); var serializerRegistry = BsonSerializer.SerializerRegistry; @@ -49,7 +55,7 @@ public void Find_with_predicate_on_Body_should_work() [Fact] public void Find_with_predicate_on_Caption_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var filter = new ExpressionFilterDefinition(x => new[] { "Test1", "Test2" }.Contains(x.Caption)); var serializerRegistry = BsonSerializer.SerializerRegistry; @@ -68,7 +74,7 @@ public void Find_with_predicate_on_Caption_should_work() public void Where_with_predicate_on_Body_should_work() { RequireServer.Check().Supports(Feature.AggregateToString); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -84,7 +90,7 @@ public void Where_with_predicate_on_Body_should_work() [Fact] public void Where_with_predicate_on_Caption_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -97,24 +103,21 @@ public void Where_with_predicate_on_Caption_should_work() results.Select(x => x.Id).Should().Equal(1, 2); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("C"); - - CreateCollection( - collection, - new Entity { Id = 1, Body = BsonDocument.Parse("{ name : 'Test1' }"), Caption = "Test1" }, - new Entity { Id = 2, Body = BsonDocument.Parse("{ name : 'Test2' }"), Caption = "Test2" }, - new Entity { Id = 3, Body = BsonDocument.Parse("{ name : 'Test3' }"), Caption = "Test3" }); - - return collection; - } - - private class Entity + public class Entity { public int Id { get; set; } public BsonDocument Body { get; set; } public string Caption { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Entity { Id = 1, Body = BsonDocument.Parse("{ name : 'Test1' }"), Caption = "Test1" }, + new Entity { Id = 2, Body = BsonDocument.Parse("{ name : 'Test2' }"), Caption = "Test2" }, + new Entity { Id = 3, Body = BsonDocument.Parse("{ name : 'Test3' }"), Caption = "Test3" } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3136Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3136Tests.cs index 23a610128b5..1341b2c93f5 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3136Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3136Tests.cs @@ -20,19 +20,24 @@ using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3136Tests : Linq3IntegrationTest + public class CSharp3136Tests : LinqIntegrationTest { + public CSharp3136Tests(ClassFixture fixture) + : base(fixture) + { + } [Fact] public void DateTime_ToString_with_no_arguments_should_work() { RequireServer.Check().Supports(Feature.ToConversionOperators); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -52,7 +57,7 @@ public void DateTime_ToString_with_no_arguments_should_work() [Fact] public void DateTime_ToString_with_format_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -76,7 +81,7 @@ public void DateTime_ToString_with_format_should_work() [InlineData("%H:%M:%S", "-04:00", "{ $project : { _v : { $dateToString : { date : '$D', format : '%H:%M:%S', timezone : '-04:00' } }, _id : 0 } }", new[] { "23:04:05", "23:04:05" })] public void DateTime_ToString_with_format_and_timezone_constants_should_work(string format, string timezone, string expectedProjectStage, string[] expectedResults) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -104,7 +109,7 @@ public void DateTime_ToString_with_format_and_timezone_constants_should_work(str [InlineData(true, true, "{ $project : { _v : { $dateToString : { date : '$D', format : '$Format', timezone : '$Timezone' } }, _id : 0 } }", new[] { "23:04:05", "23:04:05" })] public void DateTime_ToString_with_format_and_timezone_expressions_should_work(bool withFormat, bool withTimezone, string expectedProjectStage, string[] expectedResults) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var orderby = collection .AsQueryable() @@ -138,7 +143,7 @@ public void NullableDateTime_ToString_with_no_arguments_should_work() { RequireServer.Check().Supports(Feature.ToConversionOperators); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -166,7 +171,7 @@ public void NullableDateTime_ToString_with_no_arguments_should_work() [InlineData("%H:%M:%S", "-04:00", "xx", "{ $project : { _v : { $dateToString : { date : '$N', format : '%H:%M:%S', timezone : '-04:00', onNull : 'xx' } }, _id : 0 } }", new[] { "23:04:05", "xx" })] public void NullableDateTime_ToString_with_format_and_timezone_and_onNull_constants_should_work(string format, string timezone, string onNull, string expectedProjectStage, string[] expectedResults) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -198,7 +203,7 @@ public void NullableDateTime_ToString_with_format_and_timezone_and_onNull_consta [InlineData(true, true, true, "{ $project : { _v : { $dateToString : { date : '$N', format : '$Format', timezone : '$Timezone', onNull : '$OnNull' } }, _id : 0 } }", new[] { "23:04:05", "missing" })] public void NullableDateTime_ToString_with_format_and_timezone_and_onNull_expressions_should_work(bool withFormat, bool withTimezone, bool withOnNull, string expectedProjectStage, string[] expectedResults) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var orderby = collection .AsQueryable() @@ -231,18 +236,6 @@ public void NullableDateTime_ToString_with_format_and_timezone_and_onNull_expres results.Should().Equal(expectedResults); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - - CreateCollection( - collection, - new C { Id = 1, D = new DateTime(2021, 1, 2, 3, 4, 5, 123, DateTimeKind.Utc), N = new DateTime(2021, 1, 2, 3, 4, 5, 123, DateTimeKind.Utc), Format = "%H:%M:%S", Timezone = "-04:00", OnNull = "missing" }, - new C { Id = 2, D = new DateTime(2021, 1, 2, 3, 4, 5, 123, DateTimeKind.Utc), N = null, Format = "%H:%M:%S", Timezone = "-04:00", OnNull = "missing" }); - - return collection; - } - private List RemoveTrailingZFromResults(List results) { return results.Select(RemoveTrailingZ).ToList(); @@ -253,7 +246,7 @@ static string RemoveTrailingZ(string value) } } - private class C + public class C { public int Id { get; set; } public DateTime D { get; set; } @@ -263,9 +256,13 @@ private class C public string OnNull { get; set; } } - private class ProductTypeSearchResult + public sealed class ClassFixture : MongoCollectionFixture { - public bool IsExternalUrl { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 1, D = new DateTime(2021, 1, 2, 3, 4, 5, 123, DateTimeKind.Utc), N = new DateTime(2021, 1, 2, 3, 4, 5, 123, DateTimeKind.Utc), Format = "%H:%M:%S", Timezone = "-04:00", OnNull = "missing" }, + new C { Id = 2, D = new DateTime(2021, 1, 2, 3, 4, 5, 123, DateTimeKind.Utc), N = null, Format = "%H:%M:%S", Timezone = "-04:00", OnNull = "missing" } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3144Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3144Tests.cs index 2ab60aab58c..e5d1591aed6 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3144Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3144Tests.cs @@ -16,17 +16,22 @@ using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3144Tests : Linq3IntegrationTest + public class CSharp3144Tests : LinqIntegrationTest { + public CSharp3144Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Where_with_Contains_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -42,7 +47,7 @@ public void Where_with_Contains_should_work() [Fact] public void Suggested_workaround_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -55,12 +60,28 @@ public void Suggested_workaround_should_work() results.Select(r => r.Id).Should().Equal(1); } - private IMongoCollection CreateCollection() + public class Order { - var collection = GetCollection(); + public virtual int Id { get; set; } + public virtual List Items { get; set; } - CreateCollection( - collection, + public Order() + { + Items = new List(); + } + } + + public class OrderItem + { + public virtual int Id { get; set; } + public virtual int GoodId { get; set; } + public virtual int Amount { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new Order { Id = 1, @@ -77,34 +98,15 @@ private IMongoCollection CreateCollection() { Id = 2, Items = new List - { - new OrderItem { GoodId = 6, Amount = 1 }, - new OrderItem { GoodId = 7, Amount = 10 }, - new OrderItem { GoodId = 8, Amount = 20 }, - new OrderItem { GoodId = 9, Amount = 30 }, - new OrderItem { GoodId = 10, Amount = 40 } - } - }); - - return collection; - } - - class Order - { - public virtual int Id { get; set; } - public virtual List Items { get; set; } - - public Order() - { - Items = new List(); - } - } - - class OrderItem - { - public virtual int Id { get; set; } - public virtual int GoodId { get; set; } - public virtual int Amount { get; set; } + { + new OrderItem { GoodId = 6, Amount = 1 }, + new OrderItem { GoodId = 7, Amount = 10 }, + new OrderItem { GoodId = 8, Amount = 20 }, + new OrderItem { GoodId = 9, Amount = 30 }, + new OrderItem { GoodId = 10, Amount = 40 } + } + } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3197Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3197Tests.cs index c999d37b193..34282afc432 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3197Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3197Tests.cs @@ -13,19 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3197Tests : Linq3IntegrationTest + public class CSharp3197Tests : LinqIntegrationTest { + public CSharp3197Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Select_select_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -42,21 +48,18 @@ public void Select_select_should_work() result.Should().Be(new { B = 42 }); } - private IMongoCollection CreateCollection() + public class Person { - var collection = GetCollection("C"); - - CreateCollection( - collection, - new Person { Id = 1, Age = 42 }); - - return collection; + public int Id { get; set; } + public int Age { get; set; } } - private class Person + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int Age { get; set; } + protected override IEnumerable InitialData => + [ + new Person { Id = 1, Age = 42 } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3234Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3234Tests.cs index 2a2ae3a7969..b26bb8b6cc1 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3234Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3234Tests.cs @@ -13,20 +13,25 @@ * limitations under the License. */ -using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3234Tests : Linq3IntegrationTest + public class CSharp3234Tests : LinqIntegrationTest { + public CSharp3234Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Contains_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var selectedIds = new[] { 1, 2, 3 }; var queryable = collection @@ -43,7 +48,7 @@ public void Contains_should_work() [Fact] public void Contains_equals_false_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var selectedIds = new[] { 1, 2, 3 }; var queryable = collection @@ -60,7 +65,7 @@ public void Contains_equals_false_should_work() [Fact] public void Contains_equals_true_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var selectedIds = new[] { 1, 2, 3 }; var queryable = collection @@ -74,24 +79,21 @@ public void Contains_equals_true_should_work() results.OrderBy(x => x.Id).Select(x => x.Id).Should().Equal(1, 2, 3); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("C"); + public int Id { get; set; } + } - CreateCollection( - collection, + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new C { Id = 1 }, new C { Id = 2 }, new C { Id = 3 }, new C { Id = 4 }, - new C { Id = 5 }); - - return collection; - } - - private class C - { - public int Id { get; set; } + new C { Id = 5 } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3236Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3236Tests.cs index 7754bc52c6a..0245a451cd1 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3236Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3236Tests.cs @@ -16,17 +16,22 @@ using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3236Tests : Linq3IntegrationTest + public class CSharp3236Tests : LinqIntegrationTest { + public CSharp3236Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Select_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -46,12 +51,23 @@ public void Select_should_work() result.Comments.Select(c => c.Id).Should().Equal(1, 3); } - private IMongoCollection CreateCollection() + public class Post + { + public int Id { get; set; } + public List Comments { get; set; } + + } + + public class Comment { - var collection = GetCollection("C"); + public int Id { get; set; } + public string Text { get; set; } + } - CreateCollection( - collection, + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new Post { Id = 1, @@ -61,22 +77,8 @@ private IMongoCollection CreateCollection() new Comment { Id = 2, Text = "this is not" }, new Comment { Id = 3, Text = "and this is another test comment" } } - }); - - return collection; - } - - private class Post - { - public int Id { get; set; } - public List Comments { get; set; } - - } - - public class Comment - { - public int Id { get; set; } - public string Text { get; set; } + } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3614Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3614Tests.cs index 9e625c18029..9a5fb8a2309 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3614Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3614Tests.cs @@ -14,18 +14,25 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3614Tests : Linq3IntegrationTest + public class CSharp3614Tests : LinqIntegrationTest { + public CSharp3614Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Test() { - var collection = CreateBooksCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => new BookDto @@ -57,20 +64,6 @@ public void Test() results[1].Author.ShouldBeEquivalentTo(new AuthorDto { Id = 2, Name = "Two" }); } - private IMongoCollection CreateBooksCollection() - { - var collection = GetCollection(); - - var documents = new[] - { - new Book { Id = 1, PageCount = 1, Author = null }, - new Book { Id = 2, PageCount = 2, Author = new Author { Id = 2, Name = "Two" } } - }; - CreateCollection(collection, documents); - - return collection; - } - private class BookDto { public int Id { get; set; } @@ -84,18 +77,27 @@ private class AuthorDto public string Name { get; set; } } - private class Author : IEquatable + public class Author : IEquatable { public int Id { get; set; } public string Name { get; set; } public bool Equals(Author other) => Id == other.Id && Name == other.Name; } - private class Book + public class Book { public int Id { get; set; } public int PageCount { get; set; } public Author Author { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Book { Id = 1, PageCount = 1, Author = null }, + new Book { Id = 2, PageCount = 2, Author = new Author { Id = 2, Name = "Two" } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3713Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3713Tests.cs index 448a6361063..9d9ec2cf130 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3713Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3713Tests.cs @@ -13,38 +13,36 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - [Trait("Category", "Integration")] - public class CSharp3713Tests + public class CSharp3713Tests : LinqIntegrationTest { + public CSharp3713Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void DefaultIfEmpty_should_work() { - var client = DriverTestConfiguration.Client; - var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); - var collection = database.GetCollection(DriverTestConfiguration.CollectionNamespace.CollectionName); + var collection = Fixture.Collection; var subject = collection.AsQueryable(); - database.DropCollection(collection.CollectionNamespace.CollectionName); - collection.InsertMany(new[] { - new C { Id = 1, InnerArray = new A[0] }, - new C { Id = 2, InnerArray = new[] { new A { S = "abc" } } } - }); - var queryable = subject.SelectMany(outerObject => outerObject.InnerArray.DefaultIfEmpty(), (o, a) => new { o, a }); - var stages = Linq3TestHelpers.Translate(collection, queryable); + var stages = Translate(collection, queryable); var expectedStages = new[] { "{ $project : { _v : { $map : { input : { $cond : { if : { $eq : [{ $size : '$InnerArray' }, 0] }, then : [null], else : '$InnerArray' } }, as : 'a', in : { o : '$$ROOT', a : '$$a' } } }, _id : 0 } }", "{ $unwind : '$_v' }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); + AssertStages(stages, expectedStages); var result = queryable.ToList(); result.Count.Should().Be(2); @@ -57,27 +55,19 @@ public void DefaultIfEmpty_should_work() [Fact] public void DefaultIfEmpty_with_explicit_default_should_work() { - var client = DriverTestConfiguration.Client; - var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); - var collection = database.GetCollection(DriverTestConfiguration.CollectionNamespace.CollectionName); + var collection = Fixture.Collection; var subject = collection.AsQueryable(); - database.DropCollection(collection.CollectionNamespace.CollectionName); - collection.InsertMany(new[] { - new C { Id = 1, InnerArray = new A[0] }, - new C { Id = 2, InnerArray = new[] { new A { S = "abc" } } } - }); - var defaultValue = new A { S = "default" }; var queryable = subject.SelectMany(outerObject => outerObject.InnerArray.DefaultIfEmpty(defaultValue), (o, a) => new { o, a }); - var stages = Linq3TestHelpers.Translate(collection, queryable); + var stages = Translate(collection, queryable); var expectedStages = new[] { "{ $project : { _v : { $map : { input : { $cond : { if : { $eq : [{ $size : '$InnerArray' }, 0] }, then : [{ S : 'default' }], else : '$InnerArray' } }, as : 'a', in : { o : '$$ROOT', a : '$$a' } } }, _id : 0 } }", "{ $unwind : '$_v' }" }; - Linq3TestHelpers.AssertStages(stages, expectedStages); + AssertStages(stages, expectedStages); var result = queryable.ToList(); result.Count.Should().Be(2); @@ -87,15 +77,24 @@ public void DefaultIfEmpty_with_explicit_default_should_work() result[1].a.S.Should().Be("abc"); } - private class C + public class C { public int Id { get; set; } public A[] InnerArray { get; set; } } - private class A + public class A { public string S { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, InnerArray = new A[0] }, + new C { Id = 2, InnerArray = new[] { new A { S = "abc" } } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3845Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3845Tests.cs index 3d029d46a7e..cf09d4f45a0 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3845Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3845Tests.cs @@ -13,26 +13,26 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3845Tests : Linq3IntegrationTest + public class CSharp3845Tests : LinqIntegrationTest { + public CSharp3845Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Select_of_anonymous_class_with_missing_fields_should_work() { - var collection = GetCollection(); - CreateCollection( - collection, - new[] - { - new C { Id = 1, S = null, X = 0 }, - new C { Id = 2, S = "abc", X = 123 } - }); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(c => new { F = c.S, G = c.X }); @@ -52,7 +52,7 @@ public void Select_of_anonymous_class_with_missing_fields_should_work() results[1].G.Should().Be(123); } - private class C + public class C { public int Id { get; set; } [BsonIgnoreIfNull] @@ -60,5 +60,14 @@ private class C [BsonIgnoreIfDefault] public int X { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, S = null, X = 0 }, + new C { Id = 2, S = "abc", X = 123 } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3910Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3910Tests.cs index 691de55fafe..dd3dc5f81ee 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3910Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3910Tests.cs @@ -13,29 +13,24 @@ * limitations under the License. */ +using System.Collections.Generic; using FluentAssertions; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - [Trait("Category", "Integration")] - public class CSharp3910Tests + public class CSharp3910Tests : LinqIntegrationTest { + public CSharp3910Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Filter_expression_needing_partial_evaluation_should_work() { - var client = DriverTestConfiguration.Client; - var database = client.GetDatabase(DriverTestConfiguration.DatabaseNamespace.DatabaseName); - var collection = database.GetCollection("csharp3910"); - - database.DropCollection("csharp3910"); - collection.InsertMany(new[] - { - new Entity { Id = 1, Description = "Alpha" }, - new Entity { Id = 2, Description = "Alpha2" }, - new Entity { Id = 3, Description = "Bravo" }, - new Entity { Id = 4, Description = "Charlie" } - }); + var collection = Fixture.Collection; var param = "A"; var result = collection.DeleteMany(mvi => mvi.Description.StartsWith(string.Format("{0}", param))); @@ -48,5 +43,16 @@ public class Entity public int Id { get; set; } public string Description { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Entity { Id = 1, Description = "Alpha" }, + new Entity { Id = 2, Description = "Alpha2" }, + new Entity { Id = 3, Description = "Bravo" }, + new Entity { Id = 4, Description = "Charlie" } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3924Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3924Tests.cs index 88c97d0a246..4f7e4126a3c 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3924Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3924Tests.cs @@ -14,19 +14,25 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3924Tests : Linq3IntegrationTest + public class CSharp3924Tests : LinqIntegrationTest { + public CSharp3924Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Projection_with_call_to_Tuple1_constructor_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -42,7 +48,7 @@ public void Projection_with_call_to_Tuple1_constructor_should_work() [Fact] public void Projection_with_call_to_Tuple2_constructor_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -58,7 +64,7 @@ public void Projection_with_call_to_Tuple2_constructor_should_work() [Fact] public void Projection_with_call_to_Tuple3_constructor_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -74,7 +80,7 @@ public void Projection_with_call_to_Tuple3_constructor_should_work() [Fact] public void Where_with_Tuple1_item_comparisons_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -94,7 +100,7 @@ public void Where_with_Tuple1_item_comparisons_should_work() [Fact] public void Where_with_Tuple2_item_comparisons_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -114,7 +120,7 @@ public void Where_with_Tuple2_item_comparisons_should_work() [Fact] public void Where_with_Tuple3_item_comparisons_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -131,23 +137,20 @@ public void Where_with_Tuple3_item_comparisons_should_work() result.Should().Be(new Tuple(1, 11, 111)); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("C"); - - CreateCollection( - collection, - new C { Id = 1, X = 1, Y = 11, Z = 111 }); - - return collection; - } - - private class C + public class C { public int Id { get; set; } public int X { get; set; } public int Y { get; set; } public int Z { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, X = 1, Y = 11, Z = 111 } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3946Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3946Tests.cs index 10363172293..1b38b394d8d 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3946Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3946Tests.cs @@ -13,23 +13,30 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3946Tests : Linq3IntegrationTest + public class CSharp3946Tests : LinqIntegrationTest { + public CSharp3946Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Where_with_constant_limit_should_work() { RequireServer.Check().Supports(Feature.FilterLimit); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => x.IA.Where(i => i >= 2, 2)); @@ -46,7 +53,7 @@ public void Where_with_limit_computed_server_side_should_work() { RequireServer.Check().Supports(Feature.FilterLimit); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => x.IA.Where(i => i >= 2, x.Id + 1)); @@ -58,19 +65,18 @@ public void Where_with_limit_computed_server_side_should_work() results[0].Should().Equal(2, 3); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - CreateCollection( - collection, - new C { Id = 1, IA = new[] { 1, 2, 3, 4 } }); - return collection; - } - public class C { public int Id { get; set; } public int[] IA { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, IA = new[] { 1, 2, 3, 4 } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3958Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3958Tests.cs index b629728d726..1b40ffd9325 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3958Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3958Tests.cs @@ -14,24 +14,31 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3958Tests : Linq3IntegrationTest + public class CSharp3958Tests : LinqIntegrationTest { + public CSharp3958Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Sort_on_a_field_example_should_work() { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() .Select(x => new { Result = x.Team.OrderBy(m => m.Name) }); @@ -48,7 +55,7 @@ public void Sort_on_a_field_example_should_work() public void Sort_on_a_subfield_example_should_work() { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() .Select(x => new { Result = x.Team.OrderByDescending(m => m.Address.City) }); @@ -65,7 +72,7 @@ public void Sort_on_a_subfield_example_should_work() public void Sort_on_multiple_fields_example_should_work() { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() .Select(x => new { Result = x.Team.OrderByDescending(m => m.Age).ThenBy(m => m.Name) }); @@ -82,7 +89,7 @@ public void Sort_on_multiple_fields_example_should_work() public void Sort_an_array_of_integers_example_should_work() { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() .Select(x => new { Result = new[] { 1, 4, 1, 6, 12, 5 }.OrderBy(v => v) }); @@ -99,7 +106,7 @@ public void Sort_an_array_of_integers_example_should_work() public void Sort_on_mixed_type_fields_example_should_work() { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() .Select( @@ -146,7 +153,7 @@ public void OrderBy_on_entire_object_followed_by_ThenBy_should_throw( [Values(false, true)] bool enableClientSideProjections) { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; var queryable = collection @@ -177,7 +184,7 @@ public void OrderByDescending_on_entire_object_followed_by_ThenBy_should_throw( [Values(false, true)] bool enableClientSideProjections) { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; var queryable = collection @@ -208,7 +215,7 @@ public void ThenBy_on_entire_object_should_throw( [Values(false, true)] bool enableClientSideProjections) { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; var queryable = collection @@ -238,7 +245,7 @@ public void ThenByDescending_on_entire_object_should_throw( [Values(false, true)] bool enableClientSideProjections) { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; var queryable = collection @@ -266,7 +273,7 @@ public void ThenByDescending_on_entire_object_should_throw( public void Client_side_ThenBy_should_throw() { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() .Select(x => new { Result = x.Team.OrderBy(m => m.Name) }); @@ -283,7 +290,7 @@ public void Client_side_ThenBy_should_throw() public void Client_side_ThenByDescending_should_throw() { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() .Select(x => new { Result = x.Team.OrderBy(m => m.Name) }); @@ -300,7 +307,7 @@ public void Client_side_ThenByDescending_should_throw() public void IOrderedEnumerableSerializer_Serialize_should_work() { RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateEngineersCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() .Select(x => new { Result = x.Team.OrderBy(m => m.Name) }); @@ -311,33 +318,13 @@ public void IOrderedEnumerableSerializer_Serialize_should_work() json.Should().Be("{ \"Result\" : [{ \"Name\" : \"Charlie\", \"Age\" : 30, \"Address\" : { \"Street\" : \"12 French St\", \"City\" : \"New Brunswick\" } }, { \"Name\" : \"Dallas\", \"Age\" : 30, \"Address\" : { \"Street\" : \"12 Cowper St\", \"City\" : \"Palo Alto\" } }, { \"Name\" : \"Pat\", \"Age\" : 42, \"Address\" : { \"Street\" : \"12 Baker St\", \"City\" : \"London\" } }] }"); } - private IMongoCollection CreateEngineersCollection() - { - var collection = GetCollection(); - - CreateCollection( - collection, - new Engineers - { - Id = 1, - Team = new[] - { - new TeamMember { Name = "Pat", Age = 42, Address = new Address { Street = "12 Baker St", City = "London"}}, - new TeamMember { Name = "Dallas", Age = 30, Address = new Address { Street = "12 Cowper St", City = "Palo Alto"}}, - new TeamMember { Name = "Charlie", Age = 30, Address = new Address { Street = "12 French St", City = "New Brunswick"}} - } - }); - - return collection; - } - - private class Engineers + public class Engineers { public int Id { get; set; } public TeamMember[] Team { get; set; } } - private class TeamMember : IComparable + public class TeamMember : IComparable { public string Name { get; set; } public int Age { get; set; } @@ -346,10 +333,27 @@ private class TeamMember : IComparable public int CompareTo(TeamMember other) => Age.CompareTo(other.Age); } - private class Address + public class Address { public string Street { get; set; } public string City { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Engineers + { + Id = 1, + Team = new[] + { + new TeamMember { Name = "Pat", Age = 42, Address = new Address { Street = "12 Baker St", City = "London"}}, + new TeamMember { Name = "Dallas", Age = 30, Address = new Address { Street = "12 Cowper St", City = "Palo Alto"}}, + new TeamMember { Name = "Charlie", Age = 30, Address = new Address { Street = "12 French St", City = "New Brunswick"}} + } + } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3965Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3965Tests.cs index e8ada5872ef..9383f92c567 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3965Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp3965Tests.cs @@ -13,19 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp3965Tests : Linq3IntegrationTest + public class CSharp3965Tests : LinqIntegrationTest { + public CSharp3965Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void OrderBy_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -45,7 +51,7 @@ public void OrderBy_with_expression_should_work() [Fact] public void OrderBy_with_expression_and_ThenBy_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -66,7 +72,7 @@ public void OrderBy_with_expression_and_ThenBy_with_expression_should_work() [Fact] public void OrderBy_with_expression_and_ThenBy_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -87,7 +93,7 @@ public void OrderBy_with_expression_and_ThenBy_with_field_should_work() [Fact] public void OrderBy_with_expression_and_ThenByDescending_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -108,7 +114,7 @@ public void OrderBy_with_expression_and_ThenByDescending_with_expression_should_ [Fact] public void OrderBy_with_expression_and_ThenByDescending_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -129,7 +135,7 @@ public void OrderBy_with_expression_and_ThenByDescending_with_field_should_work( [Fact] public void OrderBy_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -147,7 +153,7 @@ public void OrderBy_with_field_should_work() [Fact] public void OrderBy_with_field_and_ThenBy_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -168,7 +174,7 @@ public void OrderBy_with_field_and_ThenBy_with_expression_should_work() [Fact] public void OrderBy_with_field_and_ThenBy_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -187,7 +193,7 @@ public void OrderBy_with_field_and_ThenBy_with_field_should_work() [Fact] public void OrderBy_with_field_and_ThenByDescending_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -208,7 +214,7 @@ public void OrderBy_with_field_and_ThenByDescending_with_expression_should_work( [Fact] public void OrderBy_with_field_and_ThenByDescending_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -227,7 +233,7 @@ public void OrderBy_with_field_and_ThenByDescending_with_field_should_work() [Fact] public void OrderByDescending_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -247,7 +253,7 @@ public void OrderByDescending_with_expression_should_work() [Fact] public void OrderByDescending_with_expression_and_ThenBy_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -268,7 +274,7 @@ public void OrderByDescending_with_expression_and_ThenBy_with_expression_should_ [Fact] public void OrderByDescending_with_expression_and_ThenBy_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -289,7 +295,7 @@ public void OrderByDescending_with_expression_and_ThenBy_with_field_should_work( [Fact] public void OrderByDescending_with_expression_and_ThenByDescending_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -310,7 +316,7 @@ public void OrderByDescending_with_expression_and_ThenByDescending_with_expressi [Fact] public void OrderByDescending_with_expression_and_ThenByDescending_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -331,7 +337,7 @@ public void OrderByDescending_with_expression_and_ThenByDescending_with_field_sh [Fact] public void OrderByDescending_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -349,7 +355,7 @@ public void OrderByDescending_with_field_should_work() [Fact] public void OrderByDescending_with_field_and_ThenBy_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -370,7 +376,7 @@ public void OrderByDescending_with_field_and_ThenBy_with_expression_should_work( [Fact] public void OrderByDescending_with_field_and_ThenBy_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -389,7 +395,7 @@ public void OrderByDescending_with_field_and_ThenBy_with_field_should_work() [Fact] public void OrderByDescending_with_field_and_ThenByDescending_with_expression_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -410,7 +416,7 @@ public void OrderByDescending_with_field_and_ThenByDescending_with_expression_sh [Fact] public void OrderByDescending_with_field_and_ThenByDescending_with_field_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection .AsQueryable() @@ -426,36 +432,20 @@ public void OrderByDescending_with_field_and_ThenByDescending_with_field_should_ results.Select(x => x.Id).Should().Equal(2, 1); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - - var documents = new C[] - { - new C - { - Id = 1, - X = 1, - Y = 1, - }, - new C - { - Id = 2, - X = 1, - Y = 2 - } - - }; - CreateCollection(collection, documents); - - return collection; - } - - private class C + public class C { public int Id { get; set; } public int X { get; set; } public int Y { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, X = 1, Y = 1 }, + new C { Id = 2, X = 1, Y = 2 } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4048Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4048Tests.cs index d69edbc43ce..a6bb95b69b1 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4048Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4048Tests.cs @@ -17,16 +17,22 @@ using System.Linq; using FluentAssertions; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp4048Tests : Linq3IntegrationTest + public class CSharp4048Tests : LinqIntegrationTest { + public CSharp4048Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Array_ArrayIndex_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -51,7 +57,7 @@ public void Array_ArrayIndex_of_root_should_work() [Fact] public void Array_ArrayIndex_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -76,7 +82,7 @@ public void Array_ArrayIndex_of_scalar_should_work() [Fact] public void List_get_Item_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -101,7 +107,7 @@ public void List_get_Item_of_root_should_work() [Fact] public void List_get_Item_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -126,7 +132,7 @@ public void List_get_Item_of_scalar_should_work() [Fact] public void IGrouping_Aggregate_with_func_of_root_should_return_expected_result() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -151,7 +157,7 @@ public void IGrouping_Aggregate_with_func_of_root_should_return_expected_result( [Fact] public void IGrouping_Aggregate_with_func_of_scalar_should_return_expected_result() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -176,7 +182,7 @@ public void IGrouping_Aggregate_with_func_of_scalar_should_return_expected_resul [Fact] public void IGrouping_Aggregate_with_seed_and_func_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -201,7 +207,7 @@ public void IGrouping_Aggregate_with_seed_and_func_of_root_should_work() [Fact] public void IGrouping_Aggregate_with_seed_and_func_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -226,7 +232,7 @@ public void IGrouping_Aggregate_with_seed_and_func_of_scalar_should_work() [Fact] public void IGrouping_Aggregate_with_seed_and_func_and_resultSelector_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -251,7 +257,7 @@ public void IGrouping_Aggregate_with_seed_and_func_and_resultSelector_of_root_sh [Fact] public void IGrouping_Aggregate_with_seed_and_func_and_resultSelector_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -276,7 +282,7 @@ public void IGrouping_Aggregate_with_seed_and_func_and_resultSelector_of_scalar_ [Fact] public void IGrouping_All_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -301,7 +307,7 @@ public void IGrouping_All_of_root_should_work() [Fact] public void IGrouping_All_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -326,7 +332,7 @@ public void IGrouping_All_of_scalar_should_work() [Fact] public void IGrouping_Any_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -351,7 +357,7 @@ public void IGrouping_Any_of_root_should_work() [Fact] public void IGrouping_Any_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -376,7 +382,7 @@ public void IGrouping_Any_of_scalar_should_work() [Fact] public void IGrouping_Any_with_predicate_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -401,7 +407,7 @@ public void IGrouping_Any_with_predicate_of_root_should_work() [Fact] public void IGrouping_Any_with_predicate_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -426,7 +432,7 @@ public void IGrouping_Any_with_predicate_of_scalar_should_work() [Fact] public void IGrouping_Average_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -451,7 +457,7 @@ public void IGrouping_Average_of_root_should_work() [Fact] public void IGrouping_Average_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -476,7 +482,7 @@ public void IGrouping_Average_of_scalar_should_work() [Fact] public void IGrouping_Average_with_selector_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -501,7 +507,7 @@ public void IGrouping_Average_with_selector_of_root_should_work() [Fact] public void IGrouping_Average_with_selector_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -526,7 +532,7 @@ public void IGrouping_Average_with_selector_of_scalar_should_work() [Fact] public void IGrouping_Concat_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -551,7 +557,7 @@ public void IGrouping_Concat_of_root_should_work() [Fact] public void IGrouping_Concat_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -576,7 +582,7 @@ public void IGrouping_Concat_of_scalar_should_work() [Fact] public void IGrouping_Contains_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -601,7 +607,7 @@ public void IGrouping_Contains_of_root_should_work() [Fact] public void IGrouping_Contains_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -626,7 +632,7 @@ public void IGrouping_Contains_of_scalar_should_work() [Fact] public void IGrouping_Count_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -651,7 +657,7 @@ public void IGrouping_Count_of_root_should_work() [Fact] public void IGrouping_Count_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -676,7 +682,7 @@ public void IGrouping_Count_of_scalar_should_work() [Fact] public void IGrouping_Count_with_predicate_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -701,7 +707,7 @@ public void IGrouping_Count_with_predicate_of_root_should_work() [Fact] public void IGrouping_Count_with_predicate_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -726,7 +732,7 @@ public void IGrouping_Count_with_predicate_of_scalar_should_work() [Fact] public void IGrouping_DefaultIfEmpty_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -751,7 +757,7 @@ public void IGrouping_DefaultIfEmpty_of_root_should_work() [Fact] public void IGrouping_DefaultIfEmpty_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -776,7 +782,7 @@ public void IGrouping_DefaultIfEmpty_of_scalar_should_work() [Fact] public void IGrouping_Distinct_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -801,7 +807,7 @@ public void IGrouping_Distinct_of_root_should_work() [Fact] public void IGrouping_Distinct_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -826,7 +832,7 @@ public void IGrouping_Distinct_of_scalar_should_work() [Fact] public void IGrouping_ElementAt_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -851,7 +857,7 @@ public void IGrouping_ElementAt_of_root_should_work() [Fact] public void IGrouping_ElementAt_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -876,7 +882,7 @@ public void IGrouping_ElementAt_of_scalar_should_work() [Fact] public void IGrouping_ElementAtOrDefault_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -901,7 +907,7 @@ public void IGrouping_ElementAtOrDefault_of_root_should_work() [Fact] public void IGrouping_ElementAtOrDefault_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -926,7 +932,7 @@ public void IGrouping_ElementAtOrDefault_of_scalar_should_work() [Fact] public void IGrouping_Except_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -951,7 +957,7 @@ public void IGrouping_Except_of_root_should_work() [Fact] public void IGrouping_Except_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -976,7 +982,7 @@ public void IGrouping_Except_of_scalar_should_work() [Fact] public void IGrouping_First_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1001,7 +1007,7 @@ public void IGrouping_First_of_root_should_work() [Fact] public void IGrouping_First_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1026,7 +1032,7 @@ public void IGrouping_First_of_scalar_should_work() [Fact] public void IGrouping_First_with_predicate_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1051,7 +1057,7 @@ public void IGrouping_First_with_predicate_of_root_should_work() [Fact] public void IGrouping_First_with_predicate_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1076,7 +1082,7 @@ public void IGrouping_First_with_predicate_of_scalar_should_work() [Fact] public void IGrouping_FirstOrDefault_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1101,7 +1107,7 @@ public void IGrouping_FirstOrDefault_of_root_should_work() [Fact] public void IGrouping_FirstOrDefault_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1126,7 +1132,7 @@ public void IGrouping_FirstOrDefault_of_scalar_should_work() [Fact] public void IGrouping_FirstOrDefault_with_predicate_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1152,7 +1158,7 @@ public void IGrouping_FirstOrDefault_with_predicate_of_root_should_work() [Fact] public void IGrouping_FirstOrDefault_with_predicate_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1177,7 +1183,7 @@ public void IGrouping_FirstOrDefault_with_predicate_of_scalar_should_work() [Fact] public void IGrouping_Intersect_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1202,7 +1208,7 @@ public void IGrouping_Intersect_of_root_should_work() [Fact] public void IGrouping_Intersect_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1227,7 +1233,7 @@ public void IGrouping_Intersect_of_scalar_should_work() [Fact] public void IGrouping_Last_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1252,7 +1258,7 @@ public void IGrouping_Last_of_root_should_work() [Fact] public void IGrouping_Last_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1277,7 +1283,7 @@ public void IGrouping_Last_of_scalar_should_work() [Fact] public void IGrouping_Last_with_predicate_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1302,7 +1308,7 @@ public void IGrouping_Last_with_predicate_of_root_should_work() [Fact] public void IGrouping_Last_with_predicate_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1327,7 +1333,7 @@ public void IGrouping_Last_with_predicate_of_scalar_should_work() [Fact] public void IGrouping_LastOrDefault_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1352,7 +1358,7 @@ public void IGrouping_LastOrDefault_of_root_should_work() [Fact] public void IGrouping_LastOrDefault_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1377,7 +1383,7 @@ public void IGrouping_LastOrDefault_of_scalar_should_work() [Fact] public void IGrouping_LastOrDefault_with_predicate_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1403,7 +1409,7 @@ public void IGrouping_LastOrDefault_with_predicate_of_root_should_work() [Fact] public void IGrouping_LastOrDefault_with_predicate_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1428,7 +1434,7 @@ public void IGrouping_LastOrDefault_with_predicate_of_scalar_should_work() [Fact] public void IGrouping_LongCount_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1453,7 +1459,7 @@ public void IGrouping_LongCount_of_root_should_work() [Fact] public void IGrouping_LongCount_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1478,7 +1484,7 @@ public void IGrouping_LongCount_of_scalar_should_work() [Fact] public void IGrouping_LongCount_with_predicate_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1503,7 +1509,7 @@ public void IGrouping_LongCount_with_predicate_of_root_should_work() [Fact] public void IGrouping_LongCount_with_predicate_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1528,7 +1534,7 @@ public void IGrouping_LongCount_with_predicate_of_scalar_should_work() [Fact] public void IGrouping_Max_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1553,7 +1559,7 @@ public void IGrouping_Max_of_root_should_work() [Fact] public void IGrouping_Max_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1578,7 +1584,7 @@ public void IGrouping_Max_of_scalar_should_work() [Fact] public void IGrouping_Max_with_selector_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1603,7 +1609,7 @@ public void IGrouping_Max_with_selector_of_root_should_work() [Fact] public void IGrouping_Max_with_selector_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1628,7 +1634,7 @@ public void IGrouping_Max_with_selector_of_scalar_should_work() [Fact] public void IGrouping_Min_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1653,7 +1659,7 @@ public void IGrouping_Min_of_root_should_work() [Fact] public void IGrouping_Min_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1678,7 +1684,7 @@ public void IGrouping_Min_of_scalar_should_work() [Fact] public void IGrouping_Min_with_selector_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1703,7 +1709,7 @@ public void IGrouping_Min_with_selector_of_root_should_work() [Fact] public void IGrouping_Min_with_selector_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1728,7 +1734,7 @@ public void IGrouping_Min_with_selector_of_scalar_should_work() [Fact] public void IGrouping_Reverse_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1753,7 +1759,7 @@ public void IGrouping_Reverse_of_root_should_work() [Fact] public void IGrouping_Reverse_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1778,7 +1784,7 @@ public void IGrouping_Reverse_of_scalar_should_work() [Fact] public void IGrouping_Select_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1803,7 +1809,7 @@ public void IGrouping_Select_of_root_should_work() [Fact] public void IGrouping_Select_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1828,7 +1834,7 @@ public void IGrouping_Select_of_scalar_should_work() [Fact] public void IGrouping_StandardDeviationPopulation_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1853,7 +1859,7 @@ public void IGrouping_StandardDeviationPopulation_of_root_should_work() [Fact] public void IGrouping_StandardDeviationPopulation_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1878,7 +1884,7 @@ public void IGrouping_StandardDeviationPopulation_of_scalar_should_work() [Fact] public void IGrouping_StandardDeviationPopulation_with_selector_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1903,7 +1909,7 @@ public void IGrouping_StandardDeviationPopulation_with_selector_of_root_should_w [Fact] public void IGrouping_StandardDeviationPopulation_with_selector_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1928,7 +1934,7 @@ public void IGrouping_StandardDeviationPopulation_with_selector_of_scalar_should [Fact] public void IGrouping_StandardDeviationSample_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -1953,7 +1959,7 @@ public void IGrouping_StandardDeviationSample_of_root_should_work() [Fact] public void IGrouping_StandardDeviationSample_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -1978,7 +1984,7 @@ public void IGrouping_StandardDeviationSample_of_scalar_should_work() [Fact] public void IGrouping_StandardDeviationSample_with_selector_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -2003,7 +2009,7 @@ public void IGrouping_StandardDeviationSample_with_selector_of_root_should_work( [Fact] public void IGrouping_StandardDeviationSample_with_selector_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -2028,7 +2034,7 @@ public void IGrouping_StandardDeviationSample_with_selector_of_scalar_should_wor [Fact] public void IGrouping_Sum_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -2053,7 +2059,7 @@ public void IGrouping_Sum_of_root_should_work() [Fact] public void IGrouping_Sum_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -2078,7 +2084,7 @@ public void IGrouping_Sum_of_scalar_should_work() [Fact] public void IGrouping_Take_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -2103,7 +2109,7 @@ public void IGrouping_Take_of_root_should_work() [Fact] public void IGrouping_Take_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -2128,7 +2134,7 @@ public void IGrouping_Take_of_scalar_should_work() [Fact] public void IGrouping_ToArray_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -2153,7 +2159,7 @@ public void IGrouping_ToArray_of_root_should_work() [Fact] public void IGrouping_ToArray_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -2178,7 +2184,7 @@ public void IGrouping_ToArray_of_scalar_should_work() [Fact] public void IGrouping_ToList_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -2203,7 +2209,7 @@ public void IGrouping_ToList_of_root_should_work() [Fact] public void IGrouping_ToList_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -2228,7 +2234,7 @@ public void IGrouping_ToList_of_scalar_should_work() [Fact] public void IGrouping_Union_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -2253,7 +2259,7 @@ public void IGrouping_Union_of_root_should_work() [Fact] public void IGrouping_Union_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -2278,7 +2284,7 @@ public void IGrouping_Union_of_scalar_should_work() [Fact] public void IGrouping_Where_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -2303,7 +2309,7 @@ public void IGrouping_Where_of_root_should_work() [Fact] public void IGrouping_Where_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -2328,7 +2334,7 @@ public void IGrouping_Where_of_scalar_should_work() [Fact] public void IGrouping_Zip_of_root_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id) @@ -2353,7 +2359,7 @@ public void IGrouping_Zip_of_root_should_work() [Fact] public void IGrouping_Zip_of_scalar_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .GroupBy(c => c.Id, c => c.X) @@ -2375,27 +2381,24 @@ public void IGrouping_Zip_of_scalar_should_work() results[1].ShouldBeEquivalentTo(new { Id = 2, Result = CreateList(new { X = 2, Y = 3 }) }); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - var documents = new[] - { - new C { Id = 1, X = 1 }, - new C { Id = 2, X = 2 } - }; - CreateCollection(collection, documents); - return collection; - } - private List CreateList(params TAnonymous[] items) { return new List(items); } - private class C + public class C { public int Id { get; set; } public int X { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, X = 1 }, + new C { Id = 2, X = 2 } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4049Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4049Tests.cs index 7647755fc58..39cad63b45d 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4049Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4049Tests.cs @@ -13,19 +13,26 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp4049Tests : Linq3IntegrationTest + public class CSharp4049Tests : LinqIntegrationTest { + public CSharp4049Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Aggregate_Project_should_translate_as_expected() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .Project(x => new TestClass { Property = x.Property.ToUpper() }); @@ -39,7 +46,7 @@ public void Aggregate_Project_should_translate_as_expected() [Fact] public void Queryable_Select_should_translate_as_expected() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => new TestClass { Property = x.Property.ToUpper() }); @@ -50,23 +57,18 @@ public void Queryable_Select_should_translate_as_expected() results.Property.Should().Be("ABC"); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - - var documents = new[] - { - new TestClass { Property = "abc" } - }; - CreateCollection(collection, documents); - - return collection; - } - public class TestClass { [BsonElement("_p")] public string Property { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new TestClass { Property = "abc" } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4057Tests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4057Tests.cs index 9383176fe97..dfa8e9995d1 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4057Tests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Jira/CSharp4057Tests.cs @@ -13,18 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira { - public class CSharp4057Tests : Linq3IntegrationTest + public class CSharp4057Tests : LinqIntegrationTest { + public CSharp4057Tests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Aggregate_Project_should_work() { - var collection = CreateProductsCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .Sort(Builders.Sort.Ascending(p => p.Id)) @@ -47,7 +54,7 @@ public void Aggregate_Project_should_work() [Fact] public void Queryable_Select() { - var collection = CreateProductsCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .OrderBy(p => p.Id) @@ -67,22 +74,7 @@ public void Queryable_Select() results.Select(r => r.IsExternalUrl).Should().Equal(true, true, false); } - private IMongoCollection CreateProductsCollection() - { - var collection = GetCollection(); - - var documents = new[] - { - new Product { Id = 1, ShopUrl = null }, - new Product { Id = 2, ShopUrl = "" }, - new Product { Id = 3, ShopUrl = "abc" } - }; - CreateCollection(collection, documents); - - return collection; - } - - private class Product + public class Product { public int Id { get; set; } public string ShopUrl { get; set; } @@ -92,5 +84,15 @@ private class ProductTypeSearchResult { public bool IsExternalUrl { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Product { Id = 1, ShopUrl = null }, + new Product { Id = 2, ShopUrl = "" }, + new Product { Id = 3, ShopUrl = "abc" } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AggregateMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AggregateMethodToAggregationExpressionTranslatorTests.cs index 4afb1d23bf2..5158c901e81 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AggregateMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AggregateMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class AggregateMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class AggregateMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public AggregateMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Aggregate_with_func_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Aggregate((x, y) => x * y)) : @@ -46,7 +52,7 @@ public void Aggregate_with_func_should_work( public void Aggregate_with_seed_and_func_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Aggregate(2, (x, y) => x * y)) : @@ -64,7 +70,7 @@ public void Aggregate_with_seed_and_func_should_work( public void Aggregate_with_seed_func_and_result_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Aggregate(2, (x, y) => x * y, x => x * 3)) : @@ -77,22 +83,21 @@ public void Aggregate_with_seed_func_and_result_selector_should_work( results.Should().Equal(6, 6, 12, 36); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AllMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AllMethodToAggregationExpressionTranslatorTests.cs index 70807c1cd24..8b2a90cad70 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AllMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AllMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class AllMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class AllMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public AllMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void All_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().All(x => x < 2)) : @@ -41,22 +47,21 @@ public void All_should_work( results.Should().Equal(true, true, false, false); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AnyMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AnyMethodToAggregationExpressionTranslatorTests.cs index 7e8cacaa486..e1bf60c835c 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AnyMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AnyMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class AnyMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class AnyMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public AnyMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Any_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Any()) : @@ -46,7 +52,7 @@ public void Any_should_work( public void Any_with_predicate_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Any(x => x > 2)) : @@ -62,7 +68,7 @@ public void Any_with_predicate_should_work( [Fact] public void Any_on_constant_array_should_be_optimized() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var obj = new[] { 1, 2, 3 }; var queryable = collection.AsQueryable() @@ -75,22 +81,21 @@ public void Any_on_constant_array_should_be_optimized() results.Select(x => x.Id).Should().Equal(1, 2, 3); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AverageMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AverageMethodToAggregationExpressionTranslatorTests.cs index 2a4b7d34143..07d42fbcaff 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AverageMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/AverageMethodToAggregationExpressionTranslatorTests.cs @@ -13,24 +13,30 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class AverageMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class AverageMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public AverageMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Average_with_decimals_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Decimals.AsQueryable().Average()) : @@ -48,7 +54,7 @@ public void Average_with_decimals_should_work( public void Average_with_decimals_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Decimals.AsQueryable().Average(x => x * 2.0M)) : @@ -66,7 +72,7 @@ public void Average_with_decimals_selector_should_work( public void Average_with_doubles_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Doubles.AsQueryable().Average()) : @@ -84,7 +90,7 @@ public void Average_with_doubles_should_work( public void Average_with_doubles_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Doubles.AsQueryable().Average(x => x * 2.0)) : @@ -102,7 +108,7 @@ public void Average_with_doubles_selector_should_work( public void Average_with_floats_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Floats.AsQueryable().Average()) : @@ -120,7 +126,7 @@ public void Average_with_floats_should_work( public void Average_with_floats_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Floats.AsQueryable().Average(x => x * 2.0F)) : @@ -138,7 +144,7 @@ public void Average_with_floats_selector_should_work( public void Average_with_ints_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Ints.AsQueryable().Average()) : @@ -156,7 +162,7 @@ public void Average_with_ints_should_work( public void Average_with_ints_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Ints.AsQueryable().Average(x => x * 2)) : @@ -174,7 +180,7 @@ public void Average_with_ints_selector_should_work( public void Average_with_longs_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Longs.AsQueryable().Average()) : @@ -192,7 +198,7 @@ public void Average_with_longs_should_work( public void Average_with_longs_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Longs.AsQueryable().Average(x => x * 2L)) : @@ -210,7 +216,7 @@ public void Average_with_longs_selector_should_work( public void Average_with_nullable_decimals_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDecimals.AsQueryable().Average()) : @@ -228,7 +234,7 @@ public void Average_with_nullable_decimals_should_work( public void Average_with_nullable_decimals_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDecimals.AsQueryable().Average(x => x * 2.0M)) : @@ -246,7 +252,7 @@ public void Average_with_nullable_decimals_selector_should_work( public void Average_with_nullable_doubles_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDoubles.AsQueryable().Average()) : @@ -264,7 +270,7 @@ public void Average_with_nullable_doubles_should_work( public void Average_with_nullable_doubles_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDoubles.AsQueryable().Average(x => x * 2.0)) : @@ -282,7 +288,7 @@ public void Average_with_nullable_doubles_selector_should_work( public void Average_with_nullable_floats_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableFloats.AsQueryable().Average()) : @@ -300,7 +306,7 @@ public void Average_with_nullable_floats_should_work( public void Average_with_nullable_floats_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableFloats.AsQueryable().Average(x => x * 2.0F)) : @@ -318,7 +324,7 @@ public void Average_with_nullable_floats_selector_should_work( public void Average_with_nullable_ints_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableInts.AsQueryable().Average()) : @@ -336,7 +342,7 @@ public void Average_with_nullable_ints_should_work( public void Average_with_nullable_ints_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableInts.AsQueryable().Average(x => x * 2)) : @@ -354,7 +360,7 @@ public void Average_with_nullable_ints_selector_should_work( public void Average_with_nullable_longs_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableLongs.AsQueryable().Average()) : @@ -372,7 +378,7 @@ public void Average_with_nullable_longs_should_work( public void Average_with_nullable_longs_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableLongs.AsQueryable().Average(x => x * 2L)) : @@ -385,11 +391,25 @@ public void Average_with_nullable_longs_selector_should_work( results.Should().Equal(null, null, 4.0); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, + public int Id { get; set; } + [BsonRepresentation(BsonType.Decimal128)] public decimal[] Decimals { get; set; } + public double[] Doubles { get; set; } + public float[] Floats { get; set; } + public int[] Ints { get; set; } + public long[] Longs { get; set; } + [BsonRepresentation(BsonType.Decimal128)] public decimal?[] NullableDecimals { get; set; } + public double?[] NullableDoubles { get; set; } + public float?[] NullableFloats { get; set; } + public int?[] NullableInts { get; set; } + public long?[] NullableLongs { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new C { Id = 1, @@ -431,23 +451,8 @@ private IMongoCollection CreateCollection() NullableFloats = new float?[] { null, 1.0F, 2.0F, 3.0F }, NullableInts = new int?[] { null, 1, 2, 3 }, NullableLongs = new long?[] { null, 1L, 2L, 3L } - }); - return collection; - } - - private class C - { - public int Id { get; set; } - [BsonRepresentation(BsonType.Decimal128)] public decimal[] Decimals { get; set; } - public double[] Doubles { get; set; } - public float[] Floats { get; set; } - public int[] Ints { get; set; } - public long[] Longs { get; set; } - [BsonRepresentation(BsonType.Decimal128)] public decimal?[] NullableDecimals { get; set; } - public double?[] NullableDoubles { get; set; } - public float?[] NullableFloats { get; set; } - public int?[] NullableInts { get; set; } - public long?[] NullableLongs { get; set; } + } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConcatMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConcatMethodToAggregationExpressionTranslatorTests.cs index d51d82e00df..a6a084f4ea8 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConcatMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConcatMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class ConcatMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class ConcatMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public ConcatMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Enumerable_Concat_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.Concat(x.B.AsQueryable())) : @@ -50,7 +56,7 @@ public void Enumerable_Concat_should_work( public void Queryable_Concat_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.AsQueryable().Concat(x.B.AsQueryable())) : @@ -67,23 +73,22 @@ public void Queryable_Concat_should_work( results[3].Should().Equal(1, 2); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0], B = new int[0] }, - new C { Id = 1, A = new int[0], B = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1 }, B = new int[0] }, - new C { Id = 3, A = new int[] { 1 }, B = new int[] { 2 } }); - return collection; - } - - private class C + public class C { public int Id { get; set; } public int[] A { get; set; } public int[] B { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0], B = new int[0] }, + new C { Id = 1, A = new int[0], B = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1 }, B = new int[0] }, + new C { Id = 3, A = new int[] { 1 }, B = new int[] { 2 } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ContainsMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ContainsMethodToAggregationExpressionTranslatorTests.cs index 9c9d0e01f63..f01a80013d6 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ContainsMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ContainsMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class ContainsMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class ContainsMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public ContainsMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Contains_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Contains(2)) : @@ -41,22 +47,21 @@ public void Contains_should_work( results.Should().Equal(false, false, true, true); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConvertMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConvertMethodToAggregationExpressionTranslatorTests.cs index 7759baf34dd..c2c00bf02ca 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConvertMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ConvertMethodToAggregationExpressionTranslatorTests.cs @@ -17,7 +17,6 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; -using FluentAssertions; using MongoDB.Bson; using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/CountMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/CountMethodToAggregationExpressionTranslatorTests.cs index 2db2b9c7207..42533925a3e 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/CountMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/CountMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class CountMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class CountMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public CountMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Count_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Count()) : @@ -46,7 +52,7 @@ public void Count_should_work( public void Count_with_predicate_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Count(x => x > 2)) : @@ -64,7 +70,7 @@ public void Count_with_predicate_should_work( public void LongCount_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().LongCount()) : @@ -82,7 +88,7 @@ public void LongCount_should_work( public void LongCount_with_predicate_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().LongCount(x => x > 2)) : @@ -95,22 +101,21 @@ public void LongCount_with_predicate_should_work( results.Should().Equal(0L, 0L, 0L, 1L); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DateFromStringMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DateFromStringMethodToAggregationExpressionTranslatorTests.cs index 69dae706333..12fb415064a 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DateFromStringMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DateFromStringMethodToAggregationExpressionTranslatorTests.cs @@ -21,13 +21,18 @@ using MongoDB.Bson; using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class DateFromStringMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class DateFromStringMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public DateFromStringMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [InlineData(1, "2023-12-26T12:34:56Z")] [InlineData(2, "throws:FormatException")] @@ -35,7 +40,7 @@ public class DateFromStringMethodToAggregationExpressionTranslatorTests : Linq3I [InlineData(4, "throws:MongoCommandException")] public void DateTime_Parse_should_work(int id, string expectedResult) { - var collection = GetCollection(); + var collection = Fixture.Collection; // technically this Parse method is not an Mql method but this test is to confirm that Parse and DateFromString behave the same var queryable = collection.AsQueryable() @@ -59,7 +64,7 @@ public void DateTime_Parse_should_work(int id, string expectedResult) [InlineData(4, "throws:MongoCommandException")] public void MongoDBFunctions_DateFromString_should_work(int id, string expectedResult) { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(x => x.Id == id) @@ -83,7 +88,7 @@ public void MongoDBFunctions_DateFromString_should_work(int id, string expectedR public void MongoDBFunctions_DateFromString_with_format_should_work(int id, string expectedResult) { RequireServer.Check().Supports(Feature.DateFromStringFormatArgument); - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(x => x.Id == id) @@ -107,7 +112,7 @@ public void MongoDBFunctions_DateFromString_with_format_should_work(int id, stri public void MongoDBFunctions_DateFromString_with_format_and_timezone_should_work(int id, string expectedResult) { RequireServer.Check().Supports(Feature.DateFromStringFormatArgument); - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(x => x.Id == id) @@ -134,13 +139,13 @@ public void MongoDBFunctions_DateFromString_with_format_and_timezone_should_work public void MongoDBFunctions_DateFromString_with_format_and_timezone_and_onError_and_onNull_should_work(int id, string expectedResult) { RequireServer.Check().Supports(Feature.DateFromStringFormatArgument); - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(x => x.Id == id) .Select(x => Mql.DateFromString(x.S, x.F, x.TZ, x.OnError, x.OnNull)); - var expectedStages = + var expectedStages = new[] { $"{{ $match : {{ _id : {id} }} }}", @@ -206,22 +211,7 @@ private void AssertNullableDateTimeResult(DateTime? result, string expectedResul result.Should().Be(expectedResult == "default" ? (DateTime?)default : DateTime.Parse(expectedResult, null, DateTimeStyles.AdjustToUniversal)); } - private IMongoCollection GetCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection.Database.GetCollection("test"), - BsonDocument.Parse("{ _id : 1, S : '2023-12-26T12:34:56', F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : { $date : '0001-01-01T00:00:00' } }"), - BsonDocument.Parse("{ _id : 2, F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : { $date : '0001-01-01T00:00:00' } }"), - BsonDocument.Parse("{ _id : 3, S : null, F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : { $date : '0001-01-01T00:00:00' } }"), - BsonDocument.Parse("{ _id : 4, S : 'error', F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '1111-11-11T11:11:11' }, OnNull : { $date : '0001-01-01T00:00:00' } }"), - BsonDocument.Parse("{ _id : 5, F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : null }"), - BsonDocument.Parse("{ _id : 6, S : null, F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : null }"), - BsonDocument.Parse("{ _id : 7, S : 'error', F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '1111-11-11T11:11:11' }, OnNull : null }")); - return collection; - } - - private class C + public class C { public int Id { get; set; } public string S { get; set; } @@ -230,5 +220,19 @@ private class C public DateTime? OnError { get; set; } public DateTime? OnNull { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + BsonDocument.Parse("{ _id : 1, S : '2023-12-26T12:34:56', F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : { $date : '0001-01-01T00:00:00' } }"), + BsonDocument.Parse("{ _id : 2, F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : { $date : '0001-01-01T00:00:00' } }"), + BsonDocument.Parse("{ _id : 3, S : null, F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : { $date : '0001-01-01T00:00:00' } }"), + BsonDocument.Parse("{ _id : 4, S : 'error', F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '1111-11-11T11:11:11' }, OnNull : { $date : '0001-01-01T00:00:00' } }"), + BsonDocument.Parse("{ _id : 5, F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : null }"), + BsonDocument.Parse("{ _id : 6, S : null, F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '0001-01-01T00:00:00' }, OnNull : null }"), + BsonDocument.Parse("{ _id : 7, S : 'error', F : '%Y-%m-%dT%H:%M:%S', TZ : 'UTC', OnError : { $date : '1111-11-11T11:11:11' }, OnNull : null }") + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DefaultIfEmptyMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DefaultIfEmptyMethodToAggregationExpressionTranslatorTests.cs index f4da76cee91..6887c8dd123 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DefaultIfEmptyMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DefaultIfEmptyMethodToAggregationExpressionTranslatorTests.cs @@ -13,19 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class DefaultIfEmptyMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class DefaultIfEmptyMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public DefaultIfEmptyMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Enumerable_DefaultIfEmpty_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => x.A.DefaultIfEmpty()); @@ -44,7 +50,7 @@ public void Enumerable_DefaultIfEmpty_should_work() [Fact] public void Queryable_DefaultIfEmpty_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => x.A.AsQueryable().DefaultIfEmpty()); @@ -59,22 +65,21 @@ public void Queryable_DefaultIfEmpty_should_work() results[2].Should().Equal(1, 2); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DistinctMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DistinctMethodToAggregationExpressionTranslatorTests.cs index 5395c849fec..7f7b5fe5e1c 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DistinctMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/DistinctMethodToAggregationExpressionTranslatorTests.cs @@ -13,19 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class DistinctMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class DistinctMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public DistinctMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Enumerable_Distinct_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.Distinct()); @@ -43,7 +49,7 @@ public void Enumerable_Distinct_should_work() [Fact] public void Queryable_Distinct_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().Distinct()); @@ -58,22 +64,21 @@ public void Queryable_Distinct_should_work() results[3].Should().BeEquivalentTo(1, 2); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 2 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 2 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ElementAtMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ElementAtMethodToAggregationExpressionTranslatorTests.cs index 3640db5aabc..bbfad01e5a1 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ElementAtMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ElementAtMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class ElementAtMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class ElementAtMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public ElementAtMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void ElementAt_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().ElementAt(1)) : @@ -46,7 +52,7 @@ public void ElementAt_should_work( public void ElementAtOrDefault_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().ElementAtOrDefault(1)) : @@ -59,22 +65,21 @@ public void ElementAtOrDefault_should_work( results.Should().Equal(0, 0, 2, 2); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 2 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ExceptMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ExceptMethodToAggregationExpressionTranslatorTests.cs index a7dce5dff24..47bb3f795b2 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ExceptMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ExceptMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class ExceptMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class ExceptMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public ExceptMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Enumerable_Except_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.Except(x.B.AsQueryable())) : @@ -50,7 +56,7 @@ public void Enumerable_Except_should_work( public void Queryable_Except_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.AsQueryable().Except(x.B.AsQueryable())) : @@ -67,23 +73,22 @@ public void Queryable_Except_should_work( results[3].Should().Equal(2); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0], B = new int[0] }, - new C { Id = 1, A = new int[0], B = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 }, B = new int[0] }, - new C { Id = 3, A = new int[] { 1, 2 }, B = new int[] { 1 } }); - return collection; - } - - private class C + public class C { public int Id { get; set; } public int[] A { get; set; } public int[] B { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0], B = new int[0] }, + new C { Id = 1, A = new int[0], B = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 }, B = new int[0] }, + new C { Id = 3, A = new int[] { 1, 2 }, B = new int[] { 1 } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/FirstOrLastMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/FirstOrLastMethodToAggregationExpressionTranslatorTests.cs index cbccfd68170..b131aeadb99 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/FirstOrLastMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/FirstOrLastMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class FirstOrLastMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class FirstOrLastMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public FirstOrLastMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void First_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().First()) : @@ -46,7 +52,7 @@ public void First_should_work( public void First_with_predicate_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().First(x => x > 1)) : @@ -64,7 +70,7 @@ public void First_with_predicate_should_work( public void FirstOrDefault_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().FirstOrDefault()) : @@ -82,7 +88,7 @@ public void FirstOrDefault_should_work( public void FirstOrDefault_with_predicate_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().FirstOrDefault(x => x > 1)) : @@ -100,7 +106,7 @@ public void FirstOrDefault_with_predicate_should_work( public void Last_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Last()) : @@ -118,7 +124,7 @@ public void Last_should_work( public void Last_with_predicate_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().Last(x => x > 1)) : @@ -136,7 +142,7 @@ public void Last_with_predicate_should_work( public void LastOrDefault_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().LastOrDefault()) : @@ -154,7 +160,7 @@ public void LastOrDefault_should_work( public void LastOrDefault_with_predicate_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.A.AsQueryable().LastOrDefault(x => x > 1)) : @@ -167,22 +173,21 @@ public void LastOrDefault_with_predicate_should_work( results.Should().Equal(0, 0, 2, 3); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IntersectMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IntersectMethodToAggregationExpressionTranslatorTests.cs index 49f48d4c53d..ab2be78888d 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IntersectMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IntersectMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class IntersectMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class IntersectMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public IntersectMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Enumerable_Intersect_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.Intersect(x.B.AsQueryable())) : @@ -50,7 +56,7 @@ public void Enumerable_Intersect_should_work( public void Queryable_Intersect_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.AsQueryable().Intersect(x.B.AsQueryable())) : @@ -67,23 +73,22 @@ public void Queryable_Intersect_should_work( results[3].Should().Equal(1); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0], B = new int[0] }, - new C { Id = 1, A = new int[0], B = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1 }, B = new int[] { 1 } }, - new C { Id = 3, A = new int[] { 1 }, B = new int[] { 1, 2 } }); - return collection; - } - - private class C + public class C { public int Id { get; set; } public int[] A { get; set; } public int[] B { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0], B = new int[0] }, + new C { Id = 1, A = new int[0], B = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1 }, B = new int[] { 1 } }, + new C { Id = 3, A = new int[] { 1 }, B = new int[] { 1, 2 } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsMatchMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsMatchMethodToAggregationExpressionTranslatorTests.cs index 05c0ad52535..786a8989e37 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsMatchMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsMatchMethodToAggregationExpressionTranslatorTests.cs @@ -13,24 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using FluentAssertions; using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class IsMatchMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class IsMatchMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public IsMatchMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture, server => server.Supports(Feature.RegexMatch)) + { + } + [Fact] public void Should_translate_instance_regex_isMatch() { - RequireServer.Check().Supports(Feature.RegexMatch); - - var collection = CreateCollection(); + var collection = Fixture.Collection; var regex = new Regex(@"\dB.*0"); var queryable = collection.AsQueryable() .Where(i => regex.IsMatch(i.A + i.B)); @@ -45,9 +49,9 @@ public void Should_translate_instance_regex_isMatch() [Fact] public void Should_translate_static_regex_isMatch() { - RequireServer.Check().Supports(Feature.RegexMatch); + RequireServer.Check(); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => Regex.IsMatch(i.A + i.B, @"\dB.*0")); @@ -61,9 +65,7 @@ public void Should_translate_static_regex_isMatch() [Fact] public void Should_translate_static_regex_isMatch_with_options() { - RequireServer.Check().Supports(Feature.RegexMatch); - - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => Regex.IsMatch(i.A + i.B, @"\dB.*0", RegexOptions.IgnoreCase)); @@ -74,21 +76,20 @@ public void Should_translate_static_regex_isMatch_with_options() result.Id.Should().Be(2); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new Data { Id = 1, A = "ABC", B = "1" }, - new Data { Id = 2, A = "1Br", B = "0" }); - return collection; - } - - private class Data + public class Data { public int Id { get; set; } public string A { get; set; } public string B { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Data { Id = 1, A = "ABC", B = "1" }, + new Data { Id = 2, A = "1Br", B = "0" } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsMissingMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsMissingMethodToAggregationExpressionTranslatorTests.cs index 017f64f66e4..dc7df901269 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsMissingMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsMissingMethodToAggregationExpressionTranslatorTests.cs @@ -13,20 +13,26 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class IsMissingMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class IsMissingMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public IsMissingMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Select_Exists_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => Mql.Exists(x.S)); @@ -41,7 +47,7 @@ public void Select_Exists_should_work() [Fact] public void Select_IsMissing_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => Mql.IsMissing(x.S)); @@ -56,7 +62,7 @@ public void Select_IsMissing_should_work() [Fact] public void Select_IsNullOrMissing_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(x => Mql.IsNullOrMissing(x.S)); @@ -68,21 +74,20 @@ public void Select_IsNullOrMissing_should_work() results.Should().Equal(true, true, false); } - private IMongoCollection GetCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - GetCollection("test"), - BsonDocument.Parse("{ _id : 1 }"), - BsonDocument.Parse("{ _id : 2, S : null }"), - BsonDocument.Parse("{ _id : 3, S : 'abc' }")); - return collection; + public int Id { get; set; } + public string S { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public string S { get; set; } + protected override IEnumerable InitialData => + [ + BsonDocument.Parse("{ _id : 1 }"), + BsonDocument.Parse("{ _id : 2, S : null }"), + BsonDocument.Parse("{ _id : 3, S : 'abc' }") + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsNullOrWhiteSpaceMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsNullOrWhiteSpaceMethodToAggregationExpressionTranslatorTests.cs index 2c5bc4d07e0..fb453ed5dbb 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsNullOrWhiteSpaceMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/IsNullOrWhiteSpaceMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class IsNullOrWhiteSpaceMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class IsNullOrWhiteSpaceMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public IsNullOrWhiteSpaceMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture, server => server.Supports(Feature.TrimOperator)) + { + } + [Fact] public void Project_IsNullOrWhiteSpace_using_anonymous_class_should_return_expected_results() { - RequireServer.Check().Supports(Feature.FindProjectionExpressions, Feature.TrimOperator); - var collection = CreateCollection(); + RequireServer.Check().Supports(Feature.FindProjectionExpressions); + var collection = Fixture.Collection; var find = collection.Find("{}") .Project(x => new { R = string.IsNullOrWhiteSpace(x.S) }) @@ -44,8 +50,8 @@ public void Project_IsNullOrWhiteSpace_using_anonymous_class_should_return_expec [Fact] public void Project_IsNullOrWhiteSpace_using_named_class_should_return_expected_results() { - RequireServer.Check().Supports(Feature.FindProjectionExpressions, Feature.TrimOperator); - var collection = CreateCollection(); + RequireServer.Check().Supports(Feature.FindProjectionExpressions); + var collection = Fixture.Collection; var find = collection.Find("{}") .Project(x => new Result { R = string.IsNullOrWhiteSpace(x.S) }) @@ -61,8 +67,7 @@ public void Project_IsNullOrWhiteSpace_using_named_class_should_return_expected_ [Fact] public void Select_IsNullOrWhiteSpace_using_scalar_result_should_return_expected_results() { - RequireServer.Check().Supports(Feature.TrimOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .OrderBy(x => x.Id) @@ -81,8 +86,7 @@ public void Select_IsNullOrWhiteSpace_using_scalar_result_should_return_expected [Fact] public void Select_IsNullOrWhiteSpace_using_anonymous_class_should_return_expected_results() { - RequireServer.Check().Supports(Feature.TrimOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .OrderBy(x => x.Id) @@ -101,8 +105,7 @@ public void Select_IsNullOrWhiteSpace_using_anonymous_class_should_return_expect [Fact] public void Select_IsNullOrWhiteSpace_using_named_class_should_return_expected_results() { - RequireServer.Check().Supports(Feature.TrimOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .OrderBy(x => x.Id) @@ -118,19 +121,6 @@ public void Select_IsNullOrWhiteSpace_using_named_class_should_return_expected_r results.Select(x => x.R).Should().Equal(true, true, true, true, false); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - CreateCollection( - collection, - new C { Id = 1, S = null }, - new C { Id = 2, S = "" }, - new C { Id = 3, S = " " }, - new C { Id = 4, S = " \t\r\n" }, - new C { Id = 5, S = "abc" }); - return collection; - } - public class C { public int Id { get; set; } @@ -141,5 +131,17 @@ public class Result { public bool R { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, S = null }, + new C { Id = 2, S = "" }, + new C { Id = 3, S = " " }, + new C { Id = 4, S = " \t\r\n" }, + new C { Id = 5, S = "abc" } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/MaxOrMinMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/MaxOrMinMethodToAggregationExpressionTranslatorTests.cs index 333d6c1687e..32c28979acb 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/MaxOrMinMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/MaxOrMinMethodToAggregationExpressionTranslatorTests.cs @@ -13,24 +13,30 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class MaxOrMinMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class MaxOrMinMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public MaxOrMinMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Max_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Documents.AsQueryable().Max()) : @@ -48,7 +54,7 @@ public void Max_should_work( public void Max_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Documents.AsQueryable().Max(x => x["X"])) : @@ -66,7 +72,7 @@ public void Max_with_selector_should_work( public void Max_of_decimals_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Decimals.AsQueryable().Max()) : @@ -84,7 +90,7 @@ public void Max_of_decimals_should_work( public void Max_of_decimals_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Decimals.AsQueryable().Max(x => x * 2.0M)) : @@ -102,7 +108,7 @@ public void Max_of_decimals_with_selector_should_work( public void Max_of_doubles_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Doubles.AsQueryable().Max()) : @@ -120,7 +126,7 @@ public void Max_of_doubles_should_work( public void Max_of_doubles_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Doubles.AsQueryable().Max(x => x * 2.0)) : @@ -138,7 +144,7 @@ public void Max_of_doubles_with_selector_should_work( public void Max_of_floats_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Floats.AsQueryable().Max()) : @@ -156,7 +162,7 @@ public void Max_of_floats_should_work( public void Max_of_floats_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Floats.AsQueryable().Max(x => x * 2.0F)) : @@ -174,7 +180,7 @@ public void Max_of_floats_with_selector_should_work( public void Max_of_ints_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Ints.AsQueryable().Max()) : @@ -192,7 +198,7 @@ public void Max_of_ints_should_work( public void Max_of_ints_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Ints.AsQueryable().Max(x => x * 2)) : @@ -210,7 +216,7 @@ public void Max_of_ints_with_selector_should_work( public void Max_of_longs_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Longs.AsQueryable().Max()) : @@ -228,7 +234,7 @@ public void Max_of_longs_should_work( public void Max_of_longs_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Longs.AsQueryable().Max(x => x * 2L)) : @@ -246,7 +252,7 @@ public void Max_of_longs_with_selector_should_work( public void Max_of_nullable_decimals_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDecimals.AsQueryable().Max()) : @@ -264,7 +270,7 @@ public void Max_of_nullable_decimals_should_work( public void Max_of_nullable_decimals_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDecimals.AsQueryable().Max(x => x * 2.0M)) : @@ -282,7 +288,7 @@ public void Max_of_nullable_decimals_with_selector_should_work( public void Max_of_nullable_doubles_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDoubles.AsQueryable().Max()) : @@ -300,7 +306,7 @@ public void Max_of_nullable_doubles_should_work( public void Max_of_nullable_doubles_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDoubles.AsQueryable().Max(x => x * 2.0)) : @@ -318,7 +324,7 @@ public void Max_of_nullable_doubles_with_selector_should_work( public void Max_of_nullable_floats_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableFloats.AsQueryable().Max()) : @@ -336,7 +342,7 @@ public void Max_of_nullable_floats_should_work( public void Max_of_nullable_floats_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableFloats.AsQueryable().Max(x => x * 2.0F)) : @@ -354,7 +360,7 @@ public void Max_of_nullable_floats_with_selector_should_work( public void Max_of_nullable_ints_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableInts.AsQueryable().Max()) : @@ -372,7 +378,7 @@ public void Max_of_nullable_ints_should_work( public void Max_of_nullable_ints_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableInts.AsQueryable().Max(x => x * 2)) : @@ -390,7 +396,7 @@ public void Max_of_nullable_ints_with_selector_should_work( public void Max_of_nullable_longs_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableLongs.AsQueryable().Max()) : @@ -408,7 +414,7 @@ public void Max_of_nullable_longs_should_work( public void Max_of_nullable_longs_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableLongs.AsQueryable().Max(x => x * 2L)) : @@ -426,7 +432,7 @@ public void Max_of_nullable_longs_with_selector_should_work( public void Min_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Documents.AsQueryable().Min()) : @@ -444,7 +450,7 @@ public void Min_should_work( public void Min_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Documents.AsQueryable().Min(x => x["X"])) : @@ -462,7 +468,7 @@ public void Min_with_selector_should_work( public void Min_of_decimals_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Decimals.AsQueryable().Min()) : @@ -480,7 +486,7 @@ public void Min_of_decimals_should_work( public void Min_of_decimals_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Decimals.AsQueryable().Min(x => x * 2.0M)) : @@ -498,7 +504,7 @@ public void Min_of_decimals_with_selector_should_work( public void Min_of_doubles_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Doubles.AsQueryable().Min()) : @@ -516,7 +522,7 @@ public void Min_of_doubles_should_work( public void Min_of_doubles_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Doubles.AsQueryable().Min(x => x * 2.0)) : @@ -534,7 +540,7 @@ public void Min_of_doubles_with_selector_should_work( public void Min_of_floats_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Floats.AsQueryable().Min()) : @@ -552,7 +558,7 @@ public void Min_of_floats_should_work( public void Min_of_floats_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Floats.AsQueryable().Min(x => x * 2.0F)) : @@ -570,7 +576,7 @@ public void Min_of_floats_with_selector_should_work( public void Min_of_ints_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Ints.AsQueryable().Min()) : @@ -588,7 +594,7 @@ public void Min_of_ints_should_work( public void Min_of_ints_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Ints.AsQueryable().Min(x => x * 2)) : @@ -605,7 +611,7 @@ public void Min_of_ints_with_selector_should_work( public void Min_of_longs_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Longs.AsQueryable().Min()) : @@ -623,7 +629,7 @@ public void Min_of_longs_should_work( public void Min_of_longs_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Longs.AsQueryable().Min(x => x * 2L)) : @@ -641,7 +647,7 @@ public void Min_of_longs_with_selector_should_work( public void Min_of_nullable_decimals_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDecimals.AsQueryable().Min()) : @@ -659,7 +665,7 @@ public void Min_of_nullable_decimals_should_work( public void Min_of_nullable_decimals_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDecimals.AsQueryable().Min(x => x * 2.0M)) : @@ -677,7 +683,7 @@ public void Min_of_nullable_decimals_with_selector_should_work( public void Min_of_nullable_doubles_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDoubles.AsQueryable().Min()) : @@ -695,7 +701,7 @@ public void Min_of_nullable_doubles_should_work( public void Min_of_nullable_doubles_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDoubles.AsQueryable().Min(x => x * 2.0)) : @@ -713,7 +719,7 @@ public void Min_of_nullable_doubles_with_selector_should_work( public void Min_of_nullable_floats_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableFloats.AsQueryable().Min()) : @@ -731,7 +737,7 @@ public void Min_of_nullable_floats_should_work( public void Min_of_nullable_floats_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableFloats.AsQueryable().Min(x => x * 2.0F)) : @@ -749,7 +755,7 @@ public void Min_of_nullable_floats_with_selector_should_work( public void Min_of_nullable_ints_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableInts.AsQueryable().Min()) : @@ -766,7 +772,7 @@ public void Min_of_nullable_ints_should_work( public void Min_of_nullable_ints_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableInts.AsQueryable().Min(x => x * 2)) : @@ -784,7 +790,7 @@ public void Min_of_nullable_ints_with_selector_should_work( public void Min_of_nullable_longs_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableLongs.AsQueryable().Min()) : @@ -802,7 +808,7 @@ public void Min_of_nullable_longs_should_work( public void Min_of_nullable_longs_with_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableLongs.AsQueryable().Min(x => x * 2L)) : @@ -815,11 +821,26 @@ public void Min_of_nullable_longs_with_selector_should_work( results.Should().Equal(null, null, 6L); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, + public int Id { get; set; } + [BsonRepresentation(BsonType.Decimal128)] public decimal[] Decimals { get; set; } + public BsonDocument[] Documents { get; set; } + public double[] Doubles { get; set; } + public float[] Floats { get; set; } + public int[] Ints { get; set; } + public long[] Longs { get; set; } + [BsonRepresentation(BsonType.Decimal128)] public decimal?[] NullableDecimals { get; set; } + public double?[] NullableDoubles { get; set; } + public float?[] NullableFloats { get; set; } + public int?[] NullableInts { get; set; } + public long?[] NullableLongs { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new C { Id = 1, @@ -864,24 +885,8 @@ private IMongoCollection CreateCollection() NullableFloats = new float?[] { null, 3.0F }, NullableInts = new int?[] { null, 3 }, NullableLongs = new long?[] { null, 3L } - }); - return collection; - } - - private class C - { - public int Id { get; set; } - [BsonRepresentation(BsonType.Decimal128)] public decimal[] Decimals { get; set; } - public BsonDocument[] Documents { get; set; } - public double[] Doubles { get; set; } - public float[] Floats { get; set; } - public int[] Ints { get; set; } - public long[] Longs { get; set; } - [BsonRepresentation(BsonType.Decimal128)] public decimal?[] NullableDecimals { get; set; } - public double?[] NullableDoubles { get; set; } - public float?[] NullableFloats { get; set; } - public int?[] NullableInts { get; set; } - public long?[] NullableLongs { get; set; } + } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/OrderByMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/OrderByMethodToAggregationExpressionTranslatorTests.cs index 5e07a2240ad..4cdfd5468ea 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/OrderByMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/OrderByMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,26 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Driver.Core.Misc; -using MongoDB.Driver.Core.TestHelpers.XunitExtensions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class OrderByMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class OrderByMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public OrderByMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture, server => server.Supports(Feature.SortArrayOperator)) + { + } + [Fact] public void Enumerable_OrderBy_should_work() { - RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.OrderBy(x => x.X)); @@ -42,8 +46,7 @@ public void Enumerable_OrderBy_should_work() [Fact] public void Enumerable_OrderByDescending_should_work() { - RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.OrderByDescending(x => x.X)); @@ -57,8 +60,7 @@ public void Enumerable_OrderByDescending_should_work() [Fact] public void Enumerable_ThenBy_should_work() { - RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.OrderByDescending(x => x.X).ThenBy(x => x.Y)); @@ -72,8 +74,7 @@ public void Enumerable_ThenBy_should_work() [Fact] public void Enumerable_ThenByDescending_should_work() { - RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.OrderBy(x => x.X).ThenByDescending(x => x.Y)); @@ -87,8 +88,7 @@ public void Enumerable_ThenByDescending_should_work() [Fact] public void Queryable_OrderBy_should_work() { - RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().OrderBy(x => x.X)); @@ -102,8 +102,7 @@ public void Queryable_OrderBy_should_work() [Fact] public void Queryable_OrderByDescending_should_work() { - RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().OrderByDescending(x => x.X)); @@ -117,8 +116,7 @@ public void Queryable_OrderByDescending_should_work() [Fact] public void Queryable_ThenBy_should_work() { - RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().OrderByDescending(x => x.X).ThenBy(x => x.Y)); @@ -132,8 +130,7 @@ public void Queryable_ThenBy_should_work() [Fact] public void Queryable_ThenByDescending_should_work() { - RequireServer.Check().Supports(Feature.SortArrayOperator); - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().OrderBy(x => x.X).ThenByDescending(x => x.Y)); @@ -144,16 +141,7 @@ public void Queryable_ThenByDescending_should_work() result.Select(x => x.Y).Should().Equal(2, 1, 4, 3); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 1, A = new A[] { new A(1, 1), new A(1, 2), new A(2, 3), new A(2, 4) } }); - return collection; - } - - private class C + public class C { public int Id { get; set; } public A[] A { get; set; } @@ -161,9 +149,17 @@ private class C public class A { - public A(int x, int y) { X = x; Y = y; } + public A(int x, int y) { X = x; Y = y; } public int X { get; set; } public int Y { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, A = new A[] { new A(1, 1), new A(1, 2), new A(2, 3), new A(2, 4) } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/RangeMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/RangeMethodToAggregationExpressionTranslatorTests.cs index 15473964d1f..5e0bfcbff60 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/RangeMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/RangeMethodToAggregationExpressionTranslatorTests.cs @@ -13,19 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class RangeMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class RangeMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public RangeMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Range_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => Enumerable.Range(x.Start, x.Count)); @@ -38,21 +44,20 @@ public void Range_should_work() results[1].Should().Equal(3, 4, 5, 6); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 1, Start = 1, Count = 2 }, - new C { Id = 2, Start = 3, Count = 4 }); - return collection; - } - - private class C + public class C { public int Id { get; set; } public int Start { get; set; } public int Count { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 1, Start = 1, Count = 2 }, + new C { Id = 2, Start = 3, Count = 4 } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ReverseMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ReverseMethodToAggregationExpressionTranslatorTests.cs index cf938d037b5..3a59dfee43a 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ReverseMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ReverseMethodToAggregationExpressionTranslatorTests.cs @@ -13,20 +13,25 @@ * limitations under the License. */ -using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class ReverseMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class ReverseMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public ReverseMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Enumerable_Reverse_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.Reverse()); @@ -40,7 +45,7 @@ public void Enumerable_Reverse_should_work() [Fact] public void Queryable_Reverse_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().Reverse()); @@ -51,19 +56,18 @@ public void Queryable_Reverse_should_work() result.Should().Equal(3, 2, 1); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 1, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 1, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/RoundMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/RoundMethodToAggregationExpressionTranslatorTests.cs index b39a8b61496..249c4d6dc88 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/RoundMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/RoundMethodToAggregationExpressionTranslatorTests.cs @@ -14,24 +14,28 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver.Core.Misc; -using MongoDB.Driver.Core.TestHelpers.XunitExtensions; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class RoundMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class RoundMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public RoundMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture, server => server.Supports(Feature.Round)) + { + } + [Fact] public void Math_round_double_should_work() { - RequireServer.Check().Supports(Feature.Round); - - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(i => Math.Round(i.Double)); @@ -47,9 +51,7 @@ public void Math_round_double_should_work() [Fact] public void Math_round_double_with_digits_should_work() { - RequireServer.Check().Supports(Feature.Round); - - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(i => Math.Round(i.Double, 1)); @@ -65,9 +67,7 @@ public void Math_round_double_with_digits_should_work() [Fact] public void Math_round_decimal_should_work() { - RequireServer.Check().Supports(Feature.Round); - - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(i => Math.Round(i.Decimal)); @@ -83,9 +83,7 @@ public void Math_round_decimal_should_work() [Fact] public void Math_round_decimal_with_decimals_should_work() { - RequireServer.Check().Supports(Feature.Round); - - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Select(i => Math.Round(i.Decimal, 1)); @@ -98,22 +96,21 @@ public void Math_round_decimal_with_decimals_should_work() results.Should().Equal(10.2m, 9.7m, 9.2m); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new Data { Double = 10.234, Decimal = 10.234m }, - new Data { Double = 9.66, Decimal = 9.66m }, - new Data { Double = 9.2, Decimal = 9.2m }); - return collection; - } - - private class Data + public class Data { public double Double { get; set; } [BsonRepresentation(BsonType.Decimal128)] public decimal Decimal { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Data { Double = 10.234, Decimal = 10.234m }, + new Data { Double = 9.66, Decimal = 9.66m }, + new Data { Double = 9.2, Decimal = 9.2m } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMethodToAggregationExpressionTranslatorTests.cs index c7938d63e35..e57de82ac3a 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SelectMethodToAggregationExpressionTranslatorTests.cs @@ -13,19 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class SelectMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class SelectMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public SelectMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Enumerable_Select_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.Select(x => x + 1)); @@ -39,7 +45,7 @@ public void Enumerable_Select_should_work() [Fact] public void Queryable_Select_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().Select(x => x + 1)); @@ -50,19 +56,18 @@ public void Queryable_Select_should_work() result.Should().Equal(2, 3, 4); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 1, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 1, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipOrTakeMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipOrTakeMethodToAggregationExpressionTranslatorTests.cs index e16b9b36820..5f1d92b51e6 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipOrTakeMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SkipOrTakeMethodToAggregationExpressionTranslatorTests.cs @@ -13,19 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class SkipOrTakeMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class SkipOrTakeMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public SkipOrTakeMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Enumerable_Take_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.Take(2)); @@ -43,7 +49,7 @@ public void Enumerable_Take_should_work() [Fact] public void Queryable_Take_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().Take(2)); @@ -58,22 +64,21 @@ public void Queryable_Take_should_work() results[3].Should().Equal(1, 2); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/StringConcatMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/StringConcatMethodToAggregationExpressionTranslatorTests.cs index 0995c2218ac..fb94b8f9b83 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/StringConcatMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/StringConcatMethodToAggregationExpressionTranslatorTests.cs @@ -13,18 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using FluentAssertions; using System.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class StringConcatMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class StringConcatMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public StringConcatMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Filter_using_string_concat_with_two_strings_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => string.Concat(i.A, ";") == "A1;"); @@ -41,7 +48,7 @@ public void Filter_using_string_concat_with_two_strings_should_work() [Fact] public void Projection_using_string_concat_with_two_strings_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => i.Id == 1) @@ -60,7 +67,7 @@ public void Projection_using_string_concat_with_two_strings_should_work() [Fact] public void Filter_using_string_concat_with_three_strings_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => string.Concat(i.A, ";", i.B) == "A1;B1"); @@ -77,7 +84,7 @@ public void Filter_using_string_concat_with_three_strings_should_work() [Fact] public void Projection_using_string_concat_with_three_strings_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => i.Id == 1) @@ -96,7 +103,7 @@ public void Projection_using_string_concat_with_three_strings_should_work() [Fact] public void Filter_using_string_concat_with_four_strings_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => string.Concat(i.A, ";", i.B, i.C) == "A1;B1C1"); @@ -113,7 +120,7 @@ public void Filter_using_string_concat_with_four_strings_should_work() [Fact] public void Projection_using_string_concat_with_four_strings_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => i.Id == 1) @@ -132,7 +139,7 @@ public void Projection_using_string_concat_with_four_strings_should_work() [Fact] public void Filter_using_string_concat_with_params_array_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => string.Concat(i.A, ";", i.B, ";", i.C) == "A1;B1;C1"); @@ -148,7 +155,7 @@ public void Filter_using_string_concat_with_params_array_should_work() [Fact] public void Projection_using_string_concat_with_params_array_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(i => i.Id == 1) @@ -164,17 +171,7 @@ public void Projection_using_string_concat_with_params_array_should_work() result.T.Should().Be("A1;B1;C1"); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new Data { Id = 1, A = "A1", B = "B1", C = "C1", D="D1" }, - new Data { Id = 2, A = "A2", B = "B2", C = "C2", D="D2" }); - return collection; - } - - private class Data + public class Data { public int Id { get; set; } public string A { get; set; } @@ -182,5 +179,14 @@ private class Data public string C { get; set; } public string D { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Data { Id = 1, A = "A1", B = "B1", C = "C1", D="D1" }, + new Data { Id = 2, A = "A2", B = "B2", C = "C2", D="D2" } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SumMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SumMethodToAggregationExpressionTranslatorTests.cs index 9ba27b13084..8f65d8aa349 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SumMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/SumMethodToAggregationExpressionTranslatorTests.cs @@ -13,24 +13,30 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; using MongoDB.Bson.Serialization.Attributes; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class SumMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class SumMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public SumMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Sum_with_decimals_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Decimals.AsQueryable().Sum()) : @@ -48,7 +54,7 @@ public void Sum_with_decimals_should_work( public void Sum_with_decimals_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Decimals.AsQueryable().Sum(x => x * 2.0M)) : @@ -66,7 +72,7 @@ public void Sum_with_decimals_selector_should_work( public void Sum_with_doubles_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Doubles.AsQueryable().Sum()) : @@ -84,7 +90,7 @@ public void Sum_with_doubles_should_work( public void Sum_with_doubles_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Doubles.AsQueryable().Sum(x => x * 2.0)) : @@ -102,7 +108,7 @@ public void Sum_with_doubles_selector_should_work( public void Sum_with_floats_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Floats.AsQueryable().Sum()) : @@ -120,7 +126,7 @@ public void Sum_with_floats_should_work( public void Sum_with_floats_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Floats.AsQueryable().Sum(x => x * 2.0F)) : @@ -138,7 +144,7 @@ public void Sum_with_floats_selector_should_work( public void Sum_with_ints_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Ints.AsQueryable().Sum()) : @@ -156,7 +162,7 @@ public void Sum_with_ints_should_work( public void Sum_with_ints_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Ints.AsQueryable().Sum(x => x * 2)) : @@ -174,7 +180,7 @@ public void Sum_with_ints_selector_should_work( public void Sum_with_longs_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Longs.AsQueryable().Sum()) : @@ -192,7 +198,7 @@ public void Sum_with_longs_should_work( public void Sum_with_longs_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Longs.AsQueryable().Sum(x => x * 2L)) : @@ -210,7 +216,7 @@ public void Sum_with_longs_selector_should_work( public void Sum_with_nullable_decimals_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDecimals.AsQueryable().Sum()) : @@ -228,7 +234,7 @@ public void Sum_with_nullable_decimals_should_work( public void Sum_with_nullable_decimals_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDecimals.AsQueryable().Sum(x => x * 2.0M)) : @@ -246,7 +252,7 @@ public void Sum_with_nullable_decimals_selector_should_work( public void Sum_with_nullable_doubles_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDoubles.AsQueryable().Sum()) : @@ -264,7 +270,7 @@ public void Sum_with_nullable_doubles_should_work( public void Sum_with_nullable_doubles_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableDoubles.AsQueryable().Sum(x => x * 2.0)) : @@ -282,7 +288,7 @@ public void Sum_with_nullable_doubles_selector_should_work( public void Sum_with_nullable_floats_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableFloats.AsQueryable().Sum()) : @@ -300,7 +306,7 @@ public void Sum_with_nullable_floats_should_work( public void Sum_with_nullable_floats_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableFloats.AsQueryable().Sum(x => x * 2.0F)) : @@ -318,7 +324,7 @@ public void Sum_with_nullable_floats_selector_should_work( public void Sum_with_nullable_ints_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableInts.AsQueryable().Sum()) : @@ -336,7 +342,7 @@ public void Sum_with_nullable_ints_should_work( public void Sum_with_nullable_ints_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableInts.AsQueryable().Sum(x => x * 2)) : @@ -354,7 +360,7 @@ public void Sum_with_nullable_ints_selector_should_work( public void Sum_with_nullable_longs_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableLongs.AsQueryable().Sum()) : @@ -372,7 +378,7 @@ public void Sum_with_nullable_longs_should_work( public void Sum_with_nullable_longs_selector_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.NullableLongs.AsQueryable().Sum(x => x * 2L)) : @@ -385,11 +391,25 @@ public void Sum_with_nullable_longs_selector_should_work( results.Should().Equal(0, 0, 12L); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, + public int Id { get; set; } + [BsonRepresentation(BsonType.Decimal128)] public decimal[] Decimals { get; set; } + public double[] Doubles { get; set; } + public float[] Floats { get; set; } + public int[] Ints { get; set; } + public long[] Longs { get; set; } + [BsonRepresentation(BsonType.Decimal128)] public decimal?[] NullableDecimals { get; set; } + public double?[] NullableDoubles { get; set; } + public float?[] NullableFloats { get; set; } + public int?[] NullableInts { get; set; } + public long?[] NullableLongs { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new C { Id = 1, @@ -431,23 +451,8 @@ private IMongoCollection CreateCollection() NullableFloats = new float?[] { null, 1.0F, 2.0F, 3.0F }, NullableInts = new int?[] { null, 1, 2, 3 }, NullableLongs = new long?[] { null, 1L, 2L, 3L } - }); - return collection; - } - - private class C - { - public int Id { get; set; } - [BsonRepresentation(BsonType.Decimal128)] public decimal[] Decimals { get; set; } - public double[] Doubles { get; set; } - public float[] Floats { get; set; } - public int[] Ints { get; set; } - public long[] Longs { get; set; } - [BsonRepresentation(BsonType.Decimal128)] public decimal?[] NullableDecimals { get; set; } - public double?[] NullableDoubles { get; set; } - public float?[] NullableFloats { get; set; } - public int?[] NullableInts { get; set; } - public long?[] NullableLongs { get; set; } + } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ToArrayMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ToArrayMethodToAggregationExpressionTranslatorTests.cs index 8255a187159..d04618a3a89 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ToArrayMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ToArrayMethodToAggregationExpressionTranslatorTests.cs @@ -16,20 +16,25 @@ using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class ToArrayMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class ToArrayMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public ToArrayMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Array_ToArray_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Array.AsQueryable().ToArray()) : @@ -47,7 +52,7 @@ public void Array_ToArray_should_work( public void IEnumerable_ToArray_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.IEnumerable.AsQueryable().ToArray()) : @@ -65,7 +70,7 @@ public void IEnumerable_ToArray_should_work( public void List_ToArray_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.List.AsQueryable().ToArray()) : @@ -78,27 +83,26 @@ public void List_ToArray_should_work( result.Should().Equal(1, 2, 3); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, + public int Id { get; set; } + public int[] Array { get; set; } + public IEnumerable IEnumerable { get; set; } + public List List { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new C { Id = 1, Array = new int[] { 1, 2, 3 }, IEnumerable = new List { 1, 2, 3 }, List = new List { 1, 2, 3 } - }); - return collection; - } - - private class C - { - public int Id { get; set; } - public int[] Array { get; set; } - public IEnumerable IEnumerable { get; set; } - public List List { get; set; } + } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ToListMethodToAggregationTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ToListMethodToAggregationTranslatorTests.cs index 66b405c05c8..9f6e1383914 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ToListMethodToAggregationTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ToListMethodToAggregationTranslatorTests.cs @@ -16,20 +16,25 @@ using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class ToListMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class ToListMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public ToListMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Array_ToList_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.Array.AsQueryable().ToList()) : @@ -47,7 +52,7 @@ public void Array_ToList_should_work( public void IEnumerable_ToList_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.IEnumerable.AsQueryable().ToList()) : @@ -65,7 +70,7 @@ public void IEnumerable_ToList_should_work( public void List_ToList_should_work( [Values(false, true)] bool withNestedAsQueryable) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryable ? collection.AsQueryable().Select(x => x.List.AsQueryable().ToList()) : @@ -78,27 +83,26 @@ public void List_ToList_should_work( result.Should().Equal(1, 2, 3); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, + public int Id { get; set; } + public int[] Array { get; set; } + public IEnumerable IEnumerable { get; set; } + public List List { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new C { Id = 1, Array = new int[] { 1, 2, 3 }, IEnumerable = new List { 1, 2, 3 }, List = new List { 1, 2, 3 } - }); - return collection; - } - - private class C - { - public int Id { get; set; } - public int[] Array { get; set; } - public IEnumerable IEnumerable { get; set; } - public List List { get; set; } + } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/UnionMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/UnionMethodToAggregationExpressionTranslatorTests.cs index 688e746e652..3bc0e6b1640 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/UnionMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/UnionMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class UnionMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class UnionMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public UnionMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Enumerable_Union_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.Union(x.B.AsQueryable())) : @@ -50,7 +56,7 @@ public void Enumerable_Union_should_work( public void Queryable_Union_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.AsQueryable().Union(x.B.AsQueryable())) : @@ -67,23 +73,22 @@ public void Queryable_Union_should_work( results[3].Should().BeEquivalentTo(1, 2, 3); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0], B = new int[0] }, - new C { Id = 1, A = new int[0], B = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1 }, B = new int[0] }, - new C { Id = 3, A = new int[] { 1, 2 }, B = new int[] { 2, 3 } }); - return collection; - } - - private class C + public class C { public int Id { get; set; } public int[] A { get; set; } public int[] B { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0], B = new int[0] }, + new C { Id = 1, A = new int[0], B = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1 }, B = new int[0] }, + new C { Id = 3, A = new int[] { 1, 2 }, B = new int[] { 2, 3 } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WhereMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WhereMethodToAggregationExpressionTranslatorTests.cs index 78305b10af0..a4175b4aede 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WhereMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WhereMethodToAggregationExpressionTranslatorTests.cs @@ -13,19 +13,25 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class WhereMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class WhereMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public WhereMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Enumerable_Where_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.Where(x => x > 1)); @@ -43,7 +49,7 @@ public void Enumerable_Where_should_work() [Fact] public void Enumerable_Where_Count_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.Where(x => x > 1).Count()); @@ -61,7 +67,7 @@ public void Enumerable_Where_Count_should_work() [Fact] public void Queryable_Where_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().Where(x => x > 1)); @@ -79,7 +85,7 @@ public void Queryable_Where_should_work() [Fact] public void Queryable_Where_Count_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable().Select(x => x.A.AsQueryable().Where(x => x > 1).Count()); @@ -94,22 +100,21 @@ public void Queryable_Where_Count_should_work() results[3].Should().Be(2); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0] }, - new C { Id = 1, A = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1, 2 } }, - new C { Id = 3, A = new int[] { 1, 2, 3 } }); - return collection; + public int Id { get; set; } + public int[] A { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public int[] A { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0] }, + new C { Id = 1, A = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1, 2 } }, + new C { Id = 3, A = new int[] { 1, 2, 3 } } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WindowMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WindowMethodToAggregationExpressionTranslatorTests.cs index 2fb89b2a56f..59cdd9c6539 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WindowMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/WindowMethodToAggregationExpressionTranslatorTests.cs @@ -22,17 +22,22 @@ using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class WindowMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class WindowMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public WindowMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture, server => server.Supports(Feature.SetWindowFields)) + { + } + [Fact] public void Translate_should_return_expected_result_for_AddToSet() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.AddToSet(x => x.Int32Field, null) }); @@ -52,8 +57,7 @@ public void Translate_should_return_expected_result_for_AddToSet() [Fact] public void Translate_should_return_expected_result_for_Average_with_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.DecimalField, null) }); @@ -72,8 +76,7 @@ public void Translate_should_return_expected_result_for_Average_with_Decimal() [Fact] public void Translate_should_return_expected_result_for_Average_with_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.DoubleField, null) }); @@ -92,8 +95,7 @@ public void Translate_should_return_expected_result_for_Average_with_Double() [Fact] public void Translate_should_return_expected_result_for_Average_with_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.Int32Field, null) }); @@ -112,8 +114,7 @@ public void Translate_should_return_expected_result_for_Average_with_Int32() [Fact] public void Translate_should_return_expected_result_for_Average_with_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.Int64Field, null) }); @@ -132,8 +133,7 @@ public void Translate_should_return_expected_result_for_Average_with_Int64() [Fact] public void Translate_should_return_expected_result_for_Average_with_nullable_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.NullableDecimalField, null) }); @@ -152,8 +152,7 @@ public void Translate_should_return_expected_result_for_Average_with_nullable_De [Fact] public void Translate_should_return_expected_result_for_Average_with_nullable_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.NullableDoubleField, null) }); @@ -172,8 +171,7 @@ public void Translate_should_return_expected_result_for_Average_with_nullable_Do [Fact] public void Translate_should_return_expected_result_for_Average_with_nullable_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.NullableInt32Field, null) }); @@ -192,8 +190,7 @@ public void Translate_should_return_expected_result_for_Average_with_nullable_In [Fact] public void Translate_should_return_expected_result_for_Average_with_nullable_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.NullableInt64Field, null) }); @@ -212,8 +209,7 @@ public void Translate_should_return_expected_result_for_Average_with_nullable_In [Fact] public void Translate_should_return_expected_result_for_Average_with_nullable_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.NullableSingleField, null) }); @@ -232,8 +228,7 @@ public void Translate_should_return_expected_result_for_Average_with_nullable_Si [Fact] public void Translate_should_return_expected_result_for_Average_with_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Average(x => x.SingleField, null) }); @@ -252,8 +247,7 @@ public void Translate_should_return_expected_result_for_Average_with_Single() [Fact] public void Translate_should_return_expected_result_for_Count() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Count(null) }); @@ -272,8 +266,7 @@ public void Translate_should_return_expected_result_for_Count() [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.DecimalField1, x => x.DecimalField2, null) }); @@ -292,8 +285,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.DoubleField1, x => x.DoubleField2, null) }); @@ -312,8 +304,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.Int32Field1, x => x.Int32Field2, null) }); @@ -332,8 +323,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.Int64Field1, x => x.Int64Field2, null) }); @@ -352,8 +342,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_nullable_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.NullableDecimalField1, x => x.NullableDecimalField2, null) }); @@ -372,8 +361,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_nullable_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.NullableDoubleField1, x => x.NullableDoubleField2, null) }); @@ -392,8 +380,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_nullable_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.NullableInt32Field1, x => x.NullableInt32Field2, null) }); @@ -412,8 +399,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_nullable_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.NullableInt64Field1, x => x.NullableInt64Field2, null) }); @@ -432,8 +418,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_nullable_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.NullableSingleField1, x => x.NullableSingleField2, null) }); @@ -452,8 +437,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovariancePopulation_with_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovariancePopulation(x => x.SingleField1, x => x.SingleField2, null) }); @@ -472,8 +456,7 @@ public void Translate_should_return_expected_result_for_CovariancePopulation_wit [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.DecimalField1, x => x.DecimalField2, null) }); @@ -492,8 +475,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_De [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.DoubleField1, x => x.DoubleField2, null) }); @@ -512,8 +494,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_Do [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.Int32Field1, x => x.Int32Field2, null) }); @@ -532,8 +513,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_In [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.Int64Field1, x => x.Int64Field2, null) }); @@ -552,8 +532,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_In [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_nullable_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.NullableDecimalField1, x => x.NullableDecimalField2, null) }); @@ -572,8 +551,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_nu [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_nullable_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.NullableDoubleField1, x => x.NullableDoubleField2, null) }); @@ -592,8 +570,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_nu [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_nullable_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.NullableInt32Field1, x => x.NullableInt32Field2, null) }); @@ -612,8 +589,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_nu [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_nullable_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.NullableInt64Field1, x => x.NullableInt64Field2, null) }); @@ -632,8 +608,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_nu [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_nullable_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.NullableSingleField1, x => x.NullableSingleField2, null) }); @@ -652,8 +627,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_nu [Fact] public void Translate_should_return_expected_result_for_CovarianceSample_with_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.CovarianceSample(x => x.SingleField1, x => x.SingleField2, null) }); @@ -672,8 +646,7 @@ public void Translate_should_return_expected_result_for_CovarianceSample_with_Si [Fact] public void Translate_should_return_expected_result_for_DenseRank() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -696,8 +669,7 @@ public void Translate_should_return_expected_result_for_DenseRank() [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -720,8 +692,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Decimal( [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Decimal_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -751,8 +722,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Decimal_ [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -775,8 +745,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Double() [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Double_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -806,8 +775,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Double_a [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -830,8 +798,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Int32() [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Int32_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -861,8 +828,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Int32_an [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -885,8 +851,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Int64() [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Int64_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -916,8 +881,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Int64_an [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -940,8 +904,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Single() [Fact] public void Translate_should_return_expected_result_for_Derivative_with_Single_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -971,8 +934,7 @@ public void Translate_should_return_expected_result_for_Derivative_with_Single_a [Fact] public void Translate_should_return_expected_result_for_DocumentNumber() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -995,8 +957,7 @@ public void Translate_should_return_expected_result_for_DocumentNumber() [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Decimal_and_alpha() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1019,8 +980,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Decimal_and_n() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1043,8 +1003,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Double_and_alpha() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1067,8 +1026,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Double_and_n() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1091,8 +1049,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Int32_and_alpha() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1115,8 +1072,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Int32_and_n() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1139,8 +1095,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Int64_and_alpha() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1163,8 +1118,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Int64_and_n() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1187,8 +1141,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Single_and_alpha() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1211,8 +1164,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_ExponentialMovingAverage_with_Single_and_n() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1235,8 +1187,7 @@ public void Translate_should_return_expected_result_for_ExponentialMovingAverage [Fact] public void Translate_should_return_expected_result_for_First() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.First(x => x.Int32Field, null) }); @@ -1255,8 +1206,7 @@ public void Translate_should_return_expected_result_for_First() [Fact] public void Translate_should_return_expected_result_for_Integral_with_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1279,8 +1229,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Decimal() [Fact] public void Translate_should_return_expected_result_for_Integral_with_Decimal_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1303,8 +1252,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Decimal_an [Fact] public void Translate_should_return_expected_result_for_Integral_with_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1327,8 +1275,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Double() [Fact] public void Translate_should_return_expected_result_for_Integral_with_Double_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1351,8 +1298,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Double_and [Fact] public void Translate_should_return_expected_result_for_Integral_with_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1375,8 +1321,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Int32() [Fact] public void Translate_should_return_expected_result_for_Integral_with_Int32_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1399,8 +1344,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Int32_and_ [Fact] public void Translate_should_return_expected_result_for_Integral_with_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1423,8 +1367,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Int64() [Fact] public void Translate_should_return_expected_result_for_Integral_with_Int64_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1447,8 +1390,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Int64_and_ [Fact] public void Translate_should_return_expected_result_for_Integral_with_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1471,8 +1413,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Single() [Fact] public void Translate_should_return_expected_result_for_Integral_with_Single_and_unit() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1495,8 +1436,7 @@ public void Translate_should_return_expected_result_for_Integral_with_Single_and [Fact] public void Translate_should_return_expected_result_for_Last() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Last(x => x.Int32Field, null) }); @@ -1516,7 +1456,7 @@ public void Translate_should_return_expected_result_for_Last() public void Translate_should_return_expected_result_for_Locf() { RequireServer.Check().Supports(Feature.SetWindowFieldsLocf); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Locf(x => x.Int32Field, null) }); @@ -1532,8 +1472,7 @@ public void Translate_should_return_expected_result_for_Locf() [Fact] public void Translate_should_return_expected_result_for_Max() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Max(x => x.Int32Field, null) }); @@ -1552,8 +1491,7 @@ public void Translate_should_return_expected_result_for_Max() [Fact] public void Translate_should_return_expected_result_for_Min() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Min(x => x.Int32Field, null) }); @@ -1572,8 +1510,7 @@ public void Translate_should_return_expected_result_for_Min() [Fact] public void Translate_should_return_expected_result_for_Push() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Push(x => x.Int32Field, null) }); @@ -1592,8 +1529,7 @@ public void Translate_should_return_expected_result_for_Push() [Fact] public void Translate_should_return_expected_result_for_Rank() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1616,8 +1552,7 @@ public void Translate_should_return_expected_result_for_Rank() [Fact] public void Translate_should_return_expected_result_for_Shift() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1640,8 +1575,7 @@ public void Translate_should_return_expected_result_for_Shift() [Fact] public void Translate_should_return_expected_result_for_Shift_with_defaultValue() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields( @@ -1664,8 +1598,7 @@ public void Translate_should_return_expected_result_for_Shift_with_defaultValue( [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.DecimalField, null) }); @@ -1684,8 +1617,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.DoubleField, null) }); @@ -1704,8 +1636,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.Int32Field, null) }); @@ -1724,8 +1655,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.Int64Field, null) }); @@ -1744,8 +1674,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_nullable_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.NullableDecimalField, null) }); @@ -1764,8 +1693,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_nullable_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.NullableDoubleField, null) }); @@ -1784,8 +1712,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_nullable_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.NullableInt32Field, null) }); @@ -1804,8 +1731,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_nullable_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.NullableInt64Field, null) }); @@ -1824,8 +1750,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_nullable_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.NullableSingleField, null) }); @@ -1844,8 +1769,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationPopulation_with_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationPopulation(x => x.SingleField, null) }); @@ -1864,8 +1788,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationPopulat [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.DecimalField, null) }); @@ -1884,8 +1807,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.DoubleField, null) }); @@ -1904,8 +1826,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.Int32Field, null) }); @@ -1924,8 +1845,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.Int64Field, null) }); @@ -1944,8 +1864,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_nullable_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.NullableDecimalField, null) }); @@ -1964,8 +1883,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_nullable_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.NullableDoubleField, null) }); @@ -1984,8 +1902,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_nullable_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.NullableInt32Field, null) }); @@ -2004,8 +1921,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_nullable_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.NullableInt64Field, null) }); @@ -2024,8 +1940,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_nullable_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.NullableSingleField, null) }); @@ -2044,8 +1959,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_StandardDeviationSample_with_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.StandardDeviationSample(x => x.SingleField, null) }); @@ -2064,8 +1978,7 @@ public void Translate_should_return_expected_result_for_StandardDeviationSample_ [Fact] public void Translate_should_return_expected_result_for_Sum_with_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.DecimalField, null) }); @@ -2084,8 +1997,7 @@ public void Translate_should_return_expected_result_for_Sum_with_Decimal() [Fact] public void Translate_should_return_expected_result_for_Sum_with_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.DoubleField, null) }); @@ -2104,8 +2016,7 @@ public void Translate_should_return_expected_result_for_Sum_with_Double() [Fact] public void Translate_should_return_expected_result_for_Sum_with_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.Int32Field, null) }); @@ -2124,8 +2035,7 @@ public void Translate_should_return_expected_result_for_Sum_with_Int32() [Fact] public void Translate_should_return_expected_result_for_Sum_with_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.Int64Field, null) }); @@ -2144,8 +2054,7 @@ public void Translate_should_return_expected_result_for_Sum_with_Int64() [Fact] public void Translate_should_return_expected_result_for_Sum_with_nullable_Decimal() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.NullableDecimalField, null) }); @@ -2164,8 +2073,7 @@ public void Translate_should_return_expected_result_for_Sum_with_nullable_Decima [Fact] public void Translate_should_return_expected_result_for_Sum_with_nullable_Double() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.NullableDoubleField, null) }); @@ -2184,8 +2092,7 @@ public void Translate_should_return_expected_result_for_Sum_with_nullable_Double [Fact] public void Translate_should_return_expected_result_for_Sum_with_nullable_Int32() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.NullableInt32Field, null) }); @@ -2204,8 +2111,7 @@ public void Translate_should_return_expected_result_for_Sum_with_nullable_Int32( [Fact] public void Translate_should_return_expected_result_for_Sum_with_nullable_Int64() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.NullableInt64Field, null) }); @@ -2224,8 +2130,7 @@ public void Translate_should_return_expected_result_for_Sum_with_nullable_Int64( [Fact] public void Translate_should_return_expected_result_for_Sum_with_nullable_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.NullableSingleField, null) }); @@ -2244,8 +2149,7 @@ public void Translate_should_return_expected_result_for_Sum_with_nullable_Single [Fact] public void Translate_should_return_expected_result_for_Sum_with_Single() { - RequireServer.Check().Supports(Feature.SetWindowFields); - var collection = CreateCollection(); + var collection = Fixture.Collection; var aggregate = collection.Aggregate() .SetWindowFields(output: p => new { Result = p.Sum(x => x.SingleField, null) }); @@ -2261,61 +2165,6 @@ public void Translate_should_return_expected_result_for_Sum_with_Single() } } - private IMongoCollection CreateCollection() - { - var collection = GetCollection(); - var documents = CreateTestDocuments(); - CreateCollection(collection, documents); - return collection; - } - - private IEnumerable CreateTestDocuments() - { - var documents = new C[3]; - for (var n = 1; n <= 3; n++) - { - var document = new C - { - Id = n, - DayField = new DateTime(2022, 01, 01, 0, 0, 0, DateTimeKind.Utc).AddDays(n - 1), - DecimalField = n, - DecimalField1 = n, - DecimalField2 = n, - DoubleField = n, - DoubleField1 = n, - DoubleField2 = n, - Int32Field = n, - Int32Field1 = n, - Int32Field2 = n, - Int64Field = n, - Int64Field1 = n, - Int64Field2 = n, - NullableDecimalField = n < 3 ? n : null, - NullableDecimalField1 = n < 3 ? n : null, - NullableDecimalField2 = n < 3 ? n : null, - NullableDoubleField = n < 3 ? n : null, - NullableDoubleField1 = n < 3 ? n : null, - NullableDoubleField2 = n < 3 ? n : null, - NullableInt32Field = n < 3 ? n : null, - NullableInt32Field1 = n < 3 ? n : null, - NullableInt32Field2 = n < 3 ? n : null, - NullableInt64Field = n < 3 ? n : null, - NullableInt64Field1 = n < 3 ? n : null, - NullableInt64Field2 = n < 3 ? n : null, - NullableSingleField = n < 3 ? n : null, - NullableSingleField1 = n < 3 ? n : null, - NullableSingleField2 = n < 3 ? n : null, - SingleField = n, - SingleField1 = n, - SingleField2 = n, - }; - - documents[n - 1] = document; - } - - return documents; - } - public class C { public int Id { get; set; } @@ -2357,5 +2206,53 @@ public class C public float SingleField1 { get; set; } public float SingleField2 { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData + { + get + { + for (var n = 1; n <= 3; n++) + { + yield return new C + { + Id = n, + DayField = new DateTime(2022, 01, 01, 0, 0, 0, DateTimeKind.Utc).AddDays(n - 1), + DecimalField = n, + DecimalField1 = n, + DecimalField2 = n, + DoubleField = n, + DoubleField1 = n, + DoubleField2 = n, + Int32Field = n, + Int32Field1 = n, + Int32Field2 = n, + Int64Field = n, + Int64Field1 = n, + Int64Field2 = n, + NullableDecimalField = n < 3 ? n : null, + NullableDecimalField1 = n < 3 ? n : null, + NullableDecimalField2 = n < 3 ? n : null, + NullableDoubleField = n < 3 ? n : null, + NullableDoubleField1 = n < 3 ? n : null, + NullableDoubleField2 = n < 3 ? n : null, + NullableInt32Field = n < 3 ? n : null, + NullableInt32Field1 = n < 3 ? n : null, + NullableInt32Field2 = n < 3 ? n : null, + NullableInt64Field = n < 3 ? n : null, + NullableInt64Field1 = n < 3 ? n : null, + NullableInt64Field2 = n < 3 ? n : null, + NullableSingleField = n < 3 ? n : null, + NullableSingleField1 = n < 3 ? n : null, + NullableSingleField2 = n < 3 ? n : null, + SingleField = n, + SingleField1 = n, + SingleField2 = n, + }; + } + } + } + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ZipMethodToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ZipMethodToAggregationExpressionTranslatorTests.cs index e579711e810..f4dcb953dca 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ZipMethodToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/MethodTranslators/ZipMethodToAggregationExpressionTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators.MethodTranslators { - public class ZipMethodToAggregationExpressionTranslatorTests : Linq3IntegrationTest + public class ZipMethodToAggregationExpressionTranslatorTests : LinqIntegrationTest { + public ZipMethodToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Theory] [ParameterAttributeData] public void Enumerable_Zip_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.Zip(x.B.AsQueryable(), (x, y) => x * y)) : @@ -50,7 +56,7 @@ public void Enumerable_Zip_should_work( public void Queryable_Zip_should_work( [Values(false, true)] bool withNestedAsQueryableSource2) { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = withNestedAsQueryableSource2 ? collection.AsQueryable().Select(x => x.A.AsQueryable().Zip(x.B.AsQueryable(), (x, y) => x * y)) : @@ -67,23 +73,22 @@ public void Queryable_Zip_should_work( results[3].Should().Equal(3, 8); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 0, A = new int[0], B = new int[0] }, - new C { Id = 1, A = new int[0], B = new int[] { 1 } }, - new C { Id = 2, A = new int[] { 1 }, B = new int[0] }, - new C { Id = 3, A = new int[] { 1, 2 }, B = new int[] { 3, 4, 5 } }); - return collection; - } - - private class C + public class C { public int Id { get; set; } public int[] A { get; set; } public int[] B { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new C { Id = 0, A = new int[0], B = new int[0] }, + new C { Id = 1, A = new int[0], B = new int[] { 1 } }, + new C { Id = 2, A = new int[] { 1 }, B = new int[0] }, + new C { Id = 3, A = new int[] { 1, 2 }, B = new int[] { 3, 4, 5 } } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NegateExpressionToAggregationExpressionTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NegateExpressionToAggregationExpressionTranslatorTests.cs index b7a7683eba7..1c85f959d37 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NegateExpressionToAggregationExpressionTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToAggregationExpressionTranslators/NegateExpressionToAggregationExpressionTranslatorTests.cs @@ -13,7 +13,7 @@ * limitations under the License. */ -using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; @@ -21,17 +21,23 @@ using MongoDB.Driver.Core.Misc; using MongoDB.Driver.Core.TestHelpers.XunitExtensions; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using MongoDB.TestHelpers.XunitExtensions; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToAggregationExpressionTranslators { - public class NegateExpressionToAggregationExpressionTranslatorTests: Linq3IntegrationTest + public class NegateExpressionToAggregationExpressionTranslatorTests: LinqIntegrationTest { + public NegateExpressionToAggregationExpressionTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Negate_int_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = Queryable.Select(collection.AsQueryable(), i => -i.Int); var stages = Translate(collection, queryable); @@ -46,7 +52,7 @@ public void Negate_int_should_work() [Fact] public void Negate_long_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = Queryable.Select(collection.AsQueryable(), i => -i.Long); var stages = Translate(collection, queryable); @@ -61,7 +67,7 @@ public void Negate_long_should_work() [Fact] public void Negate_single_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = Queryable.Select(collection.AsQueryable(), i => -i.Single); var stages = Translate(collection, queryable); @@ -76,7 +82,7 @@ public void Negate_single_should_work() [Fact] public void Negate_double_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = Queryable.Select(collection.AsQueryable(), i => -i.Double); var stages = Translate(collection, queryable); @@ -91,7 +97,7 @@ public void Negate_double_should_work() [Fact] public void Negate_decimal128_should_work() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = Queryable.Select(collection.AsQueryable(), i => -i.DecimalAsDecimal128); var stages = Translate(collection, queryable); @@ -109,7 +115,7 @@ public void Negate_decimal_as_string_should_throw( [Values(false, true)] bool enableClientSideProjections) { RequireServer.Check().Supports(Feature.FindProjectionExpressions); - var collection = CreateCollection(); + var collection = Fixture.Collection; var translationOptions = new ExpressionTranslationOptions { EnableClientSideProjections = enableClientSideProjections }; var queryable = Queryable.Select(collection.AsQueryable(translationOptions), i => -i.DecimalAsString); @@ -130,20 +136,7 @@ public void Negate_decimal_as_string_should_throw( } } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new Data { Id = 1, Int = -10, Double = -10, Single = -10, Long = -10, DecimalAsString = -10, DecimalAsDecimal128 = -10}, - new Data { Id = 2, Int = 5, Double = 5, Single = 5, Long = 5, DecimalAsString = 5, DecimalAsDecimal128 = 5}, - new Data { Id = 3, Int = 0, Double = 0, Single = 0, Long = 0, DecimalAsString = 0, DecimalAsDecimal128 = 0}, - new Data { Id = 4, Int = -int.MaxValue, Double = -double.MaxValue, Single = -float.MaxValue, Long = -long.MaxValue, DecimalAsString = -decimal.MaxValue, DecimalAsDecimal128 = -decimal.MaxValue}, - new Data { Id = 5, Int = int.MaxValue, Double = double.MaxValue, Single = float.MaxValue, Long = long.MaxValue, DecimalAsString = decimal.MaxValue, DecimalAsDecimal128 = decimal.MaxValue}); - return collection; - } - - private class Data + public class Data { public int Id { get; set; } public int Int { get; set; } @@ -155,5 +148,17 @@ private class Data [BsonRepresentation(BsonType.Decimal128)] public decimal DecimalAsDecimal128 { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Data { Id = 1, Int = -10, Double = -10, Single = -10, Long = -10, DecimalAsString = -10, DecimalAsDecimal128 = -10}, + new Data { Id = 2, Int = 5, Double = 5, Single = 5, Long = 5, DecimalAsString = 5, DecimalAsDecimal128 = 5}, + new Data { Id = 3, Int = 0, Double = 0, Single = 0, Long = 0, DecimalAsString = 0, DecimalAsDecimal128 = 0}, + new Data { Id = 4, Int = -int.MaxValue, Double = -double.MaxValue, Single = -float.MaxValue, Long = -long.MaxValue, DecimalAsString = -decimal.MaxValue, DecimalAsDecimal128 = -decimal.MaxValue}, + new Data { Id = 5, Int = int.MaxValue, Double = double.MaxValue, Single = float.MaxValue, Long = long.MaxValue, DecimalAsString = decimal.MaxValue, DecimalAsDecimal128 = decimal.MaxValue} + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExecutableQueryTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExecutableQueryTests.cs index bfafb2b05ca..b5af795df82 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExecutableQueryTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToExecutableQueryTranslators/ExecutableQueryTests.cs @@ -14,19 +14,25 @@ */ using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToExecutableQueryTranslators { - public class ExecutableQueryTests : Linq3IntegrationTest + public class ExecutableQueryTests : LinqIntegrationTest { + public ExecutableQueryTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void Cast_to_object_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable1 = collection.AsQueryable(); var queryable2 = queryable1.Provider.CreateQuery(queryable1.Expression); @@ -38,7 +44,7 @@ public void Cast_to_object_should_work() [Fact] public void Cast_aggregation_to_object_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable1 = collection.AsQueryable().GroupBy( p => p.Type, (k, p) => new ProductAggregation {Type = k, MaxPrice = p.Select(i => i.Price).Max()}); @@ -52,7 +58,7 @@ public void Cast_aggregation_to_object_should_work() [Fact] public void Cast_int_to_object_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable1 = collection.AsQueryable().Select(p => p.Id); var queryable2 = queryable1.Provider.CreateQuery(queryable1.Expression); @@ -64,7 +70,7 @@ public void Cast_int_to_object_should_work() [Fact] public void Cast_to_nullable_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable1 = collection.AsQueryable().Select(p => p.Id); var queryable2 = queryable1.Provider.CreateQuery(queryable1.Expression); @@ -76,7 +82,7 @@ public void Cast_to_nullable_should_work() [Fact] public void Cast_to_incompatible_type_should_throw() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable1 = collection.AsQueryable(); var queryable2 = queryable1.Provider.CreateQuery(queryable1.Expression); @@ -89,7 +95,7 @@ public void Cast_to_incompatible_type_should_throw() [Fact] public void Cast_to_interface_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable1 = collection.AsQueryable(); var queryable2 = queryable1.Provider.CreateQuery(queryable1.Expression); @@ -101,7 +107,7 @@ public void Cast_to_interface_should_work() [Fact] public void Cast_to_base_class_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable1 = collection.AsQueryable(); var queryable2 = queryable1.Provider.CreateQuery(queryable1.Expression); @@ -110,33 +116,20 @@ public void Cast_to_base_class_should_work() results.Should().HaveCount(5); } - private IMongoCollection GetCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new DerivedProduct { Id = 1, Type = "a", Price = 1 }, - new DerivedProduct { Id = 2, Type = "a", Price = 5 }, - new DerivedProduct { Id = 3, Type = "a", Price = 12 }, - new DerivedProduct { Id = 4, Type = "b", Price = 2 }, - new DerivedProduct { Id = 5, Type = "b", Price = 7 }); - return collection; - } - - private interface IProduct + public interface IProduct { string Type { get; set; } decimal Price { get; set; } } - private class ProductBase : IProduct + public class ProductBase : IProduct { public int Id { get; set; } public string Type { get; set; } public decimal Price { get; set; } } - private class DerivedProduct : ProductBase + public class DerivedProduct : ProductBase { } @@ -145,5 +138,17 @@ private class ProductAggregation public string Type { get; set; } public decimal MaxPrice { get; set; } } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new DerivedProduct { Id = 1, Type = "a", Price = 1 }, + new DerivedProduct { Id = 2, Type = "a", Price = 5 }, + new DerivedProduct { Id = 3, Type = "a", Price = 12 }, + new DerivedProduct { Id = 4, Type = "b", Price = 2 }, + new DerivedProduct { Id = 5, Type = "b", Price = 7 } + ]; + } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/IsNullOrWhiteSpaceMethodToFilterTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/IsNullOrWhiteSpaceMethodToFilterTranslatorTests.cs index 66e3a886bef..22b4de1a9c3 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/IsNullOrWhiteSpaceMethodToFilterTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToFilterTranslators/MethodTranslators/IsNullOrWhiteSpaceMethodToFilterTranslatorTests.cs @@ -13,19 +13,24 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; -using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToFilterTranslators.MethodTranslators { - public class IsNullOrWhiteSpaceMethodToFilterTranslatorTests : Linq3IntegrationTest + public class IsNullOrWhiteSpaceMethodToFilterTranslatorTests : LinqIntegrationTest { + public IsNullOrWhiteSpaceMethodToFilterTranslatorTests(ClassFixture fixture) : base(fixture) + { + } + [Fact] public void Find_using_IsNullOrWhiteSpace_should_return_expected_results() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var find = collection.Find(x => string.IsNullOrWhiteSpace(x.S)); @@ -39,7 +44,7 @@ public void Find_using_IsNullOrWhiteSpace_should_return_expected_results() [Fact] public void Where_using_IsNullOrWhiteSpace_should_return_expected_results() { - var collection = CreateCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(x => string.IsNullOrWhiteSpace(x.S)); @@ -51,23 +56,22 @@ public void Where_using_IsNullOrWhiteSpace_should_return_expected_results() results.Select(x => x.Id).Should().BeEquivalentTo(1, 2, 3, 4); } - private IMongoCollection CreateCollection() + public class C { - var collection = GetCollection(); - CreateCollection( - collection, + public int Id { get; set; } + public string S { get; set; } + } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ new C { Id = 1, S = null }, new C { Id = 2, S = "" }, new C { Id = 3, S = " " }, new C { Id = 4, S = " \t\r\n" }, - new C { Id = 5, S = "abc" }); - return collection; - } - - public class C - { - public int Id { get; set; } - public string S { get; set; } + new C { Id = 5, S = "abc" } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/AsMethodToPipelineTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/AsMethodToPipelineTranslatorTests.cs index eb133344a20..456e64c723b 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/AsMethodToPipelineTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/AsMethodToPipelineTranslatorTests.cs @@ -13,22 +13,28 @@ * limitations under the License. */ +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson; using MongoDB.Bson.Serialization.Serializers; -using MongoDB.Driver; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators { - public class AsMethodToPipelineTranslatorTests : Linq3IntegrationTest + public class AsMethodToPipelineTranslatorTests : LinqIntegrationTest { + public AsMethodToPipelineTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void As_should_work() { - var collection = GetCollection(); + var collection = Fixture.Collection; var queryable = collection.AsQueryable() .Where(x => x.Name == "John") @@ -45,20 +51,19 @@ public void As_should_work() result.Should().Be("{ _id : 1, Name : 'John' }"); } - private IMongoCollection GetCollection() + public class C { - var collection = GetCollection("test"); - CreateCollection( - collection, - new C { Id = 1, Name = "John" }, - new C { Id = 2, Name = "Jane" }); - return collection; + public int Id { get; set; } + public string Name { get; set; } } - private class C + public sealed class ClassFixture : MongoCollectionFixture { - public int Id { get; set; } - public string Name { get; set; } + protected override IEnumerable InitialData => + [ + new C { Id = 1, Name = "John" }, + new C { Id = 2, Name = "Jane" } + ]; } } } diff --git a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeMethodToPipelineTranslatorTests.cs b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeMethodToPipelineTranslatorTests.cs index dd7fd95b533..1d5d22f2b20 100644 --- a/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeMethodToPipelineTranslatorTests.cs +++ b/tests/MongoDB.Driver.Tests/Linq/Linq3Implementation/Translators/ExpressionToPipelineTranslators/OfTypeMethodToPipelineTranslatorTests.cs @@ -13,20 +13,29 @@ * limitations under the License. */ +using System; +using System.Collections.Generic; using System.Linq; using FluentAssertions; using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Driver.Core.TestHelpers.XunitExtensions; using MongoDB.Driver.Linq; +using MongoDB.Driver.TestHelpers; using Xunit; namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Translators.ExpressionToPipelineTranslators { - public class OfTypeMethodToPipelineTranslatorTests: Linq3IntegrationTest + public class OfTypeMethodToPipelineTranslatorTests: LinqIntegrationTest { + public OfTypeMethodToPipelineTranslatorTests(ClassFixture fixture) + : base(fixture) + { + } + [Fact] public void OfType_should_return_expected_results() { - var collection = CreateCollection(); + var collection = Fixture.Collection; AssertTypeOf(collection, "{ $match: { _t : 'Account' } }", 1, 2, 3); AssertTypeOf(collection, "{ $match: { _t : 'Company' } }", 1, 2); @@ -47,18 +56,6 @@ private void AssertTypeOf(IMongoCollection collection, string results.Select(x => x.Id).Should().BeEquivalentTo(expectedIds); } - private IMongoCollection CreateCollection() - { - var collection = GetCollection("test"); - CreateCollection( - collection, - new Company { Id = 1 }, - new Company { Id = 2 }, - new Contact { Id = 3 }); - - return collection; - } - [BsonDiscriminator(RootClass = true)] [BsonKnownTypes(typeof(Account), typeof(Contact), typeof(Company))] public abstract class Entity @@ -77,5 +74,15 @@ public class Contact : Account public class Company : Account { } + + public sealed class ClassFixture : MongoCollectionFixture + { + protected override IEnumerable InitialData => + [ + new Company { Id = 1 }, + new Company { Id = 2 }, + new Contact { Id = 3 } + ]; + } } }