public void Throwing_an_exception_from_an_event_handler() { _workflow = StateMachineWorkflow.New<SubjectWorkflow, Subject>(x => { x.AccessCurrentState(y => y.CurrentState); x.Initially() .When(e => e.Create) .Then(i => i.Create) .TransitionTo(s => s.Created) .InCaseOf() .Exception<SubjectException>() .Then(i => { _instanceHandlerCalled = true; }) .Then(() => _handlerCalled = true) .TransitionTo(s => s.Failed); }); _subject = new Subject(); _instance = _workflow.GetInstance(_subject); _instance.RaiseEvent(x => x.Create); }
public void Throwing_an_exception_from_an_event_handler() { _workflow = StateMachineWorkflow.New <SubjectWorkflow, Subject>(x => { x.AccessCurrentState(y => y.CurrentState); x.Initially() .When(e => e.Create) .Then(i => i.Create) .TransitionTo(s => s.Created) .InCaseOf() .Exception <SubjectException>() .Then(i => { _instanceHandlerCalled = true; }) .Then(() => _handlerCalled = true) .TransitionTo(s => s.Failed); }); _subject = new Subject(); _instance = _workflow.GetInstance(_subject); _instance.RaiseEvent(x => x.Create); }
public void Should_be_easy() { StateMachineWorkflow <RemoteRequestEngineWorkflow, RemoteRequestEngine> workflow = StateMachineWorkflow.New <RemoteRequestEngineWorkflow, RemoteRequestEngine>(x => { x.AccessCurrentState(i => i.CurrentState); x.Initially() .When(w => w.Start) .TransitionTo(y => y.Running) .When(y => y.Stop) .TransitionTo(y => y.Stopped); x.During(y => y.Running) .When(y => y.Interrupted) .Then(i => i.CancelPendingRequest) .When(y => y.Stop) .Then(i => i.CancelAllPendingRequests) .TransitionTo(y => y.Stopped); x.During(y => y.Stopped) .When(y => y.Start) .TransitionTo(y => y.Running) .When(y => y.Dispose) .Finalize(); x.Finally() .Then(instance => Trace.WriteLine("Completed")); }); var visitor = new TraceStateMachineVisitor(); workflow.Accept(visitor); var engine = new RemoteRequestEngine(); WorkflowInstance <RemoteRequestEngineWorkflow> engineInstance = workflow.GetInstance(engine); engineInstance.RaiseEvent(x => x.Start); engineInstance.RaiseEvent(x => x.Interrupted, new InterruptImpl { Source = "End of the world" }); engineInstance.RaiseEvent(x => x.Stop); engineInstance.RaiseEvent(x => x.Dispose); Trace.WriteLine("Final State: " + engineInstance.CurrentState); }
public void Raising_multiple_events() { _workflow = StateMachineWorkflow.New <TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Start) .TransitionTo(y => y.Running); x.During(y => y.Running) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Start); _instance.RaiseEvent(x => x.Finish); }
public void An_event_causing_a_state_transition() { _workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Finish); }
public void An_event_causing_a_state_transition() { _workflow = StateMachineWorkflow.New <TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Finish); }
public void A_message_event_changes_the_state() { _workflow = StateMachineWorkflow.New <TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Finish, new Result { Value = "Success" }); }
public void A_simple_event_is_raised() { _workflow = StateMachineWorkflow.New <TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .Then(() => _nonInstanceValue = true) .Then(instance => instance.ConstantValue = "Success") .TransitionTo(y => y.Completed); }); _testInstance = new TestInstance(); _instance = _workflow.GetInstance(_testInstance); _instance.RaiseEvent(x => x.Finish); }
public void A_message_event_is_raised() { _workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .Then(() => _nonInstanceValue = true) .Then(instance => instance.MessageValue = "Success") .Then((instance, message) => instance.MessageValue = message.Value) .TransitionTo(y => y.Completed); }); _testInstance = new TestInstance(); _instance = _workflow.GetInstance(_testInstance); _instance.RaiseEvent(x => x.Finish, new Result { Value = "Success" }); }
public void Raising_multiple_events() { _workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Start) .TransitionTo(y => y.Running); x.During(y => y.Running) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Start); _instance.RaiseEvent(x => x.Finish); }
public void A_message_event_changes_the_state() { _workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x => { x.AccessCurrentState(y => y.CurrentState); x.During(y => y.Initial) .When(y => y.Finish) .TransitionTo(y => y.Completed); }); _instance = _workflow.GetInstance(new TestInstance()); _instance.RaiseEvent(x => x.Finish, new Result { Value = "Success" }); }
public void Should_be_easy() { StateMachineWorkflow <RemoteRequestEngineWorkflow, RemoteRequestEngine> workflow = StateMachineWorkflow.New <RemoteRequestEngineWorkflow, RemoteRequestEngine>(x => { x.AccessCurrentState(i => i.CurrentState); x.Initially(c => { c.When(e => e.Start, t => { t.TransitionTo(y => y.Running); }); c.When(e => e.Stop, t => { t.TransitionTo(y => y.Stopped); }); }); x.During(s => s.Running, c => { c.When(e => e.Interrupted, t => { t.TransitionTo(y => y.Stopped); }); c.When(e => e.Stop, t => { t.TransitionTo(y => y.Stopped); }); }); x.During(s => s.Stopped, c => { c.When(e => e.Start, t => { t.TransitionTo(y => y.Running); }); c.When(e => e.Dispose, t => { t.Finalize(); }); }); x.DuringAny(c => { c.When(e => e.Dispose) .Then(() => {}); }); x.Finally(t => { t.Then(instance => Trace.WriteLine("Completed")); }); }); var visitor = new TraceStateMachineVisitor(); workflow.Accept(visitor); var engine = new RemoteRequestEngine(); WorkflowInstance <RemoteRequestEngineWorkflow> engineInstance = workflow.GetInstance(engine); engineInstance.RaiseEvent(x => x.Start); engineInstance.RaiseEvent(x => x.Stop); engineInstance.RaiseEvent(x => x.Dispose); Trace.WriteLine("Final State: " + engineInstance.CurrentState); }
public void Send(TChannel message) { _instance.RaiseEvent(_event, message); }