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 Norm.Collections;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Collections.Generic;
using Norm.Commands.Modifiers;

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

var results = _collection.Distinct<Address>("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);
}
}
}
158 changes: 79 additions & 79 deletions NoRM.Tests/LinqTests/LinqTests.cs
Expand Up @@ -40,38 +40,38 @@ public void ProviderSupportsProjection()
}
}

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

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

var results = db.GetCollection<TestProduct>().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<TestProduct>();

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

var results = db.GetCollection<TestProduct>().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 ProviderSupportsSophisticatedProjectionWithConcreteType()
{
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 });

var results = db.GetCollection<TestProduct>().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());
}
}

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

}
}

}

[Fact]
public void LinqQueriesShouldSupportExternalParameters()
{
Expand Down Expand Up @@ -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<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 = 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<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 } } };

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<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 = 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<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 } } };

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]
Expand Down

0 comments on commit 721515e

Please sign in to comment.