コード例 #1
0
        public async Task MixedEventsInFeed_QuerryRepo()
        {
            var mock = new Mock <IEventFeed <QueryEventHandler <TestQ, TestEv> > >();
            IEnumerable <SubscribedDomainEventWrapper> list = new [] { new SubscribedDomainEventWrapper
                                                                       {
                                                                           DomainEvent = new TestEv(Guid.NewGuid())
                                                                       },
                                                                       new SubscribedDomainEventWrapper
                                                                       {
                                                                           DomainEvent = new TestEv2(Guid.NewGuid())
                                                                       } };

            mock.Setup(feed => feed.GetEventsAsync(It.IsAny <long>())).ReturnsAsync(list);
            var versionRepo = new Mock <IVersionRepository>();

            versionRepo.Setup(repo => repo.SaveVersion(It.IsAny <LastProcessedVersion>())).Returns(Task.CompletedTask);
            versionRepo.Setup(repo => repo.GetVersionAsync(It.IsAny <string>())).ReturnsAsync(0);

            var queryRepository = new ReadModelRepositoryMongoDb(EventMongoDb);

            var eventDelegateHandler = new QueryEventHandler <TestQ, TestEv>(queryRepository, versionRepo.Object, mock.Object);
            await eventDelegateHandler.UpdateAsync();

            var result = await queryRepository.LoadAsync <TestQ>();

            Assert.AreEqual(1, result.Value.WasCalled);
        }
コード例 #2
0
        public async Task UpdateReadmodelHandler()
        {
            EntityGuid = Guid.NewGuid();

            var queryRepository = new ReadModelRepositoryMongoDb(EventMongoDb);

            var readModelHandler = new ReadModelEventHandler <TestReadModelQuerries>(queryRepository,
                                                                                     new VersionRepositoryMongoDb(EventMongoDb), new FeedMock2());
            await readModelHandler.UpdateAsync();

            var result = await queryRepository.LoadAsync <TestReadModelQuerries>(EntityGuid.ToString());

            Assert.AreEqual(EntityGuid.ToString(), result.Value.Id);
            Assert.AreEqual(14, result.Value.Version);
            Assert.AreEqual("testName", result.Value.Name);
        }
コード例 #3
0
        public async Task UpdateModel_TwoEntities()
        {
            EntityGuid  = Guid.NewGuid();
            EntityGuid2 = Guid.NewGuid();

            var queryRepository = new ReadModelRepositoryMongoDb(EventMongoDb);

            var readModelHandler = new ReadModelEventHandler <TestReadModelQuerries>(queryRepository,
                                                                                     new VersionRepositoryMongoDb(EventMongoDb), new FeedMock3());

            await readModelHandler.UpdateAsync();

            var result = await queryRepository.LoadAsync <TestReadModelQuerries>(EntityGuid.ToString());

            var result2 = await queryRepository.LoadAsync <TestReadModelQuerries>(EntityGuid2.ToString());

            Assert.AreEqual(EntityGuid.ToString(), result.Value.Id);
            Assert.AreEqual(EntityGuid2.ToString(), result2.Value.Id);
        }
コード例 #4
0
        public async Task UpdateModel_VersionUpdatedExplicitly()
        {
            EntityGuid = Guid.NewGuid();

            var queryRepository = new ReadModelRepositoryMongoDb(EventMongoDb);

            var readModelHandler = new ReadModelEventHandler <TestReadModelQuerries_VerionedHandle>(
                queryRepository,
                new VersionRepositoryMongoDb(EventMongoDb),
                new FeedMockVersioned());

            await readModelHandler.UpdateAsync();

            var result = await queryRepository.LoadAsync <TestReadModelQuerries_VerionedHandle>(EntityGuid.ToString());

            Assert.AreEqual(EntityGuid.ToString(), result.Value.EntityId);
            Assert.AreEqual(12, result.Value.InnerVersion);
            Assert.AreEqual(14, result.Value.Version);
        }
コード例 #5
0
        public async Task UpdateModel_EventsNotAppliedStillUpdatesVersion()
        {
            EntityGuid = Guid.NewGuid();

            var queryRepository = new ReadModelRepositoryMongoDb(EventMongoDb);

            var readModelHandler = new ReadModelEventHandler <TestReadModelQuerries_OnlyOneEventAndVersionIsCounted>(
                queryRepository,
                new VersionRepositoryMongoDb(EventMongoDb),
                new FeedMock5());

            await readModelHandler.UpdateAsync();

            var result = await queryRepository.LoadAsync <TestReadModelQuerries_OnlyOneEventAndVersionIsCounted>
                             (EntityGuid.ToString());

            Assert.AreEqual(14, result.Value.Version);
            Assert.AreEqual(null, result.Value.Name);
            Assert.AreEqual(EntityGuid.ToString(), result.Value.Id);
        }
コード例 #6
0
        public async Task UpdateModel_EventsPresentThatAreNotHandleble()
        {
            EntityGuid  = Guid.NewGuid();
            EntityGuid2 = Guid.NewGuid();

            var queryRepository = new ReadModelRepositoryMongoDb(EventMongoDb);

            var readModelHandler = new ReadModelEventHandler <TestReadModelQuerries>(queryRepository, new VersionRepositoryMongoDb(EventMongoDb), new FeedMock4());

            await readModelHandler.UpdateAsync();

            var result = await queryRepository.LoadAsync <TestReadModelQuerries>(EntityGuid.ToString());

            var result2 = await queryRepository.LoadAsync <TestReadModelQuerries>(EntityGuid2.ToString());

            Assert.AreEqual(EntityGuid.ToString(), result.Value.Id);
            var condition = result2.Is <NotFound>();

            Assert.IsTrue(condition);
        }
コード例 #7
0
        public async Task UpdateModel_TwoParallelReadModelHandler_SerializationBug()
        {
            EntityGuid  = Guid.NewGuid();
            EntityGuid2 = Guid.NewGuid();

            var queryRepository = new ReadModelRepositoryMongoDb(EventMongoDb);

            var readModelHandler = new ReadModelEventHandler <TestReadModelQuerries_TwoParallelFeeds1>(queryRepository, new VersionRepositoryMongoDb(EventMongoDb), new FeedMock6());

            var readModelHandler2 = new ReadModelEventHandler <TestReadModelQuerries_TwoParallelFeeds2>(queryRepository, new VersionRepositoryMongoDb(EventMongoDb), new FeedMock7());

            await readModelHandler.UpdateAsync();

            await readModelHandler2.UpdateAsync();

            var result = await queryRepository.LoadAsync <TestReadModelQuerries_TwoParallelFeeds1>(EntityGuid.ToString());

            var result2 = await queryRepository.LoadAsync <TestReadModelQuerries_TwoParallelFeeds2>(EntityGuid2.ToString());

            Assert.AreEqual(EntityGuid.ToString(), result.Value.Id);
            Assert.AreEqual(EntityGuid2.ToString(), result2.Value.IdTotallyDifferenzt);
        }