public BaseAuthenticationWorkflow(IBus bus, ICommonWorkflowService commonWorkflowService) : base(commonWorkflowService) { this.bus = bus; State(() => WaitingForSurname); State(() => WaitingForDob); State(() => CheckingCredentials); State(() => Authorized); State(() => Unauthorized); Event(() => ValidResponse); Event(() => InvalidResponse); Initially( When(Start) .Then((wf, phoneNumber) => wf.PhoneNumber = phoneNumber) .Then(wf => AskForSurname(wf)).TransitionTo(WaitingForSurname) ); During(WaitingForSurname, When(SMSReceived).Then((wf, data) => ProcessSurname(wf, data)), When(ValidResponse).Then(wf => AskForDob(wf)).TransitionTo(WaitingForDob), When(InvalidResponse).TransitionTo(Unauthorized) ); During(WaitingForDob, When(SMSReceived).Then((wf, data) => ProcessDob(wf, data)), When(ValidResponse).TransitionTo(Authorized), When(InvalidResponse).TransitionTo(Unauthorized) ); During(CheckingCredentials, When(CheckingCredentials.Enter).Then(wf => AuthorizeCredentials(wf)) ); During(Authorized, When(Authorized.Enter).Then(wf => OnPassedAuthentication(wf))); During(Unauthorized, When(Unauthorized.Enter).Then(wf => OnFailedAuthentication(wf))); }
public MovieBookingWorkflow(IMovieBookingService service, ICommonWorkflowService commonWorkflowService) : base(commonWorkflowService) { this.movieBookingService = service; State(() => WaitingForCinemaSelection); State(() => WaitingForMovieSelection); State(() => WaitingForSlotSelection); State(() => Completed); Event(() => ValidResponse); Event(() => MoreSlotsRequested); //Ideally we would have this in the BaseStateMachine, however it needs to be executed after all of the States have been setup //This could be fixed by using an AbstractFactory to create an instance of the actual workflow classes and force a call //to a method that executes this: http://stackoverflow.com/a/2747280 DuringAny(When(InvalidResponse).Then(wf => SendUnknownResponse(wf))); Initially(When(Start).Then((wf, data) => SendListOfCinemas(wf, data)).TransitionTo(WaitingForCinemaSelection)); During(WaitingForCinemaSelection, When(SMSReceived).Then((wf, data) => ProcessCinemaSelection(wf, data)), When(ValidResponse).Then(wf => SendListOfMovies(wf)).TransitionTo(WaitingForMovieSelection) ); During(WaitingForMovieSelection, When(SMSReceived).Then((wf, data) => ProcessMovieSelection(wf, data)), When(ValidResponse).Then(wf => SendMovieSlots(wf)).TransitionTo(WaitingForSlotSelection) ); During(WaitingForSlotSelection, When(SMSReceived, (msg) => !msg.Equals("MORE")).Then((wf, data) => ProcessSlotSelection(wf, data)), When(SMSReceived, (msg) => msg.Equals("MORE")).Then((wf) => this.RaiseEvent(wf, MoreSlotsRequested)), When(MoreSlotsRequested).Then((wf) => SendMovieSlots(wf)), When(ValidResponse).Then(wf => SendConfirmationCode(wf)).Finalize() ); }
public void TestInitialize() { service = Mock.Of<IMovieBookingService>(); commonWorkflowService = Mock.Of<ICommonWorkflowService>(); sut = new MovieBookingWorkflow(service, commonWorkflowService); }
public void TestInitialize() { service = Mock.Of <IMovieBookingService>(); commonWorkflowService = Mock.Of <ICommonWorkflowService>(); sut = new MovieBookingWorkflow(service, commonWorkflowService); }
public CancelBookingWorkflow(IBus bus, ICommonWorkflowService commonWorkflowService) : base(commonWorkflowService) { this.bus = bus; Initially(When(Start).Then((wf, data) => LookupReservations(wf, data))); }
public void Base_Class_Events_Should_Be_Set() { InMemoryBus bus = new InMemoryBus(); ICommonWorkflowService commonWorkflowService = Mock.Of <ICommonWorkflowService>(); CancelBookingWorkflow wf = new CancelBookingWorkflow(bus, commonWorkflowService); Assert.IsNotNull(wf.Start); Assert.IsNotNull(wf.SMSReceived); }
public void Should_send_list_of_reservations() { InMemoryBus bus = new InMemoryBus(); ICommonWorkflowService commonWorkflowService = Mock.Of <ICommonWorkflowService>(); CancelBookingInstance instance = new CancelBookingInstance(); CancelBookingWorkflow wf = new CancelBookingWorkflow(bus, commonWorkflowService); wf.RaiseEvent(instance, x => x.Start, "+447901234545"); Assert.AreEqual(1, bus.PublishedMessages <SendSms>().Count); Assert.AreEqual("Please select", bus.PublishedMessages <SendSms>().First().Body); }
public BaseStateMachine(ICommonWorkflowService commonWorkflowService) { this.commonWorkflowServer = commonWorkflowService; InstanceState(i => i.CurrentState); Event(() => SMSReceived); Event(() => Start); Event(() => InvalidResponse); Event(() => Continue); //Ideally we would setup common event handlers here e.g. InvalidResponse should fire the SendUnknownResponse method //this could be done by implementing an AbstractFactory to create the actual State Machine, see http://stackoverflow.com/a/2747280 }
public ForkStateMachine(ICommonWorkflowService commonWorkflowService, IBus bus) : base(commonWorkflowService) { this.bus = bus; State(() => WaitingForConfirmation); DuringAny(When(InvalidResponse).Then(wf => SendUnknownResponse(wf))); Initially(When(Start).Then((wf, data) => SendAreYouSure(wf, data)).TransitionTo(WaitingForConfirmation)); During(WaitingForConfirmation, When(SMSReceived, msg => msg.Equals("Y")).Then(wf => CancelExisting(wf)).TransitionTo(Final), When(SMSReceived, msg => msg.Equals("N")).Then(wf => KeepGoingWithExisting(wf)).TransitionTo(Final), When(SMSReceived, msg => IsInvalid(msg)).Then(wf => this.RaiseEvent(wf, InvalidResponse)) ); }
public ChangeBookingWorkflow(IBus bus, ICommonWorkflowService commonWorkflowService) : base(commonWorkflowService) { this.bus = bus; State(() => WaitingForBookingSelection); Event(() => ValidResponse); Initially(When(Start) .Then((wf, phoneNumber) => wf.PhoneNumber = phoneNumber) .Then(wf => SendListOfBookings(wf)) .TransitionTo(WaitingForBookingSelection)); During(WaitingForBookingSelection, When(SMSReceived).Then((wf, data) => ProcessBookingSelection(wf, data)), When(ValidResponse).Then(wf => SendConfirmationQuestion(wf)).TransitionTo(WaitingForConfirmation) ); }
public DisambiguateMovieBookingWorkflow(ICommonWorkflowService commonWorkflowService, IBus bus) : base(commonWorkflowService) { this.bus = bus; State(() => WaitingForSelection); Event(() => ValidResponse); //setup state machine... /* * Send list of movies * WaitForValidSelection */ Initially(When(Start).Then((wf, ph) => SendListOfBookings(wf, ph)).TransitionTo(WaitingForSelection)); During(WaitingForSelection, When(SMSReceived).Then((wf, msg) => ProcessSelection(wf, msg)), When(ValidResponse).Then(wf => Success(wf)).Finalize(), When(InvalidResponse).Then(wf => SendUnknownResponse(wf))); }
public AuthenticatedChangeBookingWorkflow(IBus bus, ICommonWorkflowService commonWorkflowService) : base(bus, commonWorkflowService) { this.bus = bus; State(() => WaitingForBookingSelection); State(() => WaitingForConfirmation); State(() => WaitingForSelectionDisambiguation); State(() => Starting); Event(() => BookingsFound); During(Starting, When(Starting.Enter).Then(wf => LookupBookings(wf)), When(BookingsFound, numFound => numFound == 0).Then(wf => { /*send sorry*/ }).Finalize(), When(BookingsFound, numFound => numFound == 1).Then(wf => SendConfirmationQuestion(wf)).TransitionTo(WaitingForConfirmation), When(BookingsFound, numFound => numFound > 1).Then(wf => DisambiguateBooking(wf)).TransitionTo(WaitingForSelectionDisambiguation) ); During(WaitingForSelectionDisambiguation, When(Continue).Then((wf, data) => TheNextThing(wf, data)).Then(wf => SendConfirmationQuestion(wf)).TransitionTo(WaitingForConfirmation)); }
public StateMachineMapper(IBus bus, ICommonWorkflowService commonWorkflowService) { this.bus = bus; this.commonWorkflowService = commonWorkflowService; }