RepeatAttribute
Specifies that a test should be run multiple times.
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands;
using System;
using System.Runtime.CompilerServices;
namespace NUnit.Framework
{
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class RepeatAttribute : PropertyAttribute, IRepeatTest, ICommandWrapper
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class RepeatedTestCommand : DelegatingTestCommand
{
private readonly int _repeatCount;
public RepeatedTestCommand(TestCommand innerCommand, int repeatCount)
: base(innerCommand)
{
_repeatCount = repeatCount;
}
public override TestResult Execute(TestExecutionContext context)
{
int num = _repeatCount;
while (num-- > 0) {
context.CurrentResult = innerCommand.Execute(context);
if (context.CurrentResult.ResultState != ResultState.Success)
break;
context.CurrentRepeatCount++;
}
return context.CurrentResult;
}
}
private readonly int _count;
public RepeatAttribute(int count)
: base(count)
{
_count = count;
}
[System.Runtime.CompilerServices.NullableContext(1)]
public TestCommand Wrap(TestCommand command)
{
return new RepeatedTestCommand(command, _count);
}
}
}