Пример #1
0
        public async Task Initialize_event_position_to_event_store_current_global_stream_position_when_first_time()
        {
            const long currentPosition = 1500000L;

            _eventPositionRepository.GetLastProcessedPosition().Returns((long?)null);
            _eventStore.GetCurrentGlobalStreamPosition().Returns(currentPosition);

            await _aggregator.StartAggregation(new CancellationToken(false));

            await _eventPositionRepository.Received(1).Save(currentPosition);
        }
Пример #2
0
        // ----- Private

        private async Task <long?> GetLastStreamEventPosition()
        {
            var lastPosition = await _eventPositionRepository.GetLastProcessedPosition();

            if (!lastPosition.HasValue)
            {
                lastPosition = await _eventStore.GetCurrentGlobalStreamPosition();

                await _eventPositionRepository.Save(lastPosition.Value);

                Info($"No last position found, initializing the last position to the current event store global stream position : {lastPosition}");
            }
            return(lastPosition);
        }
Пример #3
0
        public async Task Simulate_full_process_with_one_article_already_synchronized_and_1_new()
        {
            // Arrange
            var source    = new CancellationTokenSource(500);
            var mediaId   = Guid.NewGuid();
            var articleId = Guid.NewGuid();

            await _eventStore.Store(new DomainEvent[] {
                new MediaFeedAdded(mediaId, "https://mysite/feed.xml")
                {
                    Version = 1
                },
                new ArticleImported(articleId, "some title", "some summary", DateTimeOffset.Now.Date, "https://mysite/article.html", null, "someExternalId", new string[0], mediaId)
                {
                    Version = 1
                }
            });

            _eventStore.CommitEvents();
            _eventPositionRepository.GetLastProcessedPosition().Returns(1);
            _feedReader.Read("https://mysite/feed.xml").Returns(new[] {
                new FeedItem {
                    Id = "someExternalId", Title = "some title", Summary = "some summary", PublishDate = DateTimeOffset.Now.Date, Link = "https://mysite/article.html", ImageUrl = null
                },
                new FeedItem {
                    Id = "someExternalId2", Title = "some title 2", Summary = "some summary 2", PublishDate = DateTimeOffset.Now.Date, Link = "https://mysite/article2.html", ImageUrl = "https://mysite/images/article2"
                },
            });

            // Act
            await _aggregator.StartAggregation(source.Token);

            await _inMemoryBus.Push(2, new ArticleImported(articleId, "some title", "some summary", DateTimeOffset.Now.Date, "https://mysite/article.html", null, "someExternalId", new string[0], mediaId) { Version = 1 });

            _inMemoryBus.SwitchToLiveMode();
            await Task.Delay(200, source.Token);

            foreach (var newEvent in await _eventStore.GetNewEvents())
            {
                await _inMemoryBus.Push(3, (DomainEvent)newEvent);
            }

            // Asserts
            (await _eventStore.GetNewEvents())
            .Should()
            .BeEquivalentTo(new DomainEvent[] {
                new ArticleKeywordsDefined(default, new[] { new Keyword("some", 2) }),