public void AndThen_TimesOutOnSecond_WithDeferredSecondCondition() { var task = ImmediateTrue.AndThen(_ => Never).ExpectWithinSeconds(1).ToTask(this.Executor); this.Scheduler.AdvanceFrame(OneSecond); Assert.IsNotNull(GetFailureException(task)); }
public void WaitForCondition_CompletesImmediately_WhenSynchronouslyMet() { var result = ImmediateTrue .ExpectWithinSeconds(10) .ToTask(this.Executor) .Wait(TimeSpan.Zero); Assert.IsTrue(result); }
public void SelectFromCondition_GetsApplied_WhenSuccessful() { var result = ImmediateTrue .Select(r => r ? 1 : 0) .ExpectWithinSeconds(1) .ToTask(this.Executor) .AssertSynchronousResult(); Assert.AreEqual(1, result); }
public void RespondToAnyOf_WorksCorrectlyWithReferenceTypes() { var expectedObject = new object(); var instruction = RespondToAnyOf( ImmediateTrue.ThenRespondWith("Return object", Return(expectedObject)), this.responder1.Responder.BoxResult()) .Until(Never) .ExpectWithinSeconds(1); Assert.DoesNotThrow(() => instruction.ToTask(this.Executor)); }
public void ExpectResponder_ContainsErrorDetails_WhenExceptionThrown() { var responder = ImmediateTrue.ThenRespondWithAction("Throw error", _ => throw new Exception("Test")); this.AssertErrorDetailsAfterOneSecond( responder.ExpectWithinSeconds(1), @"failed.* \[!\] Throw error EXPECTED WITHIN.* \s+\[!\] Throw error .* \s+Failed with.* \s+Test operation stack"); }
public void ExpectResponder_ContainsErrorDetails_WhenInstructionTimedOut() { var responder = ImmediateTrue.ThenRespondWith("Response", Never.ExpectWithinSeconds(0.5)); this.AssertErrorDetailsAfterOneSecond( responder.BoxResult().ExpectWithinSeconds(1), @"timed out.* \[!\] Response EXPECTED WITHIN.* \s+\[!\] Never EXPECTED WITHIN.* \s+Failed with.* \s+Test operation stack"); }
public void BasicResponder_Fails_WhenContinuationThrows() { var task = ImmediateTrue .ThenRespondWith <bool, object>( "Throw exception in selector", _ => throw new Exception("Test exception")) .ExpectWithinSeconds(1) .ToTask(this.Executor); var exception = GetFailureException(task); StateAssert.StringContainsInOrder(exception.Message) .Failed("Throw exception in selector") .Completed("True") .Details("THEN RESPOND WITH ...") .Details("Test exception"); }
public void ExpectResponder_DoesNotTerminateWithTimeout_IfWaitFulfilled() { // The instruction takes longer than the timeout // => The timeout applies only to the wait! var task = ImmediateTrue .ThenRespondWith("Wait for two seconds", WaitForSeconds(2)) .ExpectWithinSeconds(1) .ToTask(this.Executor); this.Scheduler.AdvanceFrame(OneSecond); Assert.IsFalse(task.IsFaulted); Assert.IsFalse(task.IsCompleted); this.Scheduler.AdvanceFrame(OneSecond); Assert.IsFalse(task.IsFaulted); Assert.IsTrue(task.IsCompleted); }