Exemplo n.º 1
0
        public void testStatefulSel()
        {
            log.enterScope("testStatefulSel");

            bool first = true;

            var foo = new StatefulSelector(new BehaviorAction(delegate(){
                return(BehaviorReturnCode.Failure);
            }), new BehaviorAction(delegate() {
                if (first)
                {
                    first = false;
                    return(BehaviorReturnCode.Running);
                }
                else
                {
                    return(BehaviorReturnCode.Failure);
                }
            }), new BehaviorAction(delegate(){
                return(BehaviorReturnCode.Success);
            }));

            new VerificationPoint().VerifyEquals("1st running", true, foo.Behave(), BehaviorReturnCode.Running);
            new VerificationPoint().VerifyEquals("2nd success", true, foo.Behave(), BehaviorReturnCode.Success);
            new VerificationPoint().VerifyEquals("3rd success", true, foo.Behave(), BehaviorReturnCode.Success);

            log.logMessage("restting first");
            first = true;

            new VerificationPoint().VerifyEquals("after reset running", true, foo.Behave(), BehaviorReturnCode.Running);
            new VerificationPoint().VerifyEquals("final success", true, foo.Behave(), BehaviorReturnCode.Success);

            log.exitScope();
        }
Exemplo n.º 2
0
        public void When_running_Then_complete_with_many_behave_calls()
        {
            var sequence = new StatefulSelector(
                new BehaviourAction(CalledAndFailed),
                new BehaviourAction(new TestHelper().RunningTwiceThenSuccess),
                new BehaviourAction(() => BehaviourReturnCode.Success)
                );

            Assert.AreEqual(BehaviourReturnCode.Running, sequence.Behave());
            Assert.AreEqual(BehaviourReturnCode.Running, sequence.Behave());
            Assert.AreEqual(BehaviourReturnCode.Running, sequence.Behave());
            Assert.AreEqual(BehaviourReturnCode.Success, sequence.Behave());
            Assert.AreEqual(1, _calledAndFailedTimes);
        }
Exemplo n.º 3
0
        public void testStatefulSel()
        {
            _log.enterScope("testStatefulSel");

            bool first  = true;
            bool second = true;
            var  foo    = new StatefulSelector(new BehaviorAction(delegate(){
                return(BehaviorReturnCode.Failure);
            }), new BehaviorAction(delegate() {
                if (first)
                {
                    first = false;
                    return(BehaviorReturnCode.Running);
                }
                else
                {
                    return(BehaviorReturnCode.Failure);
                }
            }), new BehaviorAction(delegate(){
                if (first)
                {
                    return(BehaviorReturnCode.Success);
                }
                else
                {
                    if (second)
                    {
                        second = false;
                        return(BehaviorReturnCode.Success);
                    }
                    else
                    {
                        return(BehaviorReturnCode.Failure);
                    }
                }
            }));

            Verify.VerifyEquals("1st running", true, foo.Behave(), BehaviorReturnCode.Running);
            Verify.VerifyEquals("2nd success", true, foo.Behave(), BehaviorReturnCode.Success);
            Verify.VerifyEquals("3rd failure", true, foo.Behave(), BehaviorReturnCode.Failure);

            _log.logMessage("restting flags");
            first  = true;
            second = true;

            Verify.VerifyEquals("after reset running", true, foo.Behave(), BehaviorReturnCode.Running);
            Verify.VerifyEquals("final success", true, foo.Behave(), BehaviorReturnCode.Success);
            Verify.VerifyEquals("final failure", true, foo.Behave(), BehaviorReturnCode.Failure);

            _log.exitScope();
        }
Exemplo n.º 4
0
        public void TestStatefulSel()
        {
            bool first  = true;
            bool second = true;
            var  foo    = new StatefulSelector(new BehaviorAction(delegate(){
                return(BehaviorReturnCode.Failure);
            }), new BehaviorAction(delegate() {
                if (first)
                {
                    first = false;
                    return(BehaviorReturnCode.Running);
                }
                else
                {
                    return(BehaviorReturnCode.Failure);
                }
            }), new BehaviorAction(delegate(){
                if (first)
                {
                    return(BehaviorReturnCode.Success);
                }
                else
                {
                    if (second)
                    {
                        second = false;
                        return(BehaviorReturnCode.Success);
                    }
                    else
                    {
                        return(BehaviorReturnCode.Failure);
                    }
                }
            }));

            Assert.That(foo.Behave() == BehaviorReturnCode.Running);
            Assert.That(foo.Behave() == BehaviorReturnCode.Success);
            Assert.That(foo.Behave() == BehaviorReturnCode.Failure);

            first  = true;
            second = true;

            Assert.That(foo.Behave() == BehaviorReturnCode.Running);
            Assert.That(foo.Behave() == BehaviorReturnCode.Success);
            Assert.That(foo.Behave() == BehaviorReturnCode.Failure);
        }