コード例 #1
0
        public void State_raised_creation_event_on_machine_creation()
        {
            var given         = new Given_AutomatonymousSaga(m => m.MakingCoffee);
            var creationEvent = ExtractFirstEvent <DomainEvent>(given.SagaDataAggregate);

            Assert.IsInstanceOf <SagaCreatedEvent <SoftwareProgrammingSagaData> >(creationEvent);
        }
コード例 #2
0
        public void State_is_changed()
        {
            var given = new Given_AutomatonymousSaga(m => m.MakingCoffee);

            When_execute_valid_transaction(given.SagaInstance, new CoffeMadeEvent(Guid.NewGuid(), Guid.NewGuid()));
            Assert.AreEqual(given.SagaMachine.Coding.Name, given.SagaDataAggregate.Data.CurrentStateName);
        }
コード例 #3
0
        public void State_is_changed_on_using_non_generic_transit_method()
        {
            var    given = new Given_AutomatonymousSaga(m => m.MakingCoffee);
            object msg   = new CoffeMadeEvent(Guid.NewGuid(), Guid.NewGuid());

            given.SagaInstance.Transit(msg);
            Assert.AreEqual(given.SagaMachine.Coding.Name, given.SagaDataAggregate.Data.CurrentStateName);
        }
コード例 #4
0
        public void Message_received_events_are_filled_with_sagadata()
        {
            var given = new Given_AutomatonymousSaga(m => m.MakingCoffee);

            ClearEvents(given.SagaDataAggregate);
            When_execute_valid_transaction(given.SagaInstance, new CoffeMadeEvent(Guid.NewGuid(), Guid.NewGuid()));
            var stateChangeEvent = GetFirstOf <SagaMessageReceivedEvent <SoftwareProgrammingSagaData> >(given.SagaDataAggregate);

            Assert.AreEqual(given.SagaDataAggregate.Data, stateChangeEvent.SagaData);
        }
コード例 #5
0
        public void Commands_are_produced()
        {
            var given = new Given_AutomatonymousSaga(m => m.Coding);

            var subscriptionExpiredEvent = new GotTiredEvent(Guid.NewGuid());

            When_execute_valid_transaction(given.SagaInstance, subscriptionExpiredEvent);

            CollectionAssert.IsNotEmpty(given.SagaInstance.CommandsToDispatch);
        }
コード例 #6
0
        public void Message_received_event_is_raised()
        {
            var given = new Given_AutomatonymousSaga(m => m.Coding);

            ClearEvents(given.SagaDataAggregate);
            When_execute_valid_transaction(given.SagaInstance, new GotTiredEvent(Guid.NewGuid()));

            var messageReceivedEvent = GetFirstOf <SagaMessageReceivedEvent <SoftwareProgrammingSagaData> >(given.SagaDataAggregate);

            Assert.NotNull(messageReceivedEvent);
        }
コード例 #7
0
        public void State_transitioned_event_is_raised()
        {
            var given = new Given_AutomatonymousSaga(m => m.MakingCoffee);

            ClearEvents(given.SagaDataAggregate);
            When_execute_valid_transaction(given.SagaInstance, new CoffeMadeEvent(Guid.NewGuid(), Guid.NewGuid()));

            var stateChangeEvent = GetFirstOf <SagaTransitionEvent <SoftwareProgrammingSagaData> >(given.SagaDataAggregate);

            Assert.NotNull(stateChangeEvent);
        }
コード例 #8
0
        public void Message_received_event_contains_incoming_message()
        {
            var given = new Given_AutomatonymousSaga(m => m.MakingCoffee);

            ClearEvents(given.SagaDataAggregate);
            var message = new CoffeMadeEvent(Guid.NewGuid(), Guid.NewGuid());

            When_execute_valid_transaction(given.SagaInstance, message);
            var stateChangeEvent = GetFirstOf <SagaMessageReceivedEvent <SoftwareProgrammingSagaData> >(given.SagaDataAggregate);

            Assert.AreEqual(message, stateChangeEvent.Message);
        }
コード例 #9
0
        public void SagaData_is_changed_after_transition_by_event_data()
        {
            var given = new Given_AutomatonymousSaga(m => m.Coding);

            ClearEvents(given.SagaDataAggregate);

            var subscriptionExpiredEvent = new GotTiredEvent(Guid.NewGuid());

            When_execute_valid_transaction(given.SagaInstance, subscriptionExpiredEvent);

            var newSubscriptionId = given.SagaDataAggregate.Data.PersonId;

            Assert.AreEqual(subscriptionExpiredEvent.SourceId, newSubscriptionId);
        }
コード例 #10
0
        public void Message_received_event_is_filled_with_sagaData_after_event_apply_to_it()
        {
            var given = new Given_AutomatonymousSaga(m => m.Coding);

            ClearEvents(given.SagaDataAggregate);

            When_execute_valid_transaction(given.SagaInstance, new GotTiredEvent(Guid.NewGuid()));
            var changedSubscriptionId = given.SagaDataAggregate.Data.PersonId = Guid.NewGuid();

            var messageReceivedEvent =
                GetFirstOf <SagaMessageReceivedEvent <SoftwareProgrammingSagaData> >(given.SagaDataAggregate);

            Assert.AreEqual(changedSubscriptionId, messageReceivedEvent.SagaData.PersonId);
        }
コード例 #11
0
        public void State_transition_event_is_before_Message_received_event()
        {
            var given = new Given_AutomatonymousSaga(m => m.MakingCoffee);

            ClearEvents(given.SagaDataAggregate);
            When_execute_valid_transaction(given.SagaInstance, new CoffeMadeEvent(Guid.NewGuid(), Guid.NewGuid()));

            var allEvents            = GetAllAs <DomainEvent>(given.SagaDataAggregate);
            var messageReceivedEvent = GetFirstOf <SagaMessageReceivedEvent <SoftwareProgrammingSagaData> >(given.SagaDataAggregate);
            var stateTransitionEvent = GetFirstOf <SagaTransitionEvent <SoftwareProgrammingSagaData> >(given.SagaDataAggregate);

            int indexOfTransition      = Array.IndexOf(allEvents, stateTransitionEvent);
            int indexOfMessageReceived = Array.IndexOf(allEvents, messageReceivedEvent);

            Assert.True(indexOfMessageReceived == indexOfTransition - 1, "message received event is not followed by state transition event");
        }
 public Given_AutomatonymousSagas_When_apply_known_but_not_mapped_event_in_state(Given_AutomatonymousSaga given)
 {
     _given = given;
 }