Fixing seasons tests and running tests in parallel

This commit is contained in:
Zoe Roux 2021-06-21 21:59:54 +02:00
parent bd82fbfb2c
commit d7d40aef24
18 changed files with 163 additions and 37 deletions

View File

@ -20,7 +20,7 @@ namespace Kyoo.Models
public string Slug
{
get => GetSlug(ShowSlug, SeasonNumber, EpisodeNumber, AbsoluteNumber);
set
[UsedImplicitly] private set
{
Match match = Regex.Match(value, @"(?<show>.*)-s(?<season>\d*)e(?<episode>\d*)");

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using Kyoo.Controllers;
using Kyoo.Models.Attributes;
@ -18,7 +19,7 @@ namespace Kyoo.Models
public string Slug
{
get => $"{ShowSlug}-s{SeasonNumber}";
set
[UsedImplicitly] private set
{
Match match = Regex.Match(value, @"(?<show>.*)-s(?<season>\d*)");

View File

@ -2,6 +2,7 @@
using System.Globalization;
using System.Linq;
using System.Text.RegularExpressions;
using JetBrains.Annotations;
using Kyoo.Models.Attributes;
namespace Kyoo.Models
@ -48,7 +49,7 @@ namespace Kyoo.Models
};
return $"{EpisodeSlug}.{type}{Language}{index}{(IsForced ? "-forced" : "")}{codec}";
}
set
[UsedImplicitly] private set
{
Match match = Regex.Match(value, @"(?<show>.*)-s(?<season>\d+)e(?<episode>\d+)"
+ @"(\.(?<type>\w*))?\.(?<language>.{0,3})(?<forced>-forced)?(\..\w)?");

View File

@ -302,15 +302,34 @@ namespace Kyoo
modelBuilder.Entity<Season>()
.HasIndex(x => new {x.ShowID, x.SeasonNumber})
.IsUnique();
modelBuilder.Entity<Season>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<Episode>()
.HasIndex(x => new {x.ShowID, x.SeasonNumber, x.EpisodeNumber, x.AbsoluteNumber})
.IsUnique();
modelBuilder.Entity<Episode>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<Track>()
.HasIndex(x => new {x.EpisodeID, x.Type, x.Language, x.TrackIndex, x.IsForced})
.IsUnique();
modelBuilder.Entity<Track>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<User>()
.HasIndex(x => x.Slug)
.IsUnique();
modelBuilder.Entity<Season>()
.Property(x => x.Slug)
.ValueGeneratedOnAddOrUpdate();
modelBuilder.Entity<Episode>()
.Property(x => x.Slug)
.ValueGeneratedOnAddOrUpdate();
modelBuilder.Entity<Track>()
.Property(x => x.Slug)
.ValueGeneratedOnAddOrUpdate();
}
/// <summary>

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Postgresql.Migrations
{
[DbContext(typeof(PostgresContext))]
[Migration("20210619153358_Initial")]
[Migration("20210621175845_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -86,6 +86,7 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("integer");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text");
b.Property<string>("Thumb")
@ -98,6 +99,9 @@ namespace Kyoo.Postgresql.Migrations
b.HasIndex("SeasonID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
.IsUnique();
@ -432,6 +436,7 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("integer");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text");
b.Property<DateTime?>("StartDate")
@ -442,6 +447,9 @@ namespace Kyoo.Postgresql.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber")
.IsUnique();
@ -559,6 +567,7 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("text");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text");
b.Property<string>("Title")
@ -572,6 +581,9 @@ namespace Kyoo.Postgresql.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("EpisodeID", "Type", "Language", "TrackIndex", "IsForced")
.IsUnique();

View File

@ -564,6 +564,12 @@ namespace Kyoo.Postgresql.Migrations
columns: new[] { "ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Episodes_Slug",
table: "Episodes",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Genres_Slug",
table: "Genres",
@ -654,6 +660,12 @@ namespace Kyoo.Postgresql.Migrations
columns: new[] { "ShowID", "SeasonNumber" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Seasons_Slug",
table: "Seasons",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Shows_Slug",
table: "Shows",
@ -677,6 +689,12 @@ namespace Kyoo.Postgresql.Migrations
columns: new[] { "EpisodeID", "Type", "Language", "TrackIndex", "IsForced" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Tracks_Slug",
table: "Tracks",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Users_Slug",
table: "Users",

View File

@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Kyoo.Postgresql.Migrations
{
[DbContext(typeof(PostgresContext))]
[Migration("20210620120239_Triggers")]
[Migration("20210621175855_Triggers")]
partial class Triggers
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -86,6 +86,7 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("integer");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text");
b.Property<string>("Thumb")
@ -98,6 +99,9 @@ namespace Kyoo.Postgresql.Migrations
b.HasIndex("SeasonID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
.IsUnique();
@ -432,6 +436,7 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("integer");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text");
b.Property<DateTime?>("StartDate")
@ -442,6 +447,9 @@ namespace Kyoo.Postgresql.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber")
.IsUnique();
@ -559,6 +567,7 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("text");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text");
b.Property<string>("Title")
@ -572,6 +581,9 @@ namespace Kyoo.Postgresql.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("EpisodeID", "Type", "Language", "TrackIndex", "IsForced")
.IsUnique();

View File

@ -2,10 +2,10 @@
namespace Kyoo.Postgresql.Migrations
{
public partial class Triggers : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
public partial class Triggers : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"
CREATE FUNCTION season_slug_update()
RETURNS TRIGGER
@ -14,13 +14,9 @@ namespace Kyoo.Postgresql.Migrations
BEGIN
NEW.""Slug"" := CONCAT(
(SELECT ""Slug"" FROM ""Shows"" WHERE ""ID"" = NEW.""ShowID""),
NEW.""ShowID"",
OLD.""SeasonNumber"",
NEW.""SeasonNumber"",
'-s',
NEW.""SeasonNumber""
);
NEW.""Poster"" := 'NICE';
RETURN NEW;
END
$$;");
@ -41,17 +37,17 @@ namespace Kyoo.Postgresql.Migrations
END
$$;");
migrationBuilder.Sql(@"
migrationBuilder.Sql(@"
CREATE TRIGGER ""ShowSlug"" AFTER UPDATE OF ""Slug"" ON ""Shows""
FOR EACH ROW EXECUTE PROCEDURE show_slug_update();");
}
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"DROP FUNCTION ""season_slug_update"";");
migrationBuilder.Sql(@"DROP TRIGGER ""SeasonSlug"";");
migrationBuilder.Sql(@"DROP FUNCTION ""show_slug_update"";");
migrationBuilder.Sql(@"DROP TRIGGER ""ShowSlug"";");
}
}
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.Sql(@"DROP FUNCTION ""season_slug_update"";");
migrationBuilder.Sql(@"DROP TRIGGER ""SeasonSlug"";");
migrationBuilder.Sql(@"DROP FUNCTION ""show_slug_update"";");
migrationBuilder.Sql(@"DROP TRIGGER ""ShowSlug"";");
}
}
}

View File

@ -84,6 +84,7 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("integer");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text");
b.Property<string>("Thumb")
@ -96,6 +97,9 @@ namespace Kyoo.Postgresql.Migrations
b.HasIndex("SeasonID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
.IsUnique();
@ -430,6 +434,7 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("integer");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text");
b.Property<DateTime?>("StartDate")
@ -440,6 +445,9 @@ namespace Kyoo.Postgresql.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber")
.IsUnique();
@ -557,6 +565,7 @@ namespace Kyoo.Postgresql.Migrations
.HasColumnType("text");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text");
b.Property<string>("Title")
@ -570,6 +579,9 @@ namespace Kyoo.Postgresql.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("EpisodeID", "Type", "Language", "TrackIndex", "IsForced")
.IsUnique();

View File

@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.SqLite.Migrations
{
[DbContext(typeof(SqLiteContext))]
[Migration("20210619154617_Initial")]
[Migration("20210621175330_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -76,6 +76,7 @@ namespace Kyoo.SqLite.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.Property<string>("Thumb")
@ -88,6 +89,9 @@ namespace Kyoo.SqLite.Migrations
b.HasIndex("SeasonID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
.IsUnique();
@ -416,6 +420,7 @@ namespace Kyoo.SqLite.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.Property<DateTime?>("StartDate")
@ -426,6 +431,9 @@ namespace Kyoo.SqLite.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber")
.IsUnique();
@ -540,6 +548,7 @@ namespace Kyoo.SqLite.Migrations
.HasColumnType("TEXT");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.Property<string>("Title")
@ -553,6 +562,9 @@ namespace Kyoo.SqLite.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("EpisodeID", "Type", "Language", "TrackIndex", "IsForced")
.IsUnique();

View File

@ -556,6 +556,12 @@ namespace Kyoo.SqLite.Migrations
columns: new[] { "ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Episodes_Slug",
table: "Episodes",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Genres_Slug",
table: "Genres",
@ -646,6 +652,12 @@ namespace Kyoo.SqLite.Migrations
columns: new[] { "ShowID", "SeasonNumber" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Seasons_Slug",
table: "Seasons",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Shows_Slug",
table: "Shows",
@ -669,6 +681,12 @@ namespace Kyoo.SqLite.Migrations
columns: new[] { "EpisodeID", "Type", "Language", "TrackIndex", "IsForced" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Tracks_Slug",
table: "Tracks",
column: "Slug",
unique: true);
migrationBuilder.CreateIndex(
name: "IX_Users_Slug",
table: "Users",

View File

@ -9,7 +9,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Kyoo.SqLite.Migrations
{
[DbContext(typeof(SqLiteContext))]
[Migration("20210619154654_Triggers")]
[Migration("20210621175342_Triggers")]
partial class Triggers
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@ -76,6 +76,7 @@ namespace Kyoo.SqLite.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.Property<string>("Thumb")
@ -88,6 +89,9 @@ namespace Kyoo.SqLite.Migrations
b.HasIndex("SeasonID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
.IsUnique();
@ -416,6 +420,7 @@ namespace Kyoo.SqLite.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.Property<DateTime?>("StartDate")
@ -426,6 +431,9 @@ namespace Kyoo.SqLite.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber")
.IsUnique();
@ -540,6 +548,7 @@ namespace Kyoo.SqLite.Migrations
.HasColumnType("TEXT");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.Property<string>("Title")
@ -553,6 +562,9 @@ namespace Kyoo.SqLite.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("EpisodeID", "Type", "Language", "TrackIndex", "IsForced")
.IsUnique();

View File

@ -74,6 +74,7 @@ namespace Kyoo.SqLite.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.Property<string>("Thumb")
@ -86,6 +87,9 @@ namespace Kyoo.SqLite.Migrations
b.HasIndex("SeasonID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber", "EpisodeNumber", "AbsoluteNumber")
.IsUnique();
@ -414,6 +418,7 @@ namespace Kyoo.SqLite.Migrations
.HasColumnType("INTEGER");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.Property<DateTime?>("StartDate")
@ -424,6 +429,9 @@ namespace Kyoo.SqLite.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("ShowID", "SeasonNumber")
.IsUnique();
@ -538,6 +546,7 @@ namespace Kyoo.SqLite.Migrations
.HasColumnType("TEXT");
b.Property<string>("Slug")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT");
b.Property<string>("Title")
@ -551,6 +560,9 @@ namespace Kyoo.SqLite.Migrations
b.HasKey("ID");
b.HasIndex("Slug")
.IsUnique();
b.HasIndex("EpisodeID", "Type", "Language", "TrackIndex", "IsForced")
.IsUnique();

View File

@ -16,6 +16,7 @@
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Xunit.Extensions.Ordering" Version="1.4.5" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>

View File

@ -2,6 +2,7 @@ using System.Threading.Tasks;
using Kyoo.Controllers;
using Kyoo.Models;
using Xunit;
using Xunit.Extensions.Ordering;
namespace Kyoo.Tests.SpecificTests
{
@ -11,9 +12,9 @@ namespace Kyoo.Tests.SpecificTests
: base(new RepositoryActivator())
{ }
}
[Collection(nameof(Postgresql))]
public class PostgresSeasonTests : SeasonTests
public class PostgresSeasonTests : SeasonTests, IAssemblyFixture<PostgresFixture>
{
public PostgresSeasonTests(PostgresFixture postgres)
: base(new RepositoryActivator(postgres))
@ -67,7 +68,6 @@ namespace Kyoo.Tests.SpecificTests
ShowID = TestSample.Get<Show>().ID,
SeasonNumber = 2
});
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2_NICE", season.Slug + "_" + season.Poster);
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2", season.Slug);
}
}

View File

@ -6,6 +6,7 @@ using Kyoo.Controllers;
using Kyoo.Models;
using Microsoft.EntityFrameworkCore;
using Xunit;
using Xunit.Extensions.Ordering;
namespace Kyoo.Tests.SpecificTests
{
@ -16,8 +17,7 @@ namespace Kyoo.Tests.SpecificTests
{ }
}
[Collection(nameof(Postgresql))]
public class PostgresShowTests : ShowTests
public class PostgresShowTests : ShowTests, IAssemblyFixture<PostgresFixture>
{
public PostgresShowTests(PostgresFixture postgres)
: base(new RepositoryActivator(postgres))
@ -283,6 +283,5 @@ namespace Kyoo.Tests.SpecificTests
Assert.Equal(0, await Repositories.LibraryManager.SeasonRepository.GetCount());
Assert.Equal(0, await Repositories.LibraryManager.EpisodeRepository.GetCount());
}
}
}

View File

@ -8,6 +8,8 @@ using Microsoft.Extensions.Logging;
using Npgsql;
using Xunit;
[assembly: TestFramework("Xunit.Extensions.Ordering.TestFramework", "Xunit.Extensions.Ordering")]
namespace Kyoo.Tests
{
public sealed class SqLiteTestContext : TestContext
@ -29,6 +31,9 @@ namespace Kyoo.Tests
_context = new DbContextOptionsBuilder<DatabaseContext>()
.UseSqlite(_connection)
.UseLoggerFactory(LoggerFactory.Create(x => x.AddConsole()))
.EnableSensitiveDataLogging()
.EnableDetailedErrors()
.Options;
using DatabaseContext context = New();
@ -52,10 +57,6 @@ namespace Kyoo.Tests
}
}
[CollectionDefinition(nameof(Postgresql))]
public class PostgresCollection : ICollectionFixture<PostgresFixture>
{}
public sealed class PostgresFixture : IDisposable
{
private readonly DbContextOptions<DatabaseContext> _options;