Repository: dotnet/aspnetcore
File: src/Components/test/E2ETest/Tests/CircuitTests.cs (C#)

Code before:
    [Theory]
    [InlineData("constructor-throw")]
    [InlineData("attach-throw")]
    [InlineData("setparameters-sync-throw")]
    [InlineData("setparameters-async-throw")]
    [InlineData("render-throw")]
    [InlineData("afterrender-sync-throw")]
    [InlineData("afterrender-async-throw")]
    public void ComponentLifecycleMethodThrowsExceptionTerminatesTheCircuit(string id)
    {
        Browser.MountTestComponent<ReliabilityComponent>();
        Browser.Exists(By.Id("thecounter"));

        var targetButton = Browser.Exists(By.Id(id));
        targetButton.Click();

        // Triggering an error will show the exception UI
        Browser.Exists(By.CssSelector("#blazor-error-ui[style='display: block;']"));

        // Dismiss the error UI by clicking the dismiss button
        var dismissButton = Browser.Exists(By.CssSelector("#blazor-error-ui .dismiss"));
        dismissButton.Click();

        // Wait for error UI to be hidden
        Browser.Exists(By.CssSelector("#blazor-error-ui[style='display: none;']"));

        // Clicking the button again will trigger a server disconnect
        targetButton.Click();

        AssertLogContains("Connection disconnected.");
    }

    [Fact]
    public void ComponentDisposeMethodThrowsExceptionTerminatesTheCircuit()
    {
        Browser.MountTestComponent<ReliabilityComponent>();
        Browser.Exists(By.Id("thecounter"));

        // Arrange
        var targetButton = Browser.Exists(By.Id("dispose-throw"));

        // Clicking the button sets a boolean that renders the component
        targetButton.Click();
        // Clicking it again hides the component and invokes the rethrow which triggers the exception
        targetButton.Click();
        Browser.Exists(By.CssSelector("#blazor-error-ui[style='display: block;']"));

        // Dismiss the error UI by clicking the dismiss button
        var dismissButton = Browser.Exists(By.CssSelector("#blazor-error-ui .dismiss"));
        dismissButton.Click();


Review comment (refactor):
Consider extracting the duplicate error UI dismissal logic into a helper method since it's repeated in both test methods. This would improve maintainability and reduce code duplication.
```suggestion
        DismissBlazorErrorUI();
```

Code after:
    [Theory]
    [InlineData("constructor-throw")]
    [InlineData("attach-throw")]
    [InlineData("setparameters-sync-throw")]
    [InlineData("setparameters-async-throw")]
    [InlineData("render-throw")]
    [InlineData("afterrender-sync-throw")]
    [InlineData("afterrender-async-throw")]
    public void ComponentLifecycleMethodThrowsExceptionTerminatesTheCircuit(string id)
    {
        Browser.MountTestComponent<ReliabilityComponent>();
        Browser.Exists(By.Id("thecounter"));

        var targetButton = Browser.Exists(By.Id(id));
        targetButton.Click();

        DismissBlazorErrorUI();

        // Clicking the button again will trigger a server disconnect
        targetButton.Click();

        AssertLogContains("Connection disconnected.");
    }

    [Fact]
    public void ComponentDisposeMethodThrowsExceptionTerminatesTheCircuit()
    {
        Browser.MountTestComponent<ReliabilityComponent>();
        Browser.Exists(By.Id("thecounter"));

        // Arrange
        var targetButton = Browser.Exists(By.Id("dispose-throw"));

        // Clicking the button sets a boolean that renders the component
        targetButton.Click();
        // Clicking it again hides the component and invokes the rethrow which triggers the exception
        targetButton.Click();

        DismissBlazorErrorUI();

        // Clicking it again causes the circuit to disconnect
        targetButton.Click();
        AssertLogContains("Connection disconnected.");
    }

    [Fact]
    public void OnLocationChanged_ReportsErrorForExceptionInUserCode()
    {
        Browser.MountTestComponent<NavigationFailureComponent>();
        var targetButton = Browser.Exists(By.Id("navigate-to-page"));