Adding failing tests for tracks

This commit is contained in:
Zoe Roux 2021-06-29 23:51:12 +02:00
parent 27f2751bd0
commit 6bd7b47fd9
4 changed files with 63 additions and 1 deletions

View File

@ -0,0 +1,38 @@
using Kyoo.Controllers;
using Kyoo.Models;
using Xunit;
using Xunit.Abstractions;
namespace Kyoo.Tests.Library
{
namespace SqLite
{
public class TrackTests : ATrackTests
{
public TrackTests(ITestOutputHelper output)
: base(new RepositoryActivator(output)) { }
}
}
namespace PostgreSQL
{
[Collection(nameof(Postgresql))]
public class TrackTests : ATrackTests
{
public TrackTests(PostgresFixture postgres, ITestOutputHelper output)
: base(new RepositoryActivator(output, postgres)) { }
}
}
public abstract class ATrackTests : RepositoryTests<Track>
{
private readonly ITrackRepository _repository;
protected ATrackTests(RepositoryActivator repositories)
: base(repositories)
{
_repository = repositories.LibraryManager.TrackRepository;
}
}
}

View File

@ -88,6 +88,24 @@ namespace Kyoo.Tests
ReleaseDate = new DateTime(2020, 06, 05) ReleaseDate = new DateTime(2020, 06, 05)
} }
}, },
{
typeof(Track),
() => new Track
{
ID = 1,
EpisodeID = 1,
Codec = "subrip",
Language = "eng",
Path = "/path",
Title = "Subtitle track",
Type = StreamType.Subtitle,
EpisodeSlug = Get<Episode>().Slug,
IsDefault = true,
IsExternal = false,
IsForced = false,
TrackIndex = 1
}
},
{ {
typeof(People), typeof(People),
() => new People () => new People
@ -133,6 +151,12 @@ namespace Kyoo.Tests
episode.SeasonID = 0; episode.SeasonID = 0;
episode.Season = season; episode.Season = season;
context.Episodes.Add(episode); context.Episodes.Add(episode);
Track track = Get<Track>();
track.ID = 0;
track.EpisodeID = 0;
track.Episode = episode;
context.Tracks.Add(track);
context.SaveChanges(); context.SaveChanges();
} }

View File

@ -127,7 +127,7 @@ namespace Kyoo.Controllers
if (changed.Tracks != null || resetOld) if (changed.Tracks != null || resetOld)
{ {
await _tracks.DeleteAll(x => x.EpisodeID == resource.ID); await Database.Entry(resource).Collection(x => x.Tracks).LoadAsync();
resource.Tracks = changed.Tracks; resource.Tracks = changed.Tracks;
await ValidateTracks(resource); await ValidateTracks(resource);
} }