mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
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<RunSummary> RunAsync(
|
|
IMessageSink diagnosticMessageSink,
|
|
IMessageBus messageBus,
|
|
object[] constructorArguments,
|
|
ExceptionAggregator aggregator,
|
|
CancellationTokenSource cancellationTokenSource)
|
|
{
|
|
var summary = new RunSummary();
|
|
|
|
for (int i = 1; i <= _maxRetries; i++)
|
|
{
|
|
try
|
|
{
|
|
var result = await base.RunAsync(
|
|
diagnosticMessageSink, messageBus, constructorArguments, aggregator, cancellationTokenSource);
|
|
|
|
summary.Aggregate(result);
|
|
|
|
if (result.Failed == 0)
|
|
break; // success, stop retrying
|
|
} catch (Exception) {}
|
|
}
|
|
|
|
return summary;
|
|
}
|
|
} |