mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
SeasonsRepository: Adding creation/edits tests
This commit is contained in:
parent
c0b83d2d58
commit
1472ff1cfa
@ -1,6 +1,9 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Kyoo.Controllers;
|
using Kyoo.Controllers;
|
||||||
using Kyoo.Models;
|
using Kyoo.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
|
|
||||||
@ -75,5 +78,135 @@ namespace Kyoo.Tests.Database
|
|||||||
});
|
});
|
||||||
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2", season.Slug);
|
Assert.Equal($"{TestSample.Get<Show>().Slug}-s2", season.Slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task CreateWithExternalIdTest()
|
||||||
|
{
|
||||||
|
Season season = TestSample.GetNew<Season>();
|
||||||
|
season.ExternalIDs = new[]
|
||||||
|
{
|
||||||
|
new MetadataID
|
||||||
|
{
|
||||||
|
Provider = TestSample.Get<Provider>(),
|
||||||
|
Link = "link",
|
||||||
|
DataID = "id"
|
||||||
|
},
|
||||||
|
new MetadataID
|
||||||
|
{
|
||||||
|
Provider = TestSample.GetNew<Provider>(),
|
||||||
|
Link = "new-provider-link",
|
||||||
|
DataID = "new-id"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
await _repository.Create(season);
|
||||||
|
|
||||||
|
Season retrieved = await _repository.Get(2);
|
||||||
|
await Repositories.LibraryManager.Load(retrieved, x => x.ExternalIDs);
|
||||||
|
Assert.Equal(2, retrieved.ExternalIDs.Count);
|
||||||
|
KAssert.DeepEqual(season.ExternalIDs.First(), retrieved.ExternalIDs.First());
|
||||||
|
KAssert.DeepEqual(season.ExternalIDs.Last(), retrieved.ExternalIDs.Last());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task EditTest()
|
||||||
|
{
|
||||||
|
Season value = await _repository.Get(TestSample.Get<Season>().Slug);
|
||||||
|
value.Title = "New Title";
|
||||||
|
value.Images = new Dictionary<int, string>
|
||||||
|
{
|
||||||
|
[Images.Poster] = "new-poster"
|
||||||
|
};
|
||||||
|
await _repository.Edit(value, false);
|
||||||
|
|
||||||
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
|
Season retrieved = await database.Seasons.FirstAsync();
|
||||||
|
|
||||||
|
KAssert.DeepEqual(value, retrieved);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task EditMetadataTest()
|
||||||
|
{
|
||||||
|
Season value = await _repository.Get(TestSample.Get<Season>().Slug);
|
||||||
|
value.ExternalIDs = new[]
|
||||||
|
{
|
||||||
|
new MetadataID
|
||||||
|
{
|
||||||
|
Provider = TestSample.Get<Provider>(),
|
||||||
|
Link = "link",
|
||||||
|
DataID = "id"
|
||||||
|
},
|
||||||
|
};
|
||||||
|
await _repository.Edit(value, false);
|
||||||
|
|
||||||
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
|
Season retrieved = await database.Seasons
|
||||||
|
.Include(x => x.ExternalIDs)
|
||||||
|
.ThenInclude(x => x.Provider)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
KAssert.DeepEqual(value, retrieved);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task AddMetadataTest()
|
||||||
|
{
|
||||||
|
Season value = await _repository.Get(TestSample.Get<Season>().Slug);
|
||||||
|
value.ExternalIDs = new List<MetadataID>
|
||||||
|
{
|
||||||
|
new()
|
||||||
|
{
|
||||||
|
Provider = TestSample.Get<Provider>(),
|
||||||
|
Link = "link",
|
||||||
|
DataID = "id"
|
||||||
|
},
|
||||||
|
};
|
||||||
|
await _repository.Edit(value, false);
|
||||||
|
|
||||||
|
{
|
||||||
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
|
Season retrieved = await database.Seasons
|
||||||
|
.Include(x => x.ExternalIDs)
|
||||||
|
.ThenInclude(x => x.Provider)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
KAssert.DeepEqual(value, retrieved);
|
||||||
|
}
|
||||||
|
|
||||||
|
value.ExternalIDs.Add(new MetadataID
|
||||||
|
{
|
||||||
|
Provider = TestSample.GetNew<Provider>(),
|
||||||
|
Link = "link",
|
||||||
|
DataID = "id"
|
||||||
|
});
|
||||||
|
await _repository.Edit(value, false);
|
||||||
|
|
||||||
|
{
|
||||||
|
await using DatabaseContext database = Repositories.Context.New();
|
||||||
|
Season retrieved = await database.Seasons
|
||||||
|
.Include(x => x.ExternalIDs)
|
||||||
|
.ThenInclude(x => x.Provider)
|
||||||
|
.FirstAsync();
|
||||||
|
|
||||||
|
KAssert.DeepEqual(value, retrieved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("test")]
|
||||||
|
[InlineData("super")]
|
||||||
|
[InlineData("title")]
|
||||||
|
[InlineData("TiTlE")]
|
||||||
|
[InlineData("SuPeR")]
|
||||||
|
public async Task SearchTest(string query)
|
||||||
|
{
|
||||||
|
Season value = new()
|
||||||
|
{
|
||||||
|
Title = "This is a test super title",
|
||||||
|
};
|
||||||
|
await _repository.Create(value);
|
||||||
|
ICollection<Season> ret = await _repository.Search(query);
|
||||||
|
KAssert.DeepEqual(value, ret.First());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -53,6 +53,24 @@ namespace Kyoo.Tests
|
|||||||
Studio = null
|
Studio = null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
typeof(Season),
|
||||||
|
() => new Season
|
||||||
|
{
|
||||||
|
ID = 2,
|
||||||
|
ShowID = 1,
|
||||||
|
ShowSlug = Get<Show>().Slug,
|
||||||
|
Title = "New season",
|
||||||
|
Overview = "New overview",
|
||||||
|
EndDate = new DateTime(2000, 10, 10),
|
||||||
|
SeasonNumber = 2,
|
||||||
|
StartDate = new DateTime(2010, 10, 10),
|
||||||
|
Images = new Dictionary<int, string>
|
||||||
|
{
|
||||||
|
[Images.Logo] = "logo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
typeof(Provider),
|
typeof(Provider),
|
||||||
() => new Provider
|
() => new Provider
|
||||||
|
Loading…
x
Reference in New Issue
Block a user