Example #1
0
        public async Task CreateOrderInDBAsync_NullItems_Exception()
        => await WithDBContextAsync(async (context) =>
        {
            //Arrange
            var service = new OrderService(context);

            //Act
            Func <Task> act = () => service.CreateOrderInDBAsync(null);

            //Assert
            var exception = await Assert.ThrowsAsync <ArgumentException>(act);
            Assert.Equal("Products count should be more than thero.", exception.Message);
        });
Example #2
0
        public async Task CreateOrderInDBAsync_Success()
        => await WithDBContextAsync(async (context) =>
        {
            //Arrange
            var cartItems = new List <CartItem>
            {
                new CartItem
                {
                    ProductId = 1,
                    Count     = 20
                },
                new CartItem
                {
                    ProductId = 2,
                    Count     = 30
                },
                new CartItem
                {
                    ProductId = 3,
                    Count     = 10
                }
            };
            var service = new OrderService(context);

            //Act
            var order = await service.CreateOrderInDBAsync(cartItems);

            //Assert
            foreach (var cartItem in cartItems)
            {
                var expectedComposition = order.Order_Composition.FirstOrDefault(c => c.Product_Id == cartItem.ProductId);
                Assert.NotNull(expectedComposition);
                Assert.Equal(cartItem.Count, expectedComposition.ProductCount);
            }

            Assert.Equal(1, order.Status_Id);
            Assert.Equal(order.Status.Id, order.Status_Id);
            Assert.Equal(OrderStatus.Created.ToString(), order.Status.Name);

            Assert.Equal(2, order.User_Id);
            Assert.Equal(order.User.Id, order.User_Id);

            var expectedOrder = context.Shop_Orders.FirstOrDefault(o => o.Id == order.Id);
            Assert.NotNull(expectedOrder);
            Assert.Equal(expectedOrder, order);
        });