Exemplo n.º 1
0
        public void Given_CurrenciesAndDate_When_GetInvoked_Then_resultWithExchangeRateRetrived()
        {
            string currencyFrom = "USD", currencyTo = "EUR";
            var    date = DateTime.Today;

            var result = _serviceUnderTest.Get(currencyFrom, currencyTo, date);

            Assert.IsNotNull(result);
            Assert.AreEqual(currencyFrom, result.From);
            Assert.AreEqual(currencyTo, result.To);
            Assert.AreNotEqual(result.Rate, 0);
            Assert.AreEqual(date, result.Date);
        }
Exemplo n.º 2
0
        private async Task GetRate_Click(object sender, EventArgs e)
        {
            GetRateButton.Text    = "Loading";
            GetRateButton.Enabled = false;

            try
            {
                Either <string, IEnumerable <ExchangeRateModel> > result;
                if (dateTimePicker1.Value.Date >= DateTime.Now.Date)
                {
                    result = await _exchangeRateService.Get();
                }
                else
                {
                    result = await _exchangeRateService.Get(dateTimePicker1.Value.Date);
                }

                result.Match(r =>
                {
                    _exchangeRates = r.ToList();
                }, l =>
                {
                    MessageBox.Show(l, "Info", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                });
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                GetRateButton.Enabled = true;
                GetRateButton.Text    = "Get rate";
            }

            UpdateList();

            var currencies = _exchangeRates.GroupBy(r => r.CurrencyName)
                             .Select(g => g.Key)
                             .OrderBy(c => c)
                             .ToList();

            currencies.Insert(0, "ALL");

            currencyComboBox.DataSource = currencies;
        }
Exemplo n.º 3
0
        public IActionResult GetExchangeRate(string currencyFrom, string currencyTo, string date)
        {
            var actionResponse = GetEmptyResponseBuilder <ExchangeRate>();

            try
            {
                var parsedDate = ParseDate(date);

                actionResponse.SetData(_exchangeRateService.Get(currencyFrom, currencyTo, parsedDate));

                return(Ok(actionResponse));
            }
            catch (Exception ex)
            {
                return(Ko(actionResponse, ex));
            }
        }
Exemplo n.º 4
0
 public IActionResult Get(string date)
 {
     return(exchangeRateService.Get(date));
 }
 [HttpGet("get")] public IActionResult Get() => Json(_exchangeRateService.Get());