ApplyChangesToContextCommand
ContextSettingsCommand applies specified changes to the
TestExecutionContext prior to running a test. No special
action is needed after the test runs, since the prior
context will be restored automatically.
using NUnit.Framework.Interfaces;
using System;
using System.Threading;
namespace NUnit.Framework.Internal.Commands
{
internal class ApplyChangesToContextCommand : DelegatingTestCommand
{
private IApplyToContext[] _changes;
public ApplyChangesToContextCommand(TestCommand innerCommand, IApplyToContext[] changes)
: base(innerCommand)
{
_changes = changes;
}
public override TestResult Execute(TestExecutionContext context)
{
try {
IApplyToContext[] changes = _changes;
foreach (IApplyToContext applyToContext in changes) {
applyToContext.ApplyToContext(context);
}
context.CurrentResult = innerCommand.Execute(context);
} catch (Exception ex) {
if (ex is ThreadAbortException)
Thread.ResetAbort();
context.CurrentResult.RecordException(ex);
}
return context.CurrentResult;
}
}
}