diff --git a/UpgradeLog.XML b/UpgradeLog.XML
deleted file mode 100644
index 4a6ac96a..00000000
--- a/UpgradeLog.XML
+++ /dev/null
@@ -1,24 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/source/MongoDB.Tests/IntegrationTests/Linq/LinqDomain.cs b/source/MongoDB.Tests/IntegrationTests/Linq/LinqDomain.cs
index 571b0d5b..639a760f 100644
--- a/source/MongoDB.Tests/IntegrationTests/Linq/LinqDomain.cs
+++ b/source/MongoDB.Tests/IntegrationTests/Linq/LinqDomain.cs
@@ -1,7 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
+using System.Collections.Generic;
namespace MongoDB.IntegrationTests.Linq
{
@@ -31,6 +28,14 @@ public class Address
//[MongoAlias("city")]
public string City { get; set; }
- public bool IsInternational { get; set; }
+ public bool IsInternational { get; set; }
+
+ public AddressType AddressType { get; set; }
+ }
+
+ public enum AddressType
+ {
+ Company,
+ Private
}
}
diff --git a/source/MongoDB.Tests/IntegrationTests/Linq/LinqTestsBase.cs b/source/MongoDB.Tests/IntegrationTests/Linq/LinqTestsBase.cs
index d8e61eb9..bd376037 100644
--- a/source/MongoDB.Tests/IntegrationTests/Linq/LinqTestsBase.cs
+++ b/source/MongoDB.Tests/IntegrationTests/Linq/LinqTestsBase.cs
@@ -1,6 +1,4 @@
-using System.Collections.Generic;
-using MongoDB.Attributes;
-using NUnit.Framework;
+using NUnit.Framework;
namespace MongoDB.IntegrationTests.Linq
{
@@ -11,14 +9,14 @@ public override string TestCollections
get { return "people"; }
}
- protected IMongoCollection collection;
- protected IMongoCollection documentCollection;
+ protected IMongoCollection Collection;
+ protected IMongoCollection DocumentCollection;
[SetUp]
public virtual void TestSetup()
{
- collection = DB.GetCollection("people");
- documentCollection = DB.GetCollection("people");
+ Collection = DB.GetCollection("people");
+ DocumentCollection = DB.GetCollection("people");
}
}
}
diff --git a/source/MongoDB.Tests/IntegrationTests/Linq/MapReduceTests.cs b/source/MongoDB.Tests/IntegrationTests/Linq/MapReduceTests.cs
index 6c8367ca..f27cd317 100644
--- a/source/MongoDB.Tests/IntegrationTests/Linq/MapReduceTests.cs
+++ b/source/MongoDB.Tests/IntegrationTests/Linq/MapReduceTests.cs
@@ -17,8 +17,8 @@ public override void TestSetup()
{
base.TestSetup();
- collection.Delete(new { }, true);
- collection.Insert(
+ Collection.Delete(new { }, true);
+ Collection.Insert(
new Person
{
FirstName = "Bob",
@@ -34,7 +34,7 @@ public override void TestSetup()
EmployerIds = new[] { 1, 2 }
}, true);
- collection.Insert(
+ Collection.Insert(
new Person
{
FirstName = "Jane",
@@ -49,7 +49,7 @@ public override void TestSetup()
}, true);
- collection.Insert(
+ Collection.Insert(
new Person
{
FirstName = "Joe",
@@ -68,7 +68,7 @@ public override void TestSetup()
[Test]
public void Off_of_select()
{
- var minAge = collection.Linq().Select(x => x.Age).Min();
+ var minAge = Collection.Linq().Select(x => x.Age).Min();
Assert.AreEqual(21, minAge);
}
@@ -76,7 +76,7 @@ public void Off_of_select()
[Test]
public void Off_of_root()
{
- var minAge = collection.Linq().Min(x => x.Age);
+ var minAge = Collection.Linq().Min(x => x.Age);
Assert.AreEqual(21, minAge);
}
@@ -84,7 +84,7 @@ public void Off_of_root()
[Test]
public void NoGrouping()
{
- var grouping = Enumerable.ToList(from p in collection.Linq()
+ var grouping = Enumerable.ToList(from p in Collection.Linq()
where p.Age > 21
group p by 1 into g
select new
@@ -107,7 +107,7 @@ select new
[Test]
public void Expression_Grouping()
{
- var grouping = Enumerable.ToList(from p in collection.Linq()
+ var grouping = Enumerable.ToList(from p in Collection.Linq()
group p by p.Age % 2 into g
select new
{
@@ -132,7 +132,7 @@ select new
[Test]
public void Expression_Grouping2()
{
- var grouping = Enumerable.ToList(from p in collection.Linq()
+ var grouping = Enumerable.ToList(from p in Collection.Linq()
group p by p.FirstName[0] into g
select new
{
@@ -153,7 +153,7 @@ select new
[Test]
public void Complex()
{
- var grouping = Enumerable.ToList(from p in collection.Linq()
+ var grouping = Enumerable.ToList(from p in Collection.Linq()
where p.Age > 21
group p by new { FirstName = p.FirstName, LastName = p.LastName } into g
select new
diff --git a/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryProviderTests.cs b/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryProviderTests.cs
index 24754fca..e0afcd66 100644
--- a/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryProviderTests.cs
+++ b/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryProviderTests.cs
@@ -10,33 +10,42 @@ namespace MongoDB.IntegrationTests.Linq
public class MongoQueryProviderTests : LinqTestsBase
{
[Test]
- public void WithoutConstraints()
+ public void Boolean_Test1()
{
- var people = collection.Linq();
+ var people = Collection.Linq().Where(x => x.PrimaryAddress.IsInternational);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
-
- Assert.AreEqual(0, queryObject.NumberToLimit);
- Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(0, queryObject.Query.Count);
+ Assert.AreEqual(new Document("PrimaryAddress.IsInternational", true), queryObject.Query);
}
[Test]
- public void SingleEqualConstraint()
+ public void Boolean_Test2()
{
- var people = collection.Linq().Where(p => "Jack" == p.FirstName);
+ var people = Collection.Linq().Where(x => !x.PrimaryAddress.IsInternational);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
+ Assert.AreEqual(new Document("$not", new Document("PrimaryAddress.IsInternational", true)), queryObject.Query);
+ }
+
+ [Test]
+ public void Chained()
+ {
+ var people = Collection.Linq()
+ .Select(x => new {Name = x.FirstName + x.LastName, x.Age})
+ .Where(x => x.Age > 21)
+ .Select(x => x.Name);
+ var queryObject = ((IMongoQueryable)people).GetQueryObject();
+ Assert.AreEqual(2, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("FirstName", "Jack"), queryObject.Query);
+ Assert.AreEqual(new Document("Age", Op.GreaterThan(21)), queryObject.Query);
}
[Test]
public void ConjuctionConstraint()
{
- var people = collection.Linq().Where(p => p.Age > 21 && p.Age < 42);
+ var people = Collection.Linq().Where(p => p.Age > 21 && p.Age < 42);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
@@ -46,329 +55,332 @@ public void ConjuctionConstraint()
}
[Test]
- public void NestedClassConstraint()
+ public void ConstraintsAgainstLocalReferenceMember()
{
- var people = collection.Linq().Where(p => p.PrimaryAddress.City == "my city");
+ var local = new {Test = new {Age = 21}};
+ var people = Collection.Linq().Where(p => p.Age > local.Test.Age);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
-
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("PrimaryAddress.City", "my city"), queryObject.Query);
+ Assert.AreEqual(new Document("Age", Op.GreaterThan(local.Test.Age)), queryObject.Query);
}
[Test]
- public void Projection()
+ public void ConstraintsAgainstLocalVariable()
{
- var people = from p in collection.Linq()
- select new { Name = p.FirstName + p.LastName };
+ var age = 21;
+ var people = Collection.Linq().Where(p => p.Age > age);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(2, queryObject.Fields.Count());
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(0, queryObject.Query.Count);
+ Assert.AreEqual(new Document("Age", Op.GreaterThan(age)), queryObject.Query);
}
[Test]
- public void ProjectionWithConstraints()
+ [Ignore("Something is interesting about document comparison that causes this to fail.")]
+ public void Disjunction()
{
- var people = from p in collection.Linq()
- where p.Age > 21 && p.Age < 42
- select new { Name = p.FirstName + p.LastName };
+ var people = Collection.Linq().Where(x => x.Age == 21 || x.Age == 35);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(2, queryObject.Fields.Count());
+ Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Age", new Document().Merge(Op.GreaterThan(21)).Merge(Op.LessThan(42))), queryObject.Query);
+ Assert.AreEqual(new Document("$where", new Code("((this.Age === 21) || (this.Age === 35))")), queryObject.Query);
}
[Test]
- public void ConstraintsAgainstLocalVariable()
+ public void DocumentQuery()
{
- int age = 21;
- var people = collection.Linq().Where(p => p.Age > age);
+ var people = from p in DocumentCollection.Linq()
+ where p.Key("Age") > 21
+ select (string)p["FirstName"];
var queryObject = ((IMongoQueryable)people).GetQueryObject();
+ Assert.AreEqual(new Document("FirstName", 1), queryObject.Fields);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Age", Op.GreaterThan(age)), queryObject.Query);
+ Assert.AreEqual(new Document("Age", Op.GreaterThan(21)), queryObject.Query);
}
[Test]
- public void ConstraintsAgainstLocalReferenceMember()
+ public void Enum()
{
- var local = new { Test = new { Age = 21 } };
- var people = collection.Linq().Where(p => p.Age > local.Test.Age);
+ var people = Collection.Linq().Where(x => x.PrimaryAddress.AddressType == AddressType.Company);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
+ Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Age", Op.GreaterThan(local.Test.Age)), queryObject.Query);
+ Assert.AreEqual(new Document("PrimaryAddress.AddressType", AddressType.Company), queryObject.Query);
}
[Test]
- public void OrderBy()
+ public void LocalEnumerable_Contains()
{
- var people = collection.Linq().OrderBy(x => x.Age).ThenByDescending(x => x.LastName);
+ var names = new[] {"Jack", "Bob"};
+ var people = Collection.Linq().Where(x => names.Contains(x.FirstName));
var queryObject = ((IMongoQueryable)people).GetQueryObject();
+ Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Age", 1).Add("LastName", -1), queryObject.Sort);
+ Assert.AreEqual(new Document("FirstName", Op.In("Jack", "Bob")), queryObject.Query);
}
[Test]
- public void SkipAndTake()
+ public void LocalList_Contains()
{
- var people = collection.Linq().Skip(2).Take(1);
+ var names = new List {"Jack", "Bob"};
+ var people = Collection.Linq().Where(x => names.Contains(x.FirstName));
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(1, queryObject.NumberToLimit);
- Assert.AreEqual(2, queryObject.NumberToSkip);
+ Assert.AreEqual(0, queryObject.Fields.Count);
+ Assert.AreEqual(0, queryObject.NumberToLimit);
+ Assert.AreEqual(0, queryObject.NumberToSkip);
+ Assert.AreEqual(new Document("FirstName", Op.In("Jack", "Bob")), queryObject.Query);
}
[Test]
- public void DocumentQuery()
+ public void NestedArray_Length()
{
- var people = from p in documentCollection.Linq()
- where p.Key("Age") > 21
- select (string)p["FirstName"];
+ var people = from p in Collection.Linq()
+ where p.EmployerIds.Length == 1
+ select p;
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(new Document("FirstName", 1), queryObject.Fields);
+ Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Age", Op.GreaterThan(21)), queryObject.Query);
+ Assert.AreEqual(new Document("EmployerIds", Op.Size(1)), queryObject.Query);
}
[Test]
- public void LocalList_Contains()
+ public void NestedArray_indexer()
{
- var names = new List() { "Jack", "Bob" };
- var people = collection.Linq().Where(x => names.Contains(x.FirstName));
+ var people = Collection.Linq().Where(x => x.EmployerIds[0] == 1);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("FirstName", Op.In("Jack", "Bob")), queryObject.Query);
+ Assert.AreEqual(new Document("EmployerIds.0", 1), queryObject.Query);
}
[Test]
- public void LocalEnumerable_Contains()
+ public void NestedClassConstraint()
{
- var names = new[] { "Jack", "Bob" };
- var people = collection.Linq().Where(x => names.Contains(x.FirstName));
+ var people = Collection.Linq().Where(p => p.PrimaryAddress.City == "my city");
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(0, queryObject.Fields.Count);
+
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("FirstName", Op.In("Jack", "Bob")), queryObject.Query);
+ Assert.AreEqual(new Document("PrimaryAddress.City", "my city"), queryObject.Query);
}
[Test]
- public void String_StartsWith()
+ public void NestedCollection_Count()
{
- var people = from p in collection.Linq()
- where p.FirstName.StartsWith("J")
+ var people = from p in Collection.Linq()
+ where p.Addresses.Count == 1
select p;
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("FirstName", new MongoRegex("^J")), queryObject.Query);
+ Assert.AreEqual(new Document("Addresses", Op.Size(1)), queryObject.Query);
}
[Test]
- public void String_EndsWith()
+ public void NestedList_indexer()
{
- var people = from p in collection.Linq()
- where p.FirstName.EndsWith("e")
- select p;
+ var people = Collection.Linq().Where(x => x.Addresses[1].City == "Tokyo");
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("FirstName", new MongoRegex("e$")), queryObject.Query);
+ Assert.AreEqual(new Document("Addresses.1.City", "Tokyo"), queryObject.Query);
}
[Test]
- public void String_Contains()
+ public void NestedQueryable_Any()
{
- var people = from p in collection.Linq()
- where p.FirstName.Contains("o")
- select p;
+ var people = Collection.Linq().Where(x => x.Addresses.Any(a => a.City == "London"));
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("FirstName", new MongoRegex("o")), queryObject.Query);
+ Assert.AreEqual(new Document("Addresses", new Document("$elemMatch", new Document("City", "London"))), queryObject.Query);
}
[Test]
- public void Regex_IsMatch()
+ public void NestedQueryable_Contains()
{
- var people = from p in collection.Linq()
- where Regex.IsMatch(p.FirstName, "Joe")
- select p;
+ var people = Collection.Linq().Where(x => x.EmployerIds.Contains(1));
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("FirstName", new MongoRegex("Joe")), queryObject.Query);
+ Assert.AreEqual(new Document("EmployerIds", 1), queryObject.Query);
}
[Test]
- public void NestedArray_Length()
+ public void Nested_Queryable_Count()
{
- var people = from p in collection.Linq()
- where p.EmployerIds.Length == 1
- select p;
+ var people = Collection.Linq().Where(x => x.Addresses.Count() == 1);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("EmployerIds", Op.Size(1)), queryObject.Query);
+ Assert.AreEqual(new Document("Addresses", Op.Size(1)), queryObject.Query);
}
[Test]
- public void NestedCollection_Count()
+ public void Nested_Queryable_ElementAt()
{
- var people = from p in collection.Linq()
- where p.Addresses.Count == 1
- select p;
+ var people = Collection.Linq().Where(x => x.Addresses.ElementAt(1).City == "Tokyo");
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Addresses", Op.Size(1)), queryObject.Query);
+ Assert.AreEqual(new Document("Addresses.1.City", "Tokyo"), queryObject.Query);
}
[Test]
- public void Nested_Queryable_Count()
+ public void OrderBy()
{
- var people = collection.Linq().Where(x => x.Addresses.Count() == 1);
+ var people = Collection.Linq().OrderBy(x => x.Age).ThenByDescending(x => x.LastName);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Addresses", Op.Size(1)), queryObject.Query);
+ Assert.AreEqual(new Document("Age", 1).Add("LastName", -1), queryObject.Sort);
}
[Test]
- public void Nested_Queryable_ElementAt()
+ public void Projection()
{
- var people = collection.Linq().Where(x => x.Addresses.ElementAt(1).City == "Tokyo");
+ var people = from p in Collection.Linq()
+ select new {Name = p.FirstName + p.LastName};
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(0, queryObject.Fields.Count);
+ Assert.AreEqual(2, queryObject.Fields.Count());
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Addresses.1.City", "Tokyo"), queryObject.Query);
+ Assert.AreEqual(0, queryObject.Query.Count);
}
[Test]
- public void NestedArray_indexer()
+ public void ProjectionWithConstraints()
{
- var people = collection.Linq().Where(x => x.EmployerIds[0] == 1);
+ var people = from p in Collection.Linq()
+ where p.Age > 21 && p.Age < 42
+ select new {Name = p.FirstName + p.LastName};
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(0, queryObject.Fields.Count);
+ Assert.AreEqual(2, queryObject.Fields.Count());
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("EmployerIds.0", 1), queryObject.Query);
+ Assert.AreEqual(new Document("Age", new Document().Merge(Op.GreaterThan(21)).Merge(Op.LessThan(42))), queryObject.Query);
}
[Test]
- public void NestedList_indexer()
+ public void Regex_IsMatch()
{
- var people = collection.Linq().Where(x => x.Addresses[1].City == "Tokyo");
+ var people = from p in Collection.Linq()
+ where Regex.IsMatch(p.FirstName, "Joe")
+ select p;
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Addresses.1.City", "Tokyo"), queryObject.Query);
+ Assert.AreEqual(new Document("FirstName", new MongoRegex("Joe")), queryObject.Query);
}
[Test]
- public void NestedQueryable_Contains()
+ public void SingleEqualConstraint()
{
- var people = collection.Linq().Where(x => x.EmployerIds.Contains(1));
+ var people = Collection.Linq().Where(p => "Jack" == p.FirstName);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(0, queryObject.Fields.Count);
+
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("EmployerIds", 1), queryObject.Query);
+ Assert.AreEqual(new Document("FirstName", "Jack"), queryObject.Query);
}
[Test]
- public void NestedQueryable_Any()
+ public void SkipAndTake()
{
- var people = collection.Linq().Where(x => x.Addresses.Any(a => a.City == "London"));
+ var people = Collection.Linq().Skip(2).Take(1);
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(0, queryObject.Fields.Count);
- Assert.AreEqual(0, queryObject.NumberToLimit);
- Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Addresses", new Document("$elemMatch", new Document("City", "London"))), queryObject.Query);
+ Assert.AreEqual(1, queryObject.NumberToLimit);
+ Assert.AreEqual(2, queryObject.NumberToSkip);
}
[Test]
- [Ignore("Something is interesting about document comparison that causes this to fail.")]
- public void Disjunction()
+ public void String_Contains()
{
- var people = collection.Linq().Where(x => x.Age == 21 || x.Age == 35);
+ var people = from p in Collection.Linq()
+ where p.FirstName.Contains("o")
+ select p;
var queryObject = ((IMongoQueryable)people).GetQueryObject();
Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("$where", new Code("((this.Age === 21) || (this.Age === 35))")), queryObject.Query);
+ Assert.AreEqual(new Document("FirstName", new MongoRegex("o")), queryObject.Query);
}
[Test]
- public void Chained()
+ public void String_EndsWith()
{
- var people = collection.Linq()
- .Select(x => new { Name = x.FirstName + x.LastName, Age = x.Age })
- .Where(x => x.Age > 21)
- .Select(x => x.Name);
+ var people = from p in Collection.Linq()
+ where p.FirstName.EndsWith("e")
+ select p;
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(2, queryObject.Fields.Count);
+ Assert.AreEqual(0, queryObject.Fields.Count);
Assert.AreEqual(0, queryObject.NumberToLimit);
Assert.AreEqual(0, queryObject.NumberToSkip);
- Assert.AreEqual(new Document("Age", Op.GreaterThan(21)), queryObject.Query);
+ Assert.AreEqual(new Document("FirstName", new MongoRegex("e$")), queryObject.Query);
}
[Test]
- public void Boolean_Test1()
+ public void String_StartsWith()
{
- var people = collection.Linq().Where(x => x.PrimaryAddress.IsInternational);
+ var people = from p in Collection.Linq()
+ where p.FirstName.StartsWith("J")
+ select p;
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(new Document("PrimaryAddress.IsInternational", true), queryObject.Query);
+ Assert.AreEqual(0, queryObject.Fields.Count);
+ Assert.AreEqual(0, queryObject.NumberToLimit);
+ Assert.AreEqual(0, queryObject.NumberToSkip);
+ Assert.AreEqual(new Document("FirstName", new MongoRegex("^J")), queryObject.Query);
}
[Test]
- public void Boolean_Test2()
+ public void WithoutConstraints()
{
- var people = collection.Linq().Where(x => !x.PrimaryAddress.IsInternational);
+ var people = Collection.Linq();
var queryObject = ((IMongoQueryable)people).GetQueryObject();
- Assert.AreEqual(new Document("$not", new Document("PrimaryAddress.IsInternational", true)), queryObject.Query);
+
+ Assert.AreEqual(0, queryObject.NumberToLimit);
+ Assert.AreEqual(0, queryObject.NumberToSkip);
+ Assert.AreEqual(0, queryObject.Query.Count);
}
}
}
\ No newline at end of file
diff --git a/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs b/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs
index 3ca9622b..76f2b3c5 100644
--- a/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs
+++ b/source/MongoDB.Tests/IntegrationTests/Linq/MongoQueryTests.cs
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using System.Linq;
+using System.Text.RegularExpressions;
using MongoDB.Linq;
using NUnit.Framework;
-using System.Text.RegularExpressions;
namespace MongoDB.IntegrationTests.Linq
{
@@ -13,187 +13,181 @@ public override void TestSetup()
{
base.TestSetup();
- collection.Delete(new { }, true);
- collection.Insert(
+ Collection.Delete(new {}, true);
+ Collection.Insert(
new Person
{
FirstName = "Bob",
LastName = "McBob",
Age = 42,
- PrimaryAddress = new Address { City = "London", IsInternational = true },
- Addresses = new List
+ PrimaryAddress = new Address {City = "London", IsInternational = true, AddressType = AddressType.Company},
+ Addresses = new List
{
- new Address { City = "London", IsInternational = true },
- new Address { City = "Tokyo", IsInternational = true },
- new Address { City = "Seattle", IsInternational = false }
+ new Address { City = "London", IsInternational = true, AddressType = AddressType.Company },
+ new Address { City = "Tokyo", IsInternational = true, AddressType = AddressType.Private },
+ new Address { City = "Seattle", IsInternational = false, AddressType = AddressType.Private }
},
EmployerIds = new[] { 1, 2 }
}, true);
- collection.Insert(
+ Collection.Insert(
new Person
{
FirstName = "Jane",
LastName = "McJane",
Age = 35,
- PrimaryAddress = new Address { City = "Paris", IsInternational = true },
+ PrimaryAddress = new Address { City = "Paris", IsInternational = true, AddressType = AddressType.Private },
Addresses = new List
{
- new Address { City = "Paris", IsInternational = true }
+ new Address { City = "Paris", AddressType = AddressType.Private }
},
- EmployerIds = new[] { 1 }
-
- }, true);
+ EmployerIds = new[] {1}
+ },
+ true);
- collection.Insert(
+ Collection.Insert(
new Person
{
FirstName = "Joe",
LastName = "McJoe",
Age = 21,
- PrimaryAddress = new Address { City = "Chicago", IsInternational = true },
+ PrimaryAddress = new Address { City = "Chicago", IsInternational = true, AddressType = AddressType.Private },
Addresses = new List
{
- new Address { City = "Chicago", IsInternational = true },
- new Address { City = "London", IsInternational = true }
+ new Address { City = "Chicago", AddressType = AddressType.Private },
+ new Address { City = "London", AddressType = AddressType.Company }
},
- EmployerIds = new[] { 3 }
- }, true);
+ EmployerIds = new[] {3}
+ },
+ true);
}
[Test]
- public void WithoutConstraints()
+ public void Boolean_Test1()
{
- var people = Enumerable.ToList(collection.Linq());
+ var people = Enumerable.ToList(Collection.Linq().Where(x => x.PrimaryAddress.IsInternational));
Assert.AreEqual(3, people.Count);
}
[Test]
- public void SingleEqualConstraint()
+ public void Boolean_Test2()
{
- var people = Enumerable.ToList(collection.Linq().Where(p => "Joe" == p.FirstName));
+ var people = Enumerable.ToList(Collection.Linq().Where(x => !x.PrimaryAddress.IsInternational));
- Assert.AreEqual(1, people.Count);
+ Assert.AreEqual(0, people.Count);
}
[Test]
- public void ConjuctionConstraint()
+ public void Chained()
{
- var people = Enumerable.ToList(collection.Linq().Where(p => p.Age > 21 && p.Age < 42));
+ var people = Collection.Linq()
+ .Select(x => new { Name = x.FirstName + x.LastName, x.Age })
+ .Where(x => x.Age > 21)
+ .Select(x => x.Name).ToList();
- Assert.AreEqual(1, people.Count);
+ Assert.AreEqual(2, people.Count);
}
[Test]
- public void NestedClassConstraint()
+ public void Complex_Addition()
{
- var people = Enumerable.ToList(collection.Linq().Where(p => p.PrimaryAddress.City == "London"));
+ var people = Collection.Linq().Where(x => x.Age + 23 < 50).ToList();
Assert.AreEqual(1, people.Count);
}
[Test]
- public void Projection()
+ public void Complex_Disjunction()
{
- var people = Enumerable.ToList(from p in collection.Linq()
- select new { Name = p.FirstName + p.LastName });
+ var people = Collection.Linq().Where(x => x.Age == 21 || x.Age == 35).ToList();
- Assert.AreEqual(3, people.Count);
+ Assert.AreEqual(2, people.Count);
}
[Test]
- public void ProjectionWithConstraints()
+ public void ConjuctionConstraint()
{
- var people = Enumerable.ToList(from p in collection.Linq()
- where p.Age > 21 && p.Age < 42
- select new { Name = p.FirstName + p.LastName });
+ var people = Collection.Linq().Where(p => p.Age > 21 && p.Age < 42).ToList();
Assert.AreEqual(1, people.Count);
}
- [Test]
- public void ConstraintsAgainstLocalVariable()
- {
- int age = 21;
- var people = Enumerable.ToList(collection.Linq().Where(p => p.Age > age));
-
- Assert.AreEqual(2, people.Count);
- }
-
[Test]
public void ConstraintsAgainstLocalReferenceMember()
{
var local = new { Test = new { Age = 21 } };
- var people = Enumerable.ToList(collection.Linq().Where(p => p.Age > local.Test.Age));
+ var people = Collection.Linq().Where(p => p.Age > local.Test.Age).ToList();
Assert.AreEqual(2, people.Count);
}
[Test]
- public void OrderBy()
+ public void ConstraintsAgainstLocalVariable()
{
- var people = Enumerable.ToList(collection.Linq().OrderBy(x => x.Age).ThenByDescending(x => x.LastName));
+ var age = 21;
+ var people = Collection.Linq().Where(p => p.Age > age).ToList();
- Assert.AreEqual("Joe", people[0].FirstName);
- Assert.AreEqual("Jane", people[1].FirstName);
- Assert.AreEqual("Bob", people[2].FirstName);
+ Assert.AreEqual(2, people.Count);
}
[Test]
- public void SkipAndTake()
+ public void Count()
{
- var people = Enumerable.ToList(collection.Linq().OrderBy(x => x.Age).Skip(2).Take(1));
+ var count = Collection.Linq().Count();
- Assert.AreEqual("Bob", people[0].FirstName);
+ Assert.AreEqual(3, count);
}
[Test]
- public void First()
+ public void Count_with_predicate()
{
- var person = Queryable.First(collection.Linq().OrderBy(x => x.Age));
+ var count = Collection.Linq().Count(x => x.Age > 21);
- Assert.AreEqual("Joe", person.FirstName);
+ Assert.AreEqual(2, count);
}
[Test]
- public void Single()
+ public void Count_without_predicate()
{
- var person = Queryable.Single(collection.Linq().Where(x => x.Age == 21));
+ var count = Collection.Linq().Where(x => x.Age > 21).Count();
- Assert.AreEqual("Joe", person.FirstName);
+ Assert.AreEqual(2, count);
}
[Test]
- public void Count()
+ public void DocumentQuery()
{
- var count = Queryable.Count(collection.Linq());
+ var people = (from p in DocumentCollection.Linq()
+ where p.Key("Age") > 21
+ select (string)p["FirstName"]).ToList();
- Assert.AreEqual(3, count);
+ Assert.AreEqual(2, people.Count);
}
[Test]
- public void Count_without_predicate()
+ public void Enum()
{
- var count = Queryable.Count(collection.Linq().Where(x => x.Age > 21));
+ var people = Collection.Linq()
+ .Where(x => x.PrimaryAddress.AddressType == AddressType.Company)
+ .ToList();
- Assert.AreEqual(2, count);
+ Assert.AreEqual(1, people.Count);
}
[Test]
- public void Count_with_predicate()
+ public void First()
{
- var count = Queryable.Count(collection.Linq(), x => x.Age > 21);
+ var person = Collection.Linq().OrderBy(x => x.Age).First();
- Assert.AreEqual(2, count);
+ Assert.AreEqual("Joe", person.FirstName);
}
[Test]
- public void DocumentQuery()
+ public void LocalEnumerable_Contains()
{
- var people = Enumerable.ToList((from p in documentCollection.Linq()
- where p.Key("Age") > 21
- select (string)p["FirstName"]));
+ var names = new[] { "Joe", "Bob" };
+ var people = Collection.Linq().Where(x => names.Contains(x.FirstName)).ToList();
Assert.AreEqual(2, people.Count);
}
@@ -201,85 +195,76 @@ public void DocumentQuery()
[Test]
public void LocalList_Contains()
{
- var names = new List() { "Joe", "Bob" };
- var people = Enumerable.ToList(collection.Linq().Where(x => names.Contains(x.FirstName)));
+ var names = new List { "Joe", "Bob" };
+ var people = Collection.Linq().Where(x => names.Contains(x.FirstName)).ToList();
Assert.AreEqual(2, people.Count);
}
[Test]
- public void LocalEnumerable_Contains()
+ public void NestedArray_Length()
{
- var names = new[] { "Joe", "Bob" };
- var people = Enumerable.ToList(collection.Linq().Where(x => names.Contains(x.FirstName)));
+ var people = (from p in Collection.Linq()
+ where p.EmployerIds.Length == 1
+ select p).ToList();
Assert.AreEqual(2, people.Count);
}
- [Test]
- public void String_StartsWith()
+ [Test(Description = "This will fail < 1.4")]
+ public void NestedArray_indexer()
{
- var people = Enumerable.ToList((from p in collection.Linq()
- where p.FirstName.StartsWith("J")
- select p));
+ var people = Collection.Linq().Where(x => x.EmployerIds[0] == 1).ToList();
Assert.AreEqual(2, people.Count);
}
[Test]
- public void String_EndsWith()
+ public void NestedClassConstraint()
{
- var people = Enumerable.ToList((from p in collection.Linq()
- where p.FirstName.EndsWith("e")
- select p));
+ var people = Collection.Linq().Where(p => p.PrimaryAddress.City == "London").ToList();
- Assert.AreEqual(2, people.Count);
+ Assert.AreEqual(1, people.Count);
}
[Test]
- public void String_Contains()
+ public void NestedCollection_Count()
{
- var people = Enumerable.ToList((from p in collection.Linq()
- where p.FirstName.Contains("o")
- select p));
+ var people = (from p in Collection.Linq()
+ where p.Addresses.Count == 1
+ select p).ToList();
- Assert.AreEqual(2, people.Count);
+ Assert.AreEqual(1, people.Count);
}
- [Test]
- public void Regex_IsMatch()
+ [Test(Description = "This will fail < 1.4")]
+ public void NestedList_indexer()
{
- var people = Enumerable.ToList((from p in collection.Linq()
- where Regex.IsMatch(p.FirstName, "Joe")
- select p));
+ var people = Collection.Linq().Where(x => x.Addresses[1].City == "Tokyo").ToList();
Assert.AreEqual(1, people.Count);
}
[Test]
- public void NestedArray_Length()
+ public void NestedQueryable_Any()
{
- var people = Enumerable.ToList((from p in collection.Linq()
- where p.EmployerIds.Length == 1
- select p));
+ var people = Collection.Linq().Where(x => x.Addresses.Any(a => a.City == "London")).ToList();
Assert.AreEqual(2, people.Count);
}
[Test]
- public void NestedCollection_Count()
+ public void NestedQueryable_Contains()
{
- var people = Enumerable.ToList((from p in collection.Linq()
- where p.Addresses.Count == 1
- select p));
+ var people = Collection.Linq().Where(x => x.EmployerIds.Contains(1)).ToList();
- Assert.AreEqual(1, people.Count);
+ Assert.AreEqual(2, people.Count);
}
[Test]
public void Nested_Queryable_Count()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => x.Addresses.Count() == 1));
+ var people = Collection.Linq().Where(x => x.Addresses.Count() == 1).ToList();
Assert.AreEqual(1, people.Count);
}
@@ -287,86 +272,110 @@ public void Nested_Queryable_Count()
[Test(Description = "This will fail < 1.4")]
public void Nested_Queryable_ElementAt()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => x.Addresses.ElementAt(1).City == "Tokyo"));
+ var people = Collection.Linq().Where(x => x.Addresses.ElementAt(1).City == "Tokyo").ToList();
Assert.AreEqual(1, people.Count);
}
- [Test(Description = "This will fail < 1.4")]
- public void NestedArray_indexer()
+ [Test]
+ public void OrderBy()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => x.EmployerIds[0] == 1));
+ var people = Collection.Linq().OrderBy(x => x.Age).ThenByDescending(x => x.LastName).ToList();
- Assert.AreEqual(2, people.Count);
+ Assert.AreEqual("Joe", people[0].FirstName);
+ Assert.AreEqual("Jane", people[1].FirstName);
+ Assert.AreEqual("Bob", people[2].FirstName);
}
- [Test(Description = "This will fail < 1.4")]
- public void NestedList_indexer()
+ [Test]
+ public void Projection()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => x.Addresses[1].City == "Tokyo"));
+ var people = (from p in Collection.Linq()
+ select new { Name = p.FirstName + p.LastName }).ToList();
+
+ Assert.AreEqual(3, people.Count);
+ }
+
+ [Test]
+ public void ProjectionWithConstraints()
+ {
+ var people = (from p in Collection.Linq()
+ where p.Age > 21 && p.Age < 42
+ select new { Name = p.FirstName + p.LastName }).ToList();
Assert.AreEqual(1, people.Count);
}
[Test]
- public void NestedQueryable_Contains()
+ public void Regex_IsMatch()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => x.EmployerIds.Contains(1)));
+ var people = (from p in Collection.Linq()
+ where Regex.IsMatch(p.FirstName, "Joe")
+ select p).ToList();
- Assert.AreEqual(2, people.Count);
+ Assert.AreEqual(1, people.Count);
}
[Test]
- public void NestedQueryable_Any()
+ public void Single()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => x.Addresses.Any(a => a.City == "London")));
+ var person = Collection.Linq().Where(x => x.Age == 21).Single();
- Assert.AreEqual(2, people.Count);
+ Assert.AreEqual("Joe", person.FirstName);
}
[Test]
- public void Chained()
+ public void SingleEqualConstraint()
{
- var people = Enumerable.ToList(collection.Linq()
- .Select(x => new { Name = x.FirstName + x.LastName, Age = x.Age })
- .Where(x => x.Age > 21)
- .Select(x => x.Name));
+ var people = Collection.Linq().Where(p => "Joe" == p.FirstName).ToList();
- Assert.AreEqual(2, people.Count);
+ Assert.AreEqual(1, people.Count);
}
[Test]
- public void Boolean_Test1()
+ public void SkipAndTake()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => x.PrimaryAddress.IsInternational));
+ var people = Collection.Linq().OrderBy(x => x.Age).Skip(2).Take(1).ToList();
- Assert.AreEqual(3, people.Count);
+ Assert.AreEqual("Bob", people[0].FirstName);
}
[Test]
- public void Boolean_Test2()
+ public void String_Contains()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => !x.PrimaryAddress.IsInternational));
+ var people = (from p in Collection.Linq()
+ where p.FirstName.Contains("o")
+ select p).ToList();
- Assert.AreEqual(0, people.Count);
+ Assert.AreEqual(2, people.Count);
}
[Test]
- public void Complex_Disjunction()
+ public void String_EndsWith()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => x.Age == 21 || x.Age == 35));
+ var people = (from p in Collection.Linq()
+ where p.FirstName.EndsWith("e")
+ select p).ToList();
Assert.AreEqual(2, people.Count);
}
[Test]
- public void Complex_Addition()
+ public void String_StartsWith()
{
- var people = Enumerable.ToList(collection.Linq().Where(x => x.Age + 23 < 50));
+ var people = (from p in Collection.Linq()
+ where p.FirstName.StartsWith("J")
+ select p).ToList();
- Assert.AreEqual(1, people.Count);
+ Assert.AreEqual(2, people.Count);
}
-
+ [Test]
+ public void WithoutConstraints()
+ {
+ var people = Collection.Linq().ToList();
+
+ Assert.AreEqual(3, people.Count);
+ }
}
}
\ No newline at end of file
diff --git a/source/MongoDB.Tests/IntegrationTests/TestCollection.cs b/source/MongoDB.Tests/IntegrationTests/TestCollection.cs
index 1184df55..c8c95d9d 100644
--- a/source/MongoDB.Tests/IntegrationTests/TestCollection.cs
+++ b/source/MongoDB.Tests/IntegrationTests/TestCollection.cs
@@ -25,12 +25,9 @@ public override void OnInit()
charreads.Insert(new Document {{"test", "1234" + POUND + "56"}});
}
- private int CountDocs(ICursor cur)
+ private static int CountDocs(ICursor cur)
{
- var cnt = 0;
- foreach(var doc in cur.Documents)
- cnt++;
- return cnt;
+ return cur.Documents.Count();
}
[Test]
diff --git a/source/MongoDB.Tests/IntegrationTests/TestCollectionSafeMode.cs b/source/MongoDB.Tests/IntegrationTests/TestCollectionSafeMode.cs
index 3087f3cd..05cf555b 100644
--- a/source/MongoDB.Tests/IntegrationTests/TestCollectionSafeMode.cs
+++ b/source/MongoDB.Tests/IntegrationTests/TestCollectionSafeMode.cs
@@ -11,8 +11,6 @@ public class TestCollectionSafeMode : MongoTestBase
return "safeinsert, safeupdate, safedelete, safemupdate";
}
}
-
-
[Test]
public void TestBadInsert(){
diff --git a/source/MongoDB.Tests/MongoDB.Tests.csproj b/source/MongoDB.Tests/MongoDB.Tests.csproj
index bacee501..924010bc 100644
--- a/source/MongoDB.Tests/MongoDB.Tests.csproj
+++ b/source/MongoDB.Tests/MongoDB.Tests.csproj
@@ -121,6 +121,7 @@
+
@@ -209,4 +210,4 @@
-
+
\ No newline at end of file
diff --git a/source/MongoDB.Tests/UnitTests/Bson/TestBsonWriter.cs b/source/MongoDB.Tests/UnitTests/Bson/TestBsonWriter.cs
index 0a8f1970..150840a1 100644
--- a/source/MongoDB.Tests/UnitTests/Bson/TestBsonWriter.cs
+++ b/source/MongoDB.Tests/UnitTests/Bson/TestBsonWriter.cs
@@ -75,7 +75,7 @@ public class TestBsonWriter : BsonTestBase
var writer = new BsonWriter(ms, new BsonDocumentDescriptor());
var str = new[] {"a", "b", "c"};
- writer.WriteValue(BsonDataType.Array, str);
+ writer.WriteValue(BsonType.Array, str);
var hexdump = BitConverter.ToString(ms.ToArray());
hexdump = hexdump.Replace("-", "");
@@ -160,7 +160,7 @@ public void TestLocalDateTimeIsWrittenAsUtcTime()
BsonWriter writer = new BsonWriter(ms, new BsonDocumentDescriptor());
Single val = Single.MaxValue;
- writer.WriteValue(BsonDataType.Number, val);
+ writer.WriteValue(BsonType.Number, val);
string hexdump = BitConverter.ToString(ms.ToArray());
hexdump = hexdump.Replace("-","");
@@ -177,7 +177,7 @@ public void TestLocalDateTimeIsWrittenAsUtcTime()
BsonWriter writer = new BsonWriter(ms, new BsonDocumentDescriptor());
MongoSymbol val = "symbol";
Assert.IsTrue(String.IsInterned(val) != null);
- writer.WriteValue(BsonDataType.Symbol, val);
+ writer.WriteValue(BsonType.Symbol, val);
string hexdump = BitConverter.ToString(ms.ToArray()).Replace("-","");
Assert.AreEqual(expected, hexdump);
diff --git a/source/MongoDB.Tests/UnitTests/Configuration/MongoConfigurationTests.cs b/source/MongoDB.Tests/UnitTests/Configuration/MongoConfigurationTests.cs
index d098145f..a364dcf5 100644
--- a/source/MongoDB.Tests/UnitTests/Configuration/MongoConfigurationTests.cs
+++ b/source/MongoDB.Tests/UnitTests/Configuration/MongoConfigurationTests.cs
@@ -39,6 +39,5 @@ public void Test()
});
});
}
-
}
}
diff --git a/source/MongoDB.Tests/UnitTests/Serialization/SerializationFactoryTests.cs b/source/MongoDB.Tests/UnitTests/Serialization/SerializationFactoryTests.cs
new file mode 100644
index 00000000..d0f1b726
--- /dev/null
+++ b/source/MongoDB.Tests/UnitTests/Serialization/SerializationFactoryTests.cs
@@ -0,0 +1,27 @@
+using MongoDB.Configuration;
+using MongoDB.Serialization;
+using NUnit.Framework;
+
+namespace MongoDB.UnitTests.Serialization
+{
+ [TestFixture]
+ public class SerializationFactoryTests
+ {
+ [Test]
+ public void GetBsonReaderSettingsDefaults()
+ {
+ var factory = new SerializationFactory();
+ var readerSettings = factory.GetBsonReaderSettings(typeof(int));
+ Assert.AreEqual(readerSettings.ReadLocalTime,true);
+ Assert.IsNotNull(readerSettings.Builder);
+ }
+
+ [Test]
+ public void ReadLocalTimeCanBeChangedByConfig()
+ {
+ var factory = new SerializationFactory(new MongoConfiguration {ReadLocalTime = false});
+ var readerSettings = factory.GetBsonReaderSettings(typeof(int));
+ Assert.AreEqual(readerSettings.ReadLocalTime, false);
+ }
+ }
+}
\ No newline at end of file
diff --git a/source/MongoDB.Tests/UnitTests/TestOp.cs b/source/MongoDB.Tests/UnitTests/TestOp.cs
index 9cf524ab..5bb4b684 100644
--- a/source/MongoDB.Tests/UnitTests/TestOp.cs
+++ b/source/MongoDB.Tests/UnitTests/TestOp.cs
@@ -134,9 +134,9 @@ public void NotExists()
[Test]
public void Type()
{
- var op = Op.Type(BsonDataType.Boolean);
+ var op = Op.Type(BsonType.Boolean);
- Assert.AreEqual((int)BsonDataType.Boolean, op["$type"]);
+ Assert.AreEqual((int)BsonType.Boolean, op["$type"]);
}
[Test]
diff --git a/source/MongoDB/Bson/BsonReader.cs b/source/MongoDB/Bson/BsonReader.cs
index 3476e5d6..165fef19 100644
--- a/source/MongoDB/Bson/BsonReader.cs
+++ b/source/MongoDB/Bson/BsonReader.cs
@@ -125,46 +125,46 @@ public BsonReader(Stream stream, BsonReaderSettings settings)
/// The type number.
///
public Object ReadElementType(int typeNumber){
- switch((BsonDataType)typeNumber){
- case BsonDataType.Null:
- case BsonDataType.Undefined:
+ switch((BsonType)typeNumber){
+ case BsonType.Null:
+ case BsonType.Undefined:
return null;
- case BsonDataType.MinKey:
+ case BsonType.MinKey:
return MongoMinKey.Value;
- case BsonDataType.MaxKey:
+ case BsonType.MaxKey:
return MongoMaxKey.Value;
- case BsonDataType.Boolean:
+ case BsonType.Boolean:
Position++;
return _reader.ReadBoolean();
- case BsonDataType.Integer:
+ case BsonType.Integer:
Position += 4;
return _reader.ReadInt32();
- case BsonDataType.Long:
+ case BsonType.Long:
Position += 8;
return _reader.ReadInt64();
- case BsonDataType.Date:
+ case BsonType.Date:
return ReadDateTime();
- case BsonDataType.Oid:
+ case BsonType.Oid:
Position += 12;
return new Oid(_reader.ReadBytes(12));
- case BsonDataType.Number:
+ case BsonType.Number:
Position += 8;
return _reader.ReadDouble();
- case BsonDataType.String:
+ case BsonType.String:
return ReadLengthString();
- case BsonDataType.Symbol:
+ case BsonType.Symbol:
return new MongoSymbol(ReadLengthString());
- case BsonDataType.Obj:
+ case BsonType.Obj:
return ReadObject();
- case BsonDataType.Array:
+ case BsonType.Array:
return ReadArray();
- case BsonDataType.Regex:
+ case BsonType.Regex:
return ReadRegex();
- case BsonDataType.Code:
+ case BsonType.Code:
return ReadCode();
- case BsonDataType.CodeWScope:
+ case BsonType.CodeWScope:
return ReadScope();
- case BsonDataType.Binary:
+ case BsonType.Binary:
return ReadBinary();
default:
throw new ArgumentOutOfRangeException(String.Format("Type Number: {0} not recognized", typeNumber));
diff --git a/source/MongoDB/Bson/BsonReaderSettings.cs b/source/MongoDB/Bson/BsonReaderSettings.cs
index fc4d0d92..69d2c269 100644
--- a/source/MongoDB/Bson/BsonReaderSettings.cs
+++ b/source/MongoDB/Bson/BsonReaderSettings.cs
@@ -32,10 +32,13 @@ public BsonReaderSettings()
public IBsonObjectBuilder Builder { get; private set; }
///
- /// MongoDB stores all time values in UTC timezone. If true the
- /// time is converted from UTC to local timezone after is was read.
+ /// Reads DataTime from server as local time.
///
/// true if [read local time]; otherwise, false.
+ ///
+ /// MongoDB stores all time values in UTC timezone. If true the
+ /// time is converted from UTC to local timezone after is was read.
+ ///
public bool ReadLocalTime { get; set; }
}
}
\ No newline at end of file
diff --git a/source/MongoDB/Bson/BsonDataType.cs b/source/MongoDB/Bson/BsonType.cs
similarity index 96%
rename from source/MongoDB/Bson/BsonDataType.cs
rename to source/MongoDB/Bson/BsonType.cs
index 220d60d3..404a1a28 100644
--- a/source/MongoDB/Bson/BsonDataType.cs
+++ b/source/MongoDB/Bson/BsonType.cs
@@ -3,7 +3,7 @@ namespace MongoDB.Bson
///
///
///
- public enum BsonDataType
+ public enum BsonType
{
///
///
diff --git a/source/MongoDB/Bson/BsonWriter.cs b/source/MongoDB/Bson/BsonWriter.cs
index 4f4f6b6a..e4b1362e 100644
--- a/source/MongoDB/Bson/BsonWriter.cs
+++ b/source/MongoDB/Bson/BsonWriter.cs
@@ -49,62 +49,62 @@ public class BsonWriter
///
/// Writes the value.
///
- /// Type of the data.
+ /// Type of the data.
/// The obj.
- public void WriteValue(BsonDataType dataType, Object obj){
- switch(dataType){
- case BsonDataType.MinKey:
- case BsonDataType.MaxKey:
- case BsonDataType.Null:
+ public void WriteValue(BsonType type, Object obj){
+ switch(type){
+ case BsonType.MinKey:
+ case BsonType.MaxKey:
+ case BsonType.Null:
return;
- case BsonDataType.Boolean:
+ case BsonType.Boolean:
_writer.Write((bool)obj);
return;
- case BsonDataType.Integer:
+ case BsonType.Integer:
_writer.Write((int)obj);
return;
- case BsonDataType.Long:
+ case BsonType.Long:
_writer.Write((long)obj);
return;
- case BsonDataType.Date:
+ case BsonType.Date:
Write((DateTime)obj);
return;
- case BsonDataType.Oid:
+ case BsonType.Oid:
Write((Oid)obj);
return;
- case BsonDataType.Number:
+ case BsonType.Number:
_writer.Write(Convert.ToDouble(obj));
return;
- case BsonDataType.String:{
+ case BsonType.String:{
Write((String)obj);
return;
}
- case BsonDataType.Obj:
+ case BsonType.Obj:
if(obj is DBRef)
Write((DBRef)obj);
else
WriteObject(obj);
return;
- case BsonDataType.Array:
+ case BsonType.Array:
WriteArray((IEnumerable)obj);
return;
- case BsonDataType.Regex:{
+ case BsonType.Regex:{
Write((MongoRegex)obj);
return;
}
- case BsonDataType.Code:{
+ case BsonType.Code:{
Write((Code)obj);
return;
}
- case BsonDataType.Symbol:{
- this.WriteValue(BsonDataType.String, ((MongoSymbol)obj).Value);
+ case BsonType.Symbol:{
+ this.WriteValue(BsonType.String, ((MongoSymbol)obj).Value);
return;
}
- case BsonDataType.CodeWScope:{
+ case BsonType.CodeWScope:{
Write((CodeWScope)obj);
return;
}
- case BsonDataType.Binary:{
+ case BsonType.Binary:{
if(obj is Guid)
Write((Guid)obj);
else
@@ -157,8 +157,8 @@ public class BsonWriter
/// The code scope.
private void Write(CodeWScope codeScope){
_writer.Write(CalculateSize(codeScope));
- WriteValue(BsonDataType.String, codeScope.Value);
- WriteValue(BsonDataType.Obj, codeScope.Scope);
+ WriteValue(BsonType.String, codeScope.Value);
+ WriteValue(BsonType.Obj, codeScope.Scope);
}
///
@@ -166,7 +166,7 @@ public class BsonWriter
///
/// The code.
private void Write(Code code){
- WriteValue(BsonDataType.String, code.Value);
+ WriteValue(BsonType.String, code.Value);
}
///
@@ -283,44 +283,44 @@ private void Write(string value)
return 0;
switch(TranslateToBsonType(obj)){
- case BsonDataType.MinKey:
- case BsonDataType.MaxKey:
- case BsonDataType.Null:
+ case BsonType.MinKey:
+ case BsonType.MaxKey:
+ case BsonType.Null:
return 0;
- case BsonDataType.Boolean:
+ case BsonType.Boolean:
return 1;
- case BsonDataType.Integer:
+ case BsonType.Integer:
return 4;
- case BsonDataType.Long:
- case BsonDataType.Date:
+ case BsonType.Long:
+ case BsonType.Date:
return 8;
- case BsonDataType.Oid:
+ case BsonType.Oid:
return 12;
- case BsonDataType.Number:
+ case BsonType.Number:
return sizeof(Double);
- case BsonDataType.String:
+ case BsonType.String:
return CalculateSize((string)obj);
- case BsonDataType.Obj:{
+ case BsonType.Obj:{
if(obj.GetType() == typeof(DBRef))
return CalculateSize((DBRef)obj);
return CalculateSizeObject(obj);
}
- case BsonDataType.Array:
+ case BsonType.Array:
return CalculateSize((IEnumerable)obj);
- case BsonDataType.Regex:{
+ case BsonType.Regex:{
return CalculateSize((MongoRegex)obj);
}
- case BsonDataType.Code:
+ case BsonType.Code:
return CalculateSize((Code)obj);
- case BsonDataType.CodeWScope:{
+ case BsonType.CodeWScope:{
return CalculateSize((CodeWScope)obj);
}
- case BsonDataType.Binary:{
+ case BsonType.Binary:{
if(obj is Guid)
return CalculateSize((Guid)obj);
return CalculateSize((Binary)obj);
}
- case BsonDataType.Symbol:{
+ case BsonType.Symbol:{
MongoSymbol s = (MongoSymbol)obj;
return CalculateSize(s.Value,true);
}
@@ -483,10 +483,10 @@ private int CalculateSizeObject(object obj, IEnumerable propertys)
///
/// The obj.
///
- protected BsonDataType TranslateToBsonType(object obj){
+ protected BsonType TranslateToBsonType(object obj){
//TODO:Convert to use a dictionary
if(obj == null)
- return BsonDataType.Null;
+ return BsonType.Null;
var type = obj.GetType();
@@ -494,45 +494,45 @@ private int CalculateSizeObject(object obj, IEnumerable propertys)
type = Enum.GetUnderlyingType(type);
if(type == typeof(Double))
- return BsonDataType.Number;
+ return BsonType.Number;
if(type == typeof(Single))
- return BsonDataType.Number;
+ return BsonType.Number;
if(type == typeof(String))
- return BsonDataType.String;
+ return BsonType.String;
if(type == typeof(int))
- return BsonDataType.Integer;
+ return BsonType.Integer;
if(type == typeof(long))
- return BsonDataType.Long;
+ return BsonType.Long;
if(type == typeof(bool))
- return BsonDataType.Boolean;
+ return BsonType.Boolean;
if(type == typeof(Oid))
- return BsonDataType.Oid;
+ return BsonType.Oid;
if(type == typeof(DateTime))
- return BsonDataType.Date;
+ return BsonType.Date;
if(type == typeof(MongoRegex))
- return BsonDataType.Regex;
+ return BsonType.Regex;
if(type == typeof(DBRef))
- return BsonDataType.Obj;
+ return BsonType.Obj;
if(type == typeof(Code))
- return BsonDataType.Code;
+ return BsonType.Code;
if(type == typeof(CodeWScope))
- return BsonDataType.CodeWScope;
+ return BsonType.CodeWScope;
if(type == typeof(DBNull))
- return BsonDataType.Null;
+ return BsonType.Null;
if(type == typeof(Binary))
- return BsonDataType.Binary;
+ return BsonType.Binary;
if(type == typeof(Guid))
- return BsonDataType.Binary;
+ return BsonType.Binary;
if(type == typeof(MongoMinKey))
- return BsonDataType.MinKey;
+ return BsonType.MinKey;
if(type == typeof(MongoMaxKey))
- return BsonDataType.MaxKey;
+ return BsonType.MaxKey;
if(type == typeof(MongoSymbol))
- return BsonDataType.Symbol;
+ return BsonType.Symbol;
if(_descriptor.IsArray(obj))
- return BsonDataType.Array;
+ return BsonType.Array;
if(_descriptor.IsObject(obj))
- return BsonDataType.Obj;
+ return BsonType.Obj;
throw new ArgumentOutOfRangeException(String.Format("Type: {0} not recognized", type.FullName));
}
diff --git a/source/MongoDB/Configuration/Mapping/Model/MemberMapBase.cs b/source/MongoDB/Configuration/Mapping/Model/MemberMapBase.cs
index 733bf507..400ee5d7 100644
--- a/source/MongoDB/Configuration/Mapping/Model/MemberMapBase.cs
+++ b/source/MongoDB/Configuration/Mapping/Model/MemberMapBase.cs
@@ -20,6 +20,9 @@ public class MemberMapBase
/// The setter.
protected MemberMapBase(string memberName, Type memberReturnType, Func
/// The writer.
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.Write(FullCollectionName, false);
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.WriteObject(Selector);
}
diff --git a/source/MongoDB/Protocol/GetMoreMessage.cs b/source/MongoDB/Protocol/GetMoreMessage.cs
index 1b346805..5d8d337b 100644
--- a/source/MongoDB/Protocol/GetMoreMessage.cs
+++ b/source/MongoDB/Protocol/GetMoreMessage.cs
@@ -64,10 +64,10 @@ public GetMoreMessage(string fullCollectionName, long cursorId, int numberToRetu
///
/// The writer.
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.Write(FullCollectionName, false);
- writer.WriteValue(BsonDataType.Integer, NumberToReturn);
- writer.WriteValue(BsonDataType.Long, CursorId);
+ writer.WriteValue(BsonType.Integer, NumberToReturn);
+ writer.WriteValue(BsonType.Long, CursorId);
}
///
diff --git a/source/MongoDB/Protocol/InsertMessage.cs b/source/MongoDB/Protocol/InsertMessage.cs
index 168a1054..a46c3b39 100644
--- a/source/MongoDB/Protocol/InsertMessage.cs
+++ b/source/MongoDB/Protocol/InsertMessage.cs
@@ -104,7 +104,7 @@ public class InsertMessage : MessageBase, IRequestMessage
WriteHeader(new BinaryWriter(stream), chunk.Size);
var writer = new BsonWriter(stream, _objectDescriptor);
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.Write(FullCollectionName, false);
foreach(var document in chunk.Documents)
diff --git a/source/MongoDB/Protocol/KillCursorsMessage.cs b/source/MongoDB/Protocol/KillCursorsMessage.cs
index c22aa85f..efafd312 100644
--- a/source/MongoDB/Protocol/KillCursorsMessage.cs
+++ b/source/MongoDB/Protocol/KillCursorsMessage.cs
@@ -54,11 +54,11 @@ public KillCursorsMessage(long[] cursorIDs) : this()
///
/// The writer.
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, 0);
- writer.WriteValue(BsonDataType.Integer, CursorIds.Length);
+ writer.WriteValue(BsonType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, CursorIds.Length);
foreach(var id in CursorIds)
- writer.WriteValue(BsonDataType.Long, id);
+ writer.WriteValue(BsonType.Long, id);
}
///
diff --git a/source/MongoDB/Protocol/QueryMessage.cs b/source/MongoDB/Protocol/QueryMessage.cs
index c479898e..3da0a448 100644
--- a/source/MongoDB/Protocol/QueryMessage.cs
+++ b/source/MongoDB/Protocol/QueryMessage.cs
@@ -117,10 +117,10 @@ public QueryMessage(IBsonObjectDescriptor objectDescriptor, object query, String
///
/// The writer.
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, (int)Options);
+ writer.WriteValue(BsonType.Integer, (int)Options);
writer.Write(FullCollectionName, false);
- writer.WriteValue(BsonDataType.Integer, NumberToSkip);
- writer.WriteValue(BsonDataType.Integer, NumberToReturn);
+ writer.WriteValue(BsonType.Integer, NumberToSkip);
+ writer.WriteValue(BsonType.Integer, NumberToReturn);
writer.WriteObject(Query);
if(ReturnFieldSelector != null)
writer.WriteObject(ReturnFieldSelector);
diff --git a/source/MongoDB/Protocol/UpdateMessage.cs b/source/MongoDB/Protocol/UpdateMessage.cs
index e8f76462..8157612c 100644
--- a/source/MongoDB/Protocol/UpdateMessage.cs
+++ b/source/MongoDB/Protocol/UpdateMessage.cs
@@ -55,9 +55,9 @@ public UpdateMessage(IBsonObjectDescriptor objectDescriptor)
///
/// The writer.
protected override void WriteBody(BsonWriter writer){
- writer.WriteValue(BsonDataType.Integer, 0);
+ writer.WriteValue(BsonType.Integer, 0);
writer.Write(FullCollectionName, false);
- writer.WriteValue(BsonDataType.Integer, Flags);
+ writer.WriteValue(BsonType.Integer, Flags);
writer.WriteObject(Selector);
writer.WriteObject(Document);
}
diff --git a/source/MongoDB/Serialization/ISerializationFactory.cs b/source/MongoDB/Serialization/ISerializationFactory.cs
index 2ac83441..7de1c784 100644
--- a/source/MongoDB/Serialization/ISerializationFactory.cs
+++ b/source/MongoDB/Serialization/ISerializationFactory.cs
@@ -9,18 +9,11 @@ namespace MongoDB.Serialization
public interface ISerializationFactory
{
///
- /// Gets the bson builder.
+ /// Gets the bson writer settings.
///
/// Type of the root.
///
- IBsonObjectBuilder GetBsonBuilder(Type rootType);
-
- ///
- /// Gets the bson descriptor.
- ///
- /// Type of the root.
- ///
- IBsonObjectDescriptor GetBsonDescriptor(Type rootType);
+ BsonWriterSettings GetBsonWriterSettings(Type rootType);
///
/// Gets the name of the collection given the rootType.
@@ -35,5 +28,19 @@ public interface ISerializationFactory
/// The type.
///
IObjectDescriptor GetObjectDescriptor(Type type);
+
+ ///
+ /// Gets the descriptor.
+ ///
+ /// Type of the root.
+ ///
+ IBsonObjectDescriptor GetBsonDescriptor(Type rootType);
+
+ ///
+ /// Gets the bson reader settings.
+ ///
+ /// Type of the root.
+ ///
+ BsonReaderSettings GetBsonReaderSettings(Type rootType);
}
}
\ No newline at end of file
diff --git a/source/MongoDB/Serialization/SerializationFactory.cs b/source/MongoDB/Serialization/SerializationFactory.cs
index 951d6fbb..70f0ada1 100644
--- a/source/MongoDB/Serialization/SerializationFactory.cs
+++ b/source/MongoDB/Serialization/SerializationFactory.cs
@@ -49,6 +49,29 @@ public IBsonObjectDescriptor GetBsonDescriptor(Type rootType)
return new BsonClassMapDescriptor(_configuration.MappingStore, rootType);
}
+ ///
+ /// Gets the bson reader settings.
+ ///
+ /// Type of the root.
+ ///
+ public BsonReaderSettings GetBsonReaderSettings(Type rootType)
+ {
+ return new BsonReaderSettings(GetBsonBuilder(rootType))
+ {
+ ReadLocalTime = _configuration.ReadLocalTime
+ };
+ }
+
+ ///
+ /// Gets the bson writer settings.
+ ///
+ /// Type of the root.
+ ///
+ public BsonWriterSettings GetBsonWriterSettings(Type rootType)
+ {
+ return new BsonWriterSettings(GetBsonDescriptor(rootType));
+ }
+
///
/// Gets the name of the collection given the rootType.
///