Files
scadaproj/components/ui-theme/validation/bunit-2.7.2/probes/1.5.2/BunitCompatibilityTests.cs
T
2026-11-13 14:41:17 -05:00

32 lines
1.0 KiB
C#

using Bunit;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Xunit;
public sealed class BunitCompatibilityTests : BunitContext
{
[Fact]
public void Render_query_click_rerender_and_authorization_are_available()
{
var auth = this.AddAuthorization();
auth.SetAuthorized("synthetic-user");
auth.SetRoles("Viewer");
var cut = Render<Probe>();
Assert.Equal("Count 0", cut.Find("button").TextContent);
cut.Find("button").Click();
Assert.Equal("Count 1", cut.Find("button").TextContent);
Assert.Single(cut.FindAll("button"));
}
public sealed class Probe : ComponentBase
{
private int count;
protected override void BuildRenderTree(RenderTreeBuilder b)
{
b.OpenElement(0, "button");
b.AddAttribute(1, "onclick", EventCallback.Factory.Create(this, () => count++));
b.AddContent(2, $"Count {count}");
b.CloseElement();
}
}
}