public CrudAggregateStoreTests() { crudRepository = new InMemoryCrudRepository(); entityTypeManager = Substitute.For <IEntityTypeManager>(); publishEventBuffer = Substitute.For <IPublishEventBuffer>(); domainClasses = new List <DomainClassInfo>() { new DomainClassInfo(TestAggregateClassId, null, typeof(TestAggregate)) }; entityTypeManager.GetClassInfoByClassId(Guid.Empty) .ReturnsForAnyArgs(ci => domainClasses.Single(x => x.Id == ci.Arg <Guid>())); entityTypeManager.TryGetClassInfoByClrType(null) .ReturnsForAnyArgs(ci => domainClasses.SingleOrDefault(x => x.ClrType == ci.Arg <Type>())); entityTypeManager.GetClassInfoByClrType(null) .ReturnsForAnyArgs(ci => domainClasses.Single(x => x.ClrType == ci.Arg <Type>())); eventMessageFactory = Substitute.For <IEventMessageFactory>(); eventMessageFactory.CreateMessageAsync(null).ReturnsForAnyArgs(ci => { var @event = ci.ArgAt <IEvent>(0); Type messageType = typeof(EventMessageDraft <>).MakeGenericType(@event.GetType()); IEventMessageDraft messageDraft = (IEventMessageDraft)messageType.GetConstructor(new[] { @event.GetType() }).Invoke(new[] { @event }); messageDraft.SetMetadata("TestKey", "TestValue"); return(messageDraft); }); // TODO something more lightweight? sut = new CrudAggregateStore(crudRepository, entityTypeManager, publishEventBuffer, eventMessageFactory); }
public UnitOfWork(Lazy <IUnitOfWorkListener[]> unitOfWorkListeners, IPublishEventBuffer publishEventBuffer) { this.unitOfWorkListeners = unitOfWorkListeners; EventBuffer = publishEventBuffer; }
public UnitOfWorkTests() { innerTransactions = new[] { Substitute.For <ITransaction>(), Substitute.For <ITransaction>() }; unitOfWorkListeners = new[] { Substitute.For <IUnitOfWorkListener>(), Substitute.For <IUnitOfWorkListener>() }; publishEventBuffer = Substitute.For <IPublishEventBuffer>(); sut = new UnitOfWork(new Lazy <IUnitOfWorkListener[]>(unitOfWorkListeners), publishEventBuffer); }
public EFCoreCrudAggregateStore(ICrudRepository crudRepository, IEntityTypeManager entityTypeManager, IPublishEventBuffer publishEventBuffer, IEventMessageFactory eventMessageFactory, IEFCoreTransactionCoordinator transactionCoordinator) : base(crudRepository, entityTypeManager, publishEventBuffer, eventMessageFactory) { this.transactionCoordinator = transactionCoordinator; transactionCoordinator.AddTransactionParticipant(this); }
public EventSourcedAggregateRepository(IEventStore eventStore, IEntityTypeManager entityTypeManager, IPublishEventBuffer publishEventBuffer, IRepositoryFilter[] repositoryFilters, IEventMessageFactory eventMessageFactory, IEntityFactory entityFactory) : base(eventStore, entityTypeManager, publishEventBuffer, repositoryFilters, eventMessageFactory, entityFactory) { }
public CrudAggregateStore(ICrudRepository crudRepository, IEntityTypeManager entityTypeManager, IPublishEventBuffer publishEventBuffer, IEventMessageFactory eventMessageFactory) { this.crudRepository = crudRepository; this.entityTypeManager = entityTypeManager; this.publishEventBuffer = publishEventBuffer; this.eventMessageFactory = eventMessageFactory; }
protected EventSourcedAggregateRepository(IEventStore eventStore, IEntityTypeManager entityTypeManager, IPublishEventBuffer publishEventBuffer, IRepositoryFilter[] repositoryFilters, IEventMessageFactory eventMessageFactory, IEntityFactory entityFactory, Dictionary <Guid, IEventSourcedAggregateRoot> aggregates) : base(eventStore, entityTypeManager, publishEventBuffer, repositoryFilters, eventMessageFactory, entityFactory, aggregates) { }
public EventSourcedAggregateStore(IEventStore eventStore, IEntityTypeManager entityTypeManager, IPublishEventBuffer publishEventBuffer, IRepositoryFilter[] repositoryFilters, IEventMessageFactory eventMessageFactory, IEventSourcedAggregateFactory eventSourcedAggregateFactory) { this.eventStore = eventStore; this.entityTypeManager = entityTypeManager; this.publishEventBuffer = publishEventBuffer; this.repositoryFilters = repositoryFilters; this.eventMessageFactory = eventMessageFactory; this.eventSourcedAggregateFactory = eventSourcedAggregateFactory; }
public EFCoreEventSourcedAggregateStore(IEventStore eventStore, IEntityTypeManager entityTypeManager, IPublishEventBuffer publishEventBuffer, IRepositoryFilter[] repositoryFilters, IEventMessageFactory eventMessageFactory, IEventSourcedAggregateFactory eventSourcedAggregateFactory, IEFCoreTransactionCoordinator transactionCoordinator) : base(eventStore, entityTypeManager, publishEventBuffer, repositoryFilters, eventMessageFactory, eventSourcedAggregateFactory) { this.transactionCoordinator = transactionCoordinator; transactionCoordinator.AddTransactionParticipant(this); }
protected EventSourcedRepository(IEventStore eventStore, IEntityTypeManager entityTypeManager, IPublishEventBuffer publishEventBuffer, IRepositoryFilter[] repositoryFilters, IEventMessageFactory eventMessageFactory, IEntityFactory entityFactory, Dictionary <Guid, TBase> aggregates) : this(eventStore, entityTypeManager, publishEventBuffer, repositoryFilters, eventMessageFactory, entityFactory) { this.aggregates = aggregates; }
protected virtual EventSourcedRepository <TBase> CloneWithFilters( IEventStore eventStore, IEntityTypeManager entityTypeManager, IPublishEventBuffer publishEventBuffer, IRepositoryFilter[] repositoryFilters, IEventMessageFactory eventMessageFactory, Dictionary <Guid, TBase> aggregates) { return(new EventSourcedRepository <TBase>(eventStore, entityTypeManager, publishEventBuffer, repositoryFilters, eventMessageFactory, EntityFactory, aggregates)); }
protected override EventSourcedRepository <IEventSourcedAggregateRoot> CloneWithFilters( IEventStore eventStore, IEntityTypeManager entityTypeManager, IPublishEventBuffer publishEventBuffer, IRepositoryFilter[] repositoryFilters, IEventMessageFactory eventMessageFactory, Dictionary <Guid, IEventSourcedAggregateRoot> aggregates) { return(new EventSourcedAggregateRepository(eventStore, entityTypeManager, publishEventBuffer, repositoryFilters, eventMessageFactory, EntityFactory, aggregates)); }
public RepositoryTests() { publishEventBuffer = Substitute.For <IPublishEventBuffer>(); unitOfWork = Substitute.For <IUnitOfWork>(); unitOfWork.EventBuffer.Returns(publishEventBuffer); unitOfWork.When(x => x.AddInnerTransaction(Arg.Any <ITransaction>())).Do(ci => uowInnerTransaction = ci.ArgAt <ITransaction>(0)); aggregateStore1 = Substitute.For <IAggregateStore>(); aggregateStore1.CanHandleAggregateType(typeof(MyEntity1)).Returns(true); aggregateStoreFactory1 = Substitute.For <IAggregateStoreFactory>(); aggregateStoreFactory1.CreateAggregateStore(unitOfWork).Returns(aggregateStore1); aggregateStoreFactory1.CanHandleAggregateType(typeof(MyEntity1)).Returns(true); aggregateStore2 = Substitute.For <IAggregateStore>(); aggregateStoreFactory2 = Substitute.For <IAggregateStoreFactory>(); aggregateStoreFactory2.CreateAggregateStore(unitOfWork).Returns(aggregateStore2); sut = Substitute.ForPartsOf <Repository>(new[] { aggregateStoreFactory1, aggregateStoreFactory2 }, unitOfWork); }
public EventSourcedRepositoryTests() { publishEventBuffer = Substitute.For <IPublishEventBuffer>(); eventStore = Substitute.For <IEventStore>(); entityTypeManager = Substitute.For <IEntityTypeManager>(); repositoryFilter1 = Substitute.For <IRepositoryFilter>(); repositoryFilter2 = Substitute.For <IRepositoryFilter>(); FakeClock.Setup(); eventStore.GetEventsAsync(entity2Id) .Returns(new List <IEventStoreRecord>() { new FakeEventStoreRecord() { Event = new SetFooEvent() { AggregateId = entity2Id }, StreamSequenceNumber = 1 } }); eventStore.GetStreamMetadataAsync(entity2Id) .Returns(new Dictionary <string, string>() { { "TestKey", "TestValue" }, { AggregateEventStreamMetadataNames.ClassId, entity2ClassId.ToString() } }); eventStore.GetStreamMetadataAsync(entity3Id) .Returns(new Dictionary <string, string>() { { "TestKey", "TestValue" }, { AggregateEventStreamMetadataNames.ClassId, entity3ClassId.ToString() } }); eventStore.PushEventsAsync(Guid.Empty, null, null).ReturnsForAnyArgs(ci => { var events = ci.ArgAt <IEnumerable <IUncommittedEventStoreRecord> >(1); return(events.Select(x => new FakeEventStoreRecord() { AdditionalMetadata = x.Metadata, Event = x.Event, EventId = Guid.NewGuid(), StoreDate = DateTimeOffset.Now, StreamSequenceNumber = 0 }).ToList()); }); DomainClassInfo[] domainClasses = new[] { new DomainClassInfo(entityClassId, null, typeof(MyEntity)), new DomainClassInfo(entity2ClassId, null, typeof(MyEntity2)), new DomainClassInfo(entity3ClassId, null, typeof(MyEntity3LoadsAsDeleted)) }; entityTypeManager.GetClassInfoByClassId(Guid.Empty) .ReturnsForAnyArgs(ci => domainClasses.Single(x => x.Id == ci.Arg <Guid>())); entityTypeManager.TryGetClassInfoByClrType(null) .ReturnsForAnyArgs(ci => domainClasses.SingleOrDefault(x => x.ClrType == ci.Arg <Type>())); entityTypeManager.GetClassInfoByClrType(null) .ReturnsForAnyArgs(ci => domainClasses.Single(x => x.ClrType == ci.Arg <Type>())); eventMessageFactory = Substitute.For <IEventMessageFactory>(); eventMessageFactory.CreateMessageAsync(null).ReturnsForAnyArgs(ci => { var @event = ci.ArgAt <IEvent>(0); Type messageType = typeof(EventMessageDraft <>).MakeGenericType(@event.GetType()); IEventMessageDraft messageDraft = (IEventMessageDraft)messageType.GetConstructor(new[] { @event.GetType() }).Invoke(new[] { @event }); messageDraft.SetMetadata("TestKey", "TestValue"); return(messageDraft); }); // TODO something more lightweight? sut = new EventSourcedAggregateRepository(eventStore, entityTypeManager, publishEventBuffer, new IRepositoryFilter[] {}, eventMessageFactory, new EntityFactory()); }
public RebusEventCommandHandler(IPublishEventBuffer publishEventBuffer) { this.publishEventBuffer = publishEventBuffer; }
public EventSourcedAggregateStoreTests() { publishEventBuffer = Substitute.For <IPublishEventBuffer>(); eventStore = Substitute.For <IEventStore>(); entityTypeManager = Substitute.For <IEntityTypeManager>(); repositoryFilter1 = Substitute.For <IRepositoryFilter>(); repositoryFilter2 = Substitute.For <IRepositoryFilter>(); FakeClock.Setup(); entityEvents = new Dictionary <Guid, List <IEventStoreRecord> >() { { entity2Id, new List <IEventStoreRecord>() { new FakeEventStoreRecord() { Event = new SetFooEvent() { AggregateId = entity2Id }, StreamSequenceNumber = 1 } } }, { entity3Id, new List <IEventStoreRecord>() { new FakeEventStoreRecord() { Event = new SetFooEvent() { AggregateId = entity3Id }, StreamSequenceNumber = 1 } } }, { entity4Id, new List <IEventStoreRecord>() { new FakeEventStoreRecord() { Event = new SetFooEvent() { AggregateId = entity4Id }, StreamSequenceNumber = 1 } } } }; eventStore.FindEventsAsync(Arg.Any <Guid>()) .Returns(ci => { var id = ci.ArgAt <Guid>(0); if (entityEvents.TryGetValue(id, out var events)) { return(events); } return(new List <IEventStoreRecord>()); }); eventStore.BatchFindEventsAsync(Arg.Any <Guid[]>()) .Returns(ci => { var ids = ci.ArgAt <Guid[]>(0); var result = new Dictionary <Guid, IReadOnlyCollection <IEventStoreRecord> >(); foreach (Guid id in ids) { if (entityEvents.TryGetValue(id, out var events)) { result.Add(id, events); } } return(result); }); entityMetadata = new Dictionary <Guid, IReadOnlyDictionary <string, string> >() { { entity2Id, new Dictionary <string, string>() { { "TestKey", "TestValue" }, { AggregateEventStreamMetadataNames.ClassId, entity2ClassId.ToString() } } }, { entity3Id, new Dictionary <string, string>() { { "TestKey", "TestValue" }, { AggregateEventStreamMetadataNames.ClassId, entity3ClassId.ToString() } } }, { entity4Id, new Dictionary <string, string>() { { "TestKey", "TestValue" }, { AggregateEventStreamMetadataNames.ClassId, entity2ClassId.ToString() } } } }; eventStore.FindStreamMetadataAsync(Arg.Any <Guid>()) .Returns(ci => { var id = ci.ArgAt <Guid>(0); if (entityMetadata.TryGetValue(id, out var metadata)) { return(metadata); } return(new Dictionary <string, string>()); }); eventStore.BatchFindStreamMetadataAsync(Arg.Any <Guid[]>()) .Returns(ci => { var ids = ci.ArgAt <Guid[]>(0); var result = new Dictionary <Guid, IReadOnlyDictionary <string, string> >(); foreach (Guid id in ids) { if (entityMetadata.TryGetValue(id, out var metadata)) { result.Add(id, metadata); } } return(result); }); eventStore.PushEventsAsync(Guid.Empty, null).ReturnsForAnyArgs(ci => { var events = ci.ArgAt <IEnumerable <IUncommittedEventStoreRecord> >(1); return(events.Select(x => new FakeEventStoreRecord() { AdditionalMetadata = x.Metadata, Event = x.Event, EventId = Guid.NewGuid(), StoreDate = DateTimeOffset.Now, StreamSequenceNumber = 0 }).ToList()); }); DomainClassInfo[] domainClasses = new[] { new DomainClassInfo(entityClassId, null, typeof(MyEntity)), new DomainClassInfo(entity2ClassId, null, typeof(MyEntity2)), new DomainClassInfo(entity3ClassId, null, typeof(MyEntity3LoadsAsDeleted)) }; entityTypeManager.GetClassInfoByClassId(Guid.Empty) .ReturnsForAnyArgs(ci => domainClasses.Single(x => x.Id == ci.Arg <Guid>())); entityTypeManager.TryGetClassInfoByClrType(null) .ReturnsForAnyArgs(ci => domainClasses.SingleOrDefault(x => x.ClrType == ci.Arg <Type>())); entityTypeManager.GetClassInfoByClrType(null) .ReturnsForAnyArgs(ci => domainClasses.Single(x => x.ClrType == ci.Arg <Type>())); eventMessageFactory = Substitute.For <IEventMessageFactory>(); eventMessageFactory.CreateMessageAsync(null).ReturnsForAnyArgs(ci => { var @event = ci.ArgAt <IEvent>(0); Type messageType = typeof(EventMessageDraft <>).MakeGenericType(@event.GetType()); IEventMessageDraft messageDraft = (IEventMessageDraft)messageType.GetConstructor(new[] { @event.GetType() }).Invoke(new[] { @event }); messageDraft.SetMetadata("TestKey", "TestValue"); return(messageDraft); }); // TODO something more lightweight? eventSourcedAggregateFactory = Substitute.For <IEventSourcedAggregateFactory>(); entity2 = new MyEntity2(entity2Id); eventSourcedAggregateFactory.ConstructAndLoadEntityFromEvents(entity2Id, Arg.Is <IReadOnlyDictionary <string, string> >(x => x.SequenceEqual(entityMetadata[entity2Id])), Arg.Is <IReadOnlyCollection <IEventStoreRecord> >(x => x.SequenceEqual(entityEvents[entity2Id]))) .Returns(entity2); entity3 = new MyEntity3LoadsAsDeleted(entity3Id); eventSourcedAggregateFactory.ConstructAndLoadEntityFromEvents(entity3Id, Arg.Is <IReadOnlyDictionary <string, string> >(x => x.SequenceEqual(entityMetadata[entity3Id])), Arg.Is <IReadOnlyCollection <IEventStoreRecord> >(x => x.SequenceEqual(entityEvents[entity3Id]))) .Returns(entity3); entity4 = new MyEntity2(entity4Id); eventSourcedAggregateFactory.ConstructAndLoadEntityFromEvents(entity4Id, Arg.Is <IReadOnlyDictionary <string, string> >(x => x.SequenceEqual(entityMetadata[entity4Id])), Arg.Is <IReadOnlyCollection <IEventStoreRecord> >(x => x.SequenceEqual(entityEvents[entity4Id]))) .Returns(entity4); sut = new EventSourcedAggregateStore(eventStore, entityTypeManager, publishEventBuffer, new IRepositoryFilter[] { }, eventMessageFactory, eventSourcedAggregateFactory); }