private static ITestResponder <object> MakeErrorResponder <TWait>( ConstructionStrategy strategy, ITestWaitCondition <TWait> waitCondition) { object ThrowException(TWait _) => throw new Exception("Test"); ITestInstruction <object> throwInstruction = DoAndReturn("Throw", () => ThrowException(default));
public SelectTestInstruction( ITestInstruction <T1> first, Func <T1, T2> selector, SourceContext sourceContext) : base(() => new SelectOperationState <T1, T2>(first.CreateState(), selector, sourceContext)) { }
public SequencedTestInstruction( ITestInstruction <T1> first, ITestInstruction <T2> second, SourceContext sourceContext) : base(() => new State(first, second, sourceContext)) { }
public ContinuationTestInstruction( ITestInstruction <T1> first, Func <T1, ITestInstruction <T2> > selector, SourceContext sourceContext) : base(() => new State(first, selector, sourceContext)) { }
private void AssertErrorDetailsAfterOneSecond( ITestInstruction <object> instruction, [RegexPattern] string regex) { var task = instruction.ToTask(this.Executor); this.Scheduler.AdvanceFrame(OneSecond); var exception = GetFailureException(task); Assert.That(exception.Message, Does.Match($"(?s:{regex})")); var multipleFailuresDescription = $"Should contain only singe failure details, but was:\n{exception.Message}"; Assert.AreEqual( 1, Regex.Matches(exception.Message, "Failed with").Count, multipleFailuresDescription); Assert.AreEqual( 1, Regex.Matches(exception.Message, "Test operation stack").Count, multipleFailuresDescription); }
public State( ITestInstruction <T1> first, Func <T1, ITestInstruction <T2> > selector, SourceContext sourceContext) : base(sourceContext) { this.first = first.CreateState(); this.selector = selector; }
public State( ITestInstruction <T1> first, Func <T1, ITestInstruction <T2> > selector, SourceContext sourceContext) : base(sourceContext) { this.first = first.CreateState(); this.continuation = new Continuation <T1, T2>(firstResult => selector(firstResult).CreateState()); }
public State( ITestInstruction <T1> first, ITestInstruction <T2> second, SourceContext sourceContext) : base(sourceContext) { this.first = first.CreateState(); this.second = second.CreateState(); }
public static ITestInstruction <T2> ContinueWith <T1, T2>( this ITestInstruction <T1> first, Func <T1, ITestInstruction <T2> > continuation, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) => new ContinuationTestInstruction <T1, T2>( first, continuation, new SourceContext(nameof(ContinueWith), memberName, sourceFilePath, sourceLineNumber));
public static ITestInstruction <T2> Select <T1, T2>( this ITestInstruction <T1> instruction, Func <T1, T2> selector, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) => new SelectTestInstruction <T1, T2>( instruction, selector, new SourceContext(nameof(Select), memberName, sourceFilePath, sourceLineNumber));
/// <summary> /// Starts executing the instruction as an async task. /// </summary> /// <returns>A task which will complete with the instructions status.</returns> /// <param name="instruction">The instruction to execute.</param> /// <typeparam name="T">Return type of the test instruction.</typeparam> /// <inheritdoc cref="Docs.Inherit.CallerMemberWithExecutor{T}"/> public static Task <T> ToTask <T>( this ITestInstruction <T> instruction, TestInstructionExecutor executor, CancellationToken cancellationToken = default, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) => executor.RunInstruction( instruction.CreateState(), new SourceContext(nameof(ToTask), memberName, sourceFilePath, sourceLineNumber), cancellationToken);
public static ITestResponder <TResult> ThenRespondWith <TWait, TResult>( this ITestWaitCondition <TWait> condition, string description, ITestInstruction <TResult> instruction, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) => new TestResponder <TWait, TResult>( description, condition, _ => instruction, new SourceContext(nameof(ThenRespondWith), memberName, sourceFilePath, sourceLineNumber));
/// <summary> /// **Unity-only!** /// /// Starts executing an instruction, and returns a yield instruction which can be awaited, /// using <c>yield return</c> in a Unity coroutine. /// </summary> /// <returns>Yield instruction for Unity, which will complete when the instruction has completed.</returns> /// <param name="instruction">Instruction to execute.</param> /// <typeparam name="T">Return type of the test instruction to start.</typeparam> /// <inheritdoc cref="Docs.Inherit.YieldInstruction{T}"/> public static TestOperationYieldInstruction <T> ToYieldInstruction <T>( this ITestInstruction <T> instruction, TestInstructionExecutor executor, bool throwOnError = true, CancellationToken cancellationToken = default, [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) => new TestOperationYieldInstruction <T>(executor.RunInstruction( instruction.CreateState(), new SourceContext(nameof(ToYieldInstruction), memberName, sourceFilePath, sourceLineNumber), cancellationToken), throwOnError);
private ITestInstruction <object> ContinueWithError <T>( ITestInstruction <T> first, Strategy strategy) { switch (strategy) { case Strategy.Continuation: return(first.ContinueWith(_ => ErrorInstruction)); case Strategy.Instruction: return(first.ContinueWith(ErrorInstruction)); default: throw new ArgumentOutOfRangeException(nameof(strategy), strategy, "Unhandled strategy"); } }
private ITestInstruction <object> ContinueWithNothing <T>( ITestInstruction <T> first, Strategy strategy) { var second = this.waitForSecond.ExpectWithinSeconds(1); switch (strategy) { case Strategy.Continuation: return(first.ContinueWith(_ => second)); case Strategy.Instruction: return(first.ContinueWith(second)); default: throw new ArgumentOutOfRangeException(nameof(strategy), strategy, "Unhandled strategy"); } }
public void OneTimeSetUp() { this.waitForComplete = WaitForConditionOn("Wait", () => this.complete, val => val); this.returnTrue = DoAndReturn("Set completed", () => true); this.throwError = DoAndReturn <int>("Throw error", () => throw new Exception("")); }
public BoxedTestInstruction(ITestInstruction <T> instruction) : base(() => new BoxedOperationState <T>(instruction.CreateState())) { }
public static ITestInstruction <object> BoxResult <T>(this ITestInstruction <T> instruction) where T : struct => new BoxedTestInstruction <T>(instruction);
public BoxedTestInstruction(ITestInstruction <T> instruction) : base(() => new BoxedOperationState <T, object>( instruction.CreateState(), value => (object)value)) { }
/// <summary> /// Standard extension method required to support LINQ query syntax. /// Should not be used directly. /// </summary> public static ITestInstruction <TResult> SelectMany <TSource, TSelector, TResult>( this ITestInstruction <TSource> source, Func <TSource, ITestInstruction <TSelector> > selector, Func <TSource, TSelector, TResult> resultSelector) => source .ContinueWith(x => selector(x).Select(y => resultSelector(x, y)));
private void AssertEqual <T>(ITestInstruction <T> left, ITestInstruction <T> right) => Assert.AreEqual( left.ToTask(this.Executor).AssertSynchronousResult(), right.ToTask(this.Executor).AssertSynchronousResult());