public async void GetByProductNameAsync() { var shoppingItem = new Service.Models.ShoppingItem { ShoppingItemId = 1, Product = new Service.Models.Product { Name = "Pepsi", Description = "Classic", Quantity = 2, Price = 1 } }; mockShoppingListRepository = new Mock <IShoppingListRepository>(); mockShoppingListRepository.Setup(p => p.AddAsync(new Infrastructure.Models.ShoppingItem { ShoppingItemId = 1, Product = new Infrastructure.Models.Product { Name = "Pepsi", Description = "Classic", Quantity = 2, Price = 1 } })); mockLogger = new Mock <ILogger <ShoppingListAppService> >(); mockMapper = new Mock <IMapper>(); systemUnderTest = new ShoppingListAppService(mockShoppingListRepository.Object, mockMapper.Object, mockLogger.Object); await systemUnderTest.AddAsync(shoppingItem); mockShoppingListRepository.Setup(p => p.GetByProductNameAsync(shoppingItem.Product.Name)).ReturnsAsync(new Infrastructure.Models.ShoppingItem { ShoppingItemId = 1, Product = new Infrastructure.Models.Product { Name = "Pepsi", Description = "Classic", Quantity = 2, Price = 1 } }); var result = await systemUnderTest.GetByProductNameAsync(shoppingItem.Product.Name); Assert.NotNull(result); Assert.AreEqual(result.Product.Name, shoppingItem.Product.Name); }
public async void AddAsync() { var shoppingItem = new Service.Models.ShoppingItem { ShoppingItemId = 1, Product = new Service.Models.Product { Name = "Pepsi", Description = "Classic", Quantity = 2, Price = 1 } }; mockShoppingListRepository = new Mock <IShoppingListRepository>(); mockShoppingListRepository.Setup(p => p.AddAsync(new Infrastructure.Models.ShoppingItem { ShoppingItemId = 1, Product = new Infrastructure.Models.Product { Name = "Pepsi", Description = "Classic", Quantity = 2, Price = 1 } })); mockLogger = new Mock <ILogger <ShoppingListAppService> >(); mockMapper = new Mock <IMapper>(); systemUnderTest = new ShoppingListAppService(mockShoppingListRepository.Object, mockMapper.Object, mockLogger.Object); await systemUnderTest.AddAsync(shoppingItem); mockShoppingListRepository.VerifyAll(); }