- ScheduleController GET/POST/PUT items now assert flat ScheduleItemResponseModel shapes - LanguagesControllerTests (route + VM->DTO mapping) - ChannelController tests for music-video-credits-templates + stream-selectors literal routes - FillerPreset controller/handler tests for FillerKind field + ?fillerKind= filter Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using System.Reflection;
|
||||
using System.Threading.Channels;
|
||||
using ErsatzTV.Application;
|
||||
using ErsatzTV.Application.Artworks;
|
||||
using ErsatzTV.Application.Channels;
|
||||
using ErsatzTV.Application.Templates;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using ErsatzTV.Application.Playouts;
|
||||
using ErsatzTV.Controllers.Api;
|
||||
using ErsatzTV.Controllers.Api.Requests;
|
||||
@@ -56,6 +59,40 @@ public class ChannelControllerTests
|
||||
result.ShouldBe(new List<ChannelStateResponseModel> { state });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MusicVideoCreditsTemplates_And_StreamSelectors_Routes_Are_Literal_And_Precede_Id()
|
||||
{
|
||||
MethodInfo mvct = typeof(ChannelController).GetMethod(nameof(ChannelController.GetMusicVideoCreditsTemplates))!;
|
||||
mvct.GetCustomAttributes<HttpMethodAttribute>(inherit: true).Single().Template
|
||||
.ShouldBe("/api/channels/music-video-credits-templates");
|
||||
|
||||
MethodInfo selectors = typeof(ChannelController).GetMethod(nameof(ChannelController.GetStreamSelectors))!;
|
||||
selectors.GetCustomAttributes<HttpMethodAttribute>(inherit: true).Single().Template
|
||||
.ShouldBe("/api/channels/stream-selectors");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetMusicVideoCreditsTemplates_Should_Return_Names()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetMusicVideoCreditTemplates>(), Arg.Any<CancellationToken>())
|
||||
.Returns(["Default", "Scroll"]);
|
||||
|
||||
List<string> result = await _controller.GetMusicVideoCreditsTemplates(CancellationToken.None);
|
||||
|
||||
result.ShouldBe(["Default", "Scroll"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetStreamSelectors_Should_Return_Names()
|
||||
{
|
||||
_mediator.Send(Arg.Any<GetChannelStreamSelectors>(), Arg.Any<CancellationToken>())
|
||||
.Returns(["selector-a.yml"]);
|
||||
|
||||
List<string> result = await _controller.GetStreamSelectors(CancellationToken.None);
|
||||
|
||||
result.ShouldBe(["selector-a.yml"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Create_Should_Return_201_With_Location_And_Body()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Reflection;
|
||||
using ErsatzTV.Application.MediaItems;
|
||||
using ErsatzTV.Controllers.Api;
|
||||
using ErsatzTV.Core.Api.MediaItems;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
using NSubstitute;
|
||||
using NUnit.Framework;
|
||||
using Shouldly;
|
||||
|
||||
namespace ErsatzTV.Tests.Controllers;
|
||||
|
||||
[TestFixture]
|
||||
public class LanguagesControllerTests
|
||||
{
|
||||
private LanguagesController _controller = null!;
|
||||
private IMediator _mediator = null!;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_mediator = Substitute.For<IMediator>();
|
||||
_controller = new LanguagesController(_mediator);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Controller_Should_Expose_Idiomatic_Rest_Route()
|
||||
{
|
||||
MethodInfo action = typeof(LanguagesController).GetMethod(nameof(LanguagesController.GetLanguages))!;
|
||||
HttpMethodAttribute attribute = action.GetCustomAttributes<HttpMethodAttribute>(inherit: true).Single();
|
||||
attribute.HttpMethods.ShouldContain("GET");
|
||||
attribute.Template.ShouldBe("/api/languages");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetLanguages_Should_Map_Vm_To_ResponseModel()
|
||||
{
|
||||
List<LanguageCodeViewModel> vms =
|
||||
[
|
||||
new LanguageCodeViewModel("eng", "English"),
|
||||
new LanguageCodeViewModel("fra", "French")
|
||||
];
|
||||
_mediator.Send(Arg.Any<GetAllLanguageCodes>(), Arg.Any<CancellationToken>())
|
||||
.Returns(vms);
|
||||
|
||||
List<LanguageCodeResponseModel> result = await _controller.GetLanguages(CancellationToken.None);
|
||||
|
||||
result.ShouldBe(
|
||||
[
|
||||
new LanguageCodeResponseModel("eng", "English"),
|
||||
new LanguageCodeResponseModel("fra", "French")
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using ErsatzTV.Application.ProgramSchedules;
|
||||
using ErsatzTV.Controllers.Api;
|
||||
using ErsatzTV.Controllers.Api.Requests;
|
||||
using ErsatzTV.Core;
|
||||
using ErsatzTV.Core.Api.Scheduling;
|
||||
using ErsatzTV.Core.Domain;
|
||||
using ErsatzTV.Core.Errors;
|
||||
using ErsatzTV.Core.Scheduling;
|
||||
@@ -197,7 +199,10 @@ public class ScheduleControllerTests
|
||||
|
||||
IActionResult result = await _controller.GetItems(4, CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<OkObjectResult>().Value.ShouldBe(response);
|
||||
var envelope = result.ShouldBeOfType<OkObjectResult>().Value.ShouldBeOfType<ScheduleItemsResponseModel>();
|
||||
envelope.TotalDurationEstimate.ShouldBe(TimeSpan.FromMinutes(25));
|
||||
envelope.Items.Count.ShouldBe(1);
|
||||
envelope.Items[0].Id.ShouldBe(11);
|
||||
await _mediator.Received(1).Send(
|
||||
Arg.Is<GetProgramScheduleItemsWithDurations>(q => q.Id == 4),
|
||||
Arg.Any<CancellationToken>());
|
||||
@@ -225,7 +230,7 @@ public class ScheduleControllerTests
|
||||
|
||||
var created = result.ShouldBeOfType<CreatedResult>();
|
||||
created.Location.ShouldBe("/api/schedules/4/items/12");
|
||||
created.Value.ShouldBe(item);
|
||||
created.Value.ShouldBeOfType<ScheduleItemResponseModel>().Id.ShouldBe(12);
|
||||
await _mediator.Received(1).Send(
|
||||
Arg.Is<AddProgramScheduleItem>(c => c.ProgramScheduleId == 4 && c.PlayoutMode == PlayoutMode.One),
|
||||
Arg.Any<CancellationToken>());
|
||||
@@ -254,7 +259,9 @@ public class ScheduleControllerTests
|
||||
new ReplaceScheduleItemsRequest([MakeItemRequest(PlayoutMode.One), MakeItemRequest(PlayoutMode.Multiple)]),
|
||||
CancellationToken.None);
|
||||
|
||||
result.ShouldBeOfType<OkObjectResult>().Value.ShouldBe(items);
|
||||
var replaced = result.ShouldBeOfType<OkObjectResult>().Value
|
||||
.ShouldBeOfType<List<ScheduleItemResponseModel>>();
|
||||
replaced.Select(i => i.Id).ShouldBe([21, 22]);
|
||||
await _mediator.Received(1).Send(
|
||||
Arg.Is<ReplaceProgramScheduleItems>(c =>
|
||||
c.ProgramScheduleId == 4 &&
|
||||
|
||||
Reference in New Issue
Block a user