mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 04:04:21 -04:00
Fix tests
This commit is contained in:
parent
7018915686
commit
30d52c6061
@ -186,14 +186,11 @@ namespace Kyoo.Abstractions.Models
|
|||||||
/// If you don't know it or this is a movie, use null
|
/// If you don't know it or this is a movie, use null
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>The slug corresponding to the given arguments</returns>
|
/// <returns>The slug corresponding to the given arguments</returns>
|
||||||
/// <exception cref="ArgumentNullException">The given show slug was null.</exception>
|
|
||||||
public static string GetSlug(string showSlug,
|
public static string GetSlug(string showSlug,
|
||||||
int? seasonNumber,
|
int? seasonNumber,
|
||||||
int? episodeNumber,
|
int? episodeNumber,
|
||||||
int? absoluteNumber = null)
|
int? absoluteNumber = null)
|
||||||
{
|
{
|
||||||
if (showSlug == null)
|
|
||||||
throw new ArgumentNullException(nameof(showSlug));
|
|
||||||
return seasonNumber switch
|
return seasonNumber switch
|
||||||
{
|
{
|
||||||
null when absoluteNumber == null => showSlug,
|
null when absoluteNumber == null => showSlug,
|
||||||
|
@ -59,8 +59,6 @@ namespace Kyoo.Abstractions.Models.Utils
|
|||||||
/// <param name="slug">The slug of the resource.</param>
|
/// <param name="slug">The slug of the resource.</param>
|
||||||
public Identifier(string slug)
|
public Identifier(string slug)
|
||||||
{
|
{
|
||||||
if (slug == null)
|
|
||||||
throw new ArgumentNullException(nameof(slug));
|
|
||||||
_slug = slug;
|
_slug = slug;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,16 +33,10 @@ namespace Kyoo.Utils
|
|||||||
/// <param name="self">The enumerable to check</param>
|
/// <param name="self">The enumerable to check</param>
|
||||||
/// <param name="action">The action to execute is the list is empty</param>
|
/// <param name="action">The action to execute is the list is empty</param>
|
||||||
/// <typeparam name="T">The type of items inside the list</typeparam>
|
/// <typeparam name="T">The type of items inside the list</typeparam>
|
||||||
/// <exception cref="ArgumentNullException">The iterable and the action can't be null.</exception>
|
|
||||||
/// <returns>The iterator proxied, there is no dual iterations.</returns>
|
/// <returns>The iterator proxied, there is no dual iterations.</returns>
|
||||||
[LinqTunnel]
|
[LinqTunnel]
|
||||||
public static IEnumerable<T> IfEmpty<T>(this IEnumerable<T> self, Action action)
|
public static IEnumerable<T> IfEmpty<T>(this IEnumerable<T> self, Action action)
|
||||||
{
|
{
|
||||||
if (self == null)
|
|
||||||
throw new ArgumentNullException(nameof(self));
|
|
||||||
if (action == null)
|
|
||||||
throw new ArgumentNullException(nameof(action));
|
|
||||||
|
|
||||||
static IEnumerable<T> Generator(IEnumerable<T> self, Action action)
|
static IEnumerable<T> Generator(IEnumerable<T> self, Action action)
|
||||||
{
|
{
|
||||||
using IEnumerator<T> enumerator = self.GetEnumerator();
|
using IEnumerator<T> enumerator = self.GetEnumerator();
|
||||||
|
@ -58,7 +58,7 @@ namespace Kyoo.Utils
|
|||||||
hasChanged = false;
|
hasChanged = false;
|
||||||
if (second == null)
|
if (second == null)
|
||||||
return first;
|
return first;
|
||||||
hasChanged = second.Any(x => x.Value?.Equals(first[x.Key]) == false);
|
hasChanged = second.Any(x => !first.ContainsKey(x.Key) || x.Value?.Equals(first[x.Key]) == false);
|
||||||
foreach ((T key, T2 value) in first)
|
foreach ((T key, T2 value) in first)
|
||||||
second.TryAdd(key, value);
|
second.TryAdd(key, value);
|
||||||
return second;
|
return second;
|
||||||
|
@ -104,13 +104,8 @@ namespace Kyoo.Utils
|
|||||||
/// <param name="type">The type to check</param>
|
/// <param name="type">The type to check</param>
|
||||||
/// <param name="genericType">The generic type to check against (Only generic types are supported like typeof(IEnumerable<>).</param>
|
/// <param name="genericType">The generic type to check against (Only generic types are supported like typeof(IEnumerable<>).</param>
|
||||||
/// <returns>True if obj inherit from genericType. False otherwise</returns>
|
/// <returns>True if obj inherit from genericType. False otherwise</returns>
|
||||||
/// <exception cref="ArgumentNullException">obj and genericType can't be null</exception>
|
|
||||||
public static bool IsOfGenericType(Type type, Type genericType)
|
public static bool IsOfGenericType(Type type, Type genericType)
|
||||||
{
|
{
|
||||||
if (type == null)
|
|
||||||
throw new ArgumentNullException(nameof(type));
|
|
||||||
if (genericType == null)
|
|
||||||
throw new ArgumentNullException(nameof(genericType));
|
|
||||||
if (!genericType.IsGenericType)
|
if (!genericType.IsGenericType)
|
||||||
throw new ArgumentException($"{nameof(genericType)} is not a generic type.");
|
throw new ArgumentException($"{nameof(genericType)} is not a generic type.");
|
||||||
|
|
||||||
@ -128,14 +123,9 @@ namespace Kyoo.Utils
|
|||||||
/// <param name="type">The type to check</param>
|
/// <param name="type">The type to check</param>
|
||||||
/// <param name="genericType">The generic type to check against (Only generic types are supported like typeof(IEnumerable<>).</param>
|
/// <param name="genericType">The generic type to check against (Only generic types are supported like typeof(IEnumerable<>).</param>
|
||||||
/// <returns>The generic definition of genericType that type inherit or null if type does not implement the generic type.</returns>
|
/// <returns>The generic definition of genericType that type inherit or null if type does not implement the generic type.</returns>
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="type"/> and <paramref name="genericType"/> can't be null</exception>
|
|
||||||
/// <exception cref="ArgumentException"><paramref name="genericType"/> must be a generic type</exception>
|
/// <exception cref="ArgumentException"><paramref name="genericType"/> must be a generic type</exception>
|
||||||
public static Type? GetGenericDefinition(Type type, Type genericType)
|
public static Type? GetGenericDefinition(Type type, Type genericType)
|
||||||
{
|
{
|
||||||
if (type == null)
|
|
||||||
throw new ArgumentNullException(nameof(type));
|
|
||||||
if (genericType == null)
|
|
||||||
throw new ArgumentNullException(nameof(genericType));
|
|
||||||
if (!genericType.IsGenericType)
|
if (!genericType.IsGenericType)
|
||||||
throw new ArgumentException($"{nameof(genericType)} is not a generic type.");
|
throw new ArgumentException($"{nameof(genericType)} is not a generic type.");
|
||||||
|
|
||||||
@ -272,12 +262,6 @@ namespace Kyoo.Utils
|
|||||||
Type[] types,
|
Type[] types,
|
||||||
params object?[] args)
|
params object?[] args)
|
||||||
{
|
{
|
||||||
if (owner == null)
|
|
||||||
throw new ArgumentNullException(nameof(owner));
|
|
||||||
if (methodName == null)
|
|
||||||
throw new ArgumentNullException(nameof(methodName));
|
|
||||||
if (types == null)
|
|
||||||
throw new ArgumentNullException(nameof(types));
|
|
||||||
if (types.Length < 1)
|
if (types.Length < 1)
|
||||||
throw new ArgumentException($"The {nameof(types)} array is empty. At least one type is needed.");
|
throw new ArgumentException($"The {nameof(types)} array is empty. At least one type is needed.");
|
||||||
MethodInfo method = GetMethod(owner, BindingFlags.Static, methodName, types, args);
|
MethodInfo method = GetMethod(owner, BindingFlags.Static, methodName, types, args);
|
||||||
|
@ -209,8 +209,6 @@ namespace Kyoo.Core.Controllers
|
|||||||
where T : class, IResource
|
where T : class, IResource
|
||||||
where T2 : class, IResource
|
where T2 : class, IResource
|
||||||
{
|
{
|
||||||
if (member == null)
|
|
||||||
throw new ArgumentNullException(nameof(member));
|
|
||||||
return Load(obj, Utility.GetPropertyName(member), force);
|
return Load(obj, Utility.GetPropertyName(member), force);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -219,8 +217,6 @@ namespace Kyoo.Core.Controllers
|
|||||||
where T : class, IResource
|
where T : class, IResource
|
||||||
where T2 : class
|
where T2 : class
|
||||||
{
|
{
|
||||||
if (member == null)
|
|
||||||
throw new ArgumentNullException(nameof(member));
|
|
||||||
return Load(obj, Utility.GetPropertyName(member), force);
|
return Load(obj, Utility.GetPropertyName(member), force);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -82,9 +82,6 @@ namespace Kyoo.Core.Controllers
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task Delete(Collection obj)
|
public override async Task Delete(Collection obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
|
||||||
throw new ArgumentNullException(nameof(obj));
|
|
||||||
|
|
||||||
_database.Entry(obj).State = EntityState.Deleted;
|
_database.Entry(obj).State = EntityState.Deleted;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await base.Delete(obj);
|
await base.Delete(obj);
|
||||||
|
@ -170,9 +170,6 @@ namespace Kyoo.Core.Controllers
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task Delete(Episode obj)
|
public override async Task Delete(Episode obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
|
||||||
throw new ArgumentNullException(nameof(obj));
|
|
||||||
|
|
||||||
int epCount = await _database.Episodes.Where(x => x.ShowId == obj.ShowId).Take(2).CountAsync();
|
int epCount = await _database.Episodes.Where(x => x.ShowId == obj.ShowId).Take(2).CountAsync();
|
||||||
_database.Entry(obj).State = EntityState.Deleted;
|
_database.Entry(obj).State = EntityState.Deleted;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
|
@ -30,6 +30,7 @@ using Kyoo.Abstractions.Models.Exceptions;
|
|||||||
using Kyoo.Core.Api;
|
using Kyoo.Core.Api;
|
||||||
using Kyoo.Utils;
|
using Kyoo.Utils;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||||
|
|
||||||
namespace Kyoo.Core.Controllers
|
namespace Kyoo.Core.Controllers
|
||||||
{
|
{
|
||||||
@ -338,14 +339,15 @@ namespace Kyoo.Core.Controllers
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public virtual async Task<T> Create(T obj)
|
public virtual async Task<T> Create(T obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
|
||||||
throw new ArgumentNullException(nameof(obj));
|
|
||||||
await Validate(obj);
|
await Validate(obj);
|
||||||
if (obj is IThumbnails thumbs)
|
if (obj is IThumbnails thumbs)
|
||||||
{
|
{
|
||||||
Database.Entry(thumbs).Reference(x => x.Poster).IsModified = thumbs.Poster != null;
|
if (thumbs.Poster != null)
|
||||||
Database.Entry(thumbs).Reference(x => x.Thumbnail).IsModified = thumbs.Thumbnail != null;
|
Database.Entry(thumbs).Reference(x => x.Poster).TargetEntry.State = EntityState.Added;
|
||||||
Database.Entry(thumbs).Reference(x => x.Logo).IsModified = thumbs.Logo != null;
|
if (thumbs.Thumbnail != null)
|
||||||
|
Database.Entry(thumbs).Reference(x => x.Thumbnail).TargetEntry.State = EntityState.Added;
|
||||||
|
if (thumbs.Logo != null)
|
||||||
|
Database.Entry(thumbs).Reference(x => x.Logo).TargetEntry.State = EntityState.Added;
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -395,7 +397,7 @@ namespace Kyoo.Core.Controllers
|
|||||||
T old = await GetWithTracking(edited.Id);
|
T old = await GetWithTracking(edited.Id);
|
||||||
|
|
||||||
Merger.Complete(old, edited, x => x.GetCustomAttribute<LoadableRelationAttribute>() == null);
|
Merger.Complete(old, edited, x => x.GetCustomAttribute<LoadableRelationAttribute>() == null);
|
||||||
await EditRelations(old, edited, true);
|
await EditRelations(old, edited);
|
||||||
await Database.SaveChangesAsync();
|
await Database.SaveChangesAsync();
|
||||||
OnEdited?.Invoke(old);
|
OnEdited?.Invoke(old);
|
||||||
return old;
|
return old;
|
||||||
@ -418,6 +420,7 @@ namespace Kyoo.Core.Controllers
|
|||||||
|
|
||||||
if (!await patch(resource))
|
if (!await patch(resource))
|
||||||
throw new ArgumentException("Could not patch resource");
|
throw new ArgumentException("Could not patch resource");
|
||||||
|
|
||||||
await Database.SaveChangesAsync();
|
await Database.SaveChangesAsync();
|
||||||
OnEdited?.Invoke(resource);
|
OnEdited?.Invoke(resource);
|
||||||
return resource;
|
return resource;
|
||||||
@ -439,11 +442,8 @@ namespace Kyoo.Core.Controllers
|
|||||||
/// The new version of <paramref name="resource"/>.
|
/// The new version of <paramref name="resource"/>.
|
||||||
/// This item will be saved on the database and replace <paramref name="resource"/>
|
/// This item will be saved on the database and replace <paramref name="resource"/>
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="resetOld">
|
|
||||||
/// A boolean to indicate if all values of resource should be discarded or not.
|
|
||||||
/// </param>
|
|
||||||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||||
protected virtual Task EditRelations(T resource, T changed, bool resetOld)
|
protected virtual Task EditRelations(T resource, T changed)
|
||||||
{
|
{
|
||||||
if (resource is IThumbnails thumbs && changed is IThumbnails chng)
|
if (resource is IThumbnails thumbs && changed is IThumbnails chng)
|
||||||
{
|
{
|
||||||
|
@ -22,7 +22,6 @@ using System.Threading.Tasks;
|
|||||||
using Kyoo.Abstractions.Controllers;
|
using Kyoo.Abstractions.Controllers;
|
||||||
using Kyoo.Abstractions.Models;
|
using Kyoo.Abstractions.Models;
|
||||||
using Kyoo.Postgresql;
|
using Kyoo.Postgresql;
|
||||||
using Kyoo.Utils;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
namespace Kyoo.Core.Controllers
|
namespace Kyoo.Core.Controllers
|
||||||
@ -111,17 +110,17 @@ namespace Kyoo.Core.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task EditRelations(Movie resource, Movie changed, bool resetOld)
|
protected override async Task EditRelations(Movie resource, Movie changed)
|
||||||
{
|
{
|
||||||
await Validate(changed);
|
await Validate(changed);
|
||||||
|
|
||||||
if (changed.Studio != null || resetOld)
|
if (changed.Studio != null || changed.StudioID == null)
|
||||||
{
|
{
|
||||||
await Database.Entry(resource).Reference(x => x.Studio).LoadAsync();
|
await Database.Entry(resource).Reference(x => x.Studio).LoadAsync();
|
||||||
resource.Studio = changed.Studio;
|
resource.Studio = changed.Studio;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed.People != null || resetOld)
|
if (changed.People != null)
|
||||||
{
|
{
|
||||||
await Database.Entry(resource).Collection(x => x.People).LoadAsync();
|
await Database.Entry(resource).Collection(x => x.People).LoadAsync();
|
||||||
resource.People = changed.People;
|
resource.People = changed.People;
|
||||||
|
@ -99,11 +99,11 @@ namespace Kyoo.Core.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task EditRelations(People resource, People changed, bool resetOld)
|
protected override async Task EditRelations(People resource, People changed)
|
||||||
{
|
{
|
||||||
await Validate(changed);
|
await Validate(changed);
|
||||||
|
|
||||||
if (changed.Roles != null || resetOld)
|
if (changed.Roles != null)
|
||||||
{
|
{
|
||||||
await Database.Entry(resource).Collection(x => x.Roles).LoadAsync();
|
await Database.Entry(resource).Collection(x => x.Roles).LoadAsync();
|
||||||
resource.Roles = changed.Roles;
|
resource.Roles = changed.Roles;
|
||||||
@ -113,9 +113,6 @@ namespace Kyoo.Core.Controllers
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task Delete(People obj)
|
public override async Task Delete(People obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
|
||||||
throw new ArgumentNullException(nameof(obj));
|
|
||||||
|
|
||||||
_database.Entry(obj).State = EntityState.Deleted;
|
_database.Entry(obj).State = EntityState.Deleted;
|
||||||
obj.Roles.ForEach(x => _database.Entry(x).State = EntityState.Deleted);
|
obj.Roles.ForEach(x => _database.Entry(x).State = EntityState.Deleted);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
|
@ -137,9 +137,6 @@ namespace Kyoo.Core.Controllers
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override async Task Delete(Season obj)
|
public override async Task Delete(Season obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
|
||||||
throw new ArgumentNullException(nameof(obj));
|
|
||||||
|
|
||||||
_database.Remove(obj);
|
_database.Remove(obj);
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await base.Delete(obj);
|
await base.Delete(obj);
|
||||||
|
@ -113,17 +113,17 @@ namespace Kyoo.Core.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task EditRelations(Show resource, Show changed, bool resetOld)
|
protected override async Task EditRelations(Show resource, Show changed)
|
||||||
{
|
{
|
||||||
await Validate(changed);
|
await Validate(changed);
|
||||||
|
|
||||||
if (changed.Studio != null || resetOld)
|
if (changed.Studio != null || changed.StudioId == null)
|
||||||
{
|
{
|
||||||
await Database.Entry(resource).Reference(x => x.Studio).LoadAsync();
|
await Database.Entry(resource).Reference(x => x.Studio).LoadAsync();
|
||||||
resource.Studio = changed.Studio;
|
resource.Studio = changed.Studio;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed.People != null || resetOld)
|
if (changed.People != null)
|
||||||
{
|
{
|
||||||
await Database.Entry(resource).Collection(x => x.People).LoadAsync();
|
await Database.Entry(resource).Collection(x => x.People).LoadAsync();
|
||||||
resource.People = changed.People;
|
resource.People = changed.People;
|
||||||
|
@ -82,9 +82,6 @@ namespace Kyoo.Core.Controllers
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task Delete(Studio obj)
|
public override async Task Delete(Studio obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
|
||||||
throw new ArgumentNullException(nameof(obj));
|
|
||||||
|
|
||||||
_database.Entry(obj).State = EntityState.Deleted;
|
_database.Entry(obj).State = EntityState.Deleted;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await base.Delete(obj);
|
await base.Delete(obj);
|
||||||
|
@ -76,9 +76,6 @@ namespace Kyoo.Core.Controllers
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override async Task Delete(User obj)
|
public override async Task Delete(User obj)
|
||||||
{
|
{
|
||||||
if (obj == null)
|
|
||||||
throw new ArgumentNullException(nameof(obj));
|
|
||||||
|
|
||||||
_database.Entry(obj).State = EntityState.Deleted;
|
_database.Entry(obj).State = EntityState.Deleted;
|
||||||
await _database.SaveChangesAsync();
|
await _database.SaveChangesAsync();
|
||||||
await base.Delete(obj);
|
await base.Delete(obj);
|
||||||
|
@ -41,6 +41,7 @@ namespace Kyoo.Tests.Database
|
|||||||
StudioRepository studio = new(_NewContext());
|
StudioRepository studio = new(_NewContext());
|
||||||
PeopleRepository people = new(_NewContext(),
|
PeopleRepository people = new(_NewContext(),
|
||||||
new Lazy<IShowRepository>(() => LibraryManager.ShowRepository));
|
new Lazy<IShowRepository>(() => LibraryManager.ShowRepository));
|
||||||
|
MovieRepository movies = new(_NewContext(), studio, people);
|
||||||
ShowRepository show = new(_NewContext(), studio, people);
|
ShowRepository show = new(_NewContext(), studio, people);
|
||||||
SeasonRepository season = new(_NewContext(), show);
|
SeasonRepository season = new(_NewContext(), show);
|
||||||
LibraryItemRepository libraryItem = new(_NewContext());
|
LibraryItemRepository libraryItem = new(_NewContext());
|
||||||
@ -50,6 +51,7 @@ namespace Kyoo.Tests.Database
|
|||||||
LibraryManager = new LibraryManager(new IBaseRepository[] {
|
LibraryManager = new LibraryManager(new IBaseRepository[] {
|
||||||
libraryItem,
|
libraryItem,
|
||||||
collection,
|
collection,
|
||||||
|
movies,
|
||||||
show,
|
show,
|
||||||
season,
|
season,
|
||||||
episode,
|
episode,
|
||||||
|
@ -118,18 +118,6 @@ namespace Kyoo.Tests.Database
|
|||||||
KAssert.DeepEqual(expected, await _repository.Get(expected.Slug));
|
KAssert.DeepEqual(expected, await _repository.Get(expected.Slug));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task CreateNullTest()
|
|
||||||
{
|
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>(() => _repository.Create(null!));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
|
||||||
public async Task CreateIfNotExistNullTest()
|
|
||||||
{
|
|
||||||
await Assert.ThrowsAsync<ArgumentNullException>(() => _repository.CreateIfNotExists(null!));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public virtual async Task CreateIfNotExistTest()
|
public virtual async Task CreateIfNotExistTest()
|
||||||
{
|
{
|
||||||
|
@ -120,9 +120,7 @@ namespace Kyoo.Tests.Database
|
|||||||
await _repository.Edit(value);
|
await _repository.Edit(value);
|
||||||
|
|
||||||
await using DatabaseContext database = Repositories.Context.New();
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
Collection retrieved = await database.Collections
|
Collection retrieved = await database.Collections.FirstAsync();
|
||||||
.Include(x => x.ExternalId)
|
|
||||||
.FirstAsync();
|
|
||||||
|
|
||||||
KAssert.DeepEqual(value, retrieved);
|
KAssert.DeepEqual(value, retrieved);
|
||||||
}
|
}
|
||||||
@ -143,9 +141,7 @@ namespace Kyoo.Tests.Database
|
|||||||
|
|
||||||
{
|
{
|
||||||
await using DatabaseContext database = Repositories.Context.New();
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
Collection retrieved = await database.Collections
|
Collection retrieved = await database.Collections.FirstAsync();
|
||||||
.Include(x => x.ExternalId)
|
|
||||||
.FirstAsync();
|
|
||||||
|
|
||||||
KAssert.DeepEqual(value, retrieved);
|
KAssert.DeepEqual(value, retrieved);
|
||||||
}
|
}
|
||||||
@ -159,9 +155,7 @@ namespace Kyoo.Tests.Database
|
|||||||
|
|
||||||
{
|
{
|
||||||
await using DatabaseContext database = Repositories.Context.New();
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
Collection retrieved = await database.Collections
|
Collection retrieved = await database.Collections.FirstAsync();
|
||||||
.Include(x => x.ExternalId)
|
|
||||||
.FirstAsync();
|
|
||||||
|
|
||||||
KAssert.DeepEqual(value, retrieved);
|
KAssert.DeepEqual(value, retrieved);
|
||||||
}
|
}
|
||||||
|
@ -55,12 +55,11 @@ namespace Kyoo.Tests.Database
|
|||||||
{
|
{
|
||||||
Episode episode = await _repository.Get(1);
|
Episode episode = await _repository.Get(1);
|
||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||||
Show show = new()
|
await Repositories.LibraryManager.ShowRepository.Patch(episode.ShowId, (x) =>
|
||||||
{
|
{
|
||||||
Id = episode.ShowId,
|
x.Slug = "new-slug";
|
||||||
Slug = "new-slug"
|
return Task.FromResult(true);
|
||||||
};
|
});
|
||||||
await Repositories.LibraryManager.ShowRepository.Edit(show);
|
|
||||||
episode = await _repository.Get(1);
|
episode = await _repository.Get(1);
|
||||||
Assert.Equal("new-slug-s1e1", episode.Slug);
|
Assert.Equal("new-slug-s1e1", episode.Slug);
|
||||||
}
|
}
|
||||||
@ -70,11 +69,10 @@ namespace Kyoo.Tests.Database
|
|||||||
{
|
{
|
||||||
Episode episode = await _repository.Get(1);
|
Episode episode = await _repository.Get(1);
|
||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||||
episode = await _repository.Edit(new Episode
|
episode = await _repository.Patch(1, (x) =>
|
||||||
{
|
{
|
||||||
Id = 1,
|
x.SeasonNumber = 2;
|
||||||
SeasonNumber = 2,
|
return Task.FromResult(true);
|
||||||
ShowId = 1
|
|
||||||
});
|
});
|
||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2e1", episode.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2e1", episode.Slug);
|
||||||
episode = await _repository.Get(1);
|
episode = await _repository.Get(1);
|
||||||
@ -86,11 +84,10 @@ namespace Kyoo.Tests.Database
|
|||||||
{
|
{
|
||||||
Episode episode = await _repository.Get(1);
|
Episode episode = await _repository.Get(1);
|
||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||||
episode = await _repository.Edit(new Episode
|
episode = await Repositories.LibraryManager.Patch<Episode>(episode.Id, (x) =>
|
||||||
{
|
{
|
||||||
Id = 1,
|
x.EpisodeNumber = 2;
|
||||||
EpisodeNumber = 2,
|
return Task.FromResult(true);
|
||||||
ShowId = 1
|
|
||||||
});
|
});
|
||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
||||||
episode = await _repository.Get(1);
|
episode = await _repository.Get(1);
|
||||||
@ -100,12 +97,12 @@ namespace Kyoo.Tests.Database
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task EpisodeCreationSlugTest()
|
public async Task EpisodeCreationSlugTest()
|
||||||
{
|
{
|
||||||
Episode episode = await _repository.Create(new Episode
|
Episode model = TestSample.Get<Episode>();
|
||||||
{
|
model.Id = 0;
|
||||||
ShowId = TestSample.Get<Show>().Id,
|
model.ShowId = TestSample.Get<Show>().Id;
|
||||||
SeasonNumber = 2,
|
model.SeasonNumber = 2;
|
||||||
EpisodeNumber = 4
|
model.EpisodeNumber = 4;
|
||||||
});
|
Episode episode = await _repository.Create(model);
|
||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2e4", episode.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2e4", episode.Slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,12 +124,11 @@ namespace Kyoo.Tests.Database
|
|||||||
public async Task SlugEditAbsoluteTest()
|
public async Task SlugEditAbsoluteTest()
|
||||||
{
|
{
|
||||||
Episode episode = await _repository.Create(TestSample.GetAbsoluteEpisode());
|
Episode episode = await _repository.Create(TestSample.GetAbsoluteEpisode());
|
||||||
Show show = new()
|
await Repositories.LibraryManager.ShowRepository.Patch(episode.ShowId, (x) =>
|
||||||
{
|
{
|
||||||
Id = episode.ShowId,
|
x.Slug = "new-slug";
|
||||||
Slug = "new-slug"
|
return Task.FromResult(true);
|
||||||
};
|
});
|
||||||
await Repositories.LibraryManager.ShowRepository.Edit(show);
|
|
||||||
episode = await _repository.Get(2);
|
episode = await _repository.Get(2);
|
||||||
Assert.Equal($"new-slug-3", episode.Slug);
|
Assert.Equal($"new-slug-3", episode.Slug);
|
||||||
}
|
}
|
||||||
@ -141,11 +137,10 @@ namespace Kyoo.Tests.Database
|
|||||||
public async Task AbsoluteNumberEditTest()
|
public async Task AbsoluteNumberEditTest()
|
||||||
{
|
{
|
||||||
await _repository.Create(TestSample.GetAbsoluteEpisode());
|
await _repository.Create(TestSample.GetAbsoluteEpisode());
|
||||||
Episode episode = await _repository.Edit(new Episode
|
Episode episode = await _repository.Patch(2, (x) =>
|
||||||
{
|
{
|
||||||
Id = 2,
|
x.AbsoluteNumber = 56;
|
||||||
AbsoluteNumber = 56,
|
return Task.FromResult(true);
|
||||||
ShowId = 1
|
|
||||||
});
|
});
|
||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-56", episode.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-56", episode.Slug);
|
||||||
episode = await _repository.Get(2);
|
episode = await _repository.Get(2);
|
||||||
@ -156,12 +151,11 @@ namespace Kyoo.Tests.Database
|
|||||||
public async Task AbsoluteToNormalEditTest()
|
public async Task AbsoluteToNormalEditTest()
|
||||||
{
|
{
|
||||||
await _repository.Create(TestSample.GetAbsoluteEpisode());
|
await _repository.Create(TestSample.GetAbsoluteEpisode());
|
||||||
Episode episode = await _repository.Edit(new Episode
|
Episode episode = await _repository.Patch(2, (x) =>
|
||||||
{
|
{
|
||||||
Id = 2,
|
x.SeasonNumber = 1;
|
||||||
SeasonNumber = 1,
|
x.EpisodeNumber = 2;
|
||||||
EpisodeNumber = 2,
|
return Task.FromResult(true);
|
||||||
ShowId = 1
|
|
||||||
});
|
});
|
||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
||||||
episode = await _repository.Get(2);
|
episode = await _repository.Get(2);
|
||||||
@ -283,12 +277,10 @@ namespace Kyoo.Tests.Database
|
|||||||
[InlineData("SuPeR")]
|
[InlineData("SuPeR")]
|
||||||
public async Task SearchTest(string query)
|
public async Task SearchTest(string query)
|
||||||
{
|
{
|
||||||
Episode value = new()
|
Episode value = TestSample.Get<Episode>();
|
||||||
{
|
value.Id = 0;
|
||||||
Name = "This is a test super title",
|
value.Name = "This is a test super title";
|
||||||
ShowId = 1,
|
value.EpisodeNumber = 56;
|
||||||
AbsoluteNumber = 2
|
|
||||||
};
|
|
||||||
await _repository.Create(value);
|
await _repository.Create(value);
|
||||||
ICollection<Episode> ret = await _repository.Search(query);
|
ICollection<Episode> ret = await _repository.Search(query);
|
||||||
value.Show = TestSample.Get<Show>();
|
value.Show = TestSample.Get<Show>();
|
||||||
|
@ -53,12 +53,11 @@ namespace Kyoo.Tests.Database
|
|||||||
{
|
{
|
||||||
Season season = await _repository.Get(1);
|
Season season = await _repository.Get(1);
|
||||||
Assert.Equal("anohana-s1", season.Slug);
|
Assert.Equal("anohana-s1", season.Slug);
|
||||||
Show show = new()
|
await Repositories.LibraryManager.ShowRepository.Patch(season.ShowId, (x) =>
|
||||||
{
|
{
|
||||||
Id = season.ShowId,
|
x.Slug = "new-slug";
|
||||||
Slug = "new-slug"
|
return Task.FromResult(true);
|
||||||
};
|
});
|
||||||
await Repositories.LibraryManager.ShowRepository.Edit(show);
|
|
||||||
season = await _repository.Get(1);
|
season = await _repository.Get(1);
|
||||||
Assert.Equal("new-slug-s1", season.Slug);
|
Assert.Equal("new-slug-s1", season.Slug);
|
||||||
}
|
}
|
||||||
@ -68,12 +67,12 @@ namespace Kyoo.Tests.Database
|
|||||||
{
|
{
|
||||||
Season season = await _repository.Get(1);
|
Season season = await _repository.Get(1);
|
||||||
Assert.Equal("anohana-s1", season.Slug);
|
Assert.Equal("anohana-s1", season.Slug);
|
||||||
await _repository.Edit(new Season
|
await _repository.Patch(season.Id, (x) =>
|
||||||
{
|
{
|
||||||
Id = 1,
|
x.SeasonNumber = 2;
|
||||||
SeasonNumber = 2,
|
return Task.FromResult(true);
|
||||||
ShowId = 1
|
}
|
||||||
});
|
);
|
||||||
season = await _repository.Get(1);
|
season = await _repository.Get(1);
|
||||||
Assert.Equal("anohana-s2", season.Slug);
|
Assert.Equal("anohana-s2", season.Slug);
|
||||||
}
|
}
|
||||||
|
@ -75,9 +75,7 @@ namespace Kyoo.Tests.Database
|
|||||||
Assert.Equal(value.Genres, edited.Genres);
|
Assert.Equal(value.Genres, edited.Genres);
|
||||||
|
|
||||||
await using DatabaseContext database = Repositories.Context.New();
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
Show show = await database.Shows
|
Show show = await database.Shows.FirstAsync();
|
||||||
.Include(x => x.Genres)
|
|
||||||
.FirstAsync();
|
|
||||||
|
|
||||||
Assert.Equal(value.Slug, show.Slug);
|
Assert.Equal(value.Slug, show.Slug);
|
||||||
Assert.Equal(value.Genres, show.Genres);
|
Assert.Equal(value.Genres, show.Genres);
|
||||||
@ -94,9 +92,7 @@ namespace Kyoo.Tests.Database
|
|||||||
Assert.Equal(value.Genres, edited.Genres);
|
Assert.Equal(value.Genres, edited.Genres);
|
||||||
|
|
||||||
await using DatabaseContext database = Repositories.Context.New();
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
Show show = await database.Shows
|
Show show = await database.Shows.FirstAsync();
|
||||||
.Include(x => x.Genres)
|
|
||||||
.FirstAsync();
|
|
||||||
|
|
||||||
Assert.Equal(value.Slug, show.Slug);
|
Assert.Equal(value.Slug, show.Slug);
|
||||||
Assert.Equal(value.Genres, show.Genres);
|
Assert.Equal(value.Genres, show.Genres);
|
||||||
@ -113,9 +109,7 @@ namespace Kyoo.Tests.Database
|
|||||||
Assert.Equal("studio", edited.Studio!.Slug);
|
Assert.Equal("studio", edited.Studio!.Slug);
|
||||||
|
|
||||||
await using DatabaseContext database = Repositories.Context.New();
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
Show show = await database.Shows
|
Show show = await database.Shows.Include(x => x.Studio).FirstAsync();
|
||||||
.Include(x => x.Studio)
|
|
||||||
.FirstAsync();
|
|
||||||
|
|
||||||
Assert.Equal(value.Slug, show.Slug);
|
Assert.Equal(value.Slug, show.Slug);
|
||||||
Assert.Equal("studio", show.Studio!.Slug);
|
Assert.Equal("studio", show.Studio!.Slug);
|
||||||
@ -187,13 +181,13 @@ namespace Kyoo.Tests.Database
|
|||||||
Show edited = await _repository.Edit(value);
|
Show edited = await _repository.Edit(value);
|
||||||
|
|
||||||
Assert.Equal(value.Slug, edited.Slug);
|
Assert.Equal(value.Slug, edited.Slug);
|
||||||
Assert.Equal(value.ExternalId, edited.ExternalId);
|
KAssert.DeepEqual(value.ExternalId, edited.ExternalId);
|
||||||
|
|
||||||
await using DatabaseContext database = Repositories.Context.New();
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
Show show = await database.Shows.FirstAsync();
|
Show show = await database.Shows.FirstAsync();
|
||||||
|
|
||||||
Assert.Equal(value.Slug, show.Slug);
|
Assert.Equal(value.Slug, show.Slug);
|
||||||
Assert.Equal(value.ExternalId, show.ExternalId);
|
KAssert.DeepEqual(value.ExternalId, show.ExternalId);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
@ -227,8 +221,6 @@ namespace Kyoo.Tests.Database
|
|||||||
|
|
||||||
await using DatabaseContext context = Repositories.Context.New();
|
await using DatabaseContext context = Repositories.Context.New();
|
||||||
Show retrieved = await context.Shows
|
Show retrieved = await context.Shows
|
||||||
.Include(x => x.ExternalId)
|
|
||||||
.Include(x => x.Genres)
|
|
||||||
.Include(x => x.People)
|
.Include(x => x.People)
|
||||||
.ThenInclude(x => x.People)
|
.ThenInclude(x => x.People)
|
||||||
.Include(x => x.Studio)
|
.Include(x => x.Studio)
|
||||||
@ -264,9 +256,7 @@ namespace Kyoo.Tests.Database
|
|||||||
Show created = await _repository.Create(expected);
|
Show created = await _repository.Create(expected);
|
||||||
KAssert.DeepEqual(expected, created);
|
KAssert.DeepEqual(expected, created);
|
||||||
await using DatabaseContext context = Repositories.Context.New();
|
await using DatabaseContext context = Repositories.Context.New();
|
||||||
Show retrieved = await context.Shows
|
Show retrieved = await context.Shows.FirstAsync(x => x.Id == created.Id);
|
||||||
.Include(x => x.ExternalId)
|
|
||||||
.FirstAsync(x => x.Id == created.Id);
|
|
||||||
KAssert.DeepEqual(expected, retrieved);
|
KAssert.DeepEqual(expected, retrieved);
|
||||||
Assert.Single(retrieved.ExternalId);
|
Assert.Single(retrieved.ExternalId);
|
||||||
Assert.Equal("ID", retrieved.ExternalId["test"].DataId);
|
Assert.Equal("ID", retrieved.ExternalId["test"].DataId);
|
||||||
|
@ -102,8 +102,8 @@ namespace Kyoo.Tests
|
|||||||
{
|
{
|
||||||
string server = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "127.0.0.1";
|
string server = Environment.GetEnvironmentVariable("POSTGRES_HOST") ?? "127.0.0.1";
|
||||||
string port = Environment.GetEnvironmentVariable("POSTGRES_PORT") ?? "5432";
|
string port = Environment.GetEnvironmentVariable("POSTGRES_PORT") ?? "5432";
|
||||||
string username = Environment.GetEnvironmentVariable("POSTGRES_USER") ?? "kyoo";
|
string username = Environment.GetEnvironmentVariable("POSTGRES_USER") ?? "KyooUser";
|
||||||
string password = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "kyooPassword";
|
string password = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "KyooPassword";
|
||||||
return $"Server={server};Port={port};Database={database};User ID={username};Password={password};Include Error Detail=true";
|
return $"Server={server};Port={port};Database={database};User ID={username};Password={password};Include Error Detail=true";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,9 +30,6 @@ namespace Kyoo.Tests.Utility
|
|||||||
{
|
{
|
||||||
int[] list = { 1, 2, 3, 4 };
|
int[] list = { 1, 2, 3, 4 };
|
||||||
list = list.IfEmpty(() => KAssert.Fail("Empty action should not be triggered.")).ToArray();
|
list = list.IfEmpty(() => KAssert.Fail("Empty action should not be triggered.")).ToArray();
|
||||||
Assert.Throws<ArgumentNullException>(() => list.IfEmpty(null!).ToList());
|
|
||||||
list = null;
|
|
||||||
Assert.Throws<ArgumentNullException>(() => list!.IfEmpty(() => { }).ToList());
|
|
||||||
list = Array.Empty<int>();
|
list = Array.Empty<int>();
|
||||||
Assert.Throws<ArgumentException>(() => list.IfEmpty(() => throw new ArgumentException()).ToList());
|
Assert.Throws<ArgumentException>(() => list.IfEmpty(() => throw new ArgumentException()).ToList());
|
||||||
Assert.Empty(list.IfEmpty(() => { }));
|
Assert.Empty(list.IfEmpty(() => { }));
|
||||||
|
@ -31,12 +31,12 @@ namespace Kyoo.Tests.Utility
|
|||||||
{
|
{
|
||||||
Studio genre = new()
|
Studio genre = new()
|
||||||
{
|
{
|
||||||
Id = 5,
|
|
||||||
Name = "merged"
|
Name = "merged"
|
||||||
};
|
};
|
||||||
Studio genre2 = new()
|
Studio genre2 = new()
|
||||||
{
|
{
|
||||||
Name = "test"
|
Name = "test",
|
||||||
|
Id = 5,
|
||||||
};
|
};
|
||||||
Studio ret = Merger.Complete(genre, genre2);
|
Studio ret = Merger.Complete(genre, genre2);
|
||||||
Assert.True(ReferenceEquals(genre, ret));
|
Assert.True(ReferenceEquals(genre, ret));
|
||||||
@ -50,11 +50,11 @@ namespace Kyoo.Tests.Utility
|
|||||||
{
|
{
|
||||||
Collection collection = new()
|
Collection collection = new()
|
||||||
{
|
{
|
||||||
Id = 5,
|
|
||||||
Name = "merged",
|
Name = "merged",
|
||||||
};
|
};
|
||||||
Collection collection2 = new()
|
Collection collection2 = new()
|
||||||
{
|
{
|
||||||
|
Id = 5,
|
||||||
Name = "test",
|
Name = "test",
|
||||||
};
|
};
|
||||||
Collection ret = Merger.Complete(collection, collection2);
|
Collection ret = Merger.Complete(collection, collection2);
|
||||||
|
@ -47,8 +47,8 @@ namespace Kyoo.Tests.Utility
|
|||||||
Expression<Func<Show, int>> member = x => x.Id;
|
Expression<Func<Show, int>> member = x => x.Id;
|
||||||
Expression<Func<Show, object>> memberCast = x => x.Id;
|
Expression<Func<Show, object>> memberCast = x => x.Id;
|
||||||
|
|
||||||
Assert.Equal("ID", KUtility.GetPropertyName(member));
|
Assert.Equal("Id", KUtility.GetPropertyName(member));
|
||||||
Assert.Equal("ID", KUtility.GetPropertyName(memberCast));
|
Assert.Equal("Id", KUtility.GetPropertyName(memberCast));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user