public async Task ShouldSaveImage() { imagePath = Path.Combine(Path.GetTempPath(), imageName); await _content.SaveImgAsync(imageUri, imagePath); FileAssert.Exists(imagePath); }
/// <param name="ChapterStartUrl">URL for First Page of Chapter</param> /// <param name="NextChapterUrl">URL for First Page of Next Chapter</param> /// <param name="FilePath">Path to save Chapter</param> public async Task DownloadFullChapter(Uri ChapterStartUrl, string NextChapterUrl, string FilePath) { Uri NextLinkUrl = ChapterStartUrl; bool LoopAgain = true; bool HasNextChapterUrl = !string.IsNullOrWhiteSpace(NextChapterUrl); int ChapterPageNo = 1; do { //Download Html document string doc = await _download.LoadDocumentAsync(NextLinkUrl).ConfigureAwait(false); //Parse the Html document to get List of Series var result = _parseHtml.GetChapterLinks(doc); //Download Image Uri ImageUrl = new Uri(result.ImageUrl); await _download.SaveImgAsync(ImageUrl, Path.Combine(FilePath, ChapterPageNo.ToString())); if (HasNextChapterUrl) { /*** * If No Next is found OR Next Url is same as Starting Url, * Exit the Loop, Otherwise Assign it to 'NextLinkUrl' variable ***/ if (result.NextUrl.Equals(string.Empty) && result.NextUrl.Equals(NextChapterUrl, StringComparison.OrdinalIgnoreCase)) { LoopAgain = false; } else { NextLinkUrl = new Uri(result.NextUrl); } } } while (LoopAgain); }