Beispiel #1
0
        public void EventsQueueing(
            IAsyncStateMachine <string, int> machine,
            AutoResetEvent signal)
        {
            const int firstEvent  = 0;
            const int secondEvent = 1;

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

                var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <string, int>();
                stateMachineDefinitionBuilder.In("A").On(firstEvent).Goto("B");
                stateMachineDefinitionBuilder.In("B").On(secondEvent).Goto("C");
                stateMachineDefinitionBuilder.In("C").ExecuteOnEntry(() => signal.Set());
                machine = stateMachineDefinitionBuilder
                          .WithInitialState("A")
                          .Build()
                          .CreateActiveStateMachine();
            });

            "when firing an event onto the state machine".x(async() =>
            {
                await machine.Fire(firstEvent);
                await machine.Fire(secondEvent);
                await machine.Start();
            });

            "it should queue event at the end".x(() =>
                                                 signal
                                                 .WaitOne(1000)
                                                 .Should()
                                                 .BeTrue("state machine should arrive at destination state"));
        }
Beispiel #2
0
        public void LoadingAnInitializedStateMachine(
            IAsyncStateMachine <string, int> machine,
            Exception receivedException)
        {
            "establish an started state machine".x(() =>
            {
                var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <string, int>();
                stateMachineDefinitionBuilder.In("initial");
                machine = stateMachineDefinitionBuilder
                          .WithInitialState("initial")
                          .Build()
                          .CreatePassiveStateMachine();
                machine.Start();
            });

            "when state machine is loaded".x(async() =>
                                             receivedException = await Catch.Exception(async() =>
                                                                                       await machine.Load(A.Fake <IAsyncStateMachineLoader <string> >())));

            "it should throw invalid operation exception".x(() =>
            {
                receivedException.Should().BeOfType <InvalidOperationException>();
                receivedException.Message.Should().Be(ExceptionMessages.StateMachineIsAlreadyInitialized);
            });
        }
        public void EventsQueueing(
            IAsyncStateMachine <string, int> machine)
        {
            const int FirstEvent  = 0;
            const int SecondEvent = 1;

            var arrived = false;

            "establish a passive state machine with transitions".x(() =>
            {
                var stateMachineDefinitionBuilder = new StateMachineDefinitionBuilder <string, int>();
                stateMachineDefinitionBuilder.In("A").On(FirstEvent).Goto("B");
                stateMachineDefinitionBuilder.In("B").On(SecondEvent).Goto("C");
                stateMachineDefinitionBuilder.In("C").ExecuteOnEntry(() => arrived = true);
                machine = stateMachineDefinitionBuilder
                          .WithInitialState("A")
                          .Build()
                          .CreatePassiveStateMachine();
            });

            "when firing an event onto the state machine".x(() =>
            {
                machine.Fire(FirstEvent);
                machine.Fire(SecondEvent);
                machine.Start();
            });

            "it should queue event at the end".x(()
                                                 => arrived.Should().BeTrue("state machine should arrive at destination state"));
        }