public void DeleteProductByProduct() { using (var northwindFakeContext = new NorthwindFakeContext()) { IUnitOfWork unitOfWork = new FakeUnitofWork(northwindFakeContext); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, TrackingState = TrackingState.Added }); unitOfWork.SaveChanges(); var product = unitOfWork.Repository <Product>().Find(2); product.TrackingState = TrackingState.Deleted; unitOfWork.Repository <Product>().Delete(product); unitOfWork.SaveChanges(); var productDeleted = unitOfWork.Repository <Product>().Find(2); Assert.IsNull(productDeleted); } }
public void UpdateProduct() { using (var northwindFakeContext = new NorthwindFakeContext()) { IUnitOfWork unitOfWork = new FakeUnitofWork(northwindFakeContext); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, TrackingState = TrackingState.Added }); unitOfWork.SaveChanges(); var product = unitOfWork.Repository <Product>().Find(2); Assert.AreEqual(product.Discontinued, true, "Assert we are able to find the inserted Product."); product.Discontinued = false; product.TrackingState = TrackingState.Modified; unitOfWork.Repository <Product>().Update(product); unitOfWork.SaveChanges(); Assert.AreEqual(product.Discontinued, false, "Assert that our changes were saved."); } }
public void DeepLoadProductWithSupplier() { using (var northwindFakeContext = new NorthwindFakeContext()) { IUnitOfWork unitOfWork = new FakeUnitofWork(northwindFakeContext); unitOfWork.Repository <Supplier>().Insert(new Supplier { SupplierID = 1, CompanyName = "Nokia", City = "Tampere", Country = "Finland", ContactName = "Stephen Elop", ContactTitle = "CEO", TrackingState = TrackingState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, ProductName = "Nokia Lumia 1520", SupplierID = 1, TrackingState = TrackingState.Added }); unitOfWork.SaveChanges(); var product = unitOfWork.Repository <Product>().Find(2); Assert.IsNotNull(product); } }
public void InsertRangeOfProducts() { using (var northwindFakeContext = new NorthwindFakeContext()) { IUnitOfWork unitOfWork = new FakeUnitofWork(northwindFakeContext); var newProducts = new[] { new Product { ProductID = 1, Discontinued = false, TrackingState = TrackingState.Added }, new Product { ProductID = 2, Discontinued = true, TrackingState = TrackingState.Added }, new Product { ProductID = 3, Discontinued = true, TrackingState = TrackingState.Added } }; unitOfWork.Repository <Product>().InsertRange(newProducts); var savedProducts = unitOfWork.Repository <Product>().Query().Select(); Assert.AreEqual(savedProducts.Count(), newProducts.Length); } }
public void InsertProduct() { using (var northwindFakeContext = new NorthwindFakeContext()) { IUnitOfWork unitOfWork = new FakeUnitofWork(northwindFakeContext); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 1, Discontinued = false, TrackingState = TrackingState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, TrackingState = TrackingState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 3, Discontinued = true, TrackingState = TrackingState.Added }); unitOfWork.SaveChanges(); var product = unitOfWork.Repository <Product>().Find(2); Assert.IsNotNull(product); Assert.AreEqual(2, product.ProductID); } }
public void GetProductsThatHaveBeenDiscontinued() { using (var northwindFakeContext = new NorthwindFakeContext()) { IUnitOfWork unitOfWork = new FakeUnitofWork(northwindFakeContext); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 1, Discontinued = false, TrackingState = TrackingState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true, TrackingState = TrackingState.Added }); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 3, Discontinued = true, TrackingState = TrackingState.Added }); unitOfWork.SaveChanges(); var discontinuedProducts = unitOfWork.Repository <Product>().Query(t => t.Discontinued).Select(); Assert.AreEqual(2, discontinuedProducts.Count()); } }
public void GetProductsExecutesQuery() { using (var context = new NorthwindFakeContext()) { IUnitOfWork unitOfWork = new FakeUnitofWork(context); var products = unitOfWork.Repository <Product>().Query().Select().ToList(); Assert.IsInstanceOfType(products, typeof(List <Product>)); } }
public async Task FindProductKeyAsync() { using (var northwindFakeContext = new NorthwindFakeContext()) { IUnitOfWorkAsync unitOfWork = new FakeUnitofWork(northwindFakeContext); unitOfWork.Repository <Product>().Insert(new Product { ProductID = 2, Discontinued = true }); unitOfWork.SaveChanges(); var product = await unitOfWork.RepositoryAsync <Product>().FindAsync(2); Assert.AreEqual(product.ProductID, 2); } }