public void TestWhile1_Loop0_FaultedCondition() { WhileCondition whileCondition = new WhileCondition(0, DelegateBehavior.Faulted); WhileBody whileBody = new WhileBody(); // declaring these makes it clear we are testing the correct overload Func<bool> condition = whileCondition.Evaluate; 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.EvaluateCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.SyncPartExecutionCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.ExecutionCount); } }
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_NullConditionFunction() { // declaring these makes it clear we are testing the correct overload Func <Task <bool> > condition = null; Func <Task> body = new WhileBody().ExecuteAsync; TaskBlocks.While(condition, body); }
public void TestWhile1_Loop3_Success() { WhileCondition whileCondition = new WhileCondition(3); WhileBody whileBody = new WhileBody(); // declaring these makes it clear we are testing the correct overload Func <bool> condition = whileCondition.Evaluate; Func <Task> body = whileBody.ExecuteAsync; Task whileTask = TaskBlocks.While(condition, body); whileTask.Wait(); Assert.AreEqual(whileCondition.TotalIterations + 1, whileCondition.EvaluateCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.SyncPartExecutionCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.ExecutionCount); }
public void TestWhile1_Loop0_Success() { WhileCondition whileCondition = new WhileCondition(0); WhileBody whileBody = new WhileBody(); // declaring these makes it clear we are testing the correct overload Func<bool> condition = whileCondition.Evaluate; Func<Task> body = whileBody.ExecuteAsync; Task whileTask = TaskBlocks.While(condition, body); whileTask.Wait(); Assert.AreEqual(whileCondition.TotalIterations + 1, whileCondition.EvaluateCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.SyncPartExecutionCount); Assert.AreEqual(whileCondition.TotalIterations, whileBody.ExecutionCount); }
public void TestWhile2_NullConditionFunction() { // declaring these makes it clear we are testing the correct overload Func<Task<bool>> condition = null; Func<Task> body = new WhileBody().ExecuteAsync; TaskBlocks.While(condition, body); }
public void TestWhile2_Loop3_NullTaskCondition() { AsyncWhileCondition whileCondition = new AsyncWhileCondition(3, DelegateBehavior.NullTask); 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.IsInstanceOfType(ex.InnerExceptions[0], typeof(InvalidOperationException)); 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 TestWhile1_Loop3_CanceledBody() { WhileCondition whileCondition = WhileCondition.True(); WhileBody whileBody = new WhileBody(3, DelegateBehavior.Canceled); // declaring these makes it clear we are testing the correct overload Func<bool> condition = whileCondition.Evaluate; 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.Canceled, whileTask.Status); Assert.AreEqual(1, ex.InnerExceptions.Count); Assert.IsInstanceOfType(ex.InnerExceptions[0], typeof(TaskCanceledException)); Assert.AreEqual(whileBody.MaxExecutions, whileCondition.EvaluateCount); Assert.AreEqual(whileBody.MaxExecutions, whileBody.SyncPartExecutionCount); Assert.AreEqual(whileBody.MaxExecutions, whileBody.ExecutionCount); } }