示例#1
0
        public void GetQuote_bycurrency_valid()
        {
            // MOCK

            var quotes = new List <Quote> {
                new Quote {
                    Currency = "usd"
                },
                new Quote {
                    Currency = "can"
                },
                new Quote {
                    Currency = "usd"
                }
            };

            _quoteRepository.GetQuotes().Returns(quotes);

            // Execute

            var filter = new QuotesFilter();

            filter.AddFilterByCurrency("usd");

            var result = _sut.GetQuotes().ToList();

            result = _sut.FilterQuotes(result, filter).ToList();

            // Assert

            Assert.AreEqual(2, result.Count);
            Assert.AreEqual(0, result.Count(x => x.Currency == "can"));
            Assert.IsTrue(result.Count == 2);
        }
        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));
        }
示例#3
0
        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"));
        }