Skip to content

Commit

Permalink
Line Endings...boooo
Browse files Browse the repository at this point in the history
  • Loading branch information
schotime committed Jul 8, 2010
1 parent 979afd4 commit 721515e
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 225 deletions.
102 changes: 51 additions & 51 deletions NoRM.Tests/CollectionFindTests/QueryTests.cs
Expand Up @@ -5,7 +5,7 @@
using Xunit; using Xunit;
using Norm.Collections; using Norm.Collections;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Collections.Generic; using System.Collections.Generic;
using Norm.Commands.Modifiers; using Norm.Commands.Modifiers;


namespace Norm.Tests namespace Norm.Tests
Expand Down Expand Up @@ -382,55 +382,55 @@ public void DistinctOnComplexProperty()


var results = _collection.Distinct<Address>("Address"); var results = _collection.Distinct<Address>("Address");
Assert.Equal(3, results.Count()); Assert.Equal(3, results.Count());
} }


[Fact] [Fact]
public void FindAndModify() public void FindAndModify()
{ {
_collection.Insert(new Person { Name = "Joe Cool", Age = 10 }); _collection.Insert(new Person { Name = "Joe Cool", Age = 10 });


var update = new Expando(); var update = new Expando();
update["$inc"] = new { Age = 1 }; update["$inc"] = new { Age = 1 };


var result = _collection.FindAndModify(new { Name = "Joe Cool" }, update); var result = _collection.FindAndModify(new { Name = "Joe Cool" }, update);
Assert.Equal(10, result.Age); Assert.Equal(10, result.Age);


var result2 = _collection.Find(new { Name = "Joe Cool" }).FirstOrDefault(); var result2 = _collection.Find(new { Name = "Joe Cool" }).FirstOrDefault();
Assert.Equal(11, result2.Age); Assert.Equal(11, result2.Age);
} }


[Fact] [Fact]
public void FindAndModifyWithSort() public void FindAndModifyWithSort()
{ {
_collection.Insert(new Person { Name = "Joe Cool", Age = 10 }); _collection.Insert(new Person { Name = "Joe Cool", Age = 10 });
_collection.Insert(new Person { Name = "Joe Cool", Age = 15 }); _collection.Insert(new Person { Name = "Joe Cool", Age = 15 });


var update = new Expando(); var update = new Expando();
update["$inc"] = new { Age = 1 }; update["$inc"] = new { Age = 1 };


var result = _collection.FindAndModify(new { Name = "Joe Cool" }, update, new { Age = Norm.OrderBy.Descending }); var result = _collection.FindAndModify(new { Name = "Joe Cool" }, update, new { Age = Norm.OrderBy.Descending });
Assert.Equal(15, result.Age); Assert.Equal(15, result.Age);


var result2 = _collection.Find(new { Name = "Joe Cool" }).OrderByDescending(x=>x.Age).ToList(); var result2 = _collection.Find(new { Name = "Joe Cool" }).OrderByDescending(x=>x.Age).ToList();
Assert.Equal(16, result2[0].Age); Assert.Equal(16, result2[0].Age);
Assert.Equal(10, result2[1].Age); Assert.Equal(10, result2[1].Age);


} }


[Fact] [Fact]
public void FindAndModifyReturnsNullWhenQueryNotFound() public void FindAndModifyReturnsNullWhenQueryNotFound()
{ {
_collection.Insert(new Person { Name = "Joe Cool", Age = 10 }); _collection.Insert(new Person { Name = "Joe Cool", Age = 10 });
_collection.Insert(new Person { Name = "Joe Cool", Age = 15 }); _collection.Insert(new Person { Name = "Joe Cool", Age = 15 });


var update = new Expando(); var update = new Expando();
update["$inc"] = new { Age = 1 }; update["$inc"] = new { Age = 1 };


var result = _collection.FindAndModify(new { Name = "Joe Cool1" }, update, new { Age = Norm.OrderBy.Descending }); var result = _collection.FindAndModify(new { Name = "Joe Cool1" }, update, new { Age = Norm.OrderBy.Descending });
Assert.Null(result); Assert.Null(result);


var result2 = _collection.Find(new { Age = 15 }).ToList(); var result2 = _collection.Find(new { Age = 15 }).ToList();
Assert.Equal(1, result2.Count); Assert.Equal(1, result2.Count);
} }
} }
} }
158 changes: 79 additions & 79 deletions NoRM.Tests/LinqTests/LinqTests.cs
Expand Up @@ -40,38 +40,38 @@ public void ProviderSupportsProjection()
} }
} }


[Fact] [Fact]
public void ProviderSupportsSophisticatedProjection() public void ProviderSupportsSophisticatedProjection()
{ {
using (var db = Mongo.Create(TestHelper.ConnectionString())) using (var db = Mongo.Create(TestHelper.ConnectionString()))
{ {
var coll = db.GetCollection<TestProduct>(); var coll = db.GetCollection<TestProduct>();


coll.Insert(new TestProduct { Available = DateTime.Now }, new TestProduct { Available = DateTime.Now }); coll.Insert(new TestProduct { Available = DateTime.Now }, new TestProduct { Available = DateTime.Now });


var results = db.GetCollection<TestProduct>().AsQueryable() var results = db.GetCollection<TestProduct>().AsQueryable()
.Select(y => new { Avail = y.Available, Id = y._id }).ToArray(); .Select(y => new { Avail = y.Available, Id = y._id }).ToArray();


Assert.Equal(2, results.Length); Assert.Equal(2, results.Length);
Assert.Equal((new { Avail = DateTime.Now, Id = ObjectId.Empty }).GetType(), Assert.Equal((new { Avail = DateTime.Now, Id = ObjectId.Empty }).GetType(),
results[0].GetType()); results[0].GetType());
} }
} }


[Fact] [Fact]
public void ProviderSupportsSophisticatedProjectionWithConcreteType() public void ProviderSupportsSophisticatedProjectionWithConcreteType()
{ {
using (var db = Mongo.Create(TestHelper.ConnectionString())) using (var db = Mongo.Create(TestHelper.ConnectionString()))
{ {
var coll = db.GetCollection<TestProduct>(); var coll = db.GetCollection<TestProduct>();


coll.Insert(new TestProduct { Name = "AAA", Price = 10 }, new TestProduct { Name = "BBB", Price = 20 }); coll.Insert(new TestProduct { Name = "AAA", Price = 10 }, new TestProduct { Name = "BBB", Price = 20 });


var results = db.GetCollection<TestProduct>().AsQueryable() var results = db.GetCollection<TestProduct>().AsQueryable()
.Select(y => new TestProductSummary { _id = y._id, Name = y.Name, Price = y.Price }).ToArray(); .Select(y => new TestProductSummary { _id = y._id, Name = y.Name, Price = y.Price }).ToArray();


Assert.Equal(2, results.Length); Assert.Equal(2, results.Length);
Assert.Equal((new TestProductSummary()).GetType(), results[0].GetType()); Assert.Equal((new TestProductSummary()).GetType(), results[0].GetType());
} }
} }


Expand Down Expand Up @@ -181,8 +181,8 @@ public void ProviderSupportsProjectionInAnyOrderWithWhereFirst()
Assert.Equal(false, stucture.IsComplex); Assert.Equal(false, stucture.IsComplex);


} }
} }


[Fact] [Fact]
public void LinqQueriesShouldSupportExternalParameters() public void LinqQueriesShouldSupportExternalParameters()
{ {
Expand Down Expand Up @@ -1754,64 +1754,64 @@ public void CanQueryWithinEmbeddedArrayUsingAny()
Assert.Equal("Second", found.Title); Assert.Equal("Second", found.Title);
Assert.Equal(false, queryable.QueryStructure().IsComplex); Assert.Equal(false, queryable.QueryStructure().IsComplex);
} }
} }


[Fact] [Fact]
public void CanQueryWithinEmbeddedArrayUsingAnyWithBool() public void CanQueryWithinEmbeddedArrayUsingAnyWithBool()
{ {
using (var session = new Session()) using (var session = new Session())
{ {
var post1 = new Post var post1 = new Post
{ {
Title = "First", Title = "First",
Comments = new List<Comment> { Comments = new List<Comment> {
new Comment { Text = "comment1", IsOld = false }, new Comment { Text = "comment1", IsOld = false },
new Comment { Text = "comment2", IsOld = false } new Comment { Text = "comment2", IsOld = false }
} }
}; };
var post2 = new Post var post2 = new Post
{ {
Title = "Second", Title = "Second",
Comments = new List<Comment> { Comments = new List<Comment> {
new Comment { Text = "commentA", Name = "name1", IsOld = true }, new Comment { Text = "commentA", Name = "name1", IsOld = true },
new Comment { Text = "commentB", Name = "name2", IsOld = false } new Comment { Text = "commentB", Name = "name2", IsOld = false }
} }
}; };


session.Add(post1); session.Add(post1);
session.Add(post2); session.Add(post2);


var queryable = session.Posts; var queryable = session.Posts;
var found = queryable.Where(p => p.Comments.Any(x => x.IsOld)).ToList(); var found = queryable.Where(p => p.Comments.Any(x => x.IsOld)).ToList();


Assert.Equal(1, found.Count); Assert.Equal(1, found.Count);
Assert.Equal("Second", found[0].Title); Assert.Equal("Second", found[0].Title);


Assert.Equal(false, queryable.QueryStructure().IsComplex); Assert.Equal(false, queryable.QueryStructure().IsComplex);
} }
} }


[Fact] [Fact]
public void CanQueryWithinEmbeddedArrayUsingAnyWithBoolNegated() public void CanQueryWithinEmbeddedArrayUsingAnyWithBoolNegated()
{ {
using (var session = new Session()) using (var session = new Session())
{ {
var tf = false; var tf = false;


var post1 = new Post { Title = "First", Comments = new List<Comment> { new Comment { Text = "comment1", IsOld = false }, new Comment { Text = "comment2", IsOld = false } } }; var post1 = new Post { Title = "First", Comments = new List<Comment> { new Comment { Text = "comment1", IsOld = false }, new Comment { Text = "comment2", IsOld = false } } };
var post2 = new Post { Title = "Second", Comments = new List<Comment> { new Comment { Text = "commentA", Name = "name1", IsOld = true }, new Comment { Text = "commentB", Name = "name2", IsOld = true } } }; var post2 = new Post { Title = "Second", Comments = new List<Comment> { new Comment { Text = "commentA", Name = "name1", IsOld = true }, new Comment { Text = "commentB", Name = "name2", IsOld = true } } };


session.Add(post1); session.Add(post1);
session.Add(post2); session.Add(post2);


var queryable = session.Posts; var queryable = session.Posts;
var found = queryable.Where(p => p.Comments.Any(x => x.IsOld == tf)).ToList(); var found = queryable.Where(p => p.Comments.Any(x => x.IsOld == tf)).ToList();


Assert.Equal(1, found.Count); Assert.Equal(1, found.Count);
Assert.Equal("First", found[0].Title); Assert.Equal("First", found[0].Title);


Assert.Equal(false, queryable.QueryStructure().IsComplex); Assert.Equal(false, queryable.QueryStructure().IsComplex);
} }
} }


[Fact] [Fact]
Expand Down

0 comments on commit 721515e

Please sign in to comment.