Files
duempelkas/tests/Duempelkas.Tests/ErrorRecoveryTests.cs
T

29 lines
1.1 KiB
C#

using Bunit;
using Duempelkas.App.Components;
using Duempelkas.App.Services;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Rendering;
using Microsoft.Extensions.DependencyInjection;
using Xunit;
namespace Duempelkas.Tests;
public class ErrorRecoveryTests
{
[Fact]
public void UnexpectedError_OffersRecoveryWithoutLeakingBookingData()
{
using var context = new BunitContext();
context.Services.AddSingleton<ToastService>();
var boundary = context.Render<AppErrorBoundary>(p => p.AddChildContent<Throws>());
boundary.WaitForAssertion(() => Assert.Contains("nicht bestätigt", boundary.Markup));
Assert.Contains("Zur Kontenübersicht", boundary.Markup);
Assert.Contains("InvalidOperationException", boundary.Markup);
Assert.DoesNotContain("SECRET_BOOKING_DATA", boundary.Markup);
}
private sealed class Throws : ComponentBase
{
protected override void BuildRenderTree(RenderTreeBuilder builder) => throw new InvalidOperationException("SECRET_BOOKING_DATA");
}
}