public void TestWhile2_Loop3_NullTaskBody() { AsyncWhileCondition whileCondition = AsyncWhileCondition.True(); WhileBody whileBody = new WhileBody(3, DelegateBehavior.NullTask); // declaring these makes it clear we are testing the correct overload Func <Task <bool> > condition = whileCondition.EvaluateAsync; Func <Task> body = whileBody.ExecuteAsync; Task whileTask = null; try { whileTask = TaskBlocks.While(condition, body); whileTask.Wait(); Assert.Fail("Expected an exception"); } catch (AggregateException ex) { Assert.IsNotNull(whileTask); Assert.AreEqual(TaskStatus.Faulted, whileTask.Status); Assert.AreEqual(1, ex.InnerExceptions.Count); Assert.IsInstanceOfType(ex.InnerExceptions[0], typeof(InvalidOperationException)); Assert.AreEqual(whileBody.MaxExecutions, whileCondition.EvaluateAsyncCount); Assert.AreEqual(whileBody.MaxExecutions, whileCondition.SyncPartEvaluateAsyncCount); Assert.AreEqual(whileBody.MaxExecutions, whileBody.SyncPartExecutionCount); Assert.AreEqual(whileBody.MaxExecutions - 1, whileBody.ExecutionCount); } }
public void TestWhile2_Loop3_SyncFaultedCondition() { AsyncWhileCondition whileCondition = new AsyncWhileCondition(3, DelegateBehavior.SyncFaulted); WhileBody whileBody = new WhileBody(); // declaring these makes it clear we are testing the correct overload Func <Task <bool> > condition = whileCondition.EvaluateAsync; Func <Task> body = whileBody.ExecuteAsync; Task whileTask = null; try { whileTask = TaskBlocks.While(condition, body); whileTask.Wait(); Assert.Fail("Expected an exception"); } catch (AggregateException ex) { Assert.IsNotNull(whileTask); Assert.AreEqual(TaskStatus.Faulted, whileTask.Status); Assert.AreEqual(1, ex.InnerExceptions.Count); Assert.AreSame(whileCondition.ExpectedException, ex.InnerExceptions[0]); Assert.AreEqual(whileCondition.TotalIterations + 1, whileCondition.SyncPartEvaluateAsyncCount); Assert.AreEqual(whileCondition.TotalIterations, whileCondition.EvaluateAsyncCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.SyncPartExecutionCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.ExecutionCount); } }
public void TestWhile2_Loop3_Success() { AsyncWhileCondition whileCondition = new AsyncWhileCondition(3); WhileBody whileBody = new WhileBody(); // declaring these makes it clear we are testing the correct overload Func <Task <bool> > condition = whileCondition.EvaluateAsync; Func <Task> body = whileBody.ExecuteAsync; Task whileTask = TaskBlocks.While(condition, body); whileTask.Wait(); Assert.AreEqual(whileCondition.TotalIterations + 1, whileCondition.SyncPartEvaluateAsyncCount); Assert.AreEqual(whileCondition.TotalIterations + 1, whileCondition.EvaluateAsyncCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.SyncPartExecutionCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.ExecutionCount); }
public void TestWhile2_NullBodyFunction() { AsyncWhileCondition whileCondition = new AsyncWhileCondition(0); // declaring these makes it clear we are testing the correct overload Func <Task <bool> > condition = whileCondition.EvaluateAsync; Func <Task> body = null; try { TaskBlocks.While(condition, body); } catch { Assert.AreEqual(0, whileCondition.SyncPartEvaluateAsyncCount); Assert.AreEqual(0, whileCondition.EvaluateAsyncCount); throw; } }
public void TestWhile2_NullBodyFunction() { AsyncWhileCondition whileCondition = new AsyncWhileCondition(0); // declaring these makes it clear we are testing the correct overload Func<Task<bool>> condition = whileCondition.EvaluateAsync; Func<Task> body = null; try { TaskBlocks.While(condition, body); } catch { Assert.AreEqual(0, whileCondition.SyncPartEvaluateAsyncCount); Assert.AreEqual(0, whileCondition.EvaluateAsyncCount); throw; } }
public void TestWhile2_Loop3_SyncFaultedCondition() { AsyncWhileCondition whileCondition = new AsyncWhileCondition(3, DelegateBehavior.SyncFaulted); WhileBody whileBody = new WhileBody(); // declaring these makes it clear we are testing the correct overload Func<Task<bool>> condition = whileCondition.EvaluateAsync; Func<Task> body = whileBody.ExecuteAsync; Task whileTask = null; try { whileTask = TaskBlocks.While(condition, body); whileTask.Wait(); Assert.Fail("Expected an exception"); } catch (AggregateException ex) { Assert.IsNotNull(whileTask); Assert.AreEqual(TaskStatus.Faulted, whileTask.Status); Assert.AreEqual(1, ex.InnerExceptions.Count); Assert.AreSame(whileCondition.ExpectedException, ex.InnerExceptions[0]); Assert.AreEqual(whileCondition.TotalIterations + 1, whileCondition.SyncPartEvaluateAsyncCount); Assert.AreEqual(whileCondition.TotalIterations, whileCondition.EvaluateAsyncCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.SyncPartExecutionCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.ExecutionCount); } }
public void TestWhile2_Loop3_Success() { AsyncWhileCondition whileCondition = new AsyncWhileCondition(3); WhileBody whileBody = new WhileBody(); // declaring these makes it clear we are testing the correct overload Func<Task<bool>> condition = whileCondition.EvaluateAsync; Func<Task> body = whileBody.ExecuteAsync; Task whileTask = TaskBlocks.While(condition, body); whileTask.Wait(); Assert.AreEqual(whileCondition.TotalIterations + 1, whileCondition.SyncPartEvaluateAsyncCount); Assert.AreEqual(whileCondition.TotalIterations + 1, whileCondition.EvaluateAsyncCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.SyncPartExecutionCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.ExecutionCount); }