public void IdTest() { object identifier = new Object(); State target = StateArtifactsFactories.CreateState(identifier); Assert.AreEqual(identifier, target.Id); }
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); }
public void CleanupTest() { StateTransitionTrigger target = StateArtifactsFactories.CreateTrigger(); target.Cleanup(); Assert.IsTrue(((TestTrigger)target).CleanupInvoked); }
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."); } } }
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); } }
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); } }