public void Include_Test() { using (var db = new IncludeDatabase(new MemoryStream())) { var customer = new Customer { Name = "John Doe" }; var product1 = new Product { Name = "TV", Price = 800 }; var product2 = new Product { Name = "DVD", Price = 200 }; // insert ref documents db.Customers.Insert(customer); db.Products.Insert(new Product[] { product1, product2 }); var order = new Order { Customer = customer, CustomerNull = null, Products = new List <Product>() { product1, product2 }, ProductArray = new Product[] { product1 }, ProductColl = new List <Product>() { product2 }, ProductEmpty = new List <Product>(), ProductsNull = null }; db.Orders.Insert(order); var query = db.Orders .Include(x => x.Customer) .Include(x => x.CustomerNull) .Include(x => x.Products) .Include(x => x.ProductArray) .Include(x => x.ProductColl) .Include(x => x.ProductsNull) .FindAll() .FirstOrDefault(); Assert.AreEqual(customer.Name, query.Customer.Name); Assert.AreEqual(product1.Price, query.Products[0].Price); Assert.AreEqual(product2.Name, query.Products[1].Name); Assert.AreEqual(product1.Name, query.ProductArray[0].Name); Assert.AreEqual(product2.Price, query.ProductColl.ElementAt(0).Price); Assert.AreEqual(null, query.ProductsNull); Assert.AreEqual(0, query.ProductEmpty.Count); } }
public void Include_Test() { using (var db = new IncludeDatabase()) { var customer = new Customer { Name = "John Doe" }; var product1 = new Product { Name = "TV", Price = 800 }; var product2 = new Product { Name = "DVD", Price = 200 }; // insert ref documents db.Customers.Insert(customer); db.Products.Insert(new Product[] { product1, product2 }); var order = new Order { Customer = customer, CustomerNull = null, Products = new List<Product>() { product1, product2 }, ProductArray = new Product[] { product1 }, ProductColl = new List<Product>() { product2 }, ProductEmpty = new List<Product>(), ProductsNull = null }; db.Orders.Insert(order); var query = db.Orders .Include(x => x.Customer) .Include(x => x.CustomerNull) .Include(x => x.Products) .Include(x => x.ProductArray) .Include(x => x.ProductColl) .Include(x => x.ProductsNull) .FindAll() .FirstOrDefault(); Assert.AreEqual(customer.Name, query.Customer.Name); Assert.AreEqual(product1.Price, query.Products[0].Price); Assert.AreEqual(product2.Name, query.Products[1].Name); Assert.AreEqual(product1.Name, query.ProductArray[0].Name); Assert.AreEqual(product2.Price, query.ProductColl.ElementAt(0).Price); Assert.AreEqual(null, query.ProductsNull); Assert.AreEqual(0, query.ProductEmpty.Count); } }