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 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);
        }
Exemplo n.º 3
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
            }
        }
Exemplo n.º 4
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);
            }
        }
        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);
        }
Exemplo n.º 6
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());
            }
        }
Exemplo n.º 7
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);
            }
        }
        public void Customer_IsValid_Returns_True_When_Valid()
        {
            //Arrange
            var customer = CustomerFactory.CreateValidEntity();

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

            //Assert
            Assert.IsTrue(result);
        }
        public void Order_IsValid_Returns_True_When_Valid()
        {
            //Arrange
            var customer = CustomerFactory.CreateValidEntity();

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

            order.Id = Guid.NewGuid();

            //Act
            var result = order.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);
        }
Exemplo n.º 11
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);
            }
        }
Exemplo n.º 12
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);
            }
        }
        public void Remove_Deletes_Customer()
        {
            //Arrange
            var customer               = CustomerFactory.CreateValidEntity();
            var unitOfWorkMock         = new Mock <IUnitOfWork>();
            var customerRepositoryMock = new Mock <ICustomerRepository>();
            var orderRepositoryMock    = new Mock <IOrderRepository>();
            var customerService        = new CustomerService(unitOfWorkMock.Object);

            customerRepositoryMock.Setup(ir => ir.Get(It.IsAny <Guid>())).Returns(customer);
            customerRepositoryMock.Setup(rir => rir.Remove(It.IsAny <Guid>()));
            unitOfWorkMock.Setup(uow => uow.Customers).Returns(customerRepositoryMock.Object);
            unitOfWorkMock.Setup(uow => uow.Orders).Returns(orderRepositoryMock.Object);
            unitOfWorkMock.Setup(uow => uow.Complete()).Returns(1);

            //Act
            var result = customerService.Remove(customer.Id);

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