From 721515e5705e99e3b0d74efcc8054fdcb0f3d612 Mon Sep 17 00:00:00 2001 From: Adam Schroder Date: Thu, 8 Jul 2010 16:29:57 +1000 Subject: [PATCH] Line Endings...boooo --- NoRM.Tests/CollectionFindTests/QueryTests.cs | 102 +++++----- NoRM.Tests/LinqTests/LinqTests.cs | 158 +++++++-------- NoRM.Tests/MongoCollectionTests.cs | 190 +++++++++---------- 3 files changed, 225 insertions(+), 225 deletions(-) diff --git a/NoRM.Tests/CollectionFindTests/QueryTests.cs b/NoRM.Tests/CollectionFindTests/QueryTests.cs index 847c9472..06f50f31 100644 --- a/NoRM.Tests/CollectionFindTests/QueryTests.cs +++ b/NoRM.Tests/CollectionFindTests/QueryTests.cs @@ -5,7 +5,7 @@ using Xunit; using Norm.Collections; using System.Text.RegularExpressions; -using System.Collections.Generic; +using System.Collections.Generic; using Norm.Commands.Modifiers; namespace Norm.Tests @@ -382,55 +382,55 @@ public void DistinctOnComplexProperty() var results = _collection.Distinct
("Address"); Assert.Equal(3, results.Count()); - } - - [Fact] - public void FindAndModify() - { - _collection.Insert(new Person { Name = "Joe Cool", Age = 10 }); - - var update = new Expando(); - update["$inc"] = new { Age = 1 }; - - var result = _collection.FindAndModify(new { Name = "Joe Cool" }, update); - Assert.Equal(10, result.Age); - - var result2 = _collection.Find(new { Name = "Joe Cool" }).FirstOrDefault(); - Assert.Equal(11, result2.Age); - } - - [Fact] - public void FindAndModifyWithSort() - { - _collection.Insert(new Person { Name = "Joe Cool", Age = 10 }); - _collection.Insert(new Person { Name = "Joe Cool", Age = 15 }); - - var update = new Expando(); - update["$inc"] = new { Age = 1 }; - - var result = _collection.FindAndModify(new { Name = "Joe Cool" }, update, new { Age = Norm.OrderBy.Descending }); - Assert.Equal(15, result.Age); - - var result2 = _collection.Find(new { Name = "Joe Cool" }).OrderByDescending(x=>x.Age).ToList(); - Assert.Equal(16, result2[0].Age); - Assert.Equal(10, result2[1].Age); - - } - - [Fact] - public void FindAndModifyReturnsNullWhenQueryNotFound() - { - _collection.Insert(new Person { Name = "Joe Cool", Age = 10 }); - _collection.Insert(new Person { Name = "Joe Cool", Age = 15 }); - - var update = new Expando(); - update["$inc"] = new { Age = 1 }; - - var result = _collection.FindAndModify(new { Name = "Joe Cool1" }, update, new { Age = Norm.OrderBy.Descending }); - Assert.Null(result); - - var result2 = _collection.Find(new { Age = 15 }).ToList(); - Assert.Equal(1, result2.Count); - } + } + + [Fact] + public void FindAndModify() + { + _collection.Insert(new Person { Name = "Joe Cool", Age = 10 }); + + var update = new Expando(); + update["$inc"] = new { Age = 1 }; + + var result = _collection.FindAndModify(new { Name = "Joe Cool" }, update); + Assert.Equal(10, result.Age); + + var result2 = _collection.Find(new { Name = "Joe Cool" }).FirstOrDefault(); + Assert.Equal(11, result2.Age); + } + + [Fact] + public void FindAndModifyWithSort() + { + _collection.Insert(new Person { Name = "Joe Cool", Age = 10 }); + _collection.Insert(new Person { Name = "Joe Cool", Age = 15 }); + + var update = new Expando(); + update["$inc"] = new { Age = 1 }; + + var result = _collection.FindAndModify(new { Name = "Joe Cool" }, update, new { Age = Norm.OrderBy.Descending }); + Assert.Equal(15, result.Age); + + var result2 = _collection.Find(new { Name = "Joe Cool" }).OrderByDescending(x=>x.Age).ToList(); + Assert.Equal(16, result2[0].Age); + Assert.Equal(10, result2[1].Age); + + } + + [Fact] + public void FindAndModifyReturnsNullWhenQueryNotFound() + { + _collection.Insert(new Person { Name = "Joe Cool", Age = 10 }); + _collection.Insert(new Person { Name = "Joe Cool", Age = 15 }); + + var update = new Expando(); + update["$inc"] = new { Age = 1 }; + + var result = _collection.FindAndModify(new { Name = "Joe Cool1" }, update, new { Age = Norm.OrderBy.Descending }); + Assert.Null(result); + + var result2 = _collection.Find(new { Age = 15 }).ToList(); + Assert.Equal(1, result2.Count); + } } } \ No newline at end of file diff --git a/NoRM.Tests/LinqTests/LinqTests.cs b/NoRM.Tests/LinqTests/LinqTests.cs index e17f71a4..447c1c56 100644 --- a/NoRM.Tests/LinqTests/LinqTests.cs +++ b/NoRM.Tests/LinqTests/LinqTests.cs @@ -40,22 +40,22 @@ public void ProviderSupportsProjection() } } - [Fact] - public void ProviderSupportsSophisticatedProjection() - { - using (var db = Mongo.Create(TestHelper.ConnectionString())) - { - var coll = db.GetCollection(); - - coll.Insert(new TestProduct { Available = DateTime.Now }, new TestProduct { Available = DateTime.Now }); - - var results = db.GetCollection().AsQueryable() - .Select(y => new { Avail = y.Available, Id = y._id }).ToArray(); - - Assert.Equal(2, results.Length); - Assert.Equal((new { Avail = DateTime.Now, Id = ObjectId.Empty }).GetType(), - results[0].GetType()); - } + [Fact] + public void ProviderSupportsSophisticatedProjection() + { + using (var db = Mongo.Create(TestHelper.ConnectionString())) + { + var coll = db.GetCollection(); + + coll.Insert(new TestProduct { Available = DateTime.Now }, new TestProduct { Available = DateTime.Now }); + + var results = db.GetCollection().AsQueryable() + .Select(y => new { Avail = y.Available, Id = y._id }).ToArray(); + + Assert.Equal(2, results.Length); + Assert.Equal((new { Avail = DateTime.Now, Id = ObjectId.Empty }).GetType(), + results[0].GetType()); + } } [Fact] @@ -63,15 +63,15 @@ public void ProviderSupportsSophisticatedProjectionWithConcreteType() { using (var db = Mongo.Create(TestHelper.ConnectionString())) { - var coll = db.GetCollection(); - + var coll = db.GetCollection(); + coll.Insert(new TestProduct { Name = "AAA", Price = 10 }, new TestProduct { Name = "BBB", Price = 20 }); var results = db.GetCollection().AsQueryable() .Select(y => new TestProductSummary { _id = y._id, Name = y.Name, Price = y.Price }).ToArray(); Assert.Equal(2, results.Length); - Assert.Equal((new TestProductSummary()).GetType(), results[0].GetType()); + Assert.Equal((new TestProductSummary()).GetType(), results[0].GetType()); } } @@ -181,8 +181,8 @@ public void ProviderSupportsProjectionInAnyOrderWithWhereFirst() Assert.Equal(false, stucture.IsComplex); } - } - + } + [Fact] public void LinqQueriesShouldSupportExternalParameters() { @@ -1754,64 +1754,64 @@ public void CanQueryWithinEmbeddedArrayUsingAny() Assert.Equal("Second", found.Title); Assert.Equal(false, queryable.QueryStructure().IsComplex); } - } - - [Fact] - public void CanQueryWithinEmbeddedArrayUsingAnyWithBool() - { - using (var session = new Session()) - { - var post1 = new Post - { - Title = "First", - Comments = new List { - new Comment { Text = "comment1", IsOld = false }, - new Comment { Text = "comment2", IsOld = false } - } - }; - var post2 = new Post - { - Title = "Second", - Comments = new List { - new Comment { Text = "commentA", Name = "name1", IsOld = true }, - new Comment { Text = "commentB", Name = "name2", IsOld = false } - } - }; - - session.Add(post1); - session.Add(post2); - - var queryable = session.Posts; - var found = queryable.Where(p => p.Comments.Any(x => x.IsOld)).ToList(); - - Assert.Equal(1, found.Count); - Assert.Equal("Second", found[0].Title); - - Assert.Equal(false, queryable.QueryStructure().IsComplex); - } - } - - [Fact] - public void CanQueryWithinEmbeddedArrayUsingAnyWithBoolNegated() - { - using (var session = new Session()) - { - var tf = false; - - var post1 = new Post { Title = "First", Comments = new List { new Comment { Text = "comment1", IsOld = false }, new Comment { Text = "comment2", IsOld = false } } }; - var post2 = new Post { Title = "Second", Comments = new List { new Comment { Text = "commentA", Name = "name1", IsOld = true }, new Comment { Text = "commentB", Name = "name2", IsOld = true } } }; - - session.Add(post1); - session.Add(post2); - - var queryable = session.Posts; - var found = queryable.Where(p => p.Comments.Any(x => x.IsOld == tf)).ToList(); - - Assert.Equal(1, found.Count); - Assert.Equal("First", found[0].Title); - - Assert.Equal(false, queryable.QueryStructure().IsComplex); - } + } + + [Fact] + public void CanQueryWithinEmbeddedArrayUsingAnyWithBool() + { + using (var session = new Session()) + { + var post1 = new Post + { + Title = "First", + Comments = new List { + new Comment { Text = "comment1", IsOld = false }, + new Comment { Text = "comment2", IsOld = false } + } + }; + var post2 = new Post + { + Title = "Second", + Comments = new List { + new Comment { Text = "commentA", Name = "name1", IsOld = true }, + new Comment { Text = "commentB", Name = "name2", IsOld = false } + } + }; + + session.Add(post1); + session.Add(post2); + + var queryable = session.Posts; + var found = queryable.Where(p => p.Comments.Any(x => x.IsOld)).ToList(); + + Assert.Equal(1, found.Count); + Assert.Equal("Second", found[0].Title); + + Assert.Equal(false, queryable.QueryStructure().IsComplex); + } + } + + [Fact] + public void CanQueryWithinEmbeddedArrayUsingAnyWithBoolNegated() + { + using (var session = new Session()) + { + var tf = false; + + var post1 = new Post { Title = "First", Comments = new List { new Comment { Text = "comment1", IsOld = false }, new Comment { Text = "comment2", IsOld = false } } }; + var post2 = new Post { Title = "Second", Comments = new List { new Comment { Text = "commentA", Name = "name1", IsOld = true }, new Comment { Text = "commentB", Name = "name2", IsOld = true } } }; + + session.Add(post1); + session.Add(post2); + + var queryable = session.Posts; + var found = queryable.Where(p => p.Comments.Any(x => x.IsOld == tf)).ToList(); + + Assert.Equal(1, found.Count); + Assert.Equal("First", found[0].Title); + + Assert.Equal(false, queryable.QueryStructure().IsComplex); + } } [Fact] diff --git a/NoRM.Tests/MongoCollectionTests.cs b/NoRM.Tests/MongoCollectionTests.cs index c722adb9..c7620804 100644 --- a/NoRM.Tests/MongoCollectionTests.cs +++ b/NoRM.Tests/MongoCollectionTests.cs @@ -19,7 +19,7 @@ public MongoCollectionTests() using (var mongo = Mongo.Create(TestHelper.ConnectionString("strict=false"))) { - mongo.Database.DropCollection("Fake"); + mongo.Database.DropCollection("Fake"); mongo.Database.DropCollection("Faker"); } } @@ -332,100 +332,100 @@ public void InsertingMultipleNewEntityWithObjectIdKeyGeneratesAKey() Assert.NotNull(product2._id); Assert.NotEqual(ObjectId.Empty, product2._id); } - } - - [Fact] - public void InsertingANewEntityGeneratingTheIntKeyFirst() - { - using (var mongo = Mongo.Create(TestHelper.ConnectionString())) - { - var collection = mongo.GetCollection("Fake"); - - var identity = (int)collection.GenerateId(); - var testint = new TestIntGeneration { _id = identity, Name = "TestMe" }; - collection.Insert(testint); - - var result = collection.FindOne(new { _id = testint._id }); - - Assert.NotNull(testint._id); - Assert.Equal(result.Name, "TestMe"); - } - } - - [Fact] - public void InsertingANewEntityWithNullableIntGeneratesAKey() - { - using (var mongo = Mongo.Create(TestHelper.ConnectionString())) - { - var testint = new TestIntGeneration { _id = null }; - mongo.GetCollection("Fake").Insert(testint); - - Assert.NotNull(testint._id); - Assert.NotEqual(0, testint._id.Value); - } - } - - [Fact] - public void InsertingANewEntityWithNullableIntGeneratesAKeyComplex() - { - using (var mongo = Mongo.Create(TestHelper.ConnectionString())) - { - var idents = new List(); - for (int i = 0; i < 15; i++) - { - var testint = new TestIntGeneration { _id = null }; - mongo.GetCollection("Fake").Insert(testint); - idents.Add(testint._id.Value); - } - - var list = mongo.GetCollection("Fake").Find(new { _id = Q.In(idents.ToArray()) }); - - foreach (var item in list) - { - Assert.True(idents.Contains(item._id.Value)); - } - - Assert.Equal(idents.Distinct().Count(), list.Select(x => x._id.Value).Distinct().Count()); - } - } - - [Fact] - public void InsertingANewEntityWithNullableIntGeneratesAKeyComplexWith2Collections() - { - using (var mongo = Mongo.Create(TestHelper.ConnectionString())) - { - var idents = new List(); - for (int i = 0; i < 15; i++) - { - var testint = new TestIntGeneration { _id = null }; - mongo.GetCollection("Fake").Insert(testint); - idents.Add(testint._id.Value); - } - - var idents2 = new List(); - for (int i = 0; i < 15; i++) - { - var testint = new TestIntGeneration { _id = null }; - mongo.GetCollection("Faker").Insert(testint); - idents2.Add(testint._id.Value); - } - - var list = mongo.GetCollection("Fake").Find(new { _id = Q.In(idents.ToArray()) }); - var list2 = mongo.GetCollection("Faker").Find(new { _id = Q.In(idents2.ToArray()) }); - - foreach (var item in list) - { - Assert.True(idents.Contains(item._id.Value)); - } - - foreach (var item in list2) - { - Assert.True(idents2.Contains(item._id.Value)); - } - - Assert.Equal(idents.Distinct().Count(), list.Select(x => x._id.Value).Distinct().Count()); - Assert.Equal(idents2.Distinct().Count(), list2.Select(x => x._id.Value).Distinct().Count()); - } + } + + [Fact] + public void InsertingANewEntityGeneratingTheIntKeyFirst() + { + using (var mongo = Mongo.Create(TestHelper.ConnectionString())) + { + var collection = mongo.GetCollection("Fake"); + + var identity = (int)collection.GenerateId(); + var testint = new TestIntGeneration { _id = identity, Name = "TestMe" }; + collection.Insert(testint); + + var result = collection.FindOne(new { _id = testint._id }); + + Assert.NotNull(testint._id); + Assert.Equal(result.Name, "TestMe"); + } + } + + [Fact] + public void InsertingANewEntityWithNullableIntGeneratesAKey() + { + using (var mongo = Mongo.Create(TestHelper.ConnectionString())) + { + var testint = new TestIntGeneration { _id = null }; + mongo.GetCollection("Fake").Insert(testint); + + Assert.NotNull(testint._id); + Assert.NotEqual(0, testint._id.Value); + } + } + + [Fact] + public void InsertingANewEntityWithNullableIntGeneratesAKeyComplex() + { + using (var mongo = Mongo.Create(TestHelper.ConnectionString())) + { + var idents = new List(); + for (int i = 0; i < 15; i++) + { + var testint = new TestIntGeneration { _id = null }; + mongo.GetCollection("Fake").Insert(testint); + idents.Add(testint._id.Value); + } + + var list = mongo.GetCollection("Fake").Find(new { _id = Q.In(idents.ToArray()) }); + + foreach (var item in list) + { + Assert.True(idents.Contains(item._id.Value)); + } + + Assert.Equal(idents.Distinct().Count(), list.Select(x => x._id.Value).Distinct().Count()); + } + } + + [Fact] + public void InsertingANewEntityWithNullableIntGeneratesAKeyComplexWith2Collections() + { + using (var mongo = Mongo.Create(TestHelper.ConnectionString())) + { + var idents = new List(); + for (int i = 0; i < 15; i++) + { + var testint = new TestIntGeneration { _id = null }; + mongo.GetCollection("Fake").Insert(testint); + idents.Add(testint._id.Value); + } + + var idents2 = new List(); + for (int i = 0; i < 15; i++) + { + var testint = new TestIntGeneration { _id = null }; + mongo.GetCollection("Faker").Insert(testint); + idents2.Add(testint._id.Value); + } + + var list = mongo.GetCollection("Fake").Find(new { _id = Q.In(idents.ToArray()) }); + var list2 = mongo.GetCollection("Faker").Find(new { _id = Q.In(idents2.ToArray()) }); + + foreach (var item in list) + { + Assert.True(idents.Contains(item._id.Value)); + } + + foreach (var item in list2) + { + Assert.True(idents2.Contains(item._id.Value)); + } + + Assert.Equal(idents.Distinct().Count(), list.Select(x => x._id.Value).Distinct().Count()); + Assert.Equal(idents2.Distinct().Count(), list2.Select(x => x._id.Value).Distinct().Count()); + } } [Fact]