Пример #1
0
        public async Task AddBasketApiResponseTest_TrueUpdateBasket()
        {
            var userId    = Guid.NewGuid();
            var productId = Guid.NewGuid();
            var count     = 5;

            Basket basket = new Basket {
                Id = Guid.NewGuid(), UserId = userId, ProductId = productId, Count = 1
            };
            User user = new User {
                Id = userId, AccountName = "a", AccountPassword = "******"
            };
            Product product = new Product {
                Id = productId, Count = 10, Name = "asd", Price = 12
            };

            //IEnumerable<Product> productsTest = new List<Product>
            //  {
            //   new Product{Id = Guid.NewGuid(),Count=1,Name ="a",Price=1},
            //   new Product{Id = Guid.NewGuid(),Count=2,Name ="1a",Price=1}
            //  };

            var userRepositoriesMock = new Mock <IUserRepository>(MockBehavior.Loose);

            userRepositoriesMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(user);

            var productRepositoriesMock = new Mock <IProductRepository>(MockBehavior.Loose);

            productRepositoriesMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(product);

            var basketRepositoriesMock = new Mock <IBasketRepository>(MockBehavior.Loose);

            basketRepositoriesMock.Setup(x => x.GetBasketsByUserIdAndProductId(It.IsAny <Guid>(), It.IsAny <Guid>())).ReturnsAsync(basket);

            var unitOfWorkMock = new Mock <IUnitOfWork>();

            unitOfWorkMock.Setup(m => m.UserRepositories).Returns(userRepositoriesMock.Object);
            unitOfWorkMock.Setup(m => m.ProductRepositories).Returns(productRepositoriesMock.Object);
            unitOfWorkMock.Setup(m => m.BasketRepositories).Returns(basketRepositoriesMock.Object);

            IBasketService basketService = new BasketService(unitOfWorkMock.Object);

            var actual = await basketService.AddBasketApiResponseTest(basket);

            Assert.True(actual.IsSuccess);
        }