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);
        }
Ejemplo n.º 2
0
        public void ItShouldIncludeQuantityOnTheOrderSentToFulfilment()
        {
            var customerDetails = new CustomerDetails {
                Email = "*****@*****.**"
            };
            var orderLine = new UnvalidatedOrderLine {
                ProductCode = "W1234", Quantity = 10
            };
            var orderForm = new OrderForm {
                CustomerDetails = customerDetails, OrderLines = new[] { orderLine }
            };

            var widget = new Widget {
                Code = orderLine.ProductCode
            };
            var productCatalogue = A.Fake <IProductCatalogue>();

            A.CallTo(() => productCatalogue.Get(orderLine.ProductCode)).Returns(widget);

            var processedOrderLineFactory = new OrderLineFactory(productCatalogue);

            var   fulfilment    = A.Fake <IFulfilment>();
            Order capturedOrder = null;

            A.CallTo(() => fulfilment.Process(A <Order> ._)).Invokes((Order o) => capturedOrder = o);

            var sut = new Orders(A.Dummy <ICustomers>(), processedOrderLineFactory, fulfilment);

            sut.Process(orderForm);

            var widgetOrderLine = (WidgetOrderLine)capturedOrder.OrderLines[0];

            Assert.Equal(10, widgetOrderLine.Quantity);
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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);
        }
    /// <summary>
    /// Initializes a new instance of the <see cref="AddNewOrderLineProcessingStrategy" /> class.
    /// </summary>
    /// <param name="merchantOrderManager">The order manager.</param>
    /// <param name="orderLineFactory">The order line factory.</param>
    /// <param name="productStockManager">The product stock manager.</param>
    public AddNewOrderLineProcessingStrategy(MerchantOrderManager merchantOrderManager, OrderLineFactory orderLineFactory, IProductStockManager productStockManager)
    {
      Assert.ArgumentNotNull(merchantOrderManager, "merchantOrderManager");
      Assert.ArgumentNotNull(orderLineFactory, "orderLineFactory");
      Assert.ArgumentNotNull(productStockManager, "productStockManager");

      this.merchantOrderManager = merchantOrderManager;
      this.orderLineFactory = orderLineFactory;
      this.productStockManager = productStockManager;
    }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EditOrderLineProcessingStrategy" /> class.
        /// </summary>
        /// <param name="merchantOrderManager">The merchant order manager.</param>
        /// <param name="orderLineFactory">The order line factory.</param>
        /// <param name="productStockManager">The product stock manager.</param>
        public EditOrderLineProcessingStrategy(MerchantOrderManager merchantOrderManager, OrderLineFactory orderLineFactory, IProductStockManager productStockManager)
        {
            Assert.ArgumentNotNull(merchantOrderManager, "merchantOrderManager");
            Assert.ArgumentNotNull(orderLineFactory, "orderLineFactory");
            Assert.ArgumentNotNull(productStockManager, "productStockManager");

            this.merchantOrderManager = merchantOrderManager;
            this.orderLineFactory     = orderLineFactory;
            this.productStockManager  = productStockManager;
        }
        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);
        }
Ejemplo n.º 9
0
        public void ItShouldThrowNotFoundException()
        {
            var customerDetails = new CustomerDetails {
                Email = "*****@*****.**"
            };
            var orderLine = new UnvalidatedOrderLine {
                ProductCode = "W1234", Quantity = 1
            };
            var orderForm = new OrderForm {
                CustomerDetails = customerDetails, OrderLines = new[] { orderLine }
            };

            var productCatalogue = A.Fake <IProductCatalogue>();

            A.CallTo(() => productCatalogue.Get(orderLine.ProductCode))
            .Throws(new NotFoundException("Widget not found: " + orderLine.ProductCode));

            var processedOrderLineFactory = new OrderLineFactory(productCatalogue);

            var sut = new Orders(A.Dummy <ICustomers>(), processedOrderLineFactory, A.Dummy <IFulfilment>());

            Assert.Throws <NotFoundException>(() => sut.Process(orderForm));
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ChangeOrderLineQuantityProcessingStrategy" /> class.
 /// </summary>
 /// <param name="merchantOrderManager">The merchant order manager.</param>
 /// <param name="orderLineFactory">The order line factory.</param>
 /// <param name="productStockManager">The product stock manager.</param>
 public ChangeOrderLineQuantityProcessingStrategy(MerchantOrderManager merchantOrderManager, OrderLineFactory orderLineFactory, IProductStockManager productStockManager)
     : base(merchantOrderManager, orderLineFactory, productStockManager)
 {
 }