Пример #1
0
        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);
            }
        }
Пример #2
0
        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.");
            }
        }
Пример #3
0
        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);
            }
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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());
            }
        }
Пример #6
0
        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);
            }
        }