public void ExecutingInstruction_StartsTask() { this.state.ToTask(this.Executor); Assert.IsTrue(this.taskStarted); StateAssert.StringContainsInOrder(this.state.ToString()).Waiting(Description); }
public void WaitForCondition_ContainsCorrectDetails_WhenCanceled() { var extraContextRequested = false; var respond = WaitForCondition( "Should be canceled", () => false, _ => extraContextRequested = true) .ThenRespondWithAction("Do nothing", Nop); // Never execute the optional responder, leading to the wait being canceled. // But error out afterwards, to get a failure message. // We could do this in a simpler way using CreateState, // but that would not be as realistic. var task = respond.Optionally() .Until(ImmediateTrue) .AndThen(Never) .ExpectWithinSeconds(1) .ToTask(this.Executor); this.Scheduler.AdvanceFrame(TimeSpan.FromSeconds(2)); Assert.IsFalse(extraContextRequested, "Should not request extra context when canceled"); var error = GetFailureException(task); StateAssert.StringContainsInOrder(error.Message) .Canceled("Should be canceled") .FailureDetails(); }
public void ExceptionMessage_IncludesAllDetails() { this.GlobalContextProvider.BuildGlobalContext(Arg.Do <StateStringBuilder>( b => b.AddDetails("Global details"))); var task = WaitForCondition( "Throw", () => throw new Exception("An exception"), builder => builder.AddDetails("Local details")) .ExpectWithinSeconds(1) .ToTask(this.Executor); var failureException = GetFailureException(task); StateAssert .StringContainsInOrder(failureException.Message) .Details("Test operation execution failed") .Failed("Throw") .EmptyLine() .Details("Failed with:") .Details("An exception") .EmptyLine() .Details("Test operation stack:") .Details(@"\[ExpectWithinSeconds\].*?\(at") .Details(@"\[ToTask\].*?\(at") .EmptyLine() .Details("Local details") .EmptyLine() .Details("Global details") .EmptyLine() .Details("Error:"); }
public void ReusingSameInstruction_ProvidesSeparateState() { bool condition = true; bool WaitForIt() { if (condition) { condition = false; return(true); } return(condition); } var description = "Wait for it"; var wait = WaitForCondition(description, WaitForIt); var task = wait.AndThen(wait) .ExpectWithinSeconds(1) .ToTask(this.Executor); this.Scheduler.AdvanceFrame(OneSecond); var exception = GetFailureException(task); StateAssert.StringContainsInOrder(exception.Message) .Failed("EXPECT WITHIN") .Completed(description) .Canceled(description); }
public void StateDescription_MatchesExpected_WhenExpectInlined() { var expectState = WaitForTask("Task", this.RunTask) .ExpectWithinSeconds(1) .CreateState(); StateAssert.StringContainsInOrder(expectState.ToString()) .NotStarted("Task EXPECTED WITHIN"); }
public void SuccessfulExecution_RunsCorrectly() { var task = this.state.ToTask(this.Executor); this.completionSource.SetResult(42); StateAssert.StringContainsInOrder(this.state.ToString()).Completed(Description); Assert.IsTrue(task.IsCompleted); Assert.AreEqual(42, task.Result); }
public void Description_MatchesExpected_WithInstruction() { var state = Do("First", () => { }) .ContinueWith(Do("Second", () => { })) .CreateState(); StateAssert.StringContainsInOrder(state.ToString()) .NotStarted("First") .NotStarted("Second"); }
public void SourcePath_IsPrettified_WhenInProject() { var task = Do("Throw", () => throw new Exception()) .ToTask(this.Executor); var exception = GetFailureException(task); StateAssert.StringContainsInOrder(exception.Message) .Failed("Throw") .Details(@"\(at Assets/UnityTests/SourcePrettifyTests\.cs\:"); }
public void WaitForSeconds_ContainsCorrectStatusInDescription() { var state = WaitForSeconds(1).CreateState(); var description = "WAIT FOR 0:00:01"; StateAssert.StringContainsInOrder(state.ToString()).NotStarted(description); state.ToTask(this.Executor); StateAssert.StringContainsInOrder(state.ToString()).Waiting(description); this.Scheduler.AdvanceFrame(OneSecond); StateAssert.StringContainsInOrder(state.ToString()).Completed(description); }
public void WaitForFrames_ContainsCorrectStatusInDescription() { var state = WaitForFrames(0).CreateState(); var description = @"WAIT FOR 0 FRAME\(S\)"; StateAssert.StringContainsInOrder(state.ToString()).NotStarted(description); state.ToTask(this.Executor); StateAssert.StringContainsInOrder(state.ToString()).Waiting(description); this.AdvanceDefaultFrame(); StateAssert.StringContainsInOrder(state.ToString()).Completed(description); }
public void RespondToAllOf_Description_MatchesExpected() { var state = RespondToAllOf(this.responder1.Responder, this.responder2.Responder) .ExpectWithinSeconds(1) .CreateState(); StateAssert.StringContainsInOrder(state.ToString()) .NotStarted("EXPECT WITHIN 1.00 s ALL OF") .NotStarted("Respond") .NotStarted("Respond"); }
public void SelectFromResponder_ContainsFailureDetails_WhenResponderFailed() { this.responder.AllowCompletionWithError(new Exception("Fail!")); this.AdvanceDefaultFrame(); var error = GetFailureException(this.task); StateAssert.StringContainsInOrder(error.Message) .Details(ConditionResponder.WaitForCompletionDescription) .NotStarted("SELECT"); }
public void InlinedOutput_IsGeneratedForInitialState_WhenExpected() { var state = WaitForCondition("Never", () => false) .ExpectWithinSeconds(1) .CreateState(); var stateString = state.ToString(); StateAssert.StringContainsInOrder(stateString) .NotStarted("Never EXPECTED WITHIN"); }
public void UntilReadyToRespond_Description_MatchesExpected() { var state = this.first.Responder.Optionally() .UntilReadyTo(this.second.Responder) .CreateState(); StateAssert.StringContainsInOrder(state.ToString()) .Details("UNTIL READY TO") .NotStarted("Respond") .Details("RESPOND TO ANY OF") .NotStarted("Respond"); }
public void CanceledExecution_RunsCorrectly() { using (var cancellationSource = new CancellationTokenSource()) { var task = this.state.ToTask(this.Executor, cancellationSource.Token); cancellationSource.Cancel(); StateAssert.StringContainsInOrder(this.state.ToString()).Canceled(Description); var error = GetFailureException(task); Assert.IsInstanceOf <TaskCanceledException>(error.InnerException); } }
public void FailedExecution_RunsCorrectly() { var task = this.state.ToTask(this.Executor); var exception = new Exception("Test failure"); this.completionSource.SetException(exception); StateAssert.StringContainsInOrder(this.state.ToString()).Failed(Description); var error = GetFailureException(task); Assert.AreSame(exception, error.InnerException); }
public void SelectFromInstruction_ContainsFailureDetails_WhenFailed() { var task = Return(2) .Select <int, int>(_ => throw new Exception("Fail!")) .ToTask(this.Executor); var exception = GetFailureException(task); StateAssert.StringContainsInOrder(exception.Message) .Failed("SELECT") .FailureDetails(); }
public void WaitForAllOf_Description_MatchesExpected() { var state = WaitForAllOf( WaitForCondition("First", () => false), WaitForCondition("Second", () => false)) .CreateState(); StateAssert.StringContainsInOrder(state.ToString()) .NotStarted("WAIT FOR ALL OF") .NotStarted("First") .NotStarted("Second"); }
public void InlinedOutput_IsGeneratedForCompletedState_WhenExpected() { var state = WaitForCondition("Immediately", () => true) .ExpectWithinSeconds(1) .CreateState(); state.ToTask(this.Executor); // Trigger completion var stateString = state.ToString(); StateAssert.StringContainsInOrder(stateString) .Completed("Immediately EXPECTED WITHIN"); }
public void SelectFromResponder_ContainsCorrectDetails_WhenSelectFails() { this.selector = _ => throw new Exception("Fail!"); this.responder.AllowFullCompletion(); this.AdvanceDefaultFrame(); var error = GetFailureException(this.task); StateAssert.StringContainsInOrder(error.Message) .Failed("SELECT") .FailureDetails() .Nowhere(ConditionResponder.WaitForCompletionDescription); }
public void SelectFromInstruction_ContainsCorrectDetails_WhenInstructionFailed() { var task = DoAndReturn <int>("Throw", () => throw new Exception("Fail!")) .Select(i => i) .ToTask(this.Executor); var exception = GetFailureException(task); StateAssert.StringContainsInOrder(exception.Message) .Failed("Throw") .FailureDetails() .NotStarted("SELECT"); }
public void SourcePath_IsNotPrettified_WhenNotInProject() { var task = Do( "Throw", () => throw new Exception(), // ReSharper disable once ExplicitCallerInfoArgument sourceFilePath: "/foo/bar.cs") .ToTask(this.Executor); var exception = GetFailureException(task); StateAssert.StringContainsInOrder(exception.Message) .Failed("Throw") .Details(@"\(at /foo/bar\.cs\:"); }
public void SelectFromResponder_ContainsCorrectDetails_WhenResponderFails() { var failMessage = "Test failure"; this.responder.CompleteWaitWithError(new Exception(failMessage)); this.AdvanceDefaultFrame(); var error = GetFailureException(this.task); StateAssert.StringContainsInOrder(error.Message) .Failed("Respond") .Details(failMessage) .NotStarted("SELECT"); }
public void Until_Description_MatchesExpected() { var state = Never .ThenRespondWithAction("complete", _ => { }) .Optionally() .Until(Never) .CreateState(); StateAssert.StringContainsInOrder(state.ToString()) .Details("UNTIL") .NotStarted("Never") .Details("RESPOND TO ANY OF") .NotStarted("complete"); }
public void ContinueWith_PropagatesError_WhenContinuationThrows() { var task = Responsibly .Return(new object()) .ContinueWith <object, object>(_ => throw new Exception("Test exception")) .ToTask(this.Executor); var exception = GetFailureException(task); StateAssert.StringContainsInOrder(exception.Message) .Completed("Return") .Failed("...") .Details("Test exception"); }
public void SelectFromCondition_ContainsCorrectDetails_WhenConditionFailed() { var task = WaitForCondition("Throw", () => throw new Exception("Fail!")) .Select(r => r) .ExpectWithinSeconds(1) .ToTask(this.Executor); var error = GetFailureException(task); StateAssert.StringContainsInOrder(error.Message) .Failed("Throw") .FailureDetails() .NotStarted("SELECT"); }
public void SelectFromCondition_ContainsFailureDetails_WhenFailed() { var task = ImmediateTrue .Select <bool, int>(r => throw new Exception("Fail!")) .ExpectWithinSeconds(1) .ToTask(this.Executor); var error = GetFailureException(task); StateAssert.StringContainsInOrder(error.Message) .Failed("EXPECT WITHIN") .Failed("SELECT") .FailureDetails(); }
public void AndThen_Fails_IfContinuationConstructionThrows() { var expectedException = new Exception("Test exception"); var task = ImmediateTrue .AndThen <bool, object>(_ => throw expectedException) .ExpectWithinSeconds(1) .ToTask(this.Executor); var exception = GetFailureException(task); Assert.AreSame(expectedException, exception.InnerException); StateAssert.StringContainsInOrder(exception.Message) .Completed("True") .Failed("...") .Details("Test exception"); }
public void StateString_TruncatesExceptionAt100Chars() { var message = new string('x', 99) + "^~"; var state = Responsibly.Do( "Fail", () => throw new Exception(message)) .CreateState(); state.ToTask(this.Executor); // Complete task var stateString = state.ToString(); StateAssert.StringContainsInOrder(stateString) .Failed("Fail") .Details(@"xxxxxxx\^") .Nowhere("~"); }
public void BasicResponder_FailureDescription_IsAsExpected() { var task = WaitForCondition("Condition", () => false) .ThenRespondWith("Response", _ => Return(0)) .ExpectWithinSeconds(1) .ToTask(this.Executor); this.Scheduler.AdvanceFrame(OneSecond); var message = GetFailureException(task).Message; StateAssert.StringContainsInOrder(message) .Failed("Response CONDITION EXPECTED WITHIN") .Details("WAIT FOR") .Canceled("Condition") .Details("THEN RESPOND WITH ..."); }