Esempio n. 1
0
        public async Task Update_article_when_receiving_article_updated_event()
        {
            await _synchronizer.StartSynchronization();

            // Acts

            var articleSynchronized = new ArticleImported(
                Guid.NewGuid(),
                "My title",
                "This is a simple summary",
                new DateTimeOffset(2020, 05, 06, 10, 0, 0, TimeSpan.FromHours(2)),
                "https://test.com",
                "https://test/image/jpg",
                "externalId",
                Array.Empty <string>(),
                Guid.NewGuid()
                );

            var articleUpdated = new ArticleUpdated(
                articleSynchronized.Id,
                "My title 2",
                "This is a simple summary 2",
                new DateTimeOffset(2020, 05, 07, 10, 0, 0, TimeSpan.FromHours(2)),
                "https://test2.com",
                "https://test/image2/jpg"
                );

            await _inMemoryBus.Push(1, articleSynchronized);

            await _inMemoryBus.Push(2, articleUpdated);

            // Asserts

            var articles = await _dbConnection.Articles.ToArrayAsync();

            articles
            .Should()
            .BeEquivalentTo(new[] {
                new ArticleTable {
                    Id          = articleSynchronized.Id,
                    Title       = articleUpdated.Title,
                    ImageUrl    = articleUpdated.ImageUrl,
                    Url         = articleUpdated.Url,
                    Summary     = articleUpdated.Summary,
                    PublishDate = articleUpdated.PublishDate,
                    MediaId     = articleSynchronized.MediaId,
                    Keywords    = ""
                }
            });
        }
Esempio n. 2
0
        public async Task On(ArticleUpdated @event)
        {
            var source = (await GetAll())
                         .SingleOrDefault(x => x.ArticleId == @event.Id);

            if (source != null)
            {
                source.PublishDate = @event.PublishDate;
            }
            else
            {
                LogError($"Unable to find article '{@event.Id}' to update.");
            }
        }
        public async Task On(ArticleUpdated @event)
        {
            if (string.IsNullOrWhiteSpace(@event.Title))
            {
                return;
            }

            await _dbConnection.Articles
            .Where(x => x.Id == @event.Id)
            .Set(x => x.Title, @event.Title)
            .Set(x => x.Url, @event.Url)
            .Set(x => x.Summary, @event.Summary)
            .Set(x => x.ImageUrl, @event.ImageUrl)
            .Set(x => x.PublishDate, @event.PublishDate)
            .UpdateAsync();
        }