From df1e8a23607944d310b219161fcce4fb1505b160 Mon Sep 17 00:00:00 2001 From: Brian Bicknell Date: Tue, 27 May 2025 00:30:28 -0400 Subject: [PATCH] Added tests for search coordination. --- .../Search/MangaSearchCoordinatorTests.cs | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 MangaReader.Tests/Search/MangaSearchCoordinatorTests.cs diff --git a/MangaReader.Tests/Search/MangaSearchCoordinatorTests.cs b/MangaReader.Tests/Search/MangaSearchCoordinatorTests.cs new file mode 100644 index 0000000..febc3b2 --- /dev/null +++ b/MangaReader.Tests/Search/MangaSearchCoordinatorTests.cs @@ -0,0 +1,84 @@ +using MangaReader.Core.Search; +using NSubstitute; +using Shouldly; + +namespace MangaReader.Tests.Search; + +public class MangaSearchCoordinatorTests +{ + [Fact] + public async Task Search_Manga_From_All_Sources() + { + IMangaSearchProvider searchProvider1 = Substitute.For(); + searchProvider1.SourceId.Returns("Manga Source 1"); + searchProvider1.SearchAsync(Arg.Any(), CancellationToken.None) + .Returns( + [ + new() + { + Title = "Test Manga 1", + Url = "https://mangasource1.com/manga/1", + Thumbnail = "https://mangasource1.com/manga/cover/1.png" + }, + new() + { + Title = "Test Manga 2", + Url = "https://mangasource2.com/manga/2", + Thumbnail = "https://mangasource2.com/manga/cover/2.png" + } + ]); + + IMangaSearchProvider searchProvider2 = Substitute.For(); + searchProvider2.SourceId.Returns("Manga Source 2"); + searchProvider2.SearchAsync(Arg.Any(), CancellationToken.None) + .Returns( + [ + new() + { + Title = "Test Manga 3", + Url = "https://mangasource3.com/manga/3", + Thumbnail = "https://mangasource3.com/manga/cover/3.png" + }, + ]); + + IMangaSearchProvider searchProvider3 = Substitute.For(); + searchProvider3.SourceId.Returns("Manga Source 3"); + searchProvider3.SearchAsync(Arg.Any(), CancellationToken.None) + .Returns([]); + + MangaSearchCoordinator searchCoordinator = new([searchProvider1, searchProvider2, searchProvider3]); + + Dictionary results = await searchCoordinator.SearchAsync("Test", CancellationToken.None); + results.Count.ShouldBe(3); + + results.Keys.ToArray().ShouldBe(["Manga Source 1", "Manga Source 2", "Manga Source 3"]); + + results["Manga Source 1"].ShouldBe( + [ + new() + { + Title = "Test Manga 1", + Url = "https://mangasource1.com/manga/1", + Thumbnail = "https://mangasource1.com/manga/cover/1.png" + }, + new() + { + Title = "Test Manga 2", + Url = "https://mangasource2.com/manga/2", + Thumbnail = "https://mangasource2.com/manga/cover/2.png" + } + ]); + + results["Manga Source 2"].ShouldBe( + [ + new() + { + Title = "Test Manga 3", + Url = "https://mangasource3.com/manga/3", + Thumbnail = "https://mangasource3.com/manga/cover/3.png" + } + ]); + + results["Manga Source 3"].ShouldBe([]); + } +} \ No newline at end of file