public void GetRatesTest() { //Arrange string exampleRates = "{ 'NZD':'1', 'AUD':'0.85'}"; string testRate1 = "1"; string testRate2 = "0.85"; //Act Names rates = OpenExchangeRateApi.GetNames(exampleRates); //Assert Assert.AreEqual(rates.NZD, testRate1); Assert.AreEqual(rates.AUD, testRate2); }
public void GetNamesTest() { //Arrange string exampleNames = "{ 'NZD':'New Zealand Dollar', 'AUD':'Australian Dollar'}"; string testName1 = "New Zealand Dollar"; string testName2 = "Australian Dollar"; //Act Names names = OpenExchangeRateApi.GetNames(exampleNames); //Assert Assert.AreEqual(names.NZD, testName1); Assert.AreEqual(names.AUD, testName2); }
//Load Database private async Task LoadData() { if (IsDataLoaded) { return; } //Load previous state var oldState = await _appStateStore.GetAppStateAsync(); ObservableCollection <Currency> currencies = null; try { //Get values from API connection var OERA = new OpenExchangeRateApi(); currencies = await OERA.GetCurrency(); } catch (Exception ex) { Debug.WriteLine("\tData Failed to Load: {0}", ex.Message); } if (currencies != null) { //Save newly constructed currency data to database Currencies = currencies; await SaveCurrencyData(_currencies); Debug.WriteLine("LOADED FROM API"); var timeText = DateTime.Now.ToString("g"); if (oldState != null) { LastUpdate = timeText; oldState.LastUpdated = timeText; } } else { //If API fails to load data from Database Debug.WriteLine("LOADED FROM DATABASE"); Currencies = await _currencyStore.GetCurrenciesAsync(); LastUpdate = oldState.LastUpdated; } if (oldState == null) { Debug.WriteLine("CREATING NEW STATE"); var newState = new AppState { Id = 1, FirstIndex = 32, SecondIndex = 2, LastUpdated = DateTime.Now.ToString("g") }; await _appStateStore.AddAppState(newState); CurrentState = newState; } else { Debug.WriteLine("LOADED FROM PREVIOUS STATE"); CurrentState = oldState; } IsDataLoaded = true; //Hacky way to refresh pickers SwapCurrencies(); SwapCurrencies(); }