public async Task <IActionResult> GetProducts(int?maxPrice = null, string size = null, string wordsToHighlight = null) { var products = await _mockyApiService.FetchProducts(); var filteredAndHighlightedProducts = _productsService.FilterAndHighlightProducts(products, maxPrice, size, wordsToHighlight); //not sure from task if products or filteredAndHighlightedProducts are to be passed here... var productAggregateInfo = _productsService.AggregateProducts(products); return(Ok(new { Products = filteredAndHighlightedProducts, AggregatedProducts = productAggregateInfo })); }
// I don't think there's a better way to validate this other than hardcode expected values. // Not ideal because when test data changes test will need to be updated also... public async void TestAggregateProducts() { var products = await _mockMockyApiService.Object.FetchProducts(); var expectedMinPrice = 11; var expectedMaxPrice = 15; var expectedAllSizes = new List <string> { "medium", "large", "small" }; var expectedMostCommonWords = new List <string> { "have", "scarf", "smell", "socks", "soft", "sweater", "These", "warm" }; var aggregatedProducts = _productsService.AggregateProducts(products); Assert.True(aggregatedProducts.MinPrice == expectedMinPrice); Assert.True(aggregatedProducts.MaxPrice == expectedMaxPrice); Assert.True(aggregatedProducts.AllSizes.SequenceEqual(expectedAllSizes)); Assert.True(aggregatedProducts.MostCommonWordsInDescriptions.SequenceEqual(expectedMostCommonWords)); }