public void GetRate_WhenInventoryBaseRateSameAsSelected_ReturnsBaseRate()
        {
            var rates = GetTestRates();
            var rate  = PriceHelper.GetRate(CurrencyNames.USD, CurrencyNames.USD, rates);

            Assert.True(rate == 1);
        }
        public void GetRate_WhenInventoryBaseRateIsDifferentThanSelected_ReturnsRate()
        {
            var rates        = GetTestRates();
            var rateUsdToEur = PriceHelper.GetRate(CurrencyNames.USD, CurrencyNames.EUR, rates);
            var rateEurToSek = PriceHelper.GetRate(CurrencyNames.EUR, CurrencyNames.SEK, rates);

            Assert.True(rateUsdToEur == (decimal)0.87);
            Assert.True(rateEurToSek == (decimal)10.30);
        }
Example #3
0
        public ConfigViewModel GetAllData(string currency)
        {
            var config = _context.Config
                         .Include(x => x.SelectedCurrency)
                         .Include(x => x.InventoryCurrency).First();
            var currentRateSymbol = config.InventoryCurrency.Symbol;

            if (string.IsNullOrEmpty(currency))
            {
                currency = config.SelectedCurrency.Symbol;
            }

            var rates = _context.ExchangeRate.Select(x => new ExchangeRateModel()
            {
                TargetCurrency = x.TargetCurrency.Symbol,
                BaseCurrency   = x.BaseCurrency.Symbol,
                Rate           = x.Rate
            }).ToList();

            var rate = PriceHelper.GetRate(config.InventoryCurrency.Symbol, currency, rates);

            return(new ConfigViewModel()
            {
                CoinsInSlot = config.CoinsInSlot,
                Language = config.Language,
                InventoryCurrency = currentRateSymbol,
                SelectedCurrency = config.SelectedCurrency.Symbol,
                SupportedCurrencies = _context.Currency.Select(x => x.Symbol).ToList(),

                // TODO fix string ordering
                Inventories = _context.Inventory.OrderBy(x => x.ProductNr).Select(x => new InventoryModel()
                {
                    Quantity = x.Quantity,
                    Name = x.Name,
                    Price = x.Price,
                    ProductNr = x.ProductNr,
                    TargetCurrencyRate = rate
                }).ToList(),
                Rates = rates
            });
        }