public async Task Verify_saga_reloaded_status_after_two_events()
        {
            var orderId = new OrderId(101);
            var evt     = new OrderPlaced(orderId);

            await ApplyEventOnSaga(evt).ConfigureAwait(false);

            var evt2 = new BillPrinted(orderId);

            await ApplyEventOnSaga(evt2).ConfigureAwait(false);

            var sagaId       = _listener.GetCorrelationId(evt);
            var sagaReloaded = await _repo.GetByIdAsync <DeliverPizzaSaga2>(sagaId).ConfigureAwait(false);

            Assert.That(sagaReloaded.AccessState.PizzaActualStatus, Is.EqualTo("Bill printed"));
        }
        public void listener_tests()
        {
            var listener = new DeliverPizzaSagaListener();
            var orderId  = new OrderId(4);

            var placed    = new OrderPlaced(orderId);
            var printed   = new BillPrinted(orderId);
            var received  = new PaymentReceived(orderId, Guid.NewGuid());
            var delivered = new PizzaDelivered(orderId);
            var prefix    = listener.Prefix;

            Assert.AreEqual(prefix + (string)orderId, listener.GetCorrelationId(placed));
            Assert.AreEqual(prefix + (string)orderId, listener.GetCorrelationId(printed));
            Assert.AreEqual(prefix + (string)orderId, listener.GetCorrelationId(received));
            Assert.AreEqual(prefix + (string)orderId, listener.GetCorrelationId(delivered));
        }
Exemple #3
0
        public void Verify_saga_reloaded_status_after_two_events()
        {
            var orderId = new OrderId(42);
            var evt     = new OrderPlaced(orderId);

            ApplyEventOnSaga(evt);

            var evt2 = new BillPrinted(orderId);

            ApplyEventOnSaga(evt2);

            var sagaId       = _listener.GetCorrelationId(evt);
            var sagaReloaded = _repo.GetById <DeliverPizzaSaga2>(sagaId);

            Assert.That(sagaReloaded.PizzaActualStatus, Is.EqualTo("Bill printed"));
        }
        public async Task Verify_emittingCommand()
        {
            var orderId = new OrderId(103);
            var evt     = new OrderPlaced(orderId);

            await ApplyEventOnSaga(evt).ConfigureAwait(false);

            var sagaId     = _listener.GetCorrelationId(evt);
            var changesets = await _persistence.EventStoreReadChangeset(sagaId).ConfigureAwait(false);

            var changeset = changesets.Single();

            Assert.That(changeset.Events.Length, Is.EqualTo(1));
            var @event = changeset.Events.Single();

            Assert.That(@event, Is.InstanceOf <MessageReaction>(), "We are expecting a messagereaction as payload");
            MessageReaction reaction = (MessageReaction)@event;

            Assert.That(reaction.MessagesOut.Length, Is.EqualTo(1), "We are expeting a messageout when order is placed");
        }
Exemple #5
0
        public void Verify_that_saga_has_correct_number_of_uncommitted_events()
        {
            var orderId = new OrderId(1);
            var sagaId  = orderId;

            var eventStore = _factory.BuildEventStore(_connectionString);
            var repo       = new SagaEventStoreRepositoryEx(eventStore, new SagaFactory());

            var saga = repo.GetById <DeliverPizzaSaga>(sagaId);

            saga.Transition(new OrderPlaced(orderId));
            saga.Transition(new BillPrinted(orderId));
            saga.Transition(new PaymentReceived(orderId, Guid.NewGuid()));
            saga.Transition(new PizzaDelivered(orderId));
            //check that uncommitted events are correctly transictioned.
            var events = ((ISagaEx)saga).GetUncommittedEvents().ToArray();

            repo.Save(saga, Guid.NewGuid(), null);

            Assert.AreEqual(4, events.Count());
        }
Exemple #6
0
        public void Verify_that_saga_can_be_reloaded_and_have_no_uncommitted_events()
        {
            var orderId = new OrderId(1);
            var sagaId  = orderId;

            var eventStore = _factory.BuildEventStore(_connectionString);
            var repo       = new SagaEventStoreRepositoryEx(eventStore, new SagaFactory());

            var saga = repo.GetById <DeliverPizzaSaga>(sagaId);

            saga.Transition(new OrderPlaced(orderId));
            saga.Transition(new BillPrinted(orderId));
            saga.Transition(new PaymentReceived(orderId, Guid.NewGuid()));
            saga.Transition(new PizzaDelivered(orderId));

            repo.Save(saga, Guid.NewGuid(), null);

            var sagaReloaded = repo.GetById <DeliverPizzaSaga>(sagaId);

            Assert.That(sagaReloaded, Is.Not.Null);
            var uncommittedevents = ((ISagaEx)saga).GetUncommittedEvents().ToArray();

            Assert.AreEqual(0, uncommittedevents.Count());
        }
 public PaymentReceived(OrderId orderId, Guid billId)
 {
     OrderId = orderId;
     BillId  = billId.ToString();
 }
Exemple #8
0
 public OrderPlaced(OrderId id)
 {
     OrderId = id;
 }
 public PizzaDelivered(OrderId orderId)
 {
     OrderId = orderId;
 }
 public BillPrinted(OrderId id)
 {
     OrderId = id;
 }