Exemplo n.º 1
0
        public void CallOrderDataProviderAllMethod()
        {
            //Arrange
            var mockedOrderDataProvider = new Mock <IEfComicShopDataProvider <Order> >();
            var mockedComicDataProvider = new Mock <IEfComicShopDataProvider <Comic> >();
            var mockedOrderToCreate     = new Order();
            var userId = "Ak47";

            mockedOrderDataProvider.Setup(x => x.All()).Returns(new List <Order>().AsQueryable);

            //Act
            var actualOrderService = new ComicShop.Data.Services.OrderService(
                mockedOrderDataProvider.Object,
                mockedComicDataProvider.Object,
                mockedOrderToCreate);

            actualOrderService.GetOrdersByUserId(userId);

            //Assert
            mockedOrderDataProvider.Verify(x => x.All(), Times.Once);
        }
Exemplo n.º 2
0
        public void ReturnOnlyOrderdsWithPassedUserId()
        {
            //Arrange
            var mockedOrderDataProvider = new Mock <IEfComicShopDataProvider <Order> >();
            var mockedComicDataProvider = new Mock <IEfComicShopDataProvider <Comic> >();
            var mockedOrderToCreate     = new Order();
            var userId        = "Ak47";
            var matchingOrder = new Order()
            {
                UserId = userId
            };

            var notMatchingOrder = new Order()
            {
                UserId = "notMatchedId"
            };

            var ordersList = new List <Order>()
            {
                matchingOrder, notMatchingOrder
            };

            // ordersList has 2 orders but only one matches userId
            int expectedCount = 1;

            mockedOrderDataProvider.Setup(x => x.All()).Returns(ordersList.AsQueryable);

            //Act
            var actualOrderService = new ComicShop.Data.Services.OrderService(
                mockedOrderDataProvider.Object,
                mockedComicDataProvider.Object,
                mockedOrderToCreate);

            var resultOrdersList = actualOrderService.GetOrdersByUserId(userId);

            //Assert
            Assert.AreEqual(resultOrdersList.Count(), expectedCount);
            Assert.Contains(matchingOrder, resultOrdersList.ToList());
        }