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(); 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(); } } }