示例#1
0
        public void AddInvalidOrderShouldThrowRestException()
        {
            using (var context = GetDbContext())
            {
                //arrange
                InitDatabaseTablesForOrderTests(context);

                var command = new AddNewOrder.Command()
                {
                    CartId       = "1234-5678-0000-4444",
                    ProductsList = new List <OrderDetailDTO>()
                    {
                        new OrderDetailDTO()
                        {
                            ProductId = 1, Quantity = 10
                        },
                        new OrderDetailDTO()
                        {
                            ProductId = 2, Quantity = 2
                        },
                    }
                };
                var handler = new AddNewOrder.Handler(context);

                //assert
                Assert.ThrowsExceptionAsync <RestException>(() => handler.Handle(command, (new CancellationTokenSource()).Token));
            }
        }
示例#2
0
        public async Task AddValidOrderShouldPersistedInDatabase()
        {
            using (var context = GetDbContext())
            {
                //arrange
                InitDatabaseTablesForOrderTests(context);

                var command = new AddNewOrder.Command()
                {
                    CartId       = "1234-5678-0000-4444",
                    ProductsList = new List <OrderDetailDTO>()
                    {
                        new OrderDetailDTO()
                        {
                            ProductId = 1, Quantity = 1
                        },
                        new OrderDetailDTO()
                        {
                            ProductId = 2, Quantity = 2
                        },
                    }
                };
                var handler = new AddNewOrder.Handler(context);

                //act
                await handler.Handle(command, (new CancellationTokenSource()).Token);

                //assert
                Assert.IsTrue(context.Orders.Any(o => o.CartId == "1234-5678-0000-4444"));
            }
        }