Files
ersatztv/ErsatzTV.Tests/Controllers/TroubleshootControllerTests.cs
T
timothyandClaude Fable 5 24a26cbe34
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 4m14s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 4m37s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
fix: address #165 review findings (stale-response guard, security-test coverage, route/help-text nits)
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-07 13:55:05 +02:00

85 lines
2.9 KiB
C#

using System.IO.Abstractions;
using System.Reflection;
using System.Text.Json;
using System.Threading.Channels;
using ErsatzTV.Application;
using ErsatzTV.Application.Troubleshooting;
using ErsatzTV.Application.Troubleshooting.Queries;
using ErsatzTV.Controllers.Api;
using ErsatzTV.Core.Api.Troubleshooting;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Core.Interfaces.Troubleshooting;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using NSubstitute;
using NUnit.Framework;
using Shouldly;
namespace ErsatzTV.Tests.Controllers;
[TestFixture]
public class TroubleshootControllerTests
{
private TroubleshootController _controller = null!;
private IMediator _mediator = null!;
[SetUp]
public void SetUp()
{
_mediator = Substitute.For<IMediator>();
_controller = new TroubleshootController(
Channel.CreateUnbounded<IFFmpegWorkerRequest>().Writer,
Substitute.For<IFileSystem>(),
Substitute.For<IConfigElementRepository>(),
Substitute.For<ITroubleshootingNotifier>(),
_mediator);
}
[Test]
public void Controller_Should_Expose_Idiomatic_Rest_Route_For_Info()
{
MethodInfo action = typeof(TroubleshootController).GetMethod(nameof(TroubleshootController.GetInfo))
?? throw new AssertionException("Missing action GetInfo");
var attribute = action.GetCustomAttributes<HttpGetAttribute>().Single();
attribute.Template.ShouldBe("api/troubleshoot/info");
attribute.Name.ShouldBe("GetTroubleshootingInfo");
}
[Test]
public async Task GetInfo_Should_Serialize_General_Section_And_Carry_Platform_Capabilities()
{
var info = new TroubleshootingInfo(
"1.2.3",
new Dictionary<string, string> { ["ETV_FOO"] = "bar" },
[],
[],
[],
new ErsatzTV.Application.FFmpegProfiles.FFmpegSettingsViewModel(),
[],
[],
[],
false,
false,
"nvidia output",
"qsv output",
"vaapi output",
"videotoolbox output");
_mediator.Send(Arg.Any<GetTroubleshootingInfo>(), Arg.Any<CancellationToken>())
.Returns(info);
TroubleshootingInfoResponseModel result = await _controller.GetInfo(CancellationToken.None);
result.NvidiaCapabilities.ShouldBe("nvidia output");
result.QsvCapabilities.ShouldBe("qsv output");
result.VaapiCapabilities.ShouldBe("vaapi output");
result.VideoToolboxCapabilities.ShouldBe("videotoolbox output");
using JsonDocument document = JsonDocument.Parse(result.GeneralJson);
document.RootElement.GetProperty("Version").GetString().ShouldBe("1.2.3");
document.RootElement.GetProperty("Environment").GetProperty("ETV_FOO").GetString().ShouldBe("bar");
document.RootElement.GetProperty("AviSynth").GetProperty("Demuxer").GetBoolean().ShouldBeFalse();
}
}