Example #1
0
        public static void Main(string[] args)
        {
            InitializeFake();

            var command = new CreateOrderCommand
            {
                CustomerId = Guid.Parse("418be026-b301-4696-b062-08d70cfeca04"),
                DF         = 4,
                Discount   = 10,
                Items      = new List <CreateOrderItemCommand>
                {
                    new CreateOrderItemCommand
                    {
                        ProductId = Guid.Parse("608f1b52-07ed-42ec-a1a3-55c4e73a8755"),
                        Quantity  = 6
                    },
                    new CreateOrderItemCommand
                    {
                        ProductId = Guid.Parse("36d8130d-608f-45ff-a177-8137ca8bc7b6"),
                        Quantity  = 2
                    }
                }
            };

            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);
            var result     = (CreateOrderCommandResult)appService.Handle(command);

            Render(result);
        }
        public void PurchaseOnBirthday_SubTotalOver50_Discount10()
        {
            var command    = GetCommand(customerId: "1a59d5bf-9233-44dc-9816-3cc93372da61");
            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);
            var result     = (CreateOrderCommandResult)appService.Handle(command);

            Assert.Equal(10, result.Discount);
        }
        public void LastPurchase40DaysAgo_Discount5Percent_Total137()
        {
            var command    = GetCommand(customerId: "25eef3d0-53c6-47e0-9c2b-76d67bbd0151");
            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);
            var result     = (CreateOrderCommandResult)appService.Handle(command);

            Assert.Equal(137, result.Total);
        }
        public void FirstPurchase_Discount10Percent_Total126()
        {
            var command    = GetCommand();
            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);
            var result     = (CreateOrderCommandResult)appService.Handle(command);

            Assert.Equal(130, result.Total);
        }
        public void Handle_CreateOrderCommandNullProduct_ThrowsArgumentException()
        {
            var command = GetCommand();

            command.Items.ToList().First().ProductId = Guid.Parse("1b63e81b-3cb0-46ca-ab45-80661321817f");

            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);
            var ex         = Assert.Throws <ArgumentException>(() => appService.Handle(command));

            Assert.Equal("Product not found. (Parameter 'product')", ex.Message);
        }
        public void Handle_CreateOrderCommandNullCustumer_ThrowsArgumentException()
        {
            var command = GetCommand();

            command.CustomerId = Guid.Parse("20e24fb3-8bcd-4f48-b457-a64562b58d74");

            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);
            var ex         = Assert.Throws <ArgumentException>(() => appService.Handle(command));

            Assert.Equal("Product not found. (Parameter 'customer')", ex.Message);
        }
        public void Handle_CreateOrderCommandQuantityInvalid_ThrowsArgumentException(int quantity)
        {
            var command = GetCommand();

            command.Items.ToList().First().Quantity = quantity;

            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);

            var ex = Assert.Throws <ArgumentException>(() => appService.Handle(command));

            Assert.Equal("Quantity should be positive. (Parameter 'Quantity')", ex.Message);
        }
        public void Handle_CreateOrderCommandDeliveryFeeInvalid_ThrowsArgumentException(decimal deliveryFee)
        {
            var command = GetCommand();

            command.DF = deliveryFee;

            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);

            var ex = Assert.Throws <ArgumentException>(() => appService.Handle(command));

            Assert.Equal("DF should be applied. (Parameter 'DF')", ex.Message);
        }
        public void Handle_CreateOrderCommandDiscountInvalid_ThrowsArgumentException(decimal discount)
        {
            var command = GetCommand();

            command.Discount = discount;

            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);

            var ex = Assert.Throws <ArgumentException>(() => appService.Handle(command));

            Assert.Equal("Discount should be positive. (Parameter 'Discount')", ex.Message);
        }
        public void Handle_CreateOrderCommandValid_OrderCreated()
        {
            var command = GetCommand(discount: 25);

            var appService = new OrderApplicationService(_customerRepository, _productRepository, _orderRepository);
            var result     = (CreateOrderCommandResult)appService.Handle(command);

            Assert.Equal(DateTime.Today, result.CreatedDateTime, TimeSpan.FromDays(1));
            Assert.Equal(140m, result.SubTotal);
            Assert.Equal(4m, result.DeliveryFee);
            Assert.Equal(25m, result.Discount);
            Assert.Equal(119m, result.Total);
        }