Exemplo n.º 1
0
        public void ReturnFalseWhenAvailableCountIsLessThanZero()
        {
            //Arrange
            var mockedOrderDataProvider = new Mock <IEfComicShopDataProvider <Order> >();
            var mockedComicDataProvider = new Mock <IEfComicShopDataProvider <Comic> >();
            var mockedOrderToCreate     = new Order();
            var mockedComic             = new Comic()
            {
                Id = 2, Price = 5m, AvailableCount = -1
            };

            mockedComicDataProvider.Setup(x => x.GetById(2)).Returns(mockedComic);

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

            var result =
                actualOrderService.CreateOrder("Ak47", new List <Comic>()
            {
                mockedComic
            });

            //Assert
            Assert.AreEqual(false, result);
        }
Exemplo n.º 2
0
        public void CallOrderDataProviderAddAndSaveChangesMethod()
        {
            //Arrange
            var mockedOrderDataProvider = new Mock <IEfComicShopDataProvider <Order> >();
            var mockedComicDataProvider = new Mock <IEfComicShopDataProvider <Comic> >();
            var mockedOrderToCreate     = new Order();
            var mockedComic             = new Comic()
            {
                Id = 2, Price = 5m, AvailableCount = 1
            };

            mockedComicDataProvider.Setup(x => x.GetById(2)).Returns(mockedComic);

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

            actualOrderService.CreateOrder("Ak47", new List <Comic>()
            {
                mockedComic
            });

            //Assert
            mockedOrderDataProvider.Verify(x => x.Add(It.IsAny <Order>()), Times.Once);
            mockedOrderDataProvider.Verify(x => x.SaveChanges(), Times.Once);
        }