public void HandleOrder(Order order) { var context = new PaymentGuardContext(); var state = new State <Order, OrderState>(order, a => a.State) .Define(b => { b.From(OrderState.Initial).To(OrderState.Paid) .Changing(OnTransitioningStateFromInitialToPaidHandler) .Changed(OnTransitionedStateFromInitialToPaidHandler); b.From(OrderState.Paid).To(OrderState.Processed); b.From(OrderState.Processed).To(OrderState.Delivered); b.OnEnter(OrderState.Paid, Guards <OrderState> .From(context, ValidateRequest, PayToPaymentGateway, PersistOrderToRepository )); b.DisableSameStateTransitionFor(OrderState.Paid); }); var hasChangedState = state.ChangeTo(OrderState.Paid); //Assert.Equal(OrderState.Paid, order.State); }