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); }