Ejemplo n.º 1
0
        public IUnitOfWorkContext CreateUnitOfWork()
        {
            if(UnitOfWork.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 repository = new DomainRepository(store, bus);
            return new UnitOfWork(repository);
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        public void Save_test()
        {
            using (var work = NcqrsEnvironment.Get<IUnitOfWorkFactory>().CreateUnitOfWork())
            {
                var store = MockRepository.GenerateMock<IEventStore>();
                var bus = MockRepository.GenerateMock<IEventBus>();
                var aggregate = new MyAggregateRoot();

                aggregate.Foo();
                aggregate.Bar();

                store.Expect(s => s.Save(aggregate));
                bus.Expect(b => b.Publish((IEnumerable<IEvent>) null)).IgnoreArguments();

                var repository = new DomainRepository(store, bus);
                repository.Save(aggregate);

                bus.VerifyAllExpectations();
                store.VerifyAllExpectations();
            }
        }
Ejemplo n.º 4
0
        public void It_should_call_the_converter_for_each_event()
        {
            var store = MockRepository.GenerateMock<IEventStore>();
            var bus = MockRepository.GenerateMock<IEventBus>();
            var converter = MockRepository.GenerateMock<IEventConverter<DomainEvent, DomainEvent>>();

            Func<DomainEvent, DomainEvent> returnFirstParam = (x) => x;
            converter.Stub(c => c.Convert(null)).IgnoreArguments().Do(returnFirstParam);

            var aggId = Guid.NewGuid();
            var eventsInTheStore = new DomainEvent[]
            {
                new FooEvent(Guid.NewGuid(), aggId, 1, DateTime.UtcNow),
                new BarEvent(Guid.NewGuid(), aggId, 2, DateTime.UtcNow)
            };
            store.Expect(s => s.GetAllEvents(aggId)).Return(eventsInTheStore);

            var repository = new DomainRepository(store, bus, null, converter);

            repository.GetById<MyAggregateRoot>(aggId);

            converter.AssertWasCalled(c => c.Convert(null),options => options.IgnoreArguments().Repeat.Twice());
        }
Ejemplo n.º 5
0
 private void CreateFacade()
 {
     _persistenceEngine = new InMemoryPersistenceEngine();
     _dispatcher = new NullDispatcher();
     _eventStore = new OptimisticEventStore(_persistenceEngine, _dispatcher);
     _repository = new DomainRepository(_eventStore);
     _facade = new RemoteFacade(_repository,new SimpleAggregateRootCreationStrategy());
 }