public async Task AllFeedsOnline() { var invalids = new List<Tuple<FeedModel, SourceModel>>();; //prepare var sourceModels = await SourceTestHelper.Instance.GetSourceConfigModels(); var service = new HttpService(); //act foreach (var sourceModel in sourceModels) { foreach (var feedModel in sourceModel.Feeds) { var resp = await service.DownloadAsync(feedModel.GetLogicUri()); if (!resp.IsRequestSuccessfull) { invalids.Add(new Tuple<FeedModel, SourceModel>(feedModel, sourceModel)); } else { var str = await resp.GetResponseAsStringAsync(); if (string.IsNullOrEmpty(str)) invalids.Add(new Tuple<FeedModel, SourceModel>(feedModel, sourceModel)); } } } if (invalids.Count > 0) { var response = invalids.Aggregate("", (current, invalid) => current + ("failed in " + invalid.Item2.Abbreviation + " with feed " + invalid.Item1.Name + "\n")); Assert.Fail(response); } }
private static async Task Execute() { var service = new HttpService(); var response = await service.DownloadAsync(new Uri("http://json.bild.de/servlet/json/android/26324062,cnv=true,v=94.json")); var feed = JsonConvert.DeserializeObject<FeedRoot>(await response.GetResponseAsStringAsync()); foreach (var childNode in feed.__childNodes__) { } }
public async Task DownloadOrReadImage() { //arrange var ss = new StorageService(); var service = new HttpService(); //act var imageBytes = await ss.GetAssetFileAsync("Assets/Tests/" + TestFile); var imageResponse = await service.DownloadAsync(new Uri("http://www.spiegel.de/images/image-1028227-hppano-lqbn.jpg")); var imageBytes2 = await imageResponse.GetResponseAsByteArrayAsync(); //assert //expected Assert.IsTrue(imageBytes2.Length == imageBytes.Length); }
public async Task DownloadAndConvertImage() { //arrange var service = new HttpService(); var imageResponse = await service.DownloadAsync(new Uri("http://www.spiegel.de/images/image-1028227-hppano-lqbn.jpg")); var image = await imageResponse.GetResponseAsByteArrayAsync(); var ps = new PlatformCodeService(); //act //resize var byteSmall = await ps.DownloadResizeImage(new Uri("http://www.spiegel.de/images/image-1028227-hppano-lqbn.jpg"), 200, 200); //do not resize var bytesOrigin = await ps.DownloadResizeImage(new Uri("http://www.spiegel.de/images/image-1028227-hppano-lqbn.jpg"), 10000, 10000); //assert Assert.IsTrue(image.Length == bytesOrigin.Length); //expected //Assert.IsTrue(image.Length > byteSmall.Length); //--FAILS-- //real Assert.IsNull(byteSmall); //because of the exception occured in FlushAsync }
public Task<bool> ActualizeAsync() { return ExecuteSafe(async () => { await Initialize(); if (await _permissionsService.CanDownload()) { foreach (var forecast in ForecastManager.GetForecasts()) { Uri url = GetApiUrl(forecast); var service = new HttpService(); var feedresult = await service.DownloadAsync(url); if (feedresult.IsRequestSuccessfull) OpenWeatherMapHelper.EvaluateFeed(await feedresult.GetResponseAsStringAsync(), _weatherFontMapping, forecast); } await SaveForecastsAsync(); } return true; }); }