public Execute ( IList |
||
ops | IList |
|
remainingOps | Action |
|
return | void |
public override void Execute(IList<Action> ops, Action<IEnumerable<Action>> remainingOps)
{
var i = 0;
try
{
for (; i < ops.Count; i++)
{
if (!AcceptingJobs)
{
// ReSharper disable once AccessToModifiedClosure
remainingOps.NotNull(obj => remainingOps(ops.Skip(i + 1)));
break;
}
ops[i]();
}
}
catch (Exception ex)
{
remainingOps.NotNull(obj => remainingOps(ops.Skip(i + 1)));
_exceptionCallback(ex);
}
}
}
TryCatchExecutor::Execute ( System.Action op ) : void |
public void Should_pipe_remaining_operations_when_exception_thrown() { //arrange var handledException = false; var remainingJobsCalled = true; var remainingJobsCount = 0; Action<Exception> exCallback = exception => { handledException = true; }; Action exOperation = () => { throw new Exception("Plain old exception"); }; Executor = new TryCatchExecutor(exCallback); var wasCalled = 3.Of(false).ToList(); var callbacks = new Action[wasCalled.Count]; for (var i = 0; i < wasCalled.Count; i++) { var i1 = i; callbacks[i] = new Action(() => { wasCalled[i1] = true; }); } callbacks[1] = exOperation; //act Executor.Execute(callbacks, actions => { remainingJobsCalled = true; remainingJobsCount = actions.Count(); }); //assert Assert.IsFalse(wasCalled.All(x => x)); Assert.IsTrue(handledException); Assert.IsTrue(remainingJobsCalled); Assert.AreEqual(1, remainingJobsCount); }