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); }
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); }
public void States_should_automatically_be_created_for_the_class() { ExampleStateMachine example = new ExampleStateMachine(); Assert.IsNotNull(ExampleStateMachine.Initial); Assert.AreEqual(ExampleStateMachine.Initial.Name, "Initial"); }
public override void Exit() { base.Exit(); ExampleStateMachine exampleStateMachine = GetMachine <ExampleStateMachine>(); UnityEngine.UI.Button switchStatesButton = exampleStateMachine.switchStates; if (null != switchStatesButton) { switchStatesButton.onClick.RemoveListener(GoToExampleState1); } }
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); }
/// <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)); } }
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); }
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); } }
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); } }
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(); }
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(); }
protected void GoToExampleState1() { ExampleStateMachine exampleStateMachine = GetMachine <ExampleStateMachine>(); exampleStateMachine.ChangeState <ExampleState1>(); }
public override bool CanTransition(ExampleStateMachine machine, OtherState state, string with) { return(true); }
public void I_want_to_see_what_you_see() { var machine = new ExampleStateMachine(); StateMachineInspector.Trace(machine); }
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()); }
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()); }
public override bool CanTransition(ExampleStateMachine machine, StartState state, string with) { return(with.Length > 5); }
public void The_initial_state_should_be_set() { ExampleStateMachine example = new ExampleStateMachine(); Assert.AreEqual(ExampleStateMachine.Initial, example.CurrentState); }
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); }