Example #1
0
        public GuardTest()
        {
            this.testee = new TestStateMachine<StateMachine.States, StateMachine.Events>();

            this.testee.Initialize(StateMachine.States.A);
            this.testee.Start();
        }
Example #2
0
        public void DefineHierarchySyntax()
        {
            var stateMachine = new TestStateMachine<int, int>();

            stateMachine.DefineHierarchyOn(1)
                .WithHistoryType(HistoryType.Deep)
                .WithInitialSubState(2)
                .WithSubState(3)
                .WithSubState(4);
        }
        public ExceptionCasesTest()
        {
            this.testee = new TestStateMachine<StateMachine.States, StateMachine.Events>();

            this.testee.TransitionExceptionThrown += (sender, eventArgs) =>
                                                         {
                                                             this.recordedStateId = eventArgs.StateId;
                                                             this.recordedEventId = eventArgs.EventId;
                                                             this.recordedEventArgument = eventArgs.EventArgument;
                                                             this.recordedException = eventArgs.Exception;
                                                         };
        }
        public void Should_initialize_simple_event_property()
        {
            var stateMachine = new TestStateMachine();

            Assert.That(stateMachine.ThisIsASimpleEvent, Is.Not.Null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="TransitionsTest"/> class.
 /// </summary>
 public TransitionsTest()
 {
     this.testee = new TestStateMachine<StateMachine.States, StateMachine.Events>();
 }
 public SagaConfigurationObserver_Specs()
 {
     _machine    = new TestStateMachine();
     _repository = new InMemorySagaRepository <Instance>();
 }
        public void InstantiateStatePerTransition()
        {
            var sm = new TestStateMachine();
            sm.StateInstantiationMode = StateInstantiationMode.PerTransition;

            sm.State<IdleState>()
                .On(TelephoneTrigger.PickingUpPhone).GoesTo<CountingState>();
            sm.State<CountingState>()
                .On(TelephoneTrigger.HangingUp).GoesTo<IdleState>();

            sm.Start();

            // Goto CountingState
            sm.Trigger(TelephoneTrigger.PickingUpPhone);
            // Go back
            sm.Trigger(TelephoneTrigger.HangingUp);
            // Goto CountingState again
            sm.Trigger(TelephoneTrigger.PickingUpPhone);

            // The CurrentState should have been freshly created, meaning that CountingState.EnteringSelfCount should be 1
            Assert.IsTrue(
                (sm.CurrentState is CountingState) && ((sm.CurrentState as CountingState).EnteringSelfCount == 1),
                string.Format("Unexpected EnteringSelfCount!"));

        }
        public void StateHistoryTrim()
        {
            var sm = new TestStateMachine();

            sm.State<IdleState>()
                .On(TelephoneTrigger.PickingUpPhone).GoesTo<CountingState>();
            sm.State<CountingState>()
                .On(TelephoneTrigger.HangingUp).GoesTo<IdleState>();

            sm.Start();

            // Transition a lot of times
            for (int a = 0;a<1000;a++)
            {
                sm.Trigger(TelephoneTrigger.PickingUpPhone);
                sm.Trigger(TelephoneTrigger.HangingUp);
            }

            // The state history should be 90-100 items
            Assert.IsTrue((sm.StateHistory.Length >= 90) && (sm.StateHistory.Length <= 100),
                          string.Format("{0} states in history", sm.StateHistory.Length));

            sm.StateHistoryTrimThreshold = 50;

            // The state history should be 45-50 items
            Assert.IsTrue((sm.StateHistory.Length >= 45) && (sm.StateHistory.Length <= 50),
                          string.Format("{0} states in history", sm.StateHistory.Length));
        }
 public void A_state_is_declared()
 {
     _machine = new TestStateMachine();
 }
        public void ConfigurationReentrantState()
        {
            var sm = new TestStateMachine();

            sm.State<IdleState>()
                .On(TelephoneTrigger.PickingUpPhone).GoesTo<CountingState>();

            sm.State<CountingState>()
                .On(TelephoneTrigger.DialedNumber).GoesTo<CountingState>()
                .On(TelephoneTrigger.HangingUp).GoesTo<IdleState>();

            sm.Start();

            // Goto CountingState, EnteringCount should be 1
            sm.Trigger(TelephoneTrigger.PickingUpPhone);
            Assert.IsTrue(sm.EnteringCount == 1, "EnteringCount != 1");

            // Reentry
            sm.Trigger(TelephoneTrigger.DialedNumber);
            Assert.IsTrue((sm.EnteringCount == 2) && (sm.ExitingCount == 1), "EnteringCount != 2 || ExitingCount != 1");

            // Back to Idle
            sm.Trigger(TelephoneTrigger.HangingUp);
            Assert.IsTrue((sm.EnteringCount == 2) && (sm.ExitingCount == 2), "EnteringCount != 2 || ExitingCount != 2");
        }
 public When_a_saga_goes_straight_to_finalized()
 {
     _machine    = new TestStateMachine();
     _repository = new InMemorySagaRepository <Instance>();
 }
Example #12
0
 public When_an_event_is_defined_as_ignored_for_state()
 {
     _machine              = new TestStateMachine();
     _repository           = new InMemorySagaRepository <Instance>();
     _faultMessageContexts = new List <ConsumeContext <Fault> >();
 }
        public void Should_initialize_inherited_initial_state_property()
        {
            var stateMachine = new TestStateMachine();

            Assert.That(stateMachine.Initial, Is.Not.Null);
        }
        public void Should_initialize_generic_event_property()
        {
            var stateMachine = new TestStateMachine();

            Assert.That(stateMachine.ThisIsAnEventConsumingData, Is.Not.Null);
        }
        public void Should_register_simple_event_property()
        {
            var stateMachine = new TestStateMachine();

            Assert.That(stateMachine.Events, Contains.Item(stateMachine.ThisIsASimpleEvent));
        }
        public void Should_initialize_declared_state_property()
        {
            var stateMachine = new TestStateMachine();

            Assert.That(stateMachine.ThisIsAState, Is.Not.Null);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StateMachineBuildHierarchyTest"/> class.
 /// </summary>
 public StateMachineBuildHierarchyTest()
 {
     this.testee = new TestStateMachine <StateMachine.States, StateMachine.Events>();
 }
 public When_a_remove_expression_is_specified()
 {
     _machine    = new TestStateMachine();
     _repository = new InMemorySagaRepository <Instance>();
 }
        public void Should_register_declared_state_property()
        {
            var stateMachine = new TestStateMachine();

            Assert.That(stateMachine.States, Contains.Item(stateMachine.ThisIsAState));
        }
Example #20
0
 public Using_the_testing_framework_built_into_masstransit()
 {
     _machine = new TestStateMachine();
 }
        public void Should_register_generic_event_property()
        {
            var stateMachine = new TestStateMachine();

            Assert.That(stateMachine.Events, Contains.Item(stateMachine.ThisIsAnEventConsumingData));
        }
        public void UsingImplicitContext()
        {
            var sm = new TestStateMachine();
            sm.CurrentDate = DateTime.MinValue.Date;

            sm.State<IdleState>()
                .On(TelephoneTrigger.PickingUpPhone).GoesTo<DateReportingState>();
            sm.Start();

            sm.Trigger(TelephoneTrigger.PickingUpPhone);

            // The state should've been able to use the default context (the state machine) to set its CurrentDate property
            Assert.IsTrue(sm.CurrentDate.Equals(DateTime.Now.Date), "Wrong date in state machine!");
        }
        public void Should_register_inherited_initial_state_property()
        {
            var stateMachine = new TestStateMachine();

            Assert.That(stateMachine.States, Contains.Item(stateMachine.Initial));
        }
        public void VerifyStateSingletons()
        {
            var sm = new TestStateMachine();
            // No setting of the value here, Singleton should be the default.

            sm.State<IdleState>()
                .On(TelephoneTrigger.PickingUpPhone).GoesTo<CountingState>();
            sm.State<CountingState>()
                .On(TelephoneTrigger.HangingUp).GoesTo<IdleState>();

            sm.Start();

            // Goto CountingState
            sm.Trigger(TelephoneTrigger.PickingUpPhone);
            // Go back
            sm.Trigger(TelephoneTrigger.HangingUp);
            // Goto CountingState again
            sm.Trigger(TelephoneTrigger.PickingUpPhone);

            // The CurrentState should have been freshly created, meaning that CountingState.EnteringSelfCount should be 1
            Assert.IsTrue(
                (sm.CurrentState is CountingState) && ((sm.CurrentState as CountingState).EnteringSelfCount == 2),
                string.Format("Unexpected EnteringSelfCount!"));

        }
Example #25
0
 protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
 {
     _machine    = new TestStateMachine();
     _repository = new InMemorySagaRepository <Instance>();
 }
        public void StopCallsExit()
        {
            var sm = new TestStateMachine();

            sm.State<IdleState>()
                .On(TelephoneTrigger.PickingUpPhone).GoesTo<CountingState>();
            sm.State<CountingState>()
                .On(TelephoneTrigger.HangingUp).GoesTo<IdleState>();

            sm.Start();

            sm.Trigger(TelephoneTrigger.PickingUpPhone);
            sm.Trigger(TelephoneTrigger.HangingUp);
            sm.Trigger(TelephoneTrigger.PickingUpPhone);

            Assert.IsTrue((sm.EnteringCount == 2) && (sm.ExitingCount == 1), "Unexpected EnteringCount / ExitingCount!");

            sm.Stop();

            Assert.IsTrue((sm.EnteringCount == 2) && (sm.ExitingCount == 2), "Unexpected EnteringCount / ExitingCount on Stop!");
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="StateMachineBuildHierarchyTest"/> class.
 /// </summary>
 public StateMachineBuildHierarchyTest()
 {
     this.testee = new TestStateMachine<StateMachine.States, StateMachine.Events>();
 }
        protected override void ConfigureInputQueueEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
        {
            base.ConfigureInputQueueEndpoint(configurator);

            _repository = new InMemorySagaRepository<Request_Specs.TestState>();

            var settings = new RequestSettingsImpl(ServiceQueueAddress, QuartzQueueAddress, TimeSpan.FromSeconds(1));

            _machine = new TestStateMachine(settings);

            configurator.StateMachineSaga(_machine, _repository);
        }
Example #29
0
 public When_processing_a_lot_of_saga_instances()
 {
     _machine    = new TestStateMachine();
     _repository = new InMemorySagaRepository <Instance>();
 }
Example #30
0
 public StateActionTest()
 {
     this.testee = new TestStateMachine<StateMachine.States, StateMachine.Events>();
 }
Example #31
0
            protected override void ConfigureInMemoryReceiveEndpoint(IInMemoryReceiveEndpointConfigurator configurator)
            {
                _machine = new TestStateMachine();

                configurator.StateMachineSaga(_machine, _repository);
            }
 public Using_a_simple_state_machine()
 {
     _machine    = new TestStateMachine();
     _repository = new InMemorySagaRepository <Instance>();
 }
Example #33
0
 public Triggering_a_change_event_from_a_transition()
 {
     _machine    = new TestStateMachine();
     _repository = new InMemorySagaRepository <Instance>();
 }