public void Mongo_Configuration_With_Linq_Supports_Aliases() { MongoConfiguration.Initialize(c => c.AddMap <ShopperMap>()); using (var shoppers = new Shoppers(Mongo.Create("mongodb://localhost:27017/test"))) { shoppers.Drop <Shopper>(); shoppers.Add(new Shopper { Id = ObjectId.NewObjectId(), Name = "John", Cart = new Cart { Id = ObjectId.NewObjectId(), Name = "Cart1", Product = new TestProduct { Name = "SomeProduct" } } }); shoppers.Add(new Shopper { Id = ObjectId.NewObjectId(), Name = "Jane", Cart = new Cart { Id = ObjectId.NewObjectId(), Name = "Cart2", Product = new TestProduct { Name = "OtherProduct" } } }); var shallowResult = shoppers.Where(x => x.Name == "Jane").ToList(); Assert.Equal(1, shallowResult.Count()); var deepResult = shoppers.Where(x => x.Cart.Name == "Cart1").ToList(); Assert.Equal(1, deepResult.Count()); var deeperResult = shoppers.Where(x => x.Cart.Product.Name == "OtherProduct").ToList(); Assert.Equal(1, deeperResult.Count()); } }
public void Are_Queries_Fully_Linqified() { MongoConfiguration.Initialize(c => c.AddMap <ShopperMap>()); using (var shoppers = new Shoppers(Mongo.Create("mongodb://localhost:27017/test"))) { shoppers.Drop <Shopper>(); shoppers.Add(new Shopper { Id = ObjectId.NewObjectId(), Name = "John", Cart = new Cart { Id = ObjectId.NewObjectId(), Name = "Cart1", CartSuppliers = new[] { new Supplier { Name = "Supplier1" }, new Supplier { Name = "Supplier2" } } } }); shoppers.Add(new Shopper { Id = ObjectId.NewObjectId(), Name = "Jane", Cart = new Cart { Id = ObjectId.NewObjectId(), Name = "Cart2", CartSuppliers = new[] { new Supplier { Name = "Supplier3" }, new Supplier { Name = "Supplier4" } } } }); var deepQuery = shoppers.Where(x => x.Cart.CartSuppliers.Any(y => y.Name == "Supplier1")).ToList(); Assert.Equal("John", deepQuery[0].Name); Assert.Equal("Cart1", deepQuery[0].Cart.Name); Assert.Equal(1, deepQuery.Count); } }