public void Accepting_unit_of_work_stores_and_publishes_the_events() { var commandId = Guid.NewGuid(); var store = MockRepository.GenerateMock<IEventStore>(); var bus = MockRepository.GenerateMock<IEventBus>(); var domainRepository = MockRepository.GenerateMock<IDomainRepository>(); var snapshotStore = MockRepository.GenerateMock<ISnapshotStore>(); var snapshottingPolicy = new NoSnapshottingPolicy(); store.Expect(s => s.Store(null)).IgnoreArguments(); bus.Expect(b => b.Publish((IEnumerable<IPublishableEvent>) null)).IgnoreArguments(); var sut = new UnitOfWork(commandId, domainRepository, store, snapshotStore, bus, snapshottingPolicy); sut.Accept(); bus.VerifyAllExpectations(); store.VerifyAllExpectations(); }
public IUnitOfWorkContext CreateUnitOfWork(Guid commandId) { if(UnitOfWorkContext.Current != null) { throw new InvalidOperationException("There is already a unit of work created for this context."); } var store = NcqrsEnvironment.Get<IEventStore>(); var bus = NcqrsEnvironment.Get<IEventBus>(); var snapshotStore = NcqrsEnvironment.Get<ISnapshotStore>(); var snapshottingPolicy = NcqrsEnvironment.Get<ISnapshottingPolicy>(); var aggregateCreationStrategy = NcqrsEnvironment.Get<IAggregateRootCreationStrategy>(); var aggregateSnappshotter = NcqrsEnvironment.Get<IAggregateSnapshotter>(); var repository = new DomainRepository(aggregateCreationStrategy, aggregateSnappshotter); var unitOfWork = new UnitOfWork(commandId, repository, store, snapshotStore, bus, snapshottingPolicy); UnitOfWorkContext.Bind(unitOfWork); return unitOfWork; }