From 52e4626b75d10db65cf30b930e68087f84361cf2 Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 28 Jun 2021 14:17:09 +0200 Subject: [PATCH] Adding library item tests --- Kyoo.Tests/KAssert.cs | 3 +- .../Library/SpecificTests/LibraryItemTest.cs | 60 +++++++++++++++++++ Kyoo.Tests/Library/TestSample.cs | 15 +++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 Kyoo.Tests/Library/SpecificTests/LibraryItemTest.cs diff --git a/Kyoo.Tests/KAssert.cs b/Kyoo.Tests/KAssert.cs index 7ac753dd..fa38160d 100644 --- a/Kyoo.Tests/KAssert.cs +++ b/Kyoo.Tests/KAssert.cs @@ -1,3 +1,4 @@ +using System.Linq; using System.Reflection; using JetBrains.Annotations; using Xunit; @@ -19,7 +20,7 @@ namespace Kyoo.Tests [AssertionMethod] public static void DeepEqual(T expected, T value) { - foreach (PropertyInfo property in typeof(T).GetProperties()) + foreach (PropertyInfo property in typeof(T).GetProperties(BindingFlags.Instance)) Assert.Equal(property.GetValue(expected), property.GetValue(value)); } diff --git a/Kyoo.Tests/Library/SpecificTests/LibraryItemTest.cs b/Kyoo.Tests/Library/SpecificTests/LibraryItemTest.cs new file mode 100644 index 00000000..595ca736 --- /dev/null +++ b/Kyoo.Tests/Library/SpecificTests/LibraryItemTest.cs @@ -0,0 +1,60 @@ +using System.Threading.Tasks; +using Kyoo.Controllers; +using Kyoo.Models; +using Xunit; +using Xunit.Abstractions; + +namespace Kyoo.Tests.Library +{ + namespace SqLite + { + public class LibraryItemTest : ALibraryItemTest + { + public LibraryItemTest(ITestOutputHelper output) + : base(new RepositoryActivator(output)) { } + } + } + + + namespace PostgreSQL + { + [Collection(nameof(Postgresql))] + public class LibraryItemTest : ALibraryItemTest + { + public LibraryItemTest(PostgresFixture postgres, ITestOutputHelper output) + : base(new RepositoryActivator(output, postgres)) { } + } + } + + public abstract class ALibraryItemTest + { + private readonly ILibraryItemRepository _repository; + + public ALibraryItemTest(RepositoryActivator repositories) + { + _repository = repositories.LibraryManager.LibraryItemRepository; + } + + [Fact] + public async Task CountTest() + { + Assert.Equal(2, await _repository.GetCount()); + } + + [Fact] + public async Task GetShowTests() + { + LibraryItem expected = new(TestSample.Get()); + LibraryItem actual = await _repository.Get(1); + KAssert.DeepEqual(expected, actual); + } + + [Fact] + public async Task GetCollectionTests() + { + LibraryItem expected = new(TestSample.Get()); + LibraryItem actual = await _repository.Get(-1); + KAssert.DeepEqual(expected, actual); + } + } +} \ No newline at end of file diff --git a/Kyoo.Tests/Library/TestSample.cs b/Kyoo.Tests/Library/TestSample.cs index 937fac9a..2dea690a 100644 --- a/Kyoo.Tests/Library/TestSample.cs +++ b/Kyoo.Tests/Library/TestSample.cs @@ -17,6 +17,17 @@ namespace Kyoo.Tests private static readonly Dictionary> Samples = new() { + { + typeof(Collection), + () => new Collection + { + ID = 1, + Slug = "collection", + Name = "Collection", + Overview = "A nice collection for tests", + Poster = "Poster" + } + }, { typeof(Show), () => new Show @@ -101,6 +112,10 @@ namespace Kyoo.Tests public static void FillDatabase(DatabaseContext context) { + Collection collection = Get(); + collection.ID = 0; + context.Collections.Add(collection); + Show show = Get(); show.ID = 0; context.Shows.Add(show);