public void GetQuote_byDailyChange_valid() { // MOCK var quotes = new List <Quote> { new Quote { DailyChange = 3.12m }, new Quote { DailyChange = 0.15m }, new Quote { DailyChange = -0.09m } }; _quoteRepository.GetQuotes().Returns(quotes); // Execute var filter = new QuotesFilter(); filter.AddFilterByDailyChange(1.0m); var result = _sut.GetQuotes().ToList(); result = _sut.FilterQuotes(result, filter).ToList(); // Assert Assert.AreEqual(1, result.Count); Assert.AreEqual(1, result.Count(x => x.DailyChange == 3.12m)); }
public JsonResult Get( [FromQuery(Name = "marketcap")] decimal?marketcap, [FromQuery(Name = "dailchange")] decimal?dailchange, [FromQuery(Name = "currency")] string currency ) { var filter = new QuotesFilter(); // Load quote in memory or in file if not cached if (!_cache.TryGetValue(CACHED_QOTES, out IEnumerable <Quote> quotes)) { quotes = _quoteService.GetQuotes(); _cache.Set("CACHED_QOTES", quotes); } if (marketcap != null) { filter.AddFilterByMarketCap((decimal)marketcap); } if (dailchange != null) { filter.AddFilterByDailyChange((decimal)dailchange); } if (currency != null) { filter.AddFilterByCurrency(currency.ToUpper()); } quotes = _quoteService.FilterQuotes(quotes, filter); return(new JsonResult(quotes, _jsonSettings)); }
public void GetQuote_byAllFilter_valid() { // MOCK var quotes = new List <Quote> { new Quote { Symbol = "AAPL", DailyChange = 1.35m, MarketCap = 744.944m, Currency = "usd" }, new Quote { Symbol = "MSFF", DailyChange = 0.35m, MarketCap = 744.944m, Currency = "usd" }, new Quote { Symbol = "RY", DailyChange = 1.35m, MarketCap = 142.3m, Currency = "can" }, new Quote { Symbol = "MSFT", DailyChange = 1.095m, MarketCap = 7.84m, Currency = "usd" } }; _quoteRepository.GetQuotes().Returns(quotes); // Execute var filter = new QuotesFilter(); filter.AddFilterByMarketCap(100.0m); filter.AddFilterByDailyChange(1.0m); filter.AddFilterByCurrency("usd"); var result = _sut.GetQuotes().ToList(); result = _sut.FilterQuotes(result, filter).ToList(); // Assert Assert.AreEqual(1, result.Count); Assert.AreEqual(1, result.Count(x => x.Symbol == "AAPL")); }