public void GettingExistingByIdReturnsAggregateWhenFound()
        {
            var aggregateRootId = Guid.NewGuid();

            var eventStore = new Mock<IEventStore>();
            eventStore.Setup(x => x.GetEvents(aggregateRootId, It.IsAny<int>())).Returns(new[] { new MyTestEvent() });
            var snapshotStore = new Mock<ISnapshotStore>().Object;
            var eventBus = new Mock<IEventBus>().Object;
            var repository = new DomainRepository(eventStore.Object, snapshotStore, eventBus);

            var fetchedAggregateRoot = repository.GetExistingById<MyTestAggregateRoot>(aggregateRootId);

            Assert.IsNotNull(fetchedAggregateRoot);
        }
        public void GettingExistingByIdThrowsExceptionWhenNotFound()
        {
            var eventStore = new Mock<IEventStore>().Object;
            var snapshotStore = new Mock<ISnapshotStore>().Object;
            var eventBus = new Mock<IEventBus>().Object;
            var repository = new DomainRepository(eventStore, snapshotStore, eventBus);
            var aggregateRootId = Guid.NewGuid();

            var exception = CustomAsserts.Throws<AggregateRootNotFoundException>(() =>
                repository.GetExistingById<MyTestAggregateRoot>(aggregateRootId)
                );

            Assert.AreEqual(aggregateRootId, exception.AggregateRootId);
            Assert.AreEqual(typeof(MyTestAggregateRoot), exception.Type);
        }
        public void GettingExistingByIdThrowsExceptionWhenNotFound()
        {
            var eventStore      = new Mock <IEventStore>().Object;
            var snapshotStore   = new Mock <ISnapshotStore>().Object;
            var eventBus        = new Mock <IEventBus>().Object;
            var repository      = new DomainRepository(eventStore, snapshotStore, eventBus);
            var aggregateRootId = Guid.NewGuid();

            var exception = CustomAsserts.Throws <AggregateRootNotFoundException>(() =>
                                                                                  repository.GetExistingById <MyTestAggregateRoot>(aggregateRootId)
                                                                                  );

            Assert.AreEqual(aggregateRootId, exception.AggregateRootId);
            Assert.AreEqual(typeof(MyTestAggregateRoot), exception.Type);
        }
        public void GettingExistingByIdReturnsAggregateWhenFound()
        {
            var aggregateRootId = Guid.NewGuid();

            var eventStore = new Mock <IEventStore>();

            eventStore.Setup(x => x.GetEvents(aggregateRootId, It.IsAny <int>())).Returns(new[] { new MyTestEvent() });
            var snapshotStore = new Mock <ISnapshotStore>().Object;
            var eventBus      = new Mock <IEventBus>().Object;
            var repository    = new DomainRepository(eventStore.Object, snapshotStore, eventBus);

            var fetchedAggregateRoot = repository.GetExistingById <MyTestAggregateRoot>(aggregateRootId);

            Assert.IsNotNull(fetchedAggregateRoot);
        }