mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-07 10:14:13 -04:00
Adding library item tests
This commit is contained in:
parent
aad4336f48
commit
52e4626b75
@ -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>(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));
|
||||
}
|
||||
|
||||
|
60
Kyoo.Tests/Library/SpecificTests/LibraryItemTest.cs
Normal file
60
Kyoo.Tests/Library/SpecificTests/LibraryItemTest.cs
Normal file
@ -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<Show>());
|
||||
LibraryItem actual = await _repository.Get(1);
|
||||
KAssert.DeepEqual(expected, actual);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task GetCollectionTests()
|
||||
{
|
||||
LibraryItem expected = new(TestSample.Get<Show>());
|
||||
LibraryItem actual = await _repository.Get(-1);
|
||||
KAssert.DeepEqual(expected, actual);
|
||||
}
|
||||
}
|
||||
}
|
@ -17,6 +17,17 @@ namespace Kyoo.Tests
|
||||
|
||||
private static readonly Dictionary<Type, Func<object>> 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>();
|
||||
collection.ID = 0;
|
||||
context.Collections.Add(collection);
|
||||
|
||||
Show show = Get<Show>();
|
||||
show.ID = 0;
|
||||
context.Shows.Add(show);
|
||||
|
Loading…
x
Reference in New Issue
Block a user