public async Task GetSortedProductsQuery_SortByRecommended() { //arrange var sampleProducts = GetSampleProducts(); _mockProductsService.Setup(i => i.GetProducts()).ReturnsAsync(sampleProducts); var sampleHistory = GetSampleHistory(); _mockProductsService.Setup(i => i.GetShopperHistory()).ReturnsAsync(sampleHistory); var service = _mockProductsService.Object; var engine = new RecommendationEngine(service); var handler = new GetSortedProductsQueryHandler(service, engine); var query = new GetSortedProductsQuery(SortOrder.Recommended); //act var results = await handler.Handle(query, default(CancellationToken)); //assert _mockProductsService.Verify(i => i.GetProducts(), Times.Once, "Get Products Method should be invoked in produts service"); _mockProductsService.Verify(i => i.GetShopperHistory(), Times.Once, "Get history method should be invoked in products service"); //Assert that first item name is "Product 3" with most quantity Assert.AreEqual(results.First().Name, "Product 3", "Product with name Product 3 should be the first product"); Assert.AreEqual(results.Last().Name, "Product 1", "Product with name Product 1 should be the last product"); }
public async Task GetSortedProductsQuery_SortByLow() { //arrange var sampleProducts = GetSampleProducts(); _mockProductsService.Setup(i => i.GetProducts()).ReturnsAsync(sampleProducts); var service = _mockProductsService.Object; var engine = _mockEngine.Object; var handler = new GetSortedProductsQueryHandler(service, engine); var query = new GetSortedProductsQuery(SortOrder.Low); //act var results = await handler.Handle(query, default(CancellationToken)); //assert _mockProductsService.Verify(i => i.GetProducts(), Times.Once, "Get Products Method should be invoked in produts service"); //Assert that first item name is "Product 1" with Lowes price Assert.AreEqual(results.First().Name, "Product 1", "Product with name Product 1 should be the first product"); }