Fixing tests

This commit is contained in:
Zoe Roux 2021-07-31 01:22:46 +02:00
parent 756bfa762c
commit 47f855bdb9
14 changed files with 49 additions and 100 deletions

View File

@ -16,8 +16,6 @@
<IncludeSymbols>true</IncludeSymbols>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<LangVersion>default</LangVersion>
<!-- <DefineConstants>ENABLE_INTERNAL_LINKS</DefineConstants>-->
</PropertyGroup>
<ItemGroup>

View File

@ -1,13 +0,0 @@
using System;
using JetBrains.Annotations;
using Kyoo.Models.Attributes;
namespace Kyoo.Common.Models.Attributes
{
/// <summary>
/// An attribute to mark Link properties on resource.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
[MeansImplicitUse]
public class LinkAttribute : SerializeIgnoreAttribute { }
}

View File

@ -17,8 +17,8 @@ namespace Kyoo.Models
public string Slug => ForPeople ? Show.Slug : People.Slug;
/// <summary>
/// Should this role be used as a Show substitute (the value is <c>false</c>) or
/// as a People substitute (the value is <c>true</c>).
/// Should this role be used as a Show substitute (the value is <c>true</c>) or
/// as a People substitute (the value is <c>false</c>).
/// </summary>
public bool ForPeople { get; set; }

View File

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Kyoo.Common.Models.Attributes;
using System;
using System.Collections.Generic;
using Kyoo.Models.Attributes;
namespace Kyoo.Models
@ -30,6 +30,7 @@ namespace Kyoo.Models
/// This can be disabled using the internal query flag.
/// </summary>
[SerializeAs("{HOST}/api/collection/{Slug}/poster")]
[Obsolete("Use Images instead of this, this is only kept for the API response.")]
public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster);
/// <summary>
@ -49,18 +50,5 @@ namespace Kyoo.Models
/// <inheritdoc />
[EditableRelation] [LoadableRelation] public ICollection<MetadataID> ExternalIDs { get; set; }
#if ENABLE_INTERNAL_LINKS
/// <summary>
/// The internal link between this collection and shows in the <see cref="Shows"/> list.
/// </summary>
[Link] public ICollection<Link<Collection, Show>> ShowLinks { get; set; }
/// <summary>
/// The internal link between this collection and libraries in the <see cref="Libraries"/> list.
/// </summary>
[Link] public ICollection<Link<Library, Collection>> LibraryLinks { get; set; }
#endif
}
}

View File

@ -74,9 +74,13 @@ namespace Kyoo.Models
/// </summary>
[SerializeIgnore] public int? SeasonID { get; set; }
/// <summary>
/// The season that contains this episode. This must be explicitly loaded via a call to <see cref="ILibraryManager.Load"/>.
/// This can be null if the season is unknown and the episode is only identified by it's <see cref="AbsoluteNumber"/>.
/// The season that contains this episode.
/// This must be explicitly loaded via a call to <see cref="ILibraryManager.Load"/>.
/// </summary>
/// <remarks>
/// This can be null if the season is unknown and the episode is only identified
/// by it's <see cref="AbsoluteNumber"/>.
/// </remarks>
[LoadableRelation(nameof(SeasonID))] public Season Season { get; set; }
/// <summary>
@ -108,6 +112,7 @@ namespace Kyoo.Models
/// This can be disabled using the internal query flag.
/// </summary>
[SerializeAs("{HOST}/api/episodes/{Slug}/thumb")]
[Obsolete("Use Images instead of this, this is only kept for the API response.")]
public string Thumb => Images?.GetValueOrDefault(Thumbnails.Thumbnail);
/// <summary>

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using Kyoo.Common.Models.Attributes;
using Kyoo.Models.Attributes;
namespace Kyoo.Models
@ -25,13 +24,6 @@ namespace Kyoo.Models
/// </summary>
[LoadableRelation] public ICollection<Show> Shows { get; set; }
#if ENABLE_INTERNAL_LINKS
/// <summary>
/// The internal link between this genre and shows in the <see cref="Shows"/> list.
/// </summary>
[Link] public ICollection<Link<Show, Genre>> ShowLinks { get; set; }
#endif
/// <summary>
/// Create a new, empty <see cref="Genre"/>.
/// </summary>

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using Kyoo.Common.Models.Attributes;
using Kyoo.Models.Attributes;
namespace Kyoo.Models
@ -39,22 +38,5 @@ namespace Kyoo.Models
/// The list of collections in this library.
/// </summary>
[LoadableRelation] public ICollection<Collection> Collections { get; set; }
#if ENABLE_INTERNAL_LINKS
/// <summary>
/// The internal link between this library and provider in the <see cref="Providers"/> list.
/// </summary>
[Link] public ICollection<Link<Library, Provider>> ProviderLinks { get; set; }
/// <summary>
/// The internal link between this library and shows in the <see cref="Shows"/> list.
/// </summary>
[Link] public ICollection<Link<Library, Show>> ShowLinks { get; set; }
/// <summary>
/// The internal link between this library and collection in the <see cref="Collections"/> list.
/// </summary>
[Link] public ICollection<Link<Library, Collection>> CollectionLinks { get; set; }
#endif
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using Kyoo.Models.Attributes;
namespace Kyoo.Models
@ -28,6 +29,7 @@ namespace Kyoo.Models
/// This can be disabled using the internal query flag.
/// </summary>
[SerializeAs("{HOST}/api/people/{Slug}/poster")]
[Obsolete("Use Images instead of this, this is only kept for the API response.")]
public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster);
/// <inheritdoc />

View File

@ -1,5 +1,5 @@
using System;
using System.Collections.Generic;
using Kyoo.Common.Models.Attributes;
using Kyoo.Controllers;
using Kyoo.Models.Attributes;
@ -31,6 +31,7 @@ namespace Kyoo.Models
/// This can be disabled using the internal query flag.
/// </summary>
[SerializeAs("{HOST}/api/providers/{Slug}/logo")]
[Obsolete("Use Images instead of this, this is only kept for the API response.")]
public string Logo => Images?.GetValueOrDefault(Thumbnails.Logo);
/// <summary>
@ -38,13 +39,6 @@ namespace Kyoo.Models
/// </summary>
[LoadableRelation] public ICollection<Library> Libraries { get; set; }
#if ENABLE_INTERNAL_LINKS
/// <summary>
/// The internal link between this provider and libraries in the <see cref="Libraries"/> list.
/// </summary>
[Link] public ICollection<Link<Library, Provider>> LibraryLinks { get; set; }
#endif
/// <summary>
/// Create a new, default, <see cref="Provider"/>
/// </summary>

View File

@ -45,7 +45,8 @@ namespace Kyoo.Models
/// </summary>
[SerializeIgnore] public int ShowID { get; set; }
/// <summary>
/// The show that contains this season. This must be explicitly loaded via a call to <see cref="ILibraryManager.Load"/>.
/// The show that contains this season.
/// This must be explicitly loaded via a call to <see cref="ILibraryManager.Load"/>.
/// </summary>
[LoadableRelation(nameof(ShowID))] public Show Show { get; set; }
@ -83,6 +84,7 @@ namespace Kyoo.Models
/// This can be disabled using the internal query flag.
/// </summary>
[SerializeAs("{HOST}/api/seasons/{Slug}/thumb")]
[Obsolete("Use Images instead of this, this is only kept for the API response.")]
public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster);
/// <inheritdoc />

View File

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Kyoo.Common.Models.Attributes;
using Kyoo.Controllers;
using Kyoo.Models.Attributes;
@ -47,6 +46,7 @@ namespace Kyoo.Models
/// An URL to a trailer. This could be any path supported by the <see cref="IFileSystem"/>.
/// </summary>
/// TODO for now, this is set to a youtube url. It should be cached and converted to a local file.
[Obsolete("Use Images instead of this, this is only kept for the API response.")]
public string TrailerUrl => Images?.GetValueOrDefault(Thumbnails.Trailer);
/// <summary>
@ -70,6 +70,7 @@ namespace Kyoo.Models
/// This can be disabled using the internal query flag.
/// </summary>
[SerializeAs("{HOST}/api/shows/{Slug}/poster")]
[Obsolete("Use Images instead of this, this is only kept for the API response.")]
public string Poster => Images?.GetValueOrDefault(Thumbnails.Poster);
/// <summary>
@ -78,6 +79,7 @@ namespace Kyoo.Models
/// This can be disabled using the internal query flag.
/// </summary>
[SerializeAs("{HOST}/api/shows/{Slug}/logo")]
[Obsolete("Use Images instead of this, this is only kept for the API response.")]
public string Logo => Images?.GetValueOrDefault(Thumbnails.Logo);
/// <summary>
@ -86,6 +88,7 @@ namespace Kyoo.Models
/// This can be disabled using the internal query flag.
/// </summary>
[SerializeAs("{HOST}/api/shows/{Slug}/backdrop")]
[Obsolete("Use Images instead of this, this is only kept for the API response.")]
public string Backdrop => Images?.GetValueOrDefault(Thumbnails.Thumbnail);
/// <summary>
@ -101,7 +104,8 @@ namespace Kyoo.Models
/// </summary>
[SerializeIgnore] public int? StudioID { get; set; }
/// <summary>
/// The Studio that made this show. This must be explicitly loaded via a call to <see cref="ILibraryManager.Load"/>.
/// The Studio that made this show.
/// This must be explicitly loaded via a call to <see cref="ILibraryManager.Load"/>.
/// </summary>
[LoadableRelation(nameof(StudioID))] [EditableRelation] public Studio Studio { get; set; }
@ -137,23 +141,6 @@ namespace Kyoo.Models
/// </summary>
[LoadableRelation] public ICollection<Collection> Collections { get; set; }
#if ENABLE_INTERNAL_LINKS
/// <summary>
/// The internal link between this show and libraries in the <see cref="Libraries"/> list.
/// </summary>
[Link] public ICollection<Link<Library, Show>> LibraryLinks { get; set; }
/// <summary>
/// The internal link between this show and collections in the <see cref="Collections"/> list.
/// </summary>
[Link] public ICollection<Link<Collection, Show>> CollectionLinks { get; set; }
/// <summary>
/// The internal link between this show and genres in the <see cref="Genres"/> list.
/// </summary>
[Link] public ICollection<Link<Show, Genre>> GenreLinks { get; set; }
#endif
/// <inheritdoc />
public void OnMerge(object merged)
{

View File

@ -1,5 +1,4 @@
using System.Collections.Generic;
using Kyoo.Common.Models.Attributes;
namespace Kyoo.Models
{
@ -51,13 +50,6 @@ namespace Kyoo.Models
/// The list of episodes the user is watching (stopped in progress or the next episode of the show)
/// </summary>
public ICollection<WatchedEpisode> CurrentlyWatching { get; set; }
#if ENABLE_INTERNAL_LINKS
/// <summary>
/// Links between Users and Shows.
/// </summary>
[Link] public ICollection<Link<User, Show>> ShowLinks { get; set; }
#endif
}
/// <summary>

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using FluentAssertions;
using Kyoo.Controllers;
using Kyoo.Models;
using Microsoft.EntityFrameworkCore;
@ -243,9 +244,25 @@ namespace Kyoo.Tests.Database
.ThenInclude(x => x.Provider)
.Include(x => x.Genres)
.Include(x => x.People)
.ThenInclude(x => x.People)
.Include(x => x.Studio)
.FirstAsync(x => x.ID == created.ID);
KAssert.DeepEqual(expected, retrieved);
retrieved.People.ForEach(x =>
{
x.Show = null;
x.People.Roles = null;
});
retrieved.Studio.Shows = null;
retrieved.Genres.ForEach(x => x.Shows = null);
expected.Genres.ForEach(x => x.Shows = null);
expected.People.ForEach(x =>
{
x.Show = null;
x.People.Roles = null;
});
retrieved.Should().BeEquivalentTo(expected);
}
[Fact]

View File

@ -89,7 +89,10 @@ namespace Kyoo.Controllers
{
await base.Validate(resource);
if (resource.Studio != null)
{
resource.Studio = await _studios.CreateIfNotExists(resource.Studio);
resource.StudioID = resource.Studio.ID;
}
if (resource.Genres != null)
{