using System.Reflection;
using Microsoft.AspNetCore.Components;
using Shouldly;
using Xunit;
using ZB.MOM.WW.OtOpcUa.AdminUI.Components;
namespace ZB.MOM.WW.OtOpcUa.AdminUI.Tests.Authorization;
///
/// R04 S7: /dev/* routes exist only in DEBUG builds. The test project builds in the same
/// configuration as the AdminUI assembly, so each configuration asserts its own half — run
/// dotnet test -c Release to exercise the production half.
///
[Trait("Category", "Unit")]
public sealed class DevRouteGatingTests
{
private static IReadOnlyList DevRoutes() =>
typeof(Routes).Assembly.GetTypes()
.SelectMany(t => t.GetCustomAttributes(inherit: false))
.Select(r => r.Template)
.Where(t => t.StartsWith("/dev/", StringComparison.OrdinalIgnoreCase))
.ToList();
[Fact]
public void Dev_routes_follow_the_build_configuration()
{
#if DEBUG
DevRoutes().ShouldBe([ZB.MOM.WW.OtOpcUa.AdminUI.Components.Pages.Dev.ContextMenuDemo.RoutePath]);
#else
DevRoutes().ShouldBeEmpty();
#endif
}
[Fact]
public void Production_routes_are_present_in_every_configuration()
{
// Positive control: the scan sees routes at all (an empty assembly scan would pass the Release half).
typeof(Routes).Assembly.GetTypes()
.SelectMany(t => t.GetCustomAttributes(inherit: false))
.Select(r => r.Template)
.ShouldContain("/hosts");
}
}