using System; using Xunit; using Xunit.Abstractions; using Xunit.Sdk; namespace Berufsschule_HAM.E2ETests; [XunitTestCaseDiscoverer("YourNamespace.RetryFactDiscoverer", "YourAssemblyName")] public class RetryFactAttribute(int maxRetries = 5) : FactAttribute { public int MaxRetries { get; } = maxRetries; } public class RetryTestCase : XunitTestCase { private int _maxRetries; [Obsolete("Called by the de-serializer", true)] public RetryTestCase() { } public RetryTestCase(int maxRetries, ITestMethod testMethod) : base(new NullMessageSink(), TestMethodDisplay.Method, TestMethodDisplayOptions.None, testMethod) { _maxRetries = maxRetries; } public override async Task RunAsync( IMessageSink diagnosticMessageSink, IMessageBus messageBus, object[] constructorArguments, ExceptionAggregator aggregator, CancellationTokenSource cancellationTokenSource) { var summary = new RunSummary(); for (int i = 1; i <= _maxRetries; i++) { var result = await base.RunAsync( diagnosticMessageSink, messageBus, constructorArguments, aggregator, cancellationTokenSource); summary.Aggregate(result); if (result.Failed == 0) break; // success, stop retrying } return summary; } }