Exemple #1
0
        public void TestFailedWait()
        {
            MockQuestion.Setup(x => x.RequestAs(It.IsAny <IActor>())).Returns(1);
            MockCondition.Setup(x => x.Evaluate(It.IsAny <int>())).Returns(false);

            Actor.Invoking(actor => actor.AskingFor(ValueAfterWaiting.Until(MockQuestion.Object, MockCondition.Object).ForUpTo(0)))
            .Should().Throw <WaitingException <int> >(because: "the Question should not satisfy the condition");
        }
Exemple #2
0
        public void TestSuccessfulWait()
        {
            MockQuestion.Setup(x => x.RequestAs(It.IsAny <IActor>())).Returns(1);
            MockCondition.Setup(x => x.Evaluate(It.IsAny <int>())).Returns(true);

            Actor.AskingFor(ValueAfterWaiting.Until(MockQuestion.Object, MockCondition.Object).ForUpTo(0))
            .Should().Be(1, because: "waiting should return the Question's final answer");
        }
        /// <summary>
        /// A simplified extension method for waiting.
        /// Calls will look like `Actor.WaitsUntil(...)` instead of `Actor.AsksFor(ValueAfterWaiting.Until(...))`.
        /// </summary>
        /// <typeparam name="TAnswer">The type of the question's answer value.</typeparam>
        /// <param name="actor">The Screenplay actor.</param>
        /// <param name="question">The question upon whose answer to wait.</param>
        /// <param name="condition">The expected condition for which to wait.</param>
        /// <param name="timeout">The timeout override in seconds. If null, use the standard timeout value.</param>
        /// <param name="additional">An additional amount to add to the timeout. Defaults to 0.</param>
        /// <returns></returns>
        public static TAnswer WaitsUntil <TAnswer>(
            this IActor actor,
            IQuestion <TAnswer> question,
            ICondition <TAnswer> condition,
            int?timeout    = null,
            int additional = 0) =>

        actor.AsksFor(ValueAfterWaiting.Until(question, condition).ForUpTo(timeout).ForAnAdditional(additional));
Exemple #4
0
        public void TestSuccessfulWaitAfterChange()
        {
            const int limit       = 5;
            int       incrementer = 0;

            MockQuestion.Setup(x => x.RequestAs(It.IsAny <IActor>())).Returns(() => ++ incrementer);
            MockCondition.Setup(x => x.Evaluate(It.Is <int>(v => v < limit))).Returns(false);
            MockCondition.Setup(x => x.Evaluate(It.Is <int>(v => v >= limit))).Returns(true);

            Actor.AskingFor(ValueAfterWaiting.Until(MockQuestion.Object, MockCondition.Object).ForUpTo(1))
            .Should().Be(limit, because: "waiting should return the Question's final answer");

            incrementer.Should().Be(limit, because: $"the Question should be called {limit} times");
        }