public void EventsArePublishedOnSaveChangesAndThisInteractsWithUnitOfWorkParticipations() { var bus = new MockServiceBus(); var store = new MockEventStore(); var users = 1.Through(9).Select(i => { var u = new User(); u.Register(i + "@test.com", "abcd", Guid.NewGuid()); u.ChangeEmail("new" + i + "@test.com"); return(u); }).ToList(); using (var session = new EventStoreSession(bus, store, new SingleThreadUseGuard(), DateTimeNowTimeSource.Instance)) { var uow = new UnitOfWork(new SingleThreadUseGuard()); uow.AddParticipant(session); users.Take(3).ForEach(u => session.Save(u)); Assert.That(bus.Published.Count, Is.EqualTo(0)); session.SaveChanges(); Assert.That(bus.Published.Count, Is.EqualTo(6)); users.Skip(3).Take(3).ForEach(u => session.Save(u)); Assert.That(bus.Published.Count, Is.EqualTo(6)); session.SaveChanges(); Assert.That(bus.Published.Count, Is.EqualTo(12)); users.Skip(6).Take(3).ForEach(u => session.Save(u)); Assert.That(bus.Published.Count, Is.EqualTo(12)); Assert.That(store.SavedEvents.Count, Is.EqualTo(0)); uow.Commit(); Assert.That(bus.Published.Count, Is.EqualTo(18)); Assert.That(bus.Published.Select(e => e.EventId).Distinct().Count(), Is.EqualTo(18)); Assert.That(bus.Published, Is.EquivalentTo(store.SavedEvents)); } }
public void EventsAreDeletedWhenUnitOfWorkIsCommitted() { var bus = new MockServiceBus(); var store = new MockEventStore(); using (var session = new EventStoreSession(bus, store, new SingleThreadUseGuard(), DateTimeNowTimeSource.Instance)) { var uow = new UnitOfWork(new SingleThreadUseGuard()); uow.AddParticipant(session); var aggregate1 = new Guid("92EC4FE2-26A8-4274-8674-DC5D95513C83"); var aggregate2 = new Guid("F08200E4-8790-4ECC-9F06-A3D3BAC9E21C"); session.Delete(aggregate1); session.Delete(aggregate2); session.SaveChanges(); Assert.That(store.DeletedAggregates, Is.Empty); uow.Commit(); Assert.That(store.DeletedAggregates, Is.EquivalentTo(new[] { aggregate1, aggregate2 })); } }
public void EventsAreDeletedWhenNotAUnitOfWorkParticipant() { var bus = new MockServiceBus(); var store = new MockEventStore(); using (var session = new EventStoreSession(bus, store, new SingleThreadUseGuard(), DateTimeNowTimeSource.Instance)) { var aggregate1 = new Guid("92EC4FE2-26A8-4274-8674-DC5D95513C83"); var aggregate2 = new Guid("F08200E4-8790-4ECC-9F06-A3D3BAC9E21C"); session.Delete(aggregate1); session.Delete(aggregate2); session.SaveChanges(); session.SaveChanges(); // Verify that SaveChanges() does not delete the events twice. Assert.That(store.DeletedAggregates, Is.EquivalentTo(new[] { aggregate1, aggregate2 })); } }
public void EventsAreDeletedWhenUnitOfWorkIsCommitted() { var bus = new MockServiceBus(); var store = new MockEventStore(); using (var session = new EventStoreSession(bus, store, new SingleThreadUseGuard())) { var uow = new UnitOfWork(new SingleThreadUseGuard()); uow.AddParticipant(session); var aggregate1 = new Guid("92EC4FE2-26A8-4274-8674-DC5D95513C83"); var aggregate2 = new Guid("F08200E4-8790-4ECC-9F06-A3D3BAC9E21C"); session.Delete(aggregate1); session.Delete(aggregate2); session.SaveChanges(); Assert.That(store.DeletedAggregates, Is.Empty); uow.Commit(); Assert.That(store.DeletedAggregates, Is.EquivalentTo(new[] { aggregate1, aggregate2 })); } }
public void EventsAreDeletedWhenNotAUnitOfWorkParticipant() { var bus = new MockServiceBus(); var store = new MockEventStore(); using (var session = new EventStoreSession(bus, store, new SingleThreadUseGuard())) { var aggregate1 = new Guid("92EC4FE2-26A8-4274-8674-DC5D95513C83"); var aggregate2 = new Guid("F08200E4-8790-4ECC-9F06-A3D3BAC9E21C"); session.Delete(aggregate1); session.Delete(aggregate2); session.SaveChanges(); session.SaveChanges(); // Verify that SaveChanges() does not delete the events twice. Assert.That(store.DeletedAggregates, Is.EquivalentTo(new[] { aggregate1, aggregate2 })); } }
public void EventsArePublishedOnSaveChangesAndThisInteractsWithUnitOfWorkParticipations() { var bus = new MockServiceBus(); var store = new MockEventStore(); var users = 1.Through(9).Select(i => { var u = new User(); u.Register(i + "@test.com", "abcd", Guid.NewGuid()); u.ChangeEmail("new" + i + "@test.com"); return u; }).ToList(); using (var session = new EventStoreSession(bus, store, new SingleThreadUseGuard())) { var uow = new UnitOfWork(new SingleThreadUseGuard()); uow.AddParticipant(session); users.Take(3).ForEach(u => session.Save(u)); Assert.That(bus.Published.Count, Is.EqualTo(0)); session.SaveChanges(); Assert.That(bus.Published.Count, Is.EqualTo(6)); users.Skip(3).Take(3).ForEach(u => session.Save(u)); Assert.That(bus.Published.Count, Is.EqualTo(6)); session.SaveChanges(); Assert.That(bus.Published.Count, Is.EqualTo(12)); users.Skip(6).Take(3).ForEach(u => session.Save(u)); Assert.That(bus.Published.Count, Is.EqualTo(12)); Assert.That(store.SavedEvents.Count, Is.EqualTo(0)); uow.Commit(); Assert.That(bus.Published.Count, Is.EqualTo(18)); Assert.That(bus.Published.Select(e => e.EventId).Distinct().Count(), Is.EqualTo(18)); Assert.That(bus.Published, Is.EquivalentTo(store.SavedEvents)); } }
protected override async Task OnPostActorMethodAsync(ActorMethodContext actorMethodContext) { await EventStoreSession.SaveChanges(); }