Ejemplo n.º 1
0
        public void SubmitOrder([FromBody] OrderModel model)
        {
            //Create new order.
            commandService.SaveOrder(mapper.Map <order.commandservice.Models.Order>(model));

            //Clear the cart for the user.
            commandService.DeleteCartByUserId(model.UserId);
        }
Ejemplo n.º 2
0
        public void SaveOrderTest()
        {
            var userid = "*****@*****.**";
            var orders = new List <Order>().AsQueryable();

            var orderMock = new Mock <DbSet <Order> >();

            orderMock.As <IQueryable <Order> >().Setup(m => m.Provider).Returns(orders.Provider);
            orderMock.As <IQueryable <Order> >().Setup(m => m.Expression).Returns(orders.Expression);
            orderMock.As <IQueryable <Order> >().Setup(m => m.ElementType).Returns(orders.ElementType);
            orderMock.As <IQueryable <Order> >().Setup(m => m.GetEnumerator()).Returns(orders.GetEnumerator());

            dbContext.Setup(x => x.Order).Returns(orderMock.Object);

            command.SaveOrder(new Order {
                UserId = userid, OrderNumber = "TEST123"
            });

            orderMock.Verify(m => m.Add(It.Is <Order>(o => o.OrderNumber == "TEST123")), Times.Once);
            dbContext.Verify(m => m.SaveChanges(), Times.Once);
        }