mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-24 02:02:36 -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
|
||||
/// </param>
|
||||
/// <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,
|
||||
int? seasonNumber,
|
||||
int? episodeNumber,
|
||||
int? absoluteNumber = null)
|
||||
{
|
||||
if (showSlug == null)
|
||||
throw new ArgumentNullException(nameof(showSlug));
|
||||
return seasonNumber switch
|
||||
{
|
||||
null when absoluteNumber == null => showSlug,
|
||||
|
@ -59,8 +59,6 @@ namespace Kyoo.Abstractions.Models.Utils
|
||||
/// <param name="slug">The slug of the resource.</param>
|
||||
public Identifier(string slug)
|
||||
{
|
||||
if (slug == null)
|
||||
throw new ArgumentNullException(nameof(slug));
|
||||
_slug = slug;
|
||||
}
|
||||
|
||||
|
@ -33,16 +33,10 @@ namespace Kyoo.Utils
|
||||
/// <param name="self">The enumerable to check</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>
|
||||
/// <exception cref="ArgumentNullException">The iterable and the action can't be null.</exception>
|
||||
/// <returns>The iterator proxied, there is no dual iterations.</returns>
|
||||
[LinqTunnel]
|
||||
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)
|
||||
{
|
||||
using IEnumerator<T> enumerator = self.GetEnumerator();
|
||||
|
@ -58,7 +58,7 @@ namespace Kyoo.Utils
|
||||
hasChanged = false;
|
||||
if (second == null)
|
||||
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)
|
||||
second.TryAdd(key, value);
|
||||
return second;
|
||||
|
@ -104,13 +104,8 @@ namespace Kyoo.Utils
|
||||
/// <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>
|
||||
/// <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)
|
||||
{
|
||||
if (type == null)
|
||||
throw new ArgumentNullException(nameof(type));
|
||||
if (genericType == null)
|
||||
throw new ArgumentNullException(nameof(genericType));
|
||||
if (!genericType.IsGenericType)
|
||||
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="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>
|
||||
/// <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>
|
||||
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)
|
||||
throw new ArgumentException($"{nameof(genericType)} is not a generic type.");
|
||||
|
||||
@ -272,12 +262,6 @@ namespace Kyoo.Utils
|
||||
Type[] types,
|
||||
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)
|
||||
throw new ArgumentException($"The {nameof(types)} array is empty. At least one type is needed.");
|
||||
MethodInfo method = GetMethod(owner, BindingFlags.Static, methodName, types, args);
|
||||
|
@ -209,8 +209,6 @@ namespace Kyoo.Core.Controllers
|
||||
where T : class, IResource
|
||||
where T2 : class, IResource
|
||||
{
|
||||
if (member == null)
|
||||
throw new ArgumentNullException(nameof(member));
|
||||
return Load(obj, Utility.GetPropertyName(member), force);
|
||||
}
|
||||
|
||||
@ -219,8 +217,6 @@ namespace Kyoo.Core.Controllers
|
||||
where T : class, IResource
|
||||
where T2 : class
|
||||
{
|
||||
if (member == null)
|
||||
throw new ArgumentNullException(nameof(member));
|
||||
return Load(obj, Utility.GetPropertyName(member), force);
|
||||
}
|
||||
|
||||
|
@ -82,9 +82,6 @@ namespace Kyoo.Core.Controllers
|
||||
/// <inheritdoc />
|
||||
public override async Task Delete(Collection obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
_database.Entry(obj).State = EntityState.Deleted;
|
||||
await _database.SaveChangesAsync();
|
||||
await base.Delete(obj);
|
||||
|
@ -170,9 +170,6 @@ namespace Kyoo.Core.Controllers
|
||||
/// <inheritdoc />
|
||||
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();
|
||||
_database.Entry(obj).State = EntityState.Deleted;
|
||||
await _database.SaveChangesAsync();
|
||||
|
@ -30,6 +30,7 @@ using Kyoo.Abstractions.Models.Exceptions;
|
||||
using Kyoo.Core.Api;
|
||||
using Kyoo.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.ChangeTracking;
|
||||
|
||||
namespace Kyoo.Core.Controllers
|
||||
{
|
||||
@ -338,14 +339,15 @@ namespace Kyoo.Core.Controllers
|
||||
/// <inheritdoc/>
|
||||
public virtual async Task<T> Create(T obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
await Validate(obj);
|
||||
if (obj is IThumbnails thumbs)
|
||||
{
|
||||
Database.Entry(thumbs).Reference(x => x.Poster).IsModified = thumbs.Poster != null;
|
||||
Database.Entry(thumbs).Reference(x => x.Thumbnail).IsModified = thumbs.Thumbnail != null;
|
||||
Database.Entry(thumbs).Reference(x => x.Logo).IsModified = thumbs.Logo != null;
|
||||
if (thumbs.Poster != null)
|
||||
Database.Entry(thumbs).Reference(x => x.Poster).TargetEntry.State = EntityState.Added;
|
||||
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;
|
||||
}
|
||||
@ -395,7 +397,7 @@ namespace Kyoo.Core.Controllers
|
||||
T old = await GetWithTracking(edited.Id);
|
||||
|
||||
Merger.Complete(old, edited, x => x.GetCustomAttribute<LoadableRelationAttribute>() == null);
|
||||
await EditRelations(old, edited, true);
|
||||
await EditRelations(old, edited);
|
||||
await Database.SaveChangesAsync();
|
||||
OnEdited?.Invoke(old);
|
||||
return old;
|
||||
@ -418,6 +420,7 @@ namespace Kyoo.Core.Controllers
|
||||
|
||||
if (!await patch(resource))
|
||||
throw new ArgumentException("Could not patch resource");
|
||||
|
||||
await Database.SaveChangesAsync();
|
||||
OnEdited?.Invoke(resource);
|
||||
return resource;
|
||||
@ -439,11 +442,8 @@ namespace Kyoo.Core.Controllers
|
||||
/// The new version of <paramref name="resource"/>.
|
||||
/// This item will be saved on the database and replace <paramref name="resource"/>
|
||||
/// </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>
|
||||
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)
|
||||
{
|
||||
|
@ -22,7 +22,6 @@ using System.Threading.Tasks;
|
||||
using Kyoo.Abstractions.Controllers;
|
||||
using Kyoo.Abstractions.Models;
|
||||
using Kyoo.Postgresql;
|
||||
using Kyoo.Utils;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Kyoo.Core.Controllers
|
||||
@ -111,17 +110,17 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task EditRelations(Movie resource, Movie changed, bool resetOld)
|
||||
protected override async Task EditRelations(Movie resource, Movie 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();
|
||||
resource.Studio = changed.Studio;
|
||||
}
|
||||
|
||||
if (changed.People != null || resetOld)
|
||||
if (changed.People != null)
|
||||
{
|
||||
await Database.Entry(resource).Collection(x => x.People).LoadAsync();
|
||||
resource.People = changed.People;
|
||||
|
@ -99,11 +99,11 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task EditRelations(People resource, People changed, bool resetOld)
|
||||
protected override async Task EditRelations(People resource, People changed)
|
||||
{
|
||||
await Validate(changed);
|
||||
|
||||
if (changed.Roles != null || resetOld)
|
||||
if (changed.Roles != null)
|
||||
{
|
||||
await Database.Entry(resource).Collection(x => x.Roles).LoadAsync();
|
||||
resource.Roles = changed.Roles;
|
||||
@ -113,9 +113,6 @@ namespace Kyoo.Core.Controllers
|
||||
/// <inheritdoc />
|
||||
public override async Task Delete(People obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
_database.Entry(obj).State = EntityState.Deleted;
|
||||
obj.Roles.ForEach(x => _database.Entry(x).State = EntityState.Deleted);
|
||||
await _database.SaveChangesAsync();
|
||||
|
@ -137,9 +137,6 @@ namespace Kyoo.Core.Controllers
|
||||
/// <inheritdoc/>
|
||||
public override async Task Delete(Season obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
_database.Remove(obj);
|
||||
await _database.SaveChangesAsync();
|
||||
await base.Delete(obj);
|
||||
|
@ -113,17 +113,17 @@ namespace Kyoo.Core.Controllers
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task EditRelations(Show resource, Show changed, bool resetOld)
|
||||
protected override async Task EditRelations(Show resource, Show 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();
|
||||
resource.Studio = changed.Studio;
|
||||
}
|
||||
|
||||
if (changed.People != null || resetOld)
|
||||
if (changed.People != null)
|
||||
{
|
||||
await Database.Entry(resource).Collection(x => x.People).LoadAsync();
|
||||
resource.People = changed.People;
|
||||
|
@ -82,9 +82,6 @@ namespace Kyoo.Core.Controllers
|
||||
/// <inheritdoc />
|
||||
public override async Task Delete(Studio obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
_database.Entry(obj).State = EntityState.Deleted;
|
||||
await _database.SaveChangesAsync();
|
||||
await base.Delete(obj);
|
||||
|
@ -76,9 +76,6 @@ namespace Kyoo.Core.Controllers
|
||||
/// <inheritdoc />
|
||||
public override async Task Delete(User obj)
|
||||
{
|
||||
if (obj == null)
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
|
||||
_database.Entry(obj).State = EntityState.Deleted;
|
||||
await _database.SaveChangesAsync();
|
||||
await base.Delete(obj);
|
||||
|
@ -41,6 +41,7 @@ namespace Kyoo.Tests.Database
|
||||
StudioRepository studio = new(_NewContext());
|
||||
PeopleRepository people = new(_NewContext(),
|
||||
new Lazy<IShowRepository>(() => LibraryManager.ShowRepository));
|
||||
MovieRepository movies = new(_NewContext(), studio, people);
|
||||
ShowRepository show = new(_NewContext(), studio, people);
|
||||
SeasonRepository season = new(_NewContext(), show);
|
||||
LibraryItemRepository libraryItem = new(_NewContext());
|
||||
@ -50,6 +51,7 @@ namespace Kyoo.Tests.Database
|
||||
LibraryManager = new LibraryManager(new IBaseRepository[] {
|
||||
libraryItem,
|
||||
collection,
|
||||
movies,
|
||||
show,
|
||||
season,
|
||||
episode,
|
||||
|
@ -118,18 +118,6 @@ namespace Kyoo.Tests.Database
|
||||
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]
|
||||
public virtual async Task CreateIfNotExistTest()
|
||||
{
|
||||
|
@ -120,9 +120,7 @@ namespace Kyoo.Tests.Database
|
||||
await _repository.Edit(value);
|
||||
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
Collection retrieved = await database.Collections
|
||||
.Include(x => x.ExternalId)
|
||||
.FirstAsync();
|
||||
Collection retrieved = await database.Collections.FirstAsync();
|
||||
|
||||
KAssert.DeepEqual(value, retrieved);
|
||||
}
|
||||
@ -143,9 +141,7 @@ namespace Kyoo.Tests.Database
|
||||
|
||||
{
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
Collection retrieved = await database.Collections
|
||||
.Include(x => x.ExternalId)
|
||||
.FirstAsync();
|
||||
Collection retrieved = await database.Collections.FirstAsync();
|
||||
|
||||
KAssert.DeepEqual(value, retrieved);
|
||||
}
|
||||
@ -159,9 +155,7 @@ namespace Kyoo.Tests.Database
|
||||
|
||||
{
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
Collection retrieved = await database.Collections
|
||||
.Include(x => x.ExternalId)
|
||||
.FirstAsync();
|
||||
Collection retrieved = await database.Collections.FirstAsync();
|
||||
|
||||
KAssert.DeepEqual(value, retrieved);
|
||||
}
|
||||
|
@ -55,12 +55,11 @@ namespace Kyoo.Tests.Database
|
||||
{
|
||||
Episode episode = await _repository.Get(1);
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||
Show show = new()
|
||||
await Repositories.LibraryManager.ShowRepository.Patch(episode.ShowId, (x) =>
|
||||
{
|
||||
Id = episode.ShowId,
|
||||
Slug = "new-slug"
|
||||
};
|
||||
await Repositories.LibraryManager.ShowRepository.Edit(show);
|
||||
x.Slug = "new-slug";
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
episode = await _repository.Get(1);
|
||||
Assert.Equal("new-slug-s1e1", episode.Slug);
|
||||
}
|
||||
@ -70,11 +69,10 @@ namespace Kyoo.Tests.Database
|
||||
{
|
||||
Episode episode = await _repository.Get(1);
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e1", episode.Slug);
|
||||
episode = await _repository.Edit(new Episode
|
||||
episode = await _repository.Patch(1, (x) =>
|
||||
{
|
||||
Id = 1,
|
||||
SeasonNumber = 2,
|
||||
ShowId = 1
|
||||
x.SeasonNumber = 2;
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2e1", episode.Slug);
|
||||
episode = await _repository.Get(1);
|
||||
@ -86,11 +84,10 @@ namespace Kyoo.Tests.Database
|
||||
{
|
||||
Episode episode = await _repository.Get(1);
|
||||
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,
|
||||
EpisodeNumber = 2,
|
||||
ShowId = 1
|
||||
x.EpisodeNumber = 2;
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
||||
episode = await _repository.Get(1);
|
||||
@ -100,12 +97,12 @@ namespace Kyoo.Tests.Database
|
||||
[Fact]
|
||||
public async Task EpisodeCreationSlugTest()
|
||||
{
|
||||
Episode episode = await _repository.Create(new Episode
|
||||
{
|
||||
ShowId = TestSample.Get<Show>().Id,
|
||||
SeasonNumber = 2,
|
||||
EpisodeNumber = 4
|
||||
});
|
||||
Episode model = TestSample.Get<Episode>();
|
||||
model.Id = 0;
|
||||
model.ShowId = TestSample.Get<Show>().Id;
|
||||
model.SeasonNumber = 2;
|
||||
model.EpisodeNumber = 4;
|
||||
Episode episode = await _repository.Create(model);
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2e4", episode.Slug);
|
||||
}
|
||||
|
||||
@ -127,12 +124,11 @@ namespace Kyoo.Tests.Database
|
||||
public async Task SlugEditAbsoluteTest()
|
||||
{
|
||||
Episode episode = await _repository.Create(TestSample.GetAbsoluteEpisode());
|
||||
Show show = new()
|
||||
await Repositories.LibraryManager.ShowRepository.Patch(episode.ShowId, (x) =>
|
||||
{
|
||||
Id = episode.ShowId,
|
||||
Slug = "new-slug"
|
||||
};
|
||||
await Repositories.LibraryManager.ShowRepository.Edit(show);
|
||||
x.Slug = "new-slug";
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
episode = await _repository.Get(2);
|
||||
Assert.Equal($"new-slug-3", episode.Slug);
|
||||
}
|
||||
@ -141,11 +137,10 @@ namespace Kyoo.Tests.Database
|
||||
public async Task AbsoluteNumberEditTest()
|
||||
{
|
||||
await _repository.Create(TestSample.GetAbsoluteEpisode());
|
||||
Episode episode = await _repository.Edit(new Episode
|
||||
Episode episode = await _repository.Patch(2, (x) =>
|
||||
{
|
||||
Id = 2,
|
||||
AbsoluteNumber = 56,
|
||||
ShowId = 1
|
||||
x.AbsoluteNumber = 56;
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-56", episode.Slug);
|
||||
episode = await _repository.Get(2);
|
||||
@ -156,12 +151,11 @@ namespace Kyoo.Tests.Database
|
||||
public async Task AbsoluteToNormalEditTest()
|
||||
{
|
||||
await _repository.Create(TestSample.GetAbsoluteEpisode());
|
||||
Episode episode = await _repository.Edit(new Episode
|
||||
Episode episode = await _repository.Patch(2, (x) =>
|
||||
{
|
||||
Id = 2,
|
||||
SeasonNumber = 1,
|
||||
EpisodeNumber = 2,
|
||||
ShowId = 1
|
||||
x.SeasonNumber = 1;
|
||||
x.EpisodeNumber = 2;
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s1e2", episode.Slug);
|
||||
episode = await _repository.Get(2);
|
||||
@ -283,12 +277,10 @@ namespace Kyoo.Tests.Database
|
||||
[InlineData("SuPeR")]
|
||||
public async Task SearchTest(string query)
|
||||
{
|
||||
Episode value = new()
|
||||
{
|
||||
Name = "This is a test super title",
|
||||
ShowId = 1,
|
||||
AbsoluteNumber = 2
|
||||
};
|
||||
Episode value = TestSample.Get<Episode>();
|
||||
value.Id = 0;
|
||||
value.Name = "This is a test super title";
|
||||
value.EpisodeNumber = 56;
|
||||
await _repository.Create(value);
|
||||
ICollection<Episode> ret = await _repository.Search(query);
|
||||
value.Show = TestSample.Get<Show>();
|
||||
|
@ -53,12 +53,11 @@ namespace Kyoo.Tests.Database
|
||||
{
|
||||
Season season = await _repository.Get(1);
|
||||
Assert.Equal("anohana-s1", season.Slug);
|
||||
Show show = new()
|
||||
await Repositories.LibraryManager.ShowRepository.Patch(season.ShowId, (x) =>
|
||||
{
|
||||
Id = season.ShowId,
|
||||
Slug = "new-slug"
|
||||
};
|
||||
await Repositories.LibraryManager.ShowRepository.Edit(show);
|
||||
x.Slug = "new-slug";
|
||||
return Task.FromResult(true);
|
||||
});
|
||||
season = await _repository.Get(1);
|
||||
Assert.Equal("new-slug-s1", season.Slug);
|
||||
}
|
||||
@ -68,12 +67,12 @@ namespace Kyoo.Tests.Database
|
||||
{
|
||||
Season season = await _repository.Get(1);
|
||||
Assert.Equal("anohana-s1", season.Slug);
|
||||
await _repository.Edit(new Season
|
||||
await _repository.Patch(season.Id, (x) =>
|
||||
{
|
||||
Id = 1,
|
||||
SeasonNumber = 2,
|
||||
ShowId = 1
|
||||
});
|
||||
x.SeasonNumber = 2;
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
);
|
||||
season = await _repository.Get(1);
|
||||
Assert.Equal("anohana-s2", season.Slug);
|
||||
}
|
||||
|
@ -75,9 +75,7 @@ namespace Kyoo.Tests.Database
|
||||
Assert.Equal(value.Genres, edited.Genres);
|
||||
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
Show show = await database.Shows
|
||||
.Include(x => x.Genres)
|
||||
.FirstAsync();
|
||||
Show show = await database.Shows.FirstAsync();
|
||||
|
||||
Assert.Equal(value.Slug, show.Slug);
|
||||
Assert.Equal(value.Genres, show.Genres);
|
||||
@ -94,9 +92,7 @@ namespace Kyoo.Tests.Database
|
||||
Assert.Equal(value.Genres, edited.Genres);
|
||||
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
Show show = await database.Shows
|
||||
.Include(x => x.Genres)
|
||||
.FirstAsync();
|
||||
Show show = await database.Shows.FirstAsync();
|
||||
|
||||
Assert.Equal(value.Slug, show.Slug);
|
||||
Assert.Equal(value.Genres, show.Genres);
|
||||
@ -113,9 +109,7 @@ namespace Kyoo.Tests.Database
|
||||
Assert.Equal("studio", edited.Studio!.Slug);
|
||||
|
||||
await using DatabaseContext database = Repositories.Context.New();
|
||||
Show show = await database.Shows
|
||||
.Include(x => x.Studio)
|
||||
.FirstAsync();
|
||||
Show show = await database.Shows.Include(x => x.Studio).FirstAsync();
|
||||
|
||||
Assert.Equal(value.Slug, show.Slug);
|
||||
Assert.Equal("studio", show.Studio!.Slug);
|
||||
@ -187,13 +181,13 @@ namespace Kyoo.Tests.Database
|
||||
Show edited = await _repository.Edit(value);
|
||||
|
||||
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();
|
||||
Show show = await database.Shows.FirstAsync();
|
||||
|
||||
Assert.Equal(value.Slug, show.Slug);
|
||||
Assert.Equal(value.ExternalId, show.ExternalId);
|
||||
KAssert.DeepEqual(value.ExternalId, show.ExternalId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@ -227,8 +221,6 @@ namespace Kyoo.Tests.Database
|
||||
|
||||
await using DatabaseContext context = Repositories.Context.New();
|
||||
Show retrieved = await context.Shows
|
||||
.Include(x => x.ExternalId)
|
||||
.Include(x => x.Genres)
|
||||
.Include(x => x.People)
|
||||
.ThenInclude(x => x.People)
|
||||
.Include(x => x.Studio)
|
||||
@ -264,9 +256,7 @@ namespace Kyoo.Tests.Database
|
||||
Show created = await _repository.Create(expected);
|
||||
KAssert.DeepEqual(expected, created);
|
||||
await using DatabaseContext context = Repositories.Context.New();
|
||||
Show retrieved = await context.Shows
|
||||
.Include(x => x.ExternalId)
|
||||
.FirstAsync(x => x.Id == created.Id);
|
||||
Show retrieved = await context.Shows.FirstAsync(x => x.Id == created.Id);
|
||||
KAssert.DeepEqual(expected, retrieved);
|
||||
Assert.Single(retrieved.ExternalId);
|
||||
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 port = Environment.GetEnvironmentVariable("POSTGRES_PORT") ?? "5432";
|
||||
string username = Environment.GetEnvironmentVariable("POSTGRES_USER") ?? "kyoo";
|
||||
string password = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "kyooPassword";
|
||||
string username = Environment.GetEnvironmentVariable("POSTGRES_USER") ?? "KyooUser";
|
||||
string password = Environment.GetEnvironmentVariable("POSTGRES_PASSWORD") ?? "KyooPassword";
|
||||
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 };
|
||||
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>();
|
||||
Assert.Throws<ArgumentException>(() => list.IfEmpty(() => throw new ArgumentException()).ToList());
|
||||
Assert.Empty(list.IfEmpty(() => { }));
|
||||
|
@ -31,12 +31,12 @@ namespace Kyoo.Tests.Utility
|
||||
{
|
||||
Studio genre = new()
|
||||
{
|
||||
Id = 5,
|
||||
Name = "merged"
|
||||
};
|
||||
Studio genre2 = new()
|
||||
{
|
||||
Name = "test"
|
||||
Name = "test",
|
||||
Id = 5,
|
||||
};
|
||||
Studio ret = Merger.Complete(genre, genre2);
|
||||
Assert.True(ReferenceEquals(genre, ret));
|
||||
@ -50,11 +50,11 @@ namespace Kyoo.Tests.Utility
|
||||
{
|
||||
Collection collection = new()
|
||||
{
|
||||
Id = 5,
|
||||
Name = "merged",
|
||||
};
|
||||
Collection collection2 = new()
|
||||
{
|
||||
Id = 5,
|
||||
Name = "test",
|
||||
};
|
||||
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, object>> memberCast = x => x.Id;
|
||||
|
||||
Assert.Equal("ID", KUtility.GetPropertyName(member));
|
||||
Assert.Equal("ID", KUtility.GetPropertyName(memberCast));
|
||||
Assert.Equal("Id", KUtility.GetPropertyName(member));
|
||||
Assert.Equal("Id", KUtility.GetPropertyName(memberCast));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
Loading…
x
Reference in New Issue
Block a user