From 03ab44d50a6ea2c8ed03e6e1ef12bf3439ecf85c Mon Sep 17 00:00:00 2001 From: Robbie Davis Date: Mon, 18 Apr 2022 15:57:31 -0400 Subject: [PATCH] Fixing duplicate chapter issue and adding unit test (#1221) * Fixing duplicate chapter issue and adding unit test * Update test name --- .../Extensions/ChapterListExtensionsTests.cs | 32 +++++++++++++++++-- API/Extensions/ChapterListExtensions.cs | 8 ++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/API.Tests/Extensions/ChapterListExtensionsTests.cs b/API.Tests/Extensions/ChapterListExtensionsTests.cs index 845b1387b..a1beddf09 100644 --- a/API.Tests/Extensions/ChapterListExtensionsTests.cs +++ b/API.Tests/Extensions/ChapterListExtensionsTests.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using API.Entities; using API.Entities.Enums; @@ -83,9 +83,37 @@ namespace API.Tests.Extensions 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() + { + 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 - [Fact] + [Fact] public void GetFirstChapterWithFiles_ShouldReturnAllChapters() { var chapterList = new List() diff --git a/API/Extensions/ChapterListExtensions.cs b/API/Extensions/ChapterListExtensions.cs index 6362c0571..a5d80bb92 100644 --- a/API/Extensions/ChapterListExtensions.cs +++ b/API/Extensions/ChapterListExtensions.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using API.Entities; using API.Parser; @@ -28,8 +28,8 @@ namespace API.Extensions { var specialTreatment = info.IsSpecialInfo(); return specialTreatment - ? chapters.SingleOrDefault(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.Filename || (c.Files.Select(f => f.FilePath).Contains(info.FullFilePath))) + : chapters.FirstOrDefault(c => c.Range == info.Chapters); } } -} \ No newline at end of file +}