Exemplo n.º 1
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);
        }
Exemplo 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);
        }
Exemplo n.º 3
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");
        }
Exemplo n.º 4
0
    public override void Exit()
    {
        base.Exit();

        ExampleStateMachine exampleStateMachine = GetMachine <ExampleStateMachine>();

        UnityEngine.UI.Button switchStatesButton = exampleStateMachine.switchStates;
        if (null != switchStatesButton)
        {
            switchStatesButton.onClick.RemoveListener(GoToExampleState1);
        }
    }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
    /// <summary>
    /// StateInterface::Execute() is an abstract method where
    ///     the functionality of the state is performed.
    /// </summary>
    public override void Execute()
    {
        ExampleStateMachine exampleStateMachine = GetMachine <ExampleStateMachine>();

        Quaternion rotation = exampleStateMachine.transform.rotation;

        rotation *= Quaternion.Euler(0, -exampleStateMachine.rotationSpeed * Time.deltaTime, 0);
        exampleStateMachine.transform.rotation = rotation;

        Renderer renderer = exampleStateMachine.GetComponentInChildren <Renderer>();

        if (null != renderer)
        {
            renderer.material.color = Color.Lerp(Color.green, Color.cyan, Mathf.PingPong(Time.time, 1));
        }
    }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
0
    public override void Enter()
    {
        base.Enter();

        ExampleStateMachine exampleStateMachine = GetMachine <ExampleStateMachine>();

        UnityEngine.UI.Button switchStatesButton = exampleStateMachine.switchStates;
        if (null != switchStatesButton)
        {
            UnityEngine.UI.Text buttonText = switchStatesButton.GetComponentInChildren <UnityEngine.UI.Text>();
            if (null != buttonText)
            {
                buttonText.text = "Go to\nthe First State!";
            }

            switchStatesButton.onClick.AddListener(GoToExampleState1);
        }
    }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
		public void Saving_a_state_machine_should_work()
		{
			Guid transactionId;

			using (var unitOfWork = UnitOfWork.Start())
			using (var transaction = unitOfWork.BeginTransaction(IsolationLevel.Serializable))
			{
				using(var repository = new NHibernateRepository() )
				{
					ExampleStateMachine machine = new ExampleStateMachine();

					repository.Save(machine);

					transactionId = machine.TransactionId;
				}

				transaction.Commit();
			}
			UnitOfWork.Finish();

			using (var unitOfWork = UnitOfWork.Start())
			using (var transaction = unitOfWork.BeginTransaction(IsolationLevel.Serializable))
			{
				using (var repository = new NHibernateRepository())
				{
					ExampleStateMachine machine = repository.Get<ExampleStateMachine>(transactionId);

					machine.SubmitOrder();

					repository.Update(machine);
				}

				transaction.Commit();
			}
			UnitOfWork.Finish();


		}
Exemplo n.º 11
0
        public void Saving_a_state_machine_should_work()
        {
            Guid transactionId;

            using (var unitOfWork = UnitOfWork.Start())
                using (var transaction = unitOfWork.BeginTransaction(IsolationLevel.Serializable))
                {
                    using (var repository = new NHibernateRepository())
                    {
                        ExampleStateMachine machine = new ExampleStateMachine();

                        repository.Save(machine);

                        transactionId = machine.TransactionId;
                    }

                    transaction.Commit();
                }
            UnitOfWork.Finish();

            using (var unitOfWork = UnitOfWork.Start())
                using (var transaction = unitOfWork.BeginTransaction(IsolationLevel.Serializable))
                {
                    using (var repository = new NHibernateRepository())
                    {
                        ExampleStateMachine machine = repository.Get <ExampleStateMachine>(transactionId);

                        machine.SubmitOrder();

                        repository.Update(machine);
                    }

                    transaction.Commit();
                }
            UnitOfWork.Finish();
        }
Exemplo n.º 12
0
    protected void GoToExampleState1()
    {
        ExampleStateMachine exampleStateMachine = GetMachine <ExampleStateMachine>();

        exampleStateMachine.ChangeState <ExampleState1>();
    }
Exemplo n.º 13
0
 public override bool CanTransition(ExampleStateMachine machine, OtherState state, string with)
 {
     return(true);
 }
Exemplo n.º 14
0
        public void I_want_to_see_what_you_see()
        {
            var machine = new ExampleStateMachine();

            StateMachineInspector.Trace(machine);
        }
Exemplo n.º 15
0
        public override StartState.StartState DoTransition(ExampleStateMachine machine, OtherState state, string with)
        {
            machine.Print("You wrote literally anything! Going back to the start state.");

            return(new StartState.StartState());
        }
Exemplo n.º 16
0
        public override OtherState.OtherState DoTransition(ExampleStateMachine machine, StartState state, string with)
        {
            machine.Print("You wrote something with more than 5 characters! Now going into the other state.");

            return(new OtherState.OtherState());
        }
Exemplo n.º 17
0
 public override bool CanTransition(ExampleStateMachine machine, StartState state, string with)
 {
     return(with.Length > 5);
 }
Exemplo n.º 18
0
        public void The_initial_state_should_be_set()
        {
            ExampleStateMachine example = new ExampleStateMachine();

            Assert.AreEqual(ExampleStateMachine.Initial, example.CurrentState);
        }
Exemplo n.º 19
0
        public override StartState DoTransition(ExampleStateMachine machine, StartState state, string with)
        {
            machine.Print("You wrote something with no more than 5 characters! Staying in the start state.");

            return(state);
        }