MaxTimeCommand
TODO: Documentation needed for class
using NUnit.Framework.Interfaces;
using System;
using System.Diagnostics;
namespace NUnit.Framework.Internal.Commands
{
public class MaxTimeCommand : DelegatingTestCommand
{
private int maxTime;
public MaxTimeCommand(TestCommand innerCommand, int maxTime)
: base(innerCommand)
{
this.maxTime = maxTime;
}
public override TestResult Execute(TestExecutionContext context)
{
long timestamp = Stopwatch.GetTimestamp();
TestResult testResult = innerCommand.Execute(context);
long num = Stopwatch.GetTimestamp() - timestamp;
double value = (double)num / (double)Stopwatch.Frequency;
testResult.Duration = TimeSpan.FromSeconds(value);
if (testResult.ResultState == ResultState.Success) {
double totalMilliseconds = testResult.Duration.TotalMilliseconds;
if (totalMilliseconds > (double)maxTime)
testResult.SetResult(ResultState.Failure, $"""{totalMilliseconds}""{maxTime}""");
}
return testResult;
}
}
}