[FA-misc] Initial MassTransit implementation seems to work
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
using FictionArchive.Common.Enums;
|
||||
using FictionArchive.Service.FileService.IntegrationEvents;
|
||||
using FictionArchive.Service.NovelService.Models.Configuration;
|
||||
using FictionArchive.Service.NovelService.Models.Enums;
|
||||
using FictionArchive.Service.NovelService.Models.Images;
|
||||
@@ -8,9 +7,10 @@ using FictionArchive.Service.NovelService.Models.Novels;
|
||||
using FictionArchive.Service.NovelService.Models.SourceAdapters;
|
||||
using FictionArchive.Service.NovelService.Services;
|
||||
using FictionArchive.Service.NovelService.Services.SourceAdapters;
|
||||
using FictionArchive.Service.Shared.Services.EventBus;
|
||||
using FictionArchive.Service.Shared.Contracts.Events;
|
||||
using FluentAssertions;
|
||||
using HtmlAgilityPack;
|
||||
using MassTransit;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -72,7 +72,7 @@ public class NovelUpdateServiceTests
|
||||
private static NovelUpdateService CreateService(
|
||||
NovelServiceDbContext dbContext,
|
||||
ISourceAdapter adapter,
|
||||
IEventBus eventBus,
|
||||
IPublishEndpoint publishEndpoint,
|
||||
string pendingImageUrl = "https://pending/placeholder.jpg")
|
||||
{
|
||||
var options = Options.Create(new NovelUpdateServiceConfiguration
|
||||
@@ -80,7 +80,7 @@ public class NovelUpdateServiceTests
|
||||
PendingImageUrl = pendingImageUrl
|
||||
});
|
||||
|
||||
return new NovelUpdateService(dbContext, NullLogger<NovelUpdateService>.Instance, new[] { adapter }, eventBus, options);
|
||||
return new NovelUpdateService(dbContext, NullLogger<NovelUpdateService>.Instance, new[] { adapter }, publishEndpoint, options);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -102,13 +102,13 @@ public class NovelUpdateServiceTests
|
||||
ImageData = new List<ImageData> { image1, image2 }
|
||||
}));
|
||||
|
||||
var publishedEvents = new List<FileUploadRequestCreatedEvent>();
|
||||
var eventBus = Substitute.For<IEventBus>();
|
||||
eventBus.Publish(Arg.Do<FileUploadRequestCreatedEvent>(publishedEvents.Add)).Returns(Task.CompletedTask);
|
||||
eventBus.Publish(Arg.Any<object>(), Arg.Any<string>()).Returns(Task.CompletedTask);
|
||||
var publishedEvents = new List<IFileUploadRequestCreated>();
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
publishEndpoint.Publish(Arg.Do<IFileUploadRequestCreated>(e => publishedEvents.Add(e)), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var pendingImageUrl = "https://pending/placeholder.jpg";
|
||||
var service = CreateService(dbContext, adapter, eventBus, pendingImageUrl);
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint, pendingImageUrl);
|
||||
|
||||
var updatedChapter = await service.PullChapterContents(novel.Id, volume.Id, chapter.Order);
|
||||
|
||||
@@ -151,11 +151,9 @@ public class NovelUpdateServiceTests
|
||||
ImageData = new List<ImageData> { image }
|
||||
}));
|
||||
|
||||
var eventBus = Substitute.For<IEventBus>();
|
||||
eventBus.Publish(Arg.Any<FileUploadRequestCreatedEvent>()).Returns(Task.CompletedTask);
|
||||
eventBus.Publish(Arg.Any<object>(), Arg.Any<string>()).Returns(Task.CompletedTask);
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
|
||||
var service = CreateService(dbContext, adapter, eventBus);
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint);
|
||||
|
||||
var updatedChapter = await service.PullChapterContents(novel.Id, volume.Id, chapter.Order);
|
||||
|
||||
@@ -186,8 +184,8 @@ public class NovelUpdateServiceTests
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
var adapter = Substitute.For<ISourceAdapter>();
|
||||
var eventBus = Substitute.For<IEventBus>();
|
||||
var service = CreateService(dbContext, adapter, eventBus);
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint);
|
||||
|
||||
var newUrl = "https://cdn.example.com/uploaded/cover.jpg";
|
||||
|
||||
@@ -228,8 +226,8 @@ public class NovelUpdateServiceTests
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
var adapter = Substitute.For<ISourceAdapter>();
|
||||
var eventBus = Substitute.For<IEventBus>();
|
||||
var service = CreateService(dbContext, adapter, eventBus, pendingUrl);
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint, pendingUrl);
|
||||
|
||||
var newUrl = "https://cdn.example.com/uploaded/image.jpg";
|
||||
|
||||
@@ -277,8 +275,8 @@ public class NovelUpdateServiceTests
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
var adapter = Substitute.For<ISourceAdapter>();
|
||||
var eventBus = Substitute.For<IEventBus>();
|
||||
var service = CreateService(dbContext, adapter, eventBus, pendingUrl);
|
||||
var publishEndpoint = Substitute.For<IPublishEndpoint>();
|
||||
var service = CreateService(dbContext, adapter, publishEndpoint, pendingUrl);
|
||||
|
||||
var newUrl = "https://cdn.example.com/uploaded/img1.jpg";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user