Ejemplo n.º 1
0
        public void States_should_automatically_be_created_for_the_class()
        {
            ExampleStateMachine example = new ExampleStateMachine();

            Assert.IsNotNull(ExampleStateMachine.Initial);

            Assert.AreEqual(ExampleStateMachine.Initial.Name, "Initial");
        }
Ejemplo n.º 2
0
        public void Typed_events_should_carry_their_data_to_the_expression_other()
        {
            ExampleStateMachine example = new ExampleStateMachine();

            example.SubmitCommentCard(new CommentCard {
                IsComplaint = false
            });

            Assert.AreEqual(ExampleStateMachine.Completed, example.CurrentState);
        }
Ejemplo n.º 3
0
        public void Typed_events_should_carry_their_data_to_the_expression()
        {
            ExampleStateMachine example = new ExampleStateMachine();

            example.SubmitCommentCard(new CommentCard {
                IsComplaint = true
            });

            Assert.AreEqual(ExampleStateMachine.WaitingForManager, example.CurrentState);
        }
Ejemplo n.º 4
0
        public void Multiple_expressions_per_event_should_run_in_order()
        {
            ExampleStateMachine example = new ExampleStateMachine();

            example.SubmitCommentCard(new CommentCard {
                IsComplaint = true
            });

            Assert.AreEqual(ExampleStateMachine.WaitingForManager, example.CurrentState);

            example.BurnCommentCard();

            Assert.AreEqual(ExampleStateMachine.Completed, example.CurrentState);
        }
Ejemplo n.º 5
0
        public void The_transitions_should_work()
        {
            ExampleStateMachine example = new ExampleStateMachine();

            example.SubmitOrder();

            Assert.AreEqual(ExampleStateMachine.WaitingForPayment, example.CurrentState);

            example.SubmitPayment();

            Assert.AreEqual(ExampleStateMachine.WaitingForPaymentApproval, example.CurrentState);

            example.ApprovePayment();

            Assert.AreEqual(ExampleStateMachine.Completed, example.CurrentState);
        }
Ejemplo n.º 6
0
        public void Serializing_a_state_machine_should_restore_properly()
        {
            ExampleStateMachine example = new ExampleStateMachine();

            example.SubmitOrder();

            byte[] data;
            using (MemoryStream output = new MemoryStream())
            {
                _formatter.Serialize(output, example);
                data = output.ToArray();
            }

            using (MemoryStream input = new MemoryStream(data))
            {
                var copied = (ExampleStateMachine)_formatter.Deserialize(input);

                Assert.AreEqual(ExampleStateMachine.WaitingForPayment, copied.CurrentState);
            }
        }
Ejemplo n.º 7
0
        public void The_initial_state_should_be_set()
        {
            ExampleStateMachine example = new ExampleStateMachine();

            Assert.AreEqual(ExampleStateMachine.Initial, example.CurrentState);
        }
Ejemplo n.º 8
0
        public void I_want_to_see_what_you_see()
        {
            var machine = new ExampleStateMachine();

            StateMachineInspector.Trace(machine);
        }