Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tests/MongoDB.Driver.TestHelpers/IntegrationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

using System;
using MongoDB.Driver.Core.TestHelpers.XunitExtensions;
using MongoDB.TestHelpers.XunitExtensions;
using Xunit;

namespace MongoDB.Driver.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CSharp1326Tests.ClassFixture>
{
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<Child>.Filter.In(c => c.ParentId, parentIds) &
Expand All @@ -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<Child> CreateCollection()
{
var collection = GetCollection<Child>("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; }
Expand All @@ -83,5 +74,17 @@ public class Child
}

public enum Gender { Male, Female };

public sealed class ClassFixture : MongoCollectionFixture<Child>
{
protected override IEnumerable<Child> 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 }
];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CSharp1555Tests.ClassFixture>
{
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);
Expand All @@ -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 });

Expand All @@ -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 });

Expand All @@ -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 });

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

private IMongoCollection<Person> CreatePeopleCollection()
{
var collection = GetCollection<Person>();

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<Person>
{
protected override IEnumerable<Person> InitialData =>
[
new Person { Id = 1, Name = "A" }
];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CSharp1754Tests.ClassFixture>
{
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()
Expand All @@ -38,20 +44,6 @@ public void Test()
results.Select(r => r.Id).Should().Equal(2);
}

private IMongoCollection<C> CreateCollection()
{
var collection = GetCollection<C>();

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; }
Expand All @@ -62,5 +54,14 @@ public class Occurrence
{
public string[] Meta { get; set; }
}

public sealed class ClassFixture : MongoCollectionFixture<C>
{
protected override IEnumerable<C> 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" } } } }
];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CSharp1906Tests.ClassFixture>
{
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()));
Expand All @@ -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));
Expand All @@ -54,25 +60,20 @@ public void Using_regular_expression_should_work()
results.Select(x => x.Id).Should().Equal(1, 2);
}

private IMongoCollection<C> CreateCollection()
public class C
{
var collection = GetCollection<C>();
public int Id { get; set; }
public string S { get; set; }
}

var documents = new[]
{
public sealed class ClassFixture : MongoCollectionFixture<C>
{
protected override IEnumerable<C> 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; }
];
}
}
}
Loading