public void repository_can_serialize_access_to_the_same_entity() { var orderId = new OrderId(1); var sagaId = orderId; var eventStore = _factory.BuildEventStore(_connectionString); using (var repo1 = new SagaEventStoreRepositoryEx(eventStore, new SagaFactory())) using (var repo2 = new SagaEventStoreRepositoryEx(eventStore, new SagaFactory())) { var saga1 = repo1.GetById <DeliverPizzaSaga>(sagaId); saga1.Transition(new OrderPlaced(orderId)); //now create another thread that loads and change the same entity var task = Task <Boolean> .Factory.StartNew(() => { var saga2 = repo2.GetById <DeliverPizzaSaga>(sagaId); saga2.Transition(new OrderPlaced(orderId)); repo2.Save(saga2, Guid.NewGuid(), null); return(true); }); Thread.Sleep(100); //Let be sure the other task is started doing something. repo1.Save(saga1, Guid.NewGuid(), null); Assert.IsTrue(task.Result); //inner should not throw. } }
protected void ApplyEventOnSaga(DomainEvent evt) { var id = _listener.GetCorrelationId(evt); var saga = _repo.GetById <DeliverPizzaSaga2>(id); saga.Transition(evt); _repo.Save(saga, Guid.NewGuid(), null); }
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()); }
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()); }