/// <summary> /// Generic method for getting the data features of your choosing as an asynchronous operation. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="location"></param> /// <param name="dataFeatures"></param> /// <returns></returns> public async Task <T> GetDataAsync <T>(PwsGeographicLocation location, WunDataFeatures dataFeatures) where T : IWunData { UriProvider uriProvider = new UriProvider(); string pwsIdentifier = GetPwsIdentifier(location); Uri pwsUri = uriProvider.CreateWunUri(dataFeatures, pwsIdentifier); JsonProvider jsonProvider = new JsonProvider(); string jsonData = await jsonProvider.DownloadJsonStringAsync(pwsUri); return(await Task.Factory.StartNew(() => JsonConvert.DeserializeObject <T>(jsonData))); }
/// <summary> /// Generic method for getting the data features of your choosing as a synchronous operation. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="location"></param> /// <param name="dataFeatures"></param> /// <returns></returns> public T GetData <T>(PwsGeographicLocation location, WunDataFeatures dataFeatures) where T : IWunData { UriProvider uriProvider = new UriProvider(); string pwsIdentifier = GetPwsIdentifier(location); Uri pwsUri = uriProvider.CreateWunUri(dataFeatures, pwsIdentifier); JsonProvider jsonProvider = new JsonProvider(); string jsonData = jsonProvider.DownloadJsonString(pwsUri); return(JsonConvert.DeserializeObject <T>(jsonData)); }
public void GivenValidUri_WhenCallingDownloadJsonString_ThenStringFileReturned() { // Arrange bool actualResultValue = false; UriProvider uriProvider = new UriProvider(); Uri testUri = uriProvider.CreateWunUri(WunDataFeatures.astronomy, "INORTHLA43"); JsonProvider jsonProvider = new JsonProvider(); //Act string jsonData = jsonProvider.DownloadJsonString(testUri); if (string.IsNullOrEmpty(jsonData) == true) { actualResultValue = false; } else { actualResultValue = true; } //Assert Assert.IsTrue(actualResultValue); }