示例#1
0
文件: StateTest.cs 项目: rinavin/RCJS
        public void IdTest()
        {
            object identifier = new Object();
            State  target     = StateArtifactsFactories.CreateState(identifier);

            Assert.AreEqual(identifier, target.Id);
        }
示例#2
0
        public void TriggersTest()
        {
            StateTransitionTrigger trigger;
            PrivateObject          privateObj;

            StateArtifactsFactories.CreateStateTransitionTriggerPrivateObject(out trigger, out privateObj);

            var target = (TestTrigger)trigger;

            bool eventRaised;

            target.Triggered += (sender, args) =>
            {
                eventRaised = true;
            };

            target.Setup();
            Assert.IsTrue(target.SetupInvoked);

            eventRaised = false;
            privateObj.Invoke("OnTriggered");
            Assert.IsTrue(eventRaised);

            target.Cleanup();
            Assert.IsTrue(target.CleanupInvoked);
        }
示例#3
0
        public void CleanupTest()
        {
            StateTransitionTrigger target = StateArtifactsFactories.CreateTrigger();

            target.Cleanup();
            Assert.IsTrue(((TestTrigger)target).CleanupInvoked);
        }
示例#4
0
        public void TriggerEventsTest()
        {
            object          nextStateId = new Object();
            StateTransition target;
            PrivateObject   privateObj;

            StateArtifactsFactories.CreateTransitionPrivateObject(nextStateId, out target, out privateObj);

            var triggers = StateArtifactsFactories.CreateTriggerList(3);

            target.AddTriggers(triggers);

            bool eventRaised;

            target.TransitionTriggered += new EventHandler <StateTransitionTriggeredEventArgs>((sender, args) =>
            {
                eventRaised = true;
            });

            target.Setup();

            foreach (TestTrigger trigger in triggers)
            {
                eventRaised = false;
                trigger.TriggerNow();
                Assert.IsTrue(eventRaised, "'Triggered' event not raised.");
            }

            target.Cleanup();

            foreach (TestTrigger trigger in triggers)
            {
                eventRaised = false;
                try
                {
                    trigger.TriggerNow();
                    Assert.Fail("The test trigger did not raise an exception although it should have.");
                }
                catch (AssertFailedException)
                {
                    // This is the correct path of execution.
                    // the Test Triggers throw an assertion if you try to trigger them before
                    // setup.
                }
                finally
                {
                    // Now, just make sure nothing triggered the event.
                    Assert.IsFalse(eventRaised, "'Triggered' event not raised.");
                }
            }
        }
示例#5
0
文件: StateTest.cs 项目: rinavin/RCJS
        public void LeaveTest()
        {
            State target      = StateArtifactsFactories.CreateState("abcd");
            var   transitions = StateArtifactsFactories.CreateTransitionList("a", "b", "c");

            foreach (var t in transitions)
            {
                t.AddTrigger(StateArtifactsFactories.CreateTrigger());
            }
            target.AddTransitions(transitions);

            target.DefaultTransition = StateArtifactsFactories.CreateTransition("d");

            target.Leave();
            Assert.IsTrue(((TestState)target).OnLeaveInvoked, "OnLeave was not called");
            foreach (TestTransition t in transitions)
            {
                Assert.IsTrue(t.CleanupInvoked, "Cleanup was not called for {0}", t);
            }
        }
示例#6
0
文件: StateTest.cs 项目: rinavin/RCJS
        public void EnterTest()
        {
            State target = StateArtifactsFactories.CreateState("abcd");

            Assert.IsNotNull(target.Transitions);
            var transitions = StateArtifactsFactories.CreateTransitionList("a", "b", "c");

            foreach (var t in transitions)
            {
                t.AddTrigger(StateArtifactsFactories.CreateTrigger());
            }
            target.AddTransitions(transitions);

            target.DefaultTransition = StateArtifactsFactories.CreateTransition("d");

            target.Enter();
            Assert.IsTrue(((TestState)target).OnEnterInvoked, "OnEnter was not called");
            foreach (TestTransition t in transitions)
            {
                Assert.IsTrue(t.SetupInvoked, "Setup was not called for {0}", t);
            }
        }