public async Task Should_IsSuccessTrue_AddNewShoppingCart() { // arrange var userId = Guid.NewGuid(); var productId = Guid.NewGuid(); var count = 5; ShoppingCart shoppingCart = new ShoppingCart { UserId = userId, ProductId = productId, Count = count }; User user = new User { Id = userId, Name = "a", Password = "******" }; Product product = new Product { Id = productId, Count = 10, Name = "asd", Price = 12 }; 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 shoppingCartRepositoriesMock = new Mock <IShoppingCartRepository>(MockBehavior.Loose); shoppingCartRepositoriesMock.Setup(x => x.GetShoppingCartsByUserIdAndProductId(It.IsAny <Guid>(), It.IsAny <Guid>())).ReturnsAsync((ShoppingCart)null); _unitOfWorkMock.Setup(m => m.UserRepository).Returns(userRepositoriesMock.Object); _unitOfWorkMock.Setup(m => m.ProductRepository).Returns(productRepositoriesMock.Object); _unitOfWorkMock.Setup(m => m.ShoppingCartRepository).Returns(shoppingCartRepositoriesMock.Object); IShoppingCartService shoppingCartServce = new ShoppingCartService(_unitOfWorkMock.Object, _logger.Object); // act var actual = await shoppingCartServce.AddShoppingCart(shoppingCart); // assert Assert.True(actual.IsSuccess); }