public void InsertingANewEntityWithObjectIdKeyGeneratesAKey() { using (var mongo = Mongo.Create(TestHelper.ConnectionString())) { var product = new TestProduct { _id = null }; mongo.GetCollection <TestProduct>("Fake").Insert(product); Assert.NotNull(product._id); Assert.NotEqual(ObjectId.Empty, product._id); } }
public void DeletesEntityBasedOnItsId() { using (var mongo = Mongo.Create(TestHelper.ConnectionString())) { var collection = mongo.GetCollection <TestProduct>("Fake"); var product1 = new TestProduct(); var product2 = new TestProduct(); collection.Insert(new[] { product1, product2 }); Assert.Equal(2, collection.Count()); collection.Delete(product1); Assert.Equal(1, collection.Count()); Assert.Equal(1, collection.Count(new { Id = product2._id })); } }
public void InventorySubqueryShouldReturnOneForTwoProducts() { using (var session = new Session()) { //create a Product var p = new TestProduct() { Name = "Test1", Price = 10 }; //change the inventory p.Inventory.Add(new InventoryChange() { AmountChanged = 1 }); session.Add(p); p = new TestProduct() { Name = "Test3", Price = 10 }; //change the inventory p.Inventory.Add(new InventoryChange() { AmountChanged = 1 }); p.Inventory.Add(new InventoryChange() { AmountChanged = 2 }); p.Inventory.Add(new InventoryChange() { AmountChanged = -1 }); session.Add(p); var queryable = session.Products; var products = queryable.Where(x => x.Inventory.Count() > 2).ToArray(); Assert.Equal(1, products.Count()); Assert.Equal("Test3", products[0].Name); Assert.Equal(true, queryable.QueryStructure().IsComplex); } }