Exemple #1
0
        public async Task HandleIsOnlyCalledOnce()
        {
            var dateTimeOffset     = 1;
            var domainEventWrapper = new SubscribedDomainEventWrapper
            {
                OverallVersion = dateTimeOffset,
                DomainEvent    = new TestEv2(Guid.NewGuid())
            };

            var handleAsync           = new Handler1();
            var handleAsync2          = new Handler2();
            var eventDelegateHandler1 = new AsyncEventHandler <Handler1, TestEv2>(
                new VersionRepositoryMongoDb(EventMongoDb),
                new EventFeedMock(dateTimeOffset, domainEventWrapper), handleAsync);

            var eventDelegateHandler2 = new AsyncEventHandler <Handler1, TestEv2>(
                new VersionRepositoryMongoDb(EventMongoDb),
                new EventFeedMock(dateTimeOffset, domainEventWrapper), handleAsync2);

            await eventDelegateHandler1.UpdateAsync();

            await eventDelegateHandler2.UpdateAsync();

            Assert.AreEqual(1, handleAsync.TimesCalled);
            Assert.AreEqual(1, handleAsync2.TimesCalled);
        }
Exemple #2
0
        public async Task MixedEventsInFeed()
        {
            var mock = new Mock <IEventFeed <AsyncEventHandler <Handler, 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 handler = new Handler();
            var eventDelegateHandler = new AsyncEventHandler <Handler, TestEv>(versionRepo.Object, mock.Object, handler);
            await eventDelegateHandler.UpdateAsync();

            Assert.AreEqual(1, handler.WasCalled);
        }