Fixing duplicate chapter issue and adding unit test (#1221)

* Fixing duplicate chapter issue and adding unit test

* Update test name
This commit is contained in:
Robbie Davis 2022-04-18 15:57:31 -04:00 committed by GitHub
parent 8a78b8c746
commit 03ab44d50a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 6 deletions

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using API.Entities; using API.Entities;
using API.Entities.Enums; using API.Entities.Enums;
@ -83,9 +83,37 @@ namespace API.Tests.Extensions
Assert.Equal(chapterList[0], actualChapter); Assert.Equal(chapterList[0], actualChapter);
} }
[Fact]
public void GetChapterByRange_On_Duplicate_Files_Test_Should_Not_Error()
{
var info = new ParserInfo()
{
Chapters = "0",
Edition = "",
Format = MangaFormat.Archive,
FullFilePath = "/manga/detective comics #001.cbz",
Filename = "detective comics #001.cbz",
IsSpecial = true,
Series = "detective comics",
Title = "detective comics",
Volumes = "0"
};
var chapterList = new List<Chapter>()
{
CreateChapter("detective comics", "0", CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true),
CreateChapter("detective comics", "0", CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true)
};
var actualChapter = chapterList.GetChapterByRange(info);
Assert.Equal(chapterList[0], actualChapter);
}
#region GetFirstChapterWithFiles #region GetFirstChapterWithFiles
[Fact] [Fact]
public void GetFirstChapterWithFiles_ShouldReturnAllChapters() public void GetFirstChapterWithFiles_ShouldReturnAllChapters()
{ {
var chapterList = new List<Chapter>() var chapterList = new List<Chapter>()

View File

@ -1,4 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using API.Entities; using API.Entities;
using API.Parser; using API.Parser;
@ -28,8 +28,8 @@ namespace API.Extensions
{ {
var specialTreatment = info.IsSpecialInfo(); var specialTreatment = info.IsSpecialInfo();
return specialTreatment return specialTreatment
? chapters.SingleOrDefault(c => c.Range == info.Filename || (c.Files.Select(f => f.FilePath).Contains(info.FullFilePath))) ? chapters.FirstOrDefault(c => c.Range == info.Filename || (c.Files.Select(f => f.FilePath).Contains(info.FullFilePath)))
: chapters.SingleOrDefault(c => c.Range == info.Chapters); : chapters.FirstOrDefault(c => c.Range == info.Chapters);
} }
} }
} }