Ejemplo n.º 1
0
        public void PriorityEventsQueueing(
            IStateMachine <string, int> machine,
            AutoResetEvent signal)
        {
            const int FirstEvent  = 0;
            const int SecondEvent = 1;

            "establish an active state machine with transitions"._(() =>
            {
                signal = new AutoResetEvent(false);

                machine = new ActiveStateMachine <string, int>();

                machine.In("A").On(SecondEvent).Goto("B");
                machine.In("B").On(FirstEvent).Goto("C");
                machine.In("C").ExecuteOnEntry(() => signal.Set());

                machine.Initialize("A");
            });

            "when firing a priority event onto the state machine"._(() =>
            {
                machine.Fire(FirstEvent);
                machine.FirePriority(SecondEvent);
                machine.Start();
            });

            "it should queue event at the front"._(() =>
                                                   signal.WaitOne(1000).Should().BeTrue("state machine should arrive at destination state"));
        }
Ejemplo n.º 2
0
        public void CustomFactory(
            ActiveStateMachine <string, int> machine,
            StandardFactory <string, int> factory)
        {
            "establish a custom factory"._(() =>
            {
                factory = A.Fake <StandardFactory <string, int> >();
            });

            "when creating an active state machine"._(() =>
            {
                machine = new ActiveStateMachine <string, int>("_", factory);

                machine.In("initial").On(42).Goto("answer");
            });

            "it should use custom factory to create internal instances"._(() =>
                                                                          A.CallTo(factory).MustHaveHappened());
        }