public void Remove_Deletes_Product()
        {
            var  databaseName = Guid.NewGuid().ToString();
            Guid articleId;

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var product      = ProductFactory.CreateValidEntity();
                var articleToAdd = ArticleFactory.CreateValidEntity(product);
                context.Articles.Add(articleToAdd);
                articleId = articleToAdd.Id;
                context.SaveChanges();
            }

            //Act
            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                var articleRepository = new ArticleRepository(context);
                articleRepository.Remove(articleId);
                context.SaveChanges();
            }

            //Assert
            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                var articleRepository = new ArticleRepository(context);
                var article           = articleRepository.Get(articleId);
                Assert.IsNull(article);
            }
        }
예제 #2
0
        public void Get_Returns_Product_When_Found_With_Includes()
        {
            var  databaseName = Guid.NewGuid().ToString();
            Guid addedProductId;

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productToAdd = ProductFactory.CreateValidEntity();
                context.Products.Add(productToAdd);
                context.SaveChanges();
                addedProductId = productToAdd.Id;
            }

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Act
                var productRepository = new ProductRepository(context);
                var product           = productRepository.Get(addedProductId, new ProductIncludes {
                    ArticleOrderLines = true
                });
                //Assert
                Assert.IsNotNull(product);
            }
        }
예제 #3
0
        public void Remove_Deletes_Product()
        {
            var  databaseName = Guid.NewGuid().ToString();
            Guid productId;

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productToAdd = ProductFactory.CreateValidEntity();
                context.Products.Add(productToAdd);
                context.SaveChanges();
                productId = productToAdd.Id;
            }

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Act
                var productRepository = new ProductRepository(context);

                productRepository.Remove(productId);
                context.SaveChanges();

                var product = productRepository.Get(productId);

                //Assert
                Assert.IsNull(product);
            }
        }
        public void GetAvailableProductResults_Returns_Available_Product()
        {
            var context    = DbContextFactory.CreateInstance("GetAvailableProductResults_Returns_Available_Product");
            var unitOfWork = UnitOfWorkFactory.CreateInstance(context);

            //Arrange
            var customer = CustomerFactory.CreateValidEntity();

            customer.Id = Guid.NewGuid();
            unitOfWork.Customers.Add(customer);
            var product = ProductFactory.CreateValidEntity();

            product.Id = Guid.NewGuid();
            unitOfWork.Products.Add(product);
            var article = ArticleFactory.CreateValidEntity(product);

            article.Id = Guid.NewGuid();
            unitOfWork.Articles.Add(article);
            var article2 = ArticleFactory.CreateValidEntity(product);

            article2.Id = Guid.NewGuid();
            unitOfWork.Articles.Add(article2);
            unitOfWork.Complete();

            var productService = new ProductService(unitOfWork);

            //Act
            var result = productService.All();

            Assert.AreEqual(1, result.Count);
        }
예제 #5
0
        public void Remove_Deletes_Customer()
        {
            //Arrange
            var  databaseName = Guid.NewGuid().ToString();
            Guid customerId;

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                var customer = CustomerFactory.CreateValidEntity();
                context.Customers.Add(customer);
                customerId = customer.Id;
                context.SaveChanges();
            }

            //Act
            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                var customerRepository = new CustomerRepository(context);
                customerRepository.Remove(customerId);
                context.SaveChanges();
            }

            //Assert
            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                var dbCustomer = context.Customers.Find(customerId);

                Assert.IsNull(dbCustomer);
            }
        }
예제 #6
0
        public void Get_Returns_Order_When_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository   = new ProductRepository(context);
                var articleRepository   = new ArticleRepository(context);
                var customerRepository  = new CustomerRepository(context);
                var orderRepository     = new OrderRepository(context);
                var orderLineRepository = new OrderLineRepository(context);

                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var article = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(article);
                var customer = CustomerFactory.CreateValidEntity();
                customerRepository.Add(customer);
                var order = OrderFactory.CreateValidEntity(customer);
                orderRepository.Add(order);
                var orderLineToAdd = OrderLineFactory.CreateValidEntity(order, article);
                orderLineRepository.Add(orderLineToAdd);

                context.SaveChanges();

                //Act
                var orderLine = orderLineRepository.Get(orderLineToAdd.Id);

                //Assert
                Assert.IsNotNull(orderLine);
            }
        }
예제 #7
0
        public void Add_Returns_1_When_Adding_Valid_Order()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository   = new ProductRepository(context);
                var articleRepository   = new ArticleRepository(context);
                var customerRepository  = new CustomerRepository(context);
                var orderRepository     = new OrderRepository(context);
                var orderLineRepository = new OrderLineRepository(context);

                //Act
                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var article = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(article);
                var customer = CustomerFactory.CreateValidEntity();
                customerRepository.Add(customer);
                var order = OrderFactory.CreateValidEntity(customer);
                orderRepository.Add(order);
                var orderLine = OrderLineFactory.CreateValidEntity(order, article);
                orderLineRepository.Add(orderLine);

                var result = context.SaveChanges();

                //Assert
                Assert.AreEqual(5, result); //Because we added five entities
            }
        }
예제 #8
0
        public void GetAll_Returns_10_Orders()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var customerRepository = new CustomerRepository(context);
                var orderRepository    = new OrderRepository(context);
                for (int i = 0; i < 10; i++)
                {
                    var customer = CustomerFactory.CreateValidEntity();
                    customerRepository.Add(customer);
                    var orderToAdd = OrderFactory.CreateValidEntity(customer);
                    orderRepository.Add(orderToAdd);
                }
                context.SaveChanges();

                //Act
                var orders = orderRepository.GetAll();

                //Assert
                Assert.AreEqual(10, orders.Count());
            }
        }
        public void GetAll_Returns_10_Products()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository = new ProductRepository(context);
                var articleRepository = new ArticleRepository(context);
                for (int i = 0; i < 10; i++)
                {
                    var product = ProductFactory.CreateValidEntity();
                    productRepository.Add(product);
                    var articleToAdd = ArticleFactory.CreateValidEntity(product);
                    articleRepository.Add(articleToAdd);
                }
                context.SaveChanges();

                //Act
                var articles = articleRepository.GetAll();

                //Assert
                Assert.AreEqual(10, articles.Count());
            }
        }
예제 #10
0
        public void Get_Returns_Null_When_Not_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using var context = DbContextFactory.CreateInstance(databaseName);

            //Arrange
            var productRepository = new ProductRepository(context);

            //Act
            var product = productRepository.Get(Guid.NewGuid());

            //Assert
            Assert.IsNull(product);
        }
        public void Get_Returns_Null_When_Not_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var articleRepository = new ArticleRepository(context);

                //Act
                var article = articleRepository.Get(Guid.NewGuid());

                //Assert
                Assert.IsNull(article);
            }
        }
예제 #12
0
        public void Get_Returns_Null_When_Not_Found_With_Includes()
        {
            var databaseName = Guid.NewGuid().ToString();

            using var context = DbContextFactory.CreateInstance(databaseName);

            //Arrange
            var productRepository = new ProductRepository(context);

            //Act
            var product = productRepository.Get(Guid.NewGuid(), new ProductIncludes {
                ArticleOrderLines = true
            });

            //Assert
            Assert.IsNull(product);
        }
        public void GetAvailableProductResults_Returns_No_Available_Product_When_All_Rented()
        {
            var context    = DbContextFactory.CreateInstance("GetAvailableProductResults_Returns_No_Available_Product_When_All_Rented");
            var unitOfWork = UnitOfWorkFactory.CreateInstance(context);

            //Arrange
            var customer = CustomerFactory.CreateValidEntity();

            customer.Id = Guid.NewGuid();
            unitOfWork.Customers.Add(customer);
            var product = ProductFactory.CreateValidEntity();

            product.Id = Guid.NewGuid();
            unitOfWork.Products.Add(product);
            var article = ArticleFactory.CreateValidEntity(product);

            article.Id = Guid.NewGuid();
            unitOfWork.Articles.Add(article);
            var article2 = ArticleFactory.CreateValidEntity(product);

            article2.Id = Guid.NewGuid();
            unitOfWork.Articles.Add(article2);
            var order = OrderFactory.CreateValidEntity(customer);

            order.Id = Guid.NewGuid();
            unitOfWork.Orders.Add(order);
            var orderLine = OrderLineFactory.CreateValidEntity(order, article);

            orderLine.Id         = Guid.NewGuid();
            orderLine.ReturnedAt = null;
            unitOfWork.OrderLines.Add(orderLine);
            var orderLine2 = OrderLineFactory.CreateValidEntity(order, article2);

            orderLine2.Id         = Guid.NewGuid();
            orderLine2.ReturnedAt = null;
            unitOfWork.OrderLines.Add(orderLine2);
            unitOfWork.Complete();

            var productService = new ProductService(unitOfWork);

            //Act
            var result = productService.GetAvailableProductResults();

            Assert.AreEqual(0, result.Count);
        }
예제 #14
0
        public void Add_Returns_1_When_Adding_Valid_Customer()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var customerRepository = new CustomerRepository(context);

                //Act
                var customer = CustomerFactory.CreateValidEntity();
                customerRepository.Add(customer);

                var result = context.SaveChanges();

                //Assert
                Assert.AreEqual(1, result);
            }
        }
예제 #15
0
        public void Get_Returns_Customer_When_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var customerRepository = new CustomerRepository(context);
                var customer           = CustomerFactory.CreateValidEntity();
                customerRepository.Add(customer);
                context.SaveChanges();

                //Act
                var dbCustomer = customerRepository.Get(customer.Id);

                //Assert
                Assert.IsNotNull(dbCustomer);
            }
        }
예제 #16
0
        public void Remove_Throws_Exception_When_Not_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var customerRepository = new CustomerRepository(context);

                var customer = CustomerFactory.CreateValidEntity();
                customerRepository.Add(customer);

                context.SaveChanges();

                //Act
                customerRepository.Remove(Guid.NewGuid());
                context.SaveChanges();

                //Assert
            }
        }
        public void Add_Returns_1_When_Adding_Valid_Product()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository = new ProductRepository(context);
                var articleRepository = new ArticleRepository(context);

                //Act
                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var article = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(article);

                var result = context.SaveChanges();

                //Assert
                Assert.AreEqual(2, result); //Because we added two entities
            }
        }
        public void Get_Returns_Product_When_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository = new ProductRepository(context);
                var articleRepository = new ArticleRepository(context);

                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var articleToAdd = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(articleToAdd);
                context.SaveChanges();

                //Act
                var article = articleRepository.Get(articleToAdd.Id);

                //Assert
                Assert.IsNotNull(article);
            }
        }
예제 #19
0
        public void Add_Returns_1_When_Adding_Valid_Product()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange

                var productRepository = new ProductRepository(context);
                var product           = ProductFactory.CreateValidEntity();

                //Act
                productRepository.Add(product);
                context.SaveChanges();
            }

            //Assert
            //Use a separate instance of the context to verify correct data was saved to database
            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                Assert.AreEqual(1, context.Products.Count());
            }
        }
        public void Remove_Throws_Exception_When_Not_Found()
        {
            var databaseName = Guid.NewGuid().ToString();

            using (var context = DbContextFactory.CreateInstance(databaseName))
            {
                //Arrange
                var productRepository = new ProductRepository(context);
                var articleRepository = new ArticleRepository(context);

                var product = ProductFactory.CreateValidEntity();
                productRepository.Add(product);
                var articleToAdd = ArticleFactory.CreateValidEntity(product);
                articleRepository.Add(articleToAdd);

                context.SaveChanges();

                //Act
                articleRepository.Remove(Guid.NewGuid());
                context.SaveChanges();

                //Assert
            }
        }