Skip to content

Commit

Permalink
Fix #7 added more assert in unit tests.
Browse files Browse the repository at this point in the history
Fix a bug in MangaShare for missing first image of every chapter.
  • Loading branch information
NguyenDanPhuong committed Aug 6, 2016
1 parent 2524525 commit 3160d2b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
2 changes: 1 addition & 1 deletion MangaRipper.Core/MangaShareService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<IList<string>> FindImanges(Chapter chapter, IProgress<int> pro
string regExPages = @"<select name=""pagejump"" class=""page"" onchange=""javascript:window.location='(?<Value>[^']+)'\+this\.value\+'\.html';"">";
var pageBase = parser.Parse(regExPages, input, "Value").FirstOrDefault();

var pagesExtend = parser.Parse(@"<option value=""(?<FileName>\d+)"">Page \d+</option>", input, "FileName");
var pagesExtend = parser.Parse(@"<option value=""(?<FileName>\d+)""(| selected=""selected"")>Page \d+</option>", input, "FileName");

// transform pages link
pagesExtend = pagesExtend.Select(p =>
Expand Down
42 changes: 29 additions & 13 deletions MangaRipper.Test/UnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,18 @@ public async Task MangaReader_Test()
var chapters = await service.FindChapters(url, new Progress<int>(), source.Token);
Assert.IsTrue(chapters.Count > 0, "Cannot find chapters.");
// Test chapters are in correct order.
var lastChapter = chapters.Last();
Assert.AreEqual("Naruto 1", lastChapter.Name);
var chapter = chapters.Last();
Assert.AreEqual("Naruto 1", chapter.Name);
Assert.AreEqual("http://www.mangareader.net/naruto/1", chapter.Link);
// Test there're no duplicated chapters.
var anyDuplicated = chapters.GroupBy(x => x.Link).Any(g => g.Count() > 1);
Assert.IsFalse(anyDuplicated, "There're duplicated chapters.");
// Test service can find images.
var firstChapter = chapters.First();
var images = await service.FindImanges(firstChapter, new Progress<int>(), source.Token);
Assert.IsTrue(images.Count > 0, "Cannot find images.");

var images = await service.FindImanges(chapter, new Progress<int>(), source.Token);
Assert.AreEqual(53, images.Count);
Assert.AreEqual("http://i10.mangareader.net/naruto/1/naruto-1564773.jpg", images[0]);
Assert.AreEqual("http://i4.mangareader.net/naruto/1/naruto-1564774.jpg", images[1]);
Assert.AreEqual("http://i1.mangareader.net/naruto/1/naruto-1564825.jpg", images[52]);
}

[TestMethod]
Expand All @@ -51,9 +53,14 @@ public async Task MangaFox_Test()
var service = Framework.GetService(url);
var chapters = await service.FindChapters(url, new Progress<int>(), source.Token);
Assert.IsTrue(chapters.Count > 0, "Cannot find chapters.");
var chapter = chapters[0];
var chapter = chapters.Last();
Assert.AreEqual("Tian Jiang Xian Shu Nan 1", chapter.Name);
Assert.AreEqual("http://mangafox.me/manga/tian_jiang_xian_shu_nan/c001/1.html", chapter.Link);
var images = await service.FindImanges(chapter, new Progress<int>(), source.Token);
Assert.IsTrue(images.Count > 0, "Cannot find images.");
Assert.AreEqual(15, images.Count);
Assert.AreEqual("http://h.mfcdn.net/store/manga/19803/001.0/compressed/q001.jpg", images[0]);
Assert.AreEqual("http://h.mfcdn.net/store/manga/19803/001.0/compressed/q002.jpg", images[1]);
Assert.AreEqual("http://h.mfcdn.net/store/manga/19803/001.0/compressed/q015.jpg", images[14]);
}

[TestMethod]
Expand All @@ -63,10 +70,14 @@ public async Task MangaHere_Test()
var service = Framework.GetService(url);
var chapters = await service.FindChapters(url, new Progress<int>(), source.Token);
Assert.IsTrue(chapters.Count > 0, "Cannot find chapters.");
var chapter = chapters.First();
Assert.IsTrue(chapter.Name.Length > 0, "Chapter's name is empty string.");
var chapter = chapters.Last();
Assert.AreEqual("The God Of High School 1", chapter.Name);
Assert.AreEqual("http://www.mangahere.co/manga/the_god_of_high_school/c001/", chapter.Link);
var images = await service.FindImanges(chapter, new Progress<int>(), source.Token);
Assert.IsTrue(images.Count > 0, "Cannot find images.");
Assert.AreEqual(55, images.Count);
Assert.AreEqual("http://h.mhcdn.net/store/manga/9275/001.0/compressed/m001.01.jpg", images[0]);
Assert.AreEqual("http://h.mhcdn.net/store/manga/9275/001.0/compressed/m001.02.jpg", images[1]);
Assert.AreEqual("http://h.mhcdn.net/store/manga/9275/001.0/compressed/m001.55.jpg", images[54]);
}

[TestMethod]
Expand All @@ -76,9 +87,14 @@ public async Task MangaShare_Test()
var service = Framework.GetService(url);
var chapters = await service.FindChapters(url, new Progress<int>(), source.Token);
Assert.IsTrue(chapters.Count > 0, "Cannot find chapters.");
var chapter = chapters[0];
var chapter = chapters.Last();
Assert.AreEqual("Beelzebub 1", chapter.Name);
Assert.AreEqual("http://read.mangashare.com/Beelzebub/chapter-001/page001.html", chapter.Link);
var images = await service.FindImanges(chapter, new Progress<int>(), source.Token);
Assert.IsTrue(images.Count > 0, "Cannot find images.");
Assert.AreEqual(58, images.Count);
Assert.AreEqual("http://dl01.mangashare.com/manga/Beelzebub/001/001.jpg", images[0]);
Assert.AreEqual("http://dl01.mangashare.com/manga/Beelzebub/001/002.jpg", images[1]);
Assert.AreEqual("http://dl01.mangashare.com/manga/Beelzebub/001/058.jpg", images[57]);
}
}
}

0 comments on commit 3160d2b

Please sign in to comment.