60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using System.Reflection;
|
|
using ErsatzTV.Application.MediaSources;
|
|
using ErsatzTV.Controllers.Api;
|
|
using ErsatzTV.Core.Api.MediaSources;
|
|
using ErsatzTV.Core.Domain;
|
|
using MediatR;
|
|
using Microsoft.AspNetCore.Mvc.Routing;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Tests.Controllers;
|
|
|
|
[TestFixture]
|
|
public class MediaSourcesControllerTests
|
|
{
|
|
private MediaSourcesController _controller = null!;
|
|
private IMediator _mediator = null!;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_mediator = Substitute.For<IMediator>();
|
|
_controller = new MediaSourcesController(_mediator);
|
|
}
|
|
|
|
[Test]
|
|
public void Controller_Should_Expose_Idiomatic_Rest_Route()
|
|
{
|
|
MethodInfo action = typeof(MediaSourcesController).GetMethod(nameof(MediaSourcesController.GetAll))
|
|
?? throw new AssertionException("Missing action GetAll");
|
|
|
|
HttpMethodAttribute attribute = action.GetCustomAttributes<HttpMethodAttribute>(inherit: true).Single();
|
|
attribute.HttpMethods.ShouldContain("GET");
|
|
attribute.Template.ShouldBe("/api/media-sources");
|
|
attribute.Name.ShouldBe("GetMediaSources");
|
|
}
|
|
|
|
[Test]
|
|
public async Task GetAll_Should_Return_Results_From_Mediator()
|
|
{
|
|
var expected = new List<MediaSourceResponseModel>
|
|
{
|
|
new(
|
|
1,
|
|
"Local",
|
|
"Local",
|
|
null,
|
|
[new MediaSourceLibraryResponseModel(10, "Movies", LibraryMediaKind.Movies, null, 3)])
|
|
};
|
|
|
|
_mediator.Send(Arg.Any<GetAllMediaSourcesForApi>(), Arg.Any<CancellationToken>())
|
|
.Returns(expected);
|
|
|
|
List<MediaSourceResponseModel> result = await _controller.GetAll(CancellationToken.None);
|
|
|
|
result.ShouldBe(expected);
|
|
}
|
|
}
|