Update scheduling parameters and refactor channel endpoints: extend HorizonDays to 7 and RetentionDays to 90 in appsettings.json. Consolidate channel-related endpoint logic by removing obsolete files and enhancing the ShowEndpoints with audience and genre management capabilities. Improve error handling and streamline command handlers for channel operations.
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
using TeleWave.Domain.Library;
|
||||
using Xunit;
|
||||
|
||||
namespace TeleWave.Domain.Tests.Library;
|
||||
|
||||
public class CollectionTests
|
||||
{
|
||||
private static IReadOnlyList<Guid> Order(Collection collection) =>
|
||||
collection.Items.OrderBy(i => i.Position).Select(i => i.ShowId).ToList();
|
||||
|
||||
[Fact]
|
||||
public void AddShow_AppendsToEnd()
|
||||
{
|
||||
var collection = Collection.Create("Терминатор");
|
||||
var first = Guid.NewGuid();
|
||||
var second = Guid.NewGuid();
|
||||
|
||||
collection.AddShow(first);
|
||||
collection.AddShow(second);
|
||||
|
||||
Assert.Equal([first, second], Order(collection));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AddShow_Duplicate_ReturnsNull()
|
||||
{
|
||||
var collection = Collection.Create("Терминатор");
|
||||
var showId = Guid.NewGuid();
|
||||
|
||||
collection.AddShow(showId);
|
||||
|
||||
Assert.Null(collection.AddShow(showId));
|
||||
Assert.Single(collection.Items);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveShow_ReturnsFalse_WhenNotPresent()
|
||||
{
|
||||
var collection = Collection.Create("Терминатор");
|
||||
|
||||
Assert.False(collection.RemoveShow(Guid.NewGuid()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reorder_AppliesRequestedOrder()
|
||||
{
|
||||
var collection = Collection.Create("Терминатор");
|
||||
var a = Guid.NewGuid();
|
||||
var b = Guid.NewGuid();
|
||||
var c = Guid.NewGuid();
|
||||
collection.AddShow(a);
|
||||
collection.AddShow(b);
|
||||
collection.AddShow(c);
|
||||
|
||||
collection.Reorder([c, a, b]);
|
||||
|
||||
Assert.Equal([c, a, b], Order(collection));
|
||||
Assert.Equal([0, 1, 2], collection.Items.OrderBy(i => i.Position).Select(i => i.Position));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reorder_KeepsUnmentionedAfterRequested_InOriginalOrder()
|
||||
{
|
||||
var collection = Collection.Create("Терминатор");
|
||||
var a = Guid.NewGuid();
|
||||
var b = Guid.NewGuid();
|
||||
var c = Guid.NewGuid();
|
||||
collection.AddShow(a);
|
||||
collection.AddShow(b);
|
||||
collection.AddShow(c);
|
||||
|
||||
// Перетащили только один элемент — остальные не должны потеряться или перемешаться.
|
||||
collection.Reorder([c]);
|
||||
|
||||
Assert.Equal([c, a, b], Order(collection));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Reorder_IgnoresUnknownShows()
|
||||
{
|
||||
var collection = Collection.Create("Терминатор");
|
||||
var a = Guid.NewGuid();
|
||||
collection.AddShow(a);
|
||||
|
||||
collection.Reorder([Guid.NewGuid(), a]);
|
||||
|
||||
Assert.Equal([a], Order(collection));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RemoveThenAdd_DoesNotReusePosition()
|
||||
{
|
||||
var collection = Collection.Create("Терминатор");
|
||||
var a = Guid.NewGuid();
|
||||
var b = Guid.NewGuid();
|
||||
collection.AddShow(a);
|
||||
collection.AddShow(b);
|
||||
|
||||
collection.RemoveShow(a);
|
||||
var c = Guid.NewGuid();
|
||||
collection.AddShow(c);
|
||||
|
||||
// Новая часть встаёт после существующих, а не занимает освободившийся номер.
|
||||
Assert.Equal([b, c], Order(collection));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
using TeleWave.Domain.Library;
|
||||
using Xunit;
|
||||
|
||||
namespace TeleWave.Domain.Tests.Library;
|
||||
|
||||
public class ShowGenreTests
|
||||
{
|
||||
private static Show NewShow() => Show.Create("A", ShowKind.Series);
|
||||
|
||||
[Fact]
|
||||
public void SetGenres_MarksRequestedPrimary()
|
||||
{
|
||||
var show = NewShow();
|
||||
var action = Guid.NewGuid();
|
||||
var comedy = Guid.NewGuid();
|
||||
|
||||
show.SetGenres([action, comedy], comedy);
|
||||
|
||||
Assert.Equal(2, show.Genres.Count);
|
||||
Assert.Equal(comedy, show.PrimaryGenreId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetGenres_FallsBackToFirst_WhenPrimaryNotInSet()
|
||||
{
|
||||
var show = NewShow();
|
||||
var action = Guid.NewGuid();
|
||||
var comedy = Guid.NewGuid();
|
||||
|
||||
show.SetGenres([action, comedy], Guid.NewGuid());
|
||||
|
||||
// Шоу с жанрами не должно оставаться без основного — иначе список показывал бы прочерк.
|
||||
Assert.Equal(action, show.PrimaryGenreId);
|
||||
Assert.Single(show.Genres, g => g.IsPrimary);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetGenres_DropsDuplicatesAndEmpty()
|
||||
{
|
||||
var show = NewShow();
|
||||
var action = Guid.NewGuid();
|
||||
|
||||
show.SetGenres([action, action, Guid.Empty]);
|
||||
|
||||
Assert.Single(show.Genres);
|
||||
Assert.Equal(action, show.PrimaryGenreId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetGenres_ReplacesPreviousSet()
|
||||
{
|
||||
var show = NewShow();
|
||||
var first = Guid.NewGuid();
|
||||
var second = Guid.NewGuid();
|
||||
|
||||
show.SetGenres([first]);
|
||||
show.SetGenres([second]);
|
||||
|
||||
Assert.Single(show.Genres);
|
||||
Assert.Equal(second, show.PrimaryGenreId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetGenres_Empty_LeavesNoPrimary()
|
||||
{
|
||||
var show = NewShow();
|
||||
show.SetGenres([Guid.NewGuid()]);
|
||||
|
||||
show.SetGenres([]);
|
||||
|
||||
Assert.Empty(show.Genres);
|
||||
Assert.Null(show.PrimaryGenreId);
|
||||
}
|
||||
}
|
||||
|
||||
public class GenreTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData(" Sci-Fi ", "sci-fi")]
|
||||
[InlineData("Action & Adventure", "action & adventure")]
|
||||
[InlineData("БОЕВИК", "боевик")]
|
||||
[InlineData(" ", "")]
|
||||
[InlineData(null, "")]
|
||||
public void Normalize_CollapsesCaseAndSpacing(string? input, string expected) =>
|
||||
Assert.Equal(expected, GenreAlias.Normalize(input));
|
||||
|
||||
[Fact]
|
||||
public void AddAlias_IgnoresDuplicatesRegardlessOfSpelling()
|
||||
{
|
||||
var genre = Genre.Create("Боевик", "action");
|
||||
|
||||
genre.AddAlias("Action");
|
||||
genre.AddAlias(" action ");
|
||||
genre.AddAlias("боевик");
|
||||
|
||||
Assert.Equal(2, genre.Aliases.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReplaceAliases_DropsOldOnes()
|
||||
{
|
||||
var genre = Genre.Create("Боевик", "action");
|
||||
genre.AddAlias("tmdb:28");
|
||||
|
||||
genre.ReplaceAliases(["tmdb:10759"]);
|
||||
|
||||
Assert.Single(genre.Aliases);
|
||||
Assert.Equal("tmdb:10759", genre.Aliases[0].Value);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ProviderKey_BuildsNormalizedPrefixedAlias() =>
|
||||
Assert.Equal("tmdb:28", GenreAlias.ProviderKey("TMDB", "28"));
|
||||
}
|
||||
Reference in New Issue
Block a user