Example #1
0
        public void Should_process_the_messages_in_order_and_not_at_the_same_time()
        {
            UnsubscribeAction unsubscribeAction = LocalBus.SubscribeSaga(_sagaRepository);

            Guid transactionId = NewId.NextGuid();

            Trace.WriteLine("Creating transaction for " + transactionId);

            int startValue = 1;

            var startConcurrentSaga = new StartConcurrentSaga
            {
                CorrelationId = transactionId, Name = "Chris", Value = startValue
            };

            LocalBus.Publish(startConcurrentSaga);

            var saga = _sagaRepository.ShouldContainSaga(transactionId, 8.Seconds());

            Assert.IsNotNull(saga);

            int nextValue = 2;
            var continueConcurrentSaga = new ContinueConcurrentSaga {
                CorrelationId = transactionId, Value = nextValue
            };

            LocalBus.Publish(continueConcurrentSaga);

            saga = _sagaRepository.ShouldContainSaga(x => x.CorrelationId == transactionId && x.Value == nextValue, 8.Seconds());
            Assert.IsNotNull(saga);

            unsubscribeAction();

            Assert.AreEqual(nextValue, saga.Value);
        }
Example #2
0
        public void The_saga_should_be_subscribable()
        {
            var unsubscribeAction = LocalBus.SubscribeSaga <CreateCustomerSaga>(_repository);


            unsubscribeAction();
        }
Example #3
0
        protected override void EstablishContext()
        {
            base.EstablishContext();

            _sagaId = Guid.NewGuid();

            _repository = SetupSagaRepository <TestSaga>();

            LocalBus.SubscribeSaga <TestSaga>(_repository);
        }
Example #4
0
        public void A_simple_saga_exists_and_is_waiting_for_approval()
        {
            LocalBus.SubscribeSaga <SimpleStateMachineSaga>(Repository);

            AddExistingSaga(SagaId, x =>
            {
                x.CustomerId = CustomerId;
                x.SetCurrentState(SimpleStateMachineSaga.WaitingForApproval);
            });
        }
Example #5
0
        protected override void EstablishContext()
        {
            base.EstablishContext();

            _sagaId = Guid.NewGuid();

            _repository = SetupSagaRepository <TestSaga>();

            _remove = LocalBus.SubscribeSaga <TestSaga>(_repository);

            PipelineViewer.Trace(LocalBus.InboundPipeline);
        }
Example #6
0
        public AuctionSagaTestFixture()
        {
            LocalBus = ServiceBusFactory.New(x =>
            {
                x.ReceiveFrom(URI);

                ConfigureLocalBus(x);
            });

            Repository = SetupSagaRepository <AuctionSaga>();

            LocalBus.SubscribeSaga(Repository);
        }
        public void A_state_machine_based_saga_should_automatically_wire_up_subscriptions()
        {
            LocalBus.SubscribeSaga(_repository);

            PipelineViewer.Trace(LocalBus.InboundPipeline);
            PipelineViewer.Trace(LocalBus.OutboundPipeline);

            LocalBus.Publish(new RegisterUser(_transactionId, _username, _password, _displayName, _email));

            AutoStateMachineSaga saga = _repository.ShouldContainSaga(_transactionId, 8.Seconds());

            saga.CurrentState.ShouldEqual(AutoStateMachineSaga.WaitingForEmailValidation);

            LocalBus.Publish(new UserValidated(_transactionId));


            saga.ShouldBeInState(AutoStateMachineSaga.Completed, 8.Seconds());
        }
Example #8
0
        public void Should_process_the_messages_in_order_and_not_at_the_same_time()
        {
            Guid transactionId = NewId.NextGuid();

            _log.Info("Creating transaction for " + transactionId);

            const int startValue = 1;

            var startConcurrentSaga = new StartConcurrentSaga
            {
                CorrelationId = transactionId, Name = "Chris", Value = startValue
            };

            LocalBus.Endpoint.Send(startConcurrentSaga);
            LocalBus.Endpoint.Send(startConcurrentSaga);

            _log.Info("Just published the start message");

            UnsubscribeAction unsubscribeAction = LocalBus.SubscribeSaga(_sagaRepository);

            Thread.Sleep(1500);

            const int nextValue = 2;
            var       continueConcurrentSaga = new ContinueConcurrentSaga {
                CorrelationId = transactionId, Value = nextValue
            };

            LocalBus.Publish(continueConcurrentSaga);
            _log.Info("Just published the continue message");
            Thread.Sleep(8000);

            unsubscribeAction();
            foreach (ConcurrentLegacySaga saga in _sagaRepository.Where(x => true))
            {
                _log.Info("Found saga: " + saga.CorrelationId);
            }

            int currentValue = _sagaRepository.Where(x => x.CorrelationId == transactionId).First().Value;

            Assert.AreEqual(nextValue, currentValue);
        }
Example #9
0
        public void Should_process_the_messages_in_order_and_not_at_the_same_time()
        {
            UnsubscribeAction unsubscribeAction = LocalBus.SubscribeSaga(_sagaRepository);

            Guid transactionId = CombGuid.Generate();

            Trace.WriteLine("Creating transaction for " + transactionId);

            int startValue = 1;

            var startConcurrentSaga = new StartConcurrentSaga {
                CorrelationId = transactionId, Name = "Chris", Value = startValue
            };

            LocalBus.Publish(startConcurrentSaga);
            Trace.WriteLine("Just published the start message");

            Thread.Sleep(1500);

            int nextValue = 2;
            var continueConcurrentSaga = new ContinueConcurrentSaga {
                CorrelationId = transactionId, Value = nextValue
            };

            LocalBus.Publish(continueConcurrentSaga);
            Trace.WriteLine("Just published the continue message");
            Thread.Sleep(8000);

            unsubscribeAction();
            foreach (ConcurrentSaga saga in _sagaRepository.Where(x => true))
            {
                Trace.WriteLine("Found saga: " + saga.CorrelationId);
            }

            int currentValue = _sagaRepository.Where(x => x.CorrelationId == transactionId).First().Value;

            Assert.AreEqual(nextValue, currentValue);
        }
Example #10
0
        public void A_state_machine_should_respond_to_combined_events()
        {
            LocalBus.SubscribeSaga(_repository);

            PipelineViewer.Trace(LocalBus.InboundPipeline);
            PipelineViewer.Trace(LocalBus.OutboundPipeline);

            LocalBus.Publish(new Second {
                CorrelationId = _transactionId
            });

            CombineSaga saga = _repository.ShouldContainSaga(_transactionId, 8.Seconds());

            saga.ShouldBeInState(CombineSaga.Initial);
            saga.Combined.ShouldEqual(2);

            LocalBus.Publish(new First {
                CorrelationId = _transactionId
            });

            saga.ShouldBeInState(CombineSaga.Completed);
            saga.Combined.ShouldEqual(3);
        }
Example #11
0
 public void A_simple_saga_does_not_exist()
 {
     LocalBus.SubscribeSaga <SimpleStateMachineSaga>(Repository);
 }