mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-08 02:34:16 -04:00
Adding generic tests for every resources
This commit is contained in:
parent
dc42ed031f
commit
123898dc98
@ -77,6 +77,11 @@ namespace Kyoo.Controllers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
IProviderRepository ProviderRepository { get; }
|
IProviderRepository ProviderRepository { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The repository that handle users.
|
||||||
|
/// </summary>
|
||||||
|
IUserRepository UserRepository { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the resource by it's ID
|
/// Get the resource by it's ID
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -37,6 +37,8 @@ namespace Kyoo.Controllers
|
|||||||
public IGenreRepository GenreRepository { get; }
|
public IGenreRepository GenreRepository { get; }
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public IProviderRepository ProviderRepository { get; }
|
public IProviderRepository ProviderRepository { get; }
|
||||||
|
/// <inheritdoc />
|
||||||
|
public IUserRepository UserRepository { get; }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -58,6 +60,7 @@ namespace Kyoo.Controllers
|
|||||||
StudioRepository = GetRepository<Studio>() as IStudioRepository;
|
StudioRepository = GetRepository<Studio>() as IStudioRepository;
|
||||||
GenreRepository = GetRepository<Genre>() as IGenreRepository;
|
GenreRepository = GetRepository<Genre>() as IGenreRepository;
|
||||||
ProviderRepository = GetRepository<Provider>() as IProviderRepository;
|
ProviderRepository = GetRepository<Provider>() as IProviderRepository;
|
||||||
|
UserRepository = GetRepository<User>() as IUserRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
@ -157,6 +157,11 @@ namespace Kyoo
|
|||||||
.WithOne(x => x.Episode)
|
.WithOne(x => x.Episode)
|
||||||
.OnDelete(DeleteBehavior.Cascade);
|
.OnDelete(DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
modelBuilder.Entity<Show>()
|
||||||
|
.HasOne(x => x.Studio)
|
||||||
|
.WithMany(x => x.Shows)
|
||||||
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Provider>()
|
modelBuilder.Entity<Provider>()
|
||||||
.HasMany(x => x.Libraries)
|
.HasMany(x => x.Libraries)
|
||||||
.WithMany(x => x.Providers)
|
.WithMany(x => x.Providers)
|
||||||
|
@ -226,7 +226,7 @@ namespace Kyoo.Postgresql.Migrations
|
|||||||
column: x => x.studio_id,
|
column: x => x.studio_id,
|
||||||
principalTable: "studios",
|
principalTable: "studios",
|
||||||
principalColumn: "id",
|
principalColumn: "id",
|
||||||
onDelete: ReferentialAction.Restrict);
|
onDelete: ReferentialAction.SetNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
|
@ -218,7 +218,7 @@ namespace Kyoo.SqLite.Migrations
|
|||||||
column: x => x.StudioID,
|
column: x => x.StudioID,
|
||||||
principalTable: "Studios",
|
principalTable: "Studios",
|
||||||
principalColumn: "ID",
|
principalColumn: "ID",
|
||||||
onDelete: ReferentialAction.Restrict);
|
onDelete: ReferentialAction.SetNull);
|
||||||
});
|
});
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
|
@ -33,6 +33,7 @@ namespace Kyoo.Tests
|
|||||||
new Lazy<ILibraryRepository>(() => LibraryManager.LibraryRepository));
|
new Lazy<ILibraryRepository>(() => LibraryManager.LibraryRepository));
|
||||||
TrackRepository track = new(_database);
|
TrackRepository track = new(_database);
|
||||||
EpisodeRepository episode = new(_database, provider, track);
|
EpisodeRepository episode = new(_database, provider, track);
|
||||||
|
UserRepository user = new(_database);
|
||||||
|
|
||||||
LibraryManager = new LibraryManager(new IBaseRepository[] {
|
LibraryManager = new LibraryManager(new IBaseRepository[] {
|
||||||
provider,
|
provider,
|
||||||
@ -45,7 +46,8 @@ namespace Kyoo.Tests
|
|||||||
track,
|
track,
|
||||||
people,
|
people,
|
||||||
studio,
|
studio,
|
||||||
genre
|
genre,
|
||||||
|
user
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
37
Kyoo.Tests/Library/SpecificTests/CollectionsTests.cs
Normal file
37
Kyoo.Tests/Library/SpecificTests/CollectionsTests.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace Kyoo.Tests.Library
|
||||||
|
{
|
||||||
|
namespace SqLite
|
||||||
|
{
|
||||||
|
public class CollectionTests : ACollectionTests
|
||||||
|
{
|
||||||
|
public CollectionTests(ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace PostgreSQL
|
||||||
|
{
|
||||||
|
[Collection(nameof(Postgresql))]
|
||||||
|
public class CollectionTests : ACollectionTests
|
||||||
|
{
|
||||||
|
public CollectionTests(PostgresFixture postgres, ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output, postgres)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class ACollectionTests : RepositoryTests<Collection>
|
||||||
|
{
|
||||||
|
private readonly ICollectionRepository _repository;
|
||||||
|
|
||||||
|
protected ACollectionTests(RepositoryActivator repositories)
|
||||||
|
: base(repositories)
|
||||||
|
{
|
||||||
|
_repository = Repositories.LibraryManager.CollectionRepository;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
Kyoo.Tests/Library/SpecificTests/GenreTests.cs
Normal file
37
Kyoo.Tests/Library/SpecificTests/GenreTests.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace Kyoo.Tests.Library
|
||||||
|
{
|
||||||
|
namespace SqLite
|
||||||
|
{
|
||||||
|
public class GenreTests : AGenreTests
|
||||||
|
{
|
||||||
|
public GenreTests(ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace PostgreSQL
|
||||||
|
{
|
||||||
|
[Collection(nameof(Postgresql))]
|
||||||
|
public class GenreTests : AGenreTests
|
||||||
|
{
|
||||||
|
public GenreTests(PostgresFixture postgres, ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output, postgres)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class AGenreTests : RepositoryTests<Genre>
|
||||||
|
{
|
||||||
|
private readonly IGenreRepository _repository;
|
||||||
|
|
||||||
|
protected AGenreTests(RepositoryActivator repositories)
|
||||||
|
: base(repositories)
|
||||||
|
{
|
||||||
|
_repository = Repositories.LibraryManager.GenreRepository;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
Kyoo.Tests/Library/SpecificTests/LibraryTests.cs
Normal file
36
Kyoo.Tests/Library/SpecificTests/LibraryTests.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
using Kyoo.Controllers;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace Kyoo.Tests.Library
|
||||||
|
{
|
||||||
|
namespace SqLite
|
||||||
|
{
|
||||||
|
public class LibraryTests : ALibraryTests
|
||||||
|
{
|
||||||
|
public LibraryTests(ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace PostgreSQL
|
||||||
|
{
|
||||||
|
[Collection(nameof(Postgresql))]
|
||||||
|
public class LibraryTests : ALibraryTests
|
||||||
|
{
|
||||||
|
public LibraryTests(PostgresFixture postgres, ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output, postgres)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class ALibraryTests : RepositoryTests<Models.Library>
|
||||||
|
{
|
||||||
|
private readonly ILibraryRepository _repository;
|
||||||
|
|
||||||
|
protected ALibraryTests(RepositoryActivator repositories)
|
||||||
|
: base(repositories)
|
||||||
|
{
|
||||||
|
_repository = Repositories.LibraryManager.LibraryRepository;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
Kyoo.Tests/Library/SpecificTests/PeopleTests.cs
Normal file
37
Kyoo.Tests/Library/SpecificTests/PeopleTests.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace Kyoo.Tests.Library
|
||||||
|
{
|
||||||
|
namespace SqLite
|
||||||
|
{
|
||||||
|
public class PeopleTests : APeopleTests
|
||||||
|
{
|
||||||
|
public PeopleTests(ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace PostgreSQL
|
||||||
|
{
|
||||||
|
[Collection(nameof(Postgresql))]
|
||||||
|
public class PeopleTests : APeopleTests
|
||||||
|
{
|
||||||
|
public PeopleTests(PostgresFixture postgres, ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output, postgres)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class APeopleTests : RepositoryTests<People>
|
||||||
|
{
|
||||||
|
private readonly IPeopleRepository _repository;
|
||||||
|
|
||||||
|
protected APeopleTests(RepositoryActivator repositories)
|
||||||
|
: base(repositories)
|
||||||
|
{
|
||||||
|
_repository = Repositories.LibraryManager.PeopleRepository;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
Kyoo.Tests/Library/SpecificTests/ProviderTests.cs
Normal file
37
Kyoo.Tests/Library/SpecificTests/ProviderTests.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace Kyoo.Tests.Library
|
||||||
|
{
|
||||||
|
namespace SqLite
|
||||||
|
{
|
||||||
|
public class ProviderTests : AProviderTests
|
||||||
|
{
|
||||||
|
public ProviderTests(ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace PostgreSQL
|
||||||
|
{
|
||||||
|
[Collection(nameof(Postgresql))]
|
||||||
|
public class ProviderTests : AProviderTests
|
||||||
|
{
|
||||||
|
public ProviderTests(PostgresFixture postgres, ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output, postgres)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class AProviderTests : RepositoryTests<Provider>
|
||||||
|
{
|
||||||
|
private readonly IProviderRepository _repository;
|
||||||
|
|
||||||
|
protected AProviderTests(RepositoryActivator repositories)
|
||||||
|
: base(repositories)
|
||||||
|
{
|
||||||
|
_repository = Repositories.LibraryManager.ProviderRepository;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
Kyoo.Tests/Library/SpecificTests/StudioTests.cs
Normal file
37
Kyoo.Tests/Library/SpecificTests/StudioTests.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace Kyoo.Tests.Library
|
||||||
|
{
|
||||||
|
namespace SqLite
|
||||||
|
{
|
||||||
|
public class StudioTests : AStudioTests
|
||||||
|
{
|
||||||
|
public StudioTests(ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace PostgreSQL
|
||||||
|
{
|
||||||
|
[Collection(nameof(Postgresql))]
|
||||||
|
public class StudioTests : AStudioTests
|
||||||
|
{
|
||||||
|
public StudioTests(PostgresFixture postgres, ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output, postgres)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class AStudioTests : RepositoryTests<Studio>
|
||||||
|
{
|
||||||
|
private readonly IStudioRepository _repository;
|
||||||
|
|
||||||
|
protected AStudioTests(RepositoryActivator repositories)
|
||||||
|
: base(repositories)
|
||||||
|
{
|
||||||
|
_repository = Repositories.LibraryManager.StudioRepository;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
37
Kyoo.Tests/Library/SpecificTests/UserTests.cs
Normal file
37
Kyoo.Tests/Library/SpecificTests/UserTests.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using Kyoo.Controllers;
|
||||||
|
using Kyoo.Models;
|
||||||
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
|
namespace Kyoo.Tests.Library
|
||||||
|
{
|
||||||
|
namespace SqLite
|
||||||
|
{
|
||||||
|
public class UserTests : AUserTests
|
||||||
|
{
|
||||||
|
public UserTests(ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace PostgreSQL
|
||||||
|
{
|
||||||
|
[Collection(nameof(Postgresql))]
|
||||||
|
public class UserTests : AUserTests
|
||||||
|
{
|
||||||
|
public UserTests(PostgresFixture postgres, ITestOutputHelper output)
|
||||||
|
: base(new RepositoryActivator(output, postgres)) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract class AUserTests : RepositoryTests<User>
|
||||||
|
{
|
||||||
|
private readonly IUserRepository _repository;
|
||||||
|
|
||||||
|
protected AUserTests(RepositoryActivator repositories)
|
||||||
|
: base(repositories)
|
||||||
|
{
|
||||||
|
_repository = Repositories.LibraryManager.UserRepository;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,16 @@ namespace Kyoo.Tests
|
|||||||
|
|
||||||
private static readonly Dictionary<Type, Func<object>> Samples = new()
|
private static readonly Dictionary<Type, Func<object>> Samples = new()
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
typeof(Models.Library),
|
||||||
|
() => new Models.Library
|
||||||
|
{
|
||||||
|
ID = 1,
|
||||||
|
Slug = "deck",
|
||||||
|
Name = "Deck",
|
||||||
|
Paths = new[] {"/path/to/deck"}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
typeof(Collection),
|
typeof(Collection),
|
||||||
() => new Collection
|
() => new Collection
|
||||||
@ -115,6 +125,47 @@ namespace Kyoo.Tests
|
|||||||
Name = "The Actor",
|
Name = "The Actor",
|
||||||
Poster = "NicePoster"
|
Poster = "NicePoster"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
typeof(Studio),
|
||||||
|
() => new Studio
|
||||||
|
{
|
||||||
|
ID = 1,
|
||||||
|
Slug = "hyper-studio",
|
||||||
|
Name = "Hyper studio"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
typeof(Genre),
|
||||||
|
() => new Genre
|
||||||
|
{
|
||||||
|
ID = 1,
|
||||||
|
Slug = "action",
|
||||||
|
Name = "Action"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
typeof(Provider),
|
||||||
|
() => new Provider
|
||||||
|
{
|
||||||
|
ID = 1,
|
||||||
|
Slug = "tvdb",
|
||||||
|
Name = "The TVDB",
|
||||||
|
Logo = "path/tvdb.svg",
|
||||||
|
LogoExtension = "svg"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
typeof(User),
|
||||||
|
() => new User
|
||||||
|
{
|
||||||
|
ID = 1,
|
||||||
|
Slug = "user",
|
||||||
|
Username = "User",
|
||||||
|
Email = "user@im-a-user.com",
|
||||||
|
Password = "MD5-encoded",
|
||||||
|
Permissions = new [] {"overall.read"}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -158,6 +209,34 @@ namespace Kyoo.Tests
|
|||||||
track.Episode = episode;
|
track.Episode = episode;
|
||||||
context.Tracks.Add(track);
|
context.Tracks.Add(track);
|
||||||
|
|
||||||
|
Studio studio = Get<Studio>();
|
||||||
|
studio.ID = 0;
|
||||||
|
studio.Shows = new List<Show> {show};
|
||||||
|
context.Studios.Add(studio);
|
||||||
|
|
||||||
|
Genre genre = Get<Genre>();
|
||||||
|
genre.ID = 0;
|
||||||
|
genre.Shows = new List<Show> {show};
|
||||||
|
context.Genres.Add(genre);
|
||||||
|
|
||||||
|
People people = Get<People>();
|
||||||
|
people.ID = 0;
|
||||||
|
context.People.Add(people);
|
||||||
|
|
||||||
|
Provider provider = Get<Provider>();
|
||||||
|
provider.ID = 0;
|
||||||
|
context.Providers.Add(provider);
|
||||||
|
|
||||||
|
Models.Library library = Get<Models.Library>();
|
||||||
|
library.ID = 0;
|
||||||
|
library.Collections = new List<Collection> {collection};
|
||||||
|
library.Providers = new List<Provider> {provider};
|
||||||
|
context.Libraries.Add(library);
|
||||||
|
|
||||||
|
User user = Get<User>();
|
||||||
|
user.ID = 0;
|
||||||
|
context.Users.Add(user);
|
||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,9 +63,12 @@ namespace Kyoo.Controllers
|
|||||||
protected override async Task Validate(Library resource)
|
protected override async Task Validate(Library resource)
|
||||||
{
|
{
|
||||||
await base.Validate(resource);
|
await base.Validate(resource);
|
||||||
resource.Providers = await resource.Providers
|
await resource.ProviderLinks.ForEachAsync(async id =>
|
||||||
.SelectAsync(x => _providers.CreateIfNotExists(x))
|
{
|
||||||
.ToListAsync();
|
id.Second = await _providers.CreateIfNotExists(id.Second);
|
||||||
|
id.SecondID = id.Second.ID;
|
||||||
|
_database.Entry(id.Second).State = EntityState.Detached;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user