public void Remove_Deletes_Article_With_OrderLines()
        {
            //Arrange
            var customer     = CustomerFactory.CreateValidEntity();
            var productToAdd = ProductFactory.CreateValidEntity();
            var article      = ArticleFactory.CreateValidEntity(productToAdd);
            var order        = OrderFactory.CreateValidEntity(customer);
            var orderLine    = OrderLineFactory.CreateValidEntity(order, article);

            article.OrderLines.Add(orderLine);
            productToAdd.Articles.Add(article);

            //Setup ArticleRepository
            var articleRepositoryMock = new Mock <IArticleRepository>();

            articleRepositoryMock.Setup(ir => ir.Get(It.IsAny <Guid>(), It.IsAny <ArticleIncludes>())).Returns(article);
            articleRepositoryMock.Setup(rir => rir.Remove(It.IsAny <Guid>()));

            //Setup UnitOfWork
            var unitOfWorkMock = new Mock <IUnitOfWork>();

            unitOfWorkMock.Setup(uow => uow.Articles).Returns(articleRepositoryMock.Object);
            unitOfWorkMock.Setup(uow => uow.Complete()).Returns(1);

            var articleService = new ArticleService(unitOfWorkMock.Object);

            //Act
            var result = articleService.Remove(productToAdd.Id);

            //Assert
            Assert.IsTrue(result);
        }
        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());
            }
        }
        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);
        }
        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);
            }
        }
        public void Remove_Deletes_Product_With_Articles()
        {
            //Arrange
            var productToAdd = ProductFactory.CreateValidEntity();
            var article      = ArticleFactory.CreateValidEntity(productToAdd);

            productToAdd.Articles.Add(article);


            //Setup ProductRepository
            var productRepositoryMock = new Mock <IProductRepository>();

            productRepositoryMock.Setup(ir => ir.Get(It.IsAny <Guid>(), It.IsAny <ProductIncludes>())).Returns(productToAdd);
            productRepositoryMock.Setup(ir => ir.Remove(It.IsAny <Guid>()));

            //Setup ArticleRepository
            var articleRepositoryMock = new Mock <IArticleRepository>();

            articleRepositoryMock.Setup(rir => rir.Remove(It.IsAny <Guid>()));

            //Setup UnitOfWork
            var unitOfWorkMock = new Mock <IUnitOfWork>();

            unitOfWorkMock.Setup(uow => uow.Products).Returns(productRepositoryMock.Object);
            unitOfWorkMock.Setup(uow => uow.Articles).Returns(articleRepositoryMock.Object);
            unitOfWorkMock.Setup(uow => uow.Complete()).Returns(1);

            var productService = new ProductService(unitOfWorkMock.Object);

            //Act
            var result = productService.Remove(productToAdd.Id);

            //Assert
            Assert.IsTrue(result);
        }
Exemple #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);
            }
        }
Exemple #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
            }
        }
        public void OrderLine_IsValid_Returns_True_When_Valid()
        {
            //Arrange
            var customer = CustomerFactory.CreateValidEntity();

            customer.Id = Guid.NewGuid();
            var order = OrderFactory.CreateValidEntity(customer);

            order.Id = Guid.NewGuid();
            var product = ProductFactory.CreateValidEntity();

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

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

            orderLine.Id = Guid.NewGuid();

            //Act
            var result = orderLine.IsValid();

            //Assert
            Assert.IsTrue(result);
        }
        public void Article_IsValid_Returns_True_When_Valid()
        {
            //Arrange
            var product = ProductFactory.CreateValidEntity();

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

            article.Id = Guid.NewGuid();

            //Act
            var result = article.IsValid();

            //Assert
            Assert.IsTrue(result);
        }
        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);
        }
        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);
            }
        }
        public void Remove_Deletes_Article()
        {
            //Arrange
            var productToAdd          = ProductFactory.CreateValidEntity();
            var articleToAdd          = ArticleFactory.CreateValidEntity(productToAdd);
            var unitOfWorkMock        = new Mock <IUnitOfWork>();
            var articleRepositoryMock = new Mock <IArticleRepository>();

            //Setup ArticleRepository
            articleRepositoryMock.Setup(ir => ir.Get(It.IsAny <Guid>(), It.IsAny <ArticleIncludes>())).Returns(articleToAdd);
            articleRepositoryMock.Setup(ir => ir.Remove(It.IsAny <Guid>()));

            //Setup UnitOfWork
            unitOfWorkMock.Setup(uow => uow.Articles).Returns(articleRepositoryMock.Object);
            unitOfWorkMock.Setup(uow => uow.Complete()).Returns(1);

            var articleService = new ArticleService(unitOfWorkMock.Object);

            //Act
            var result = articleService.Remove(articleToAdd.Id);

            //Assert
            Assert.IsTrue(result);
        }
        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
            }
        }