Example #1
0
            private static CurrencyHistory CreateTestHistory()
            {
                DateTime d1 = new DateTime(2020, 01, 01);
                DateTime d2 = new DateTime(2020, 01, 02);
                DateTime d3 = new DateTime(2020, 01, 03);
                DateTime d4 = new DateTime(2020, 01, 04);

                CurrencyRate[] r1 =
                {
                    new CurrencyRate("HUF", 1), new CurrencyRate("FOO", 10), new CurrencyRate("BAR", 100)
                };

                CurrencyRate[] r2 =
                {
                    new CurrencyRate("HUF", 2), new CurrencyRate("FOO", 20), new CurrencyRate("BAR", 200)
                };

                CurrencyRate[] r3 =
                {
                    new CurrencyRate("HUF", 3), new CurrencyRate("FOO", 30), new CurrencyRate("BAR", 300)
                };

                CurrencyRate[] r4 =
                {
                    new CurrencyRate("HUF", 4), new CurrencyRate("FOO", 40), new CurrencyRate("BAR", 400)
                };

                CurrencyRatesSnapshot s1 = new CurrencyRatesSnapshot(d1, r1);
                CurrencyRatesSnapshot s2 = new CurrencyRatesSnapshot(d2, r2);
                CurrencyRatesSnapshot s3 = new CurrencyRatesSnapshot(d3, r3);
                CurrencyRatesSnapshot s4 = new CurrencyRatesSnapshot(d4, r4);

                return(CurrencyHistory.CreateFromSnapshots(new[] { s1, s2, s3, s4 }));
            }
Example #2
0
        public async Task <IActionResult> History()
        {
            var rates = await _currencyRateProvider.GetAllRatesAsync();

            CurrencyHistory history = CurrencyHistory.CreateFromSnapshots(rates);

            var result = new
            {
                codes = history.Codes.Select(c => c.Value).ToArray(),
                dates = history.Dates.Select(d => d.ToString("yyyy-MM-dd")).ToArray(),
                data  = history.Select(s => s.ToArray()).ToArray()
            };

            return(Json(result));
        }
Example #3
0
            public void ThrowsOnInconsistentInputCount()
            {
                CurrencyRate[] r1 =
                {
                    new CurrencyRate("HUF", 1)
                };

                CurrencyRate[] r2 =
                {
                    new CurrencyRate("HUF", 10), new CurrencyRate("FOO", 20)
                };

                CurrencyRatesSnapshot s1 = new CurrencyRatesSnapshot(DateTime.Now, r1);
                CurrencyRatesSnapshot s2 = new CurrencyRatesSnapshot(DateTime.Now, r2);

                Assert.ThrowsAny <Exception>(() =>
                {
                    CurrencyHistory.CreateFromSnapshots(new[] { s1, s2 });
                });
            }
Example #4
0
            public void EurIsIgnored()
            {
                CurrencyRate[] r1 =
                {
                    new CurrencyRate("HUF", 1), new CurrencyRate("EUR", 2)
                };

                CurrencyRate[] r2 =
                {
                    new CurrencyRate("HUF", 10), new CurrencyRate("EUR", 20)
                };

                CurrencyRatesSnapshot s1 = new CurrencyRatesSnapshot(DateTime.Now, r1);
                CurrencyRatesSnapshot s2 = new CurrencyRatesSnapshot(DateTime.Now, r2);

                var history = CurrencyHistory.CreateFromSnapshots(new[] { s1, s2 });

                Assert.Equal(1, history.Count);
                Assert.Equal(1, history.Codes.Count);
                Assert.NotNull(history["huf"]);
            }