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 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 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); }
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); }