Untrusted draft — no build/test had run yet. Review before building on it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
64 lines
1.9 KiB
C#
64 lines
1.9 KiB
C#
using System.Reflection;
|
|
using ErsatzTV.Application.Watermarks;
|
|
using ErsatzTV.Controllers.Api;
|
|
using ErsatzTV.Core.Api.Watermarks;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc.Routing;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Tests.Controllers;
|
|
|
|
[TestFixture]
|
|
public class WatermarkControllerTests
|
|
{
|
|
private WatermarkController _controller = null!;
|
|
private IMediator _mediator = null!;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_mediator = Substitute.For<IMediator>();
|
|
_controller = new WatermarkController(_mediator);
|
|
}
|
|
|
|
[Test]
|
|
public void Controller_Should_Expose_Idiomatic_Rest_Route()
|
|
{
|
|
MethodInfo action = typeof(WatermarkController).GetMethod(nameof(WatermarkController.GetAll))
|
|
?? throw new AssertionException("Missing action GetAll");
|
|
|
|
HttpMethodAttribute attribute = action.GetCustomAttributes<HttpMethodAttribute>(inherit: true).Single();
|
|
attribute.HttpMethods.ShouldContain("GET");
|
|
attribute.Template.ShouldBe("/api/watermarks");
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetAll_Should_Return_Watermarks()
|
|
{
|
|
List<WatermarkResponseModel> models =
|
|
[
|
|
new WatermarkResponseModel(1, "Corner Logo"),
|
|
new WatermarkResponseModel(2, "Ticker")
|
|
];
|
|
_mediator.Send(Arg.Any<GetAllWatermarksForApi>(), Arg.Any<CancellationToken>())
|
|
.Returns(models);
|
|
|
|
List<WatermarkResponseModel> result = await _controller.GetAll(CancellationToken.None);
|
|
|
|
result.ShouldBe(models);
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetAll_Should_Return_Empty_List_When_None_Exist()
|
|
{
|
|
_mediator.Send(Arg.Any<GetAllWatermarksForApi>(), Arg.Any<CancellationToken>())
|
|
.Returns([]);
|
|
|
|
List<WatermarkResponseModel> result = await _controller.GetAll(CancellationToken.None);
|
|
|
|
result.ShouldBeEmpty();
|
|
}
|
|
}
|