Ejemplo n.º 1
0
        public void GetOrderByUserIdTest()
        {
            var userid = "*****@*****.**";

            var orders = new List <Order>()
            {
                new Order {
                    Id = 1, OrderNumber = "TEST123", UserId = userid
                },
                new Order {
                    Id = 2, OrderNumber = "TEST456", UserId = "*****@*****.**"
                },
                new Order {
                    Id = 3, OrderNumber = "TEST789", UserId = userid
                },
            }.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);

            var orderResult = query.GetOrderByUserId(userid);

            Assert.IsNotNull(orderResult);
            Assert.IsTrue(orderResult.Count() == 2);
        }
Ejemplo n.º 2
0
 public IActionResult GetOrdersForUser(string userId)
 {
     return(Ok(mapper.Map <IList <OrderModel> >(queryService.GetOrderByUserId(userId).ToList())));
 }