Ejemplo n.º 1
0
        // FIXME: Disable for now. AsAsyncEnumerable issue.
        //[TestMethod]
        public void Get_Orders()
        {
            // Arrange
            var orderDataService = new OrderDataService(sourceService.Object, mockILoggerFactory.Object.CreateLogger <OrderDataService>());
            var rnd       = new Random();
            var ordersQty = 20;
            var currDate  = DateTime.UtcNow;

            var itms = Enumerable.Range(1, ordersQty).Select(x => new Order()
            {
                OrderId       = rnd.Next(x * 1000),
                OrderStatusId = rnd.Next(x * 1000),
                DateCreated   = currDate.AddDays(x)
            }.To <DbOrder>()).ToList();
            var idForCheck = itms[new Random().Next(ordersQty)].OrderId;

            var firstNum   = rnd.Next(ordersQty - 1);
            var firstDate  = itms[firstNum].DateCreated;
            var secondNum  = rnd.Next(firstNum, ordersQty);
            var secondDate = itms[secondNum].DateCreated;

            var ordersMock = TestHelper.ToDbSetMock(itms);

            sourceService.Setup(x => x.Orders).Returns(ordersMock.Object);
            sourceService.Setup(x => x.Set <DbOrder>()).Returns(ordersMock.Object);

            // Action
            var result = orderDataService.GetOrders().Result;

            // Assert
            ordersMock.Verify(x => x.Where(It.IsAny <Expression <Func <DbOrder, bool> > >()), Times.Exactly(1));
            sourceService.Verify(x => x.Set <DbOrder>(), Times.Exactly(4));

            Assert.AreEqual(ordersQty, result.Count);
        }