diff --git a/ErsatzTV.Tests/Controllers/ChannelControllerTests.cs b/ErsatzTV.Tests/Controllers/ChannelControllerTests.cs index 9377d2f7c..cb51b7013 100644 --- a/ErsatzTV.Tests/Controllers/ChannelControllerTests.cs +++ b/ErsatzTV.Tests/Controllers/ChannelControllerTests.cs @@ -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 { state }); } + [Test] + public void MusicVideoCreditsTemplates_And_StreamSelectors_Routes_Are_Literal_And_Precede_Id() + { + MethodInfo mvct = typeof(ChannelController).GetMethod(nameof(ChannelController.GetMusicVideoCreditsTemplates))!; + mvct.GetCustomAttributes(inherit: true).Single().Template + .ShouldBe("/api/channels/music-video-credits-templates"); + + MethodInfo selectors = typeof(ChannelController).GetMethod(nameof(ChannelController.GetStreamSelectors))!; + selectors.GetCustomAttributes(inherit: true).Single().Template + .ShouldBe("/api/channels/stream-selectors"); + } + + [Test] + public async Task GetMusicVideoCreditsTemplates_Should_Return_Names() + { + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(["Default", "Scroll"]); + + List result = await _controller.GetMusicVideoCreditsTemplates(CancellationToken.None); + + result.ShouldBe(["Default", "Scroll"]); + } + + [Test] + public async Task GetStreamSelectors_Should_Return_Names() + { + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(["selector-a.yml"]); + + List result = await _controller.GetStreamSelectors(CancellationToken.None); + + result.ShouldBe(["selector-a.yml"]); + } + [Test] public async Task Create_Should_Return_201_With_Location_And_Body() { diff --git a/ErsatzTV.Tests/Controllers/LanguagesControllerTests.cs b/ErsatzTV.Tests/Controllers/LanguagesControllerTests.cs new file mode 100644 index 000000000..3b8536468 --- /dev/null +++ b/ErsatzTV.Tests/Controllers/LanguagesControllerTests.cs @@ -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(); + _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(inherit: true).Single(); + attribute.HttpMethods.ShouldContain("GET"); + attribute.Template.ShouldBe("/api/languages"); + } + + [Test] + public async Task GetLanguages_Should_Map_Vm_To_ResponseModel() + { + List vms = + [ + new LanguageCodeViewModel("eng", "English"), + new LanguageCodeViewModel("fra", "French") + ]; + _mediator.Send(Arg.Any(), Arg.Any()) + .Returns(vms); + + List result = await _controller.GetLanguages(CancellationToken.None); + + result.ShouldBe( + [ + new LanguageCodeResponseModel("eng", "English"), + new LanguageCodeResponseModel("fra", "French") + ]); + } +} diff --git a/ErsatzTV.Tests/Controllers/ScheduleControllerTests.cs b/ErsatzTV.Tests/Controllers/ScheduleControllerTests.cs index 91a19e90c..e09792cc3 100644 --- a/ErsatzTV.Tests/Controllers/ScheduleControllerTests.cs +++ b/ErsatzTV.Tests/Controllers/ScheduleControllerTests.cs @@ -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().Value.ShouldBe(response); + var envelope = result.ShouldBeOfType().Value.ShouldBeOfType(); + envelope.TotalDurationEstimate.ShouldBe(TimeSpan.FromMinutes(25)); + envelope.Items.Count.ShouldBe(1); + envelope.Items[0].Id.ShouldBe(11); await _mediator.Received(1).Send( Arg.Is(q => q.Id == 4), Arg.Any()); @@ -225,7 +230,7 @@ public class ScheduleControllerTests var created = result.ShouldBeOfType(); created.Location.ShouldBe("/api/schedules/4/items/12"); - created.Value.ShouldBe(item); + created.Value.ShouldBeOfType().Id.ShouldBe(12); await _mediator.Received(1).Send( Arg.Is(c => c.ProgramScheduleId == 4 && c.PlayoutMode == PlayoutMode.One), Arg.Any()); @@ -254,7 +259,9 @@ public class ScheduleControllerTests new ReplaceScheduleItemsRequest([MakeItemRequest(PlayoutMode.One), MakeItemRequest(PlayoutMode.Multiple)]), CancellationToken.None); - result.ShouldBeOfType().Value.ShouldBe(items); + var replaced = result.ShouldBeOfType().Value + .ShouldBeOfType>(); + replaced.Select(i => i.Id).ShouldBe([21, 22]); await _mediator.Received(1).Send( Arg.Is(c => c.ProgramScheduleId == 4 &&