Exemplo n.º 1
0
        public void CallsOnceTimeMethodOfAddOffDbSetWrapperAndOnceTimeSaveChanges()
        {
            // Arrange
            ShoppingBasket shoppingBasket = new ShoppingBasket();

            this.shoppingBasketDtoMock.Setup(x => x.Products).Returns(TestsServices.CreateListWithThreeVouchersAndThreeTshirts);

            var sut = new ShoppingBasketService(this.shoppingBasketDtoMock.Object, this.mapperServiceMock.Object, this.efDbSetWrapper.Object, this.efDbContextSaveChanges.Object);

            // Act
            sut.AddShoppingBasket();

            // Assert
            this.efDbSetWrapper.Verify(x => x.Add(It.IsAny <ShoppingBasket>()), Times.Once);
            this.efDbContextSaveChanges.Verify(x => x.SaveChanges(), Times.Once);
        }
Exemplo n.º 2
0
        public void CallsAllMethodsNecessaryToAddTheNewBasket()
        {
            // Arrange
            IList <ShoppingBasket> baskets        = new List <ShoppingBasket>();
            ShoppingBasket         shoppingBasket = new ShoppingBasket();

            this.efDbSetWrapper.Setup(x => x.Add(It.IsAny <ShoppingBasket>())).Callback(() => this.efDbContext.Object.Set <ShoppingBasket>().Add(shoppingBasket));

            this.efDbContext.Setup(x => x.Set <ShoppingBasket>().Add(shoppingBasket)).Callback(() => baskets.Add(shoppingBasket));

            this.shoppingBasketDtoMock.Setup(x => x.Products).Returns(TestsServices.CreateListWithThreeVouchersAndThreeTshirts);

            var shoppingBasketDtoMock = new Mock <IShoppingBasketDto>();

            var sut = new ShoppingBasketService(this.shoppingBasketDtoMock.Object, this.mapperServiceMock.Object, this.efDbSetWrapper.Object, this.efDbContextSaveChanges.Object);

            // Act
            sut.AddShoppingBasket();

            // Assert
            Assert.IsTrue(baskets.Count > 0);
        }