using Microsoft.Extensions.Options; using Novelly.Api.Activity; using Novelly.Api.Beats; using Novelly.Api.Chapters; using Novelly.Api.Characters; using Novelly.Api.Genres; using Novelly.Api.Locations; using Novelly.Api.Novels; using Novelly.Api.Questions; using Novelly.Api.Tags; using Novelly.Api.Trash; using Novelly.Api.Users; namespace Novelly.Api.Tests; public abstract class ServiceTestFixture { protected TestDatabase Db { get; private set; } = null!; protected TestUserContext UserContext { get; private set; } = null!; protected NovelAccessService Access { get; private set; } = null!; protected ActivityLog ActivityLog { get; private set; } = null!; protected ActivityService Activity { get; private set; } = null!; protected TagService Tags { get; private set; } = null!; protected LocationService Locations { get; private set; } = null!; protected NovelService Novels { get; private set; } = null!; protected CharacterService Characters { get; private set; } = null!; protected ChapterService Chapters { get; private set; } = null!; protected ChapterDisplayNumberLookup ChapterLabels { get; private set; } = null!; protected BeatService Beats { get; private set; } = null!; protected CharacterArcService Arcs { get; private set; } = null!; protected OpenQuestionService Questions { get; private set; } = null!; protected GenreService Genres { get; private set; } = null!; protected TrashService Trash { get; private set; } = null!; protected TrashOptions TrashOptions { get; private set; } = null!; protected CapturingLogger NovelLogs { get; private set; } = null!; protected CapturingLogger CharacterLogs { get; private set; } = null!; protected CapturingLogger ChapterLogs { get; private set; } = null!; protected CapturingLogger BeatLogs { get; private set; } = null!; protected CapturingLogger TagLogs { get; private set; } = null!; protected CapturingLogger LocationLogs { get; private set; } = null!; protected CapturingLogger ArcLogs { get; private set; } = null!; protected CapturingLogger QuestionLogs { get; private set; } = null!; protected CapturingLogger GenreLogs { get; private set; } = null!; protected CapturingLogger TrashLogs { get; private set; } = null!; [SetUp] public void SetUpFixture() { Db = new TestDatabase(); UserContext = new TestUserContext(); Access = new NovelAccessService(Db.Context, UserContext, new CapturingLogger()); ActivityLog = new ActivityLog(Db.Context, UserContext, new CapturingLogger()); Activity = new ActivityService(Db.Context, Access, new CapturingLogger()); Db.Context.Users.Add(new NovellyUser { Id = UserContext.UserId!.Value, UserName = "admin@novelly.test", Email = "admin@novelly.test", DisplayName = "Test Admin", GlobalRole = GlobalRole.Admin }); Db.Context.SaveChanges(); TagLogs = new CapturingLogger(); LocationLogs = new CapturingLogger(); NovelLogs = new CapturingLogger(); CharacterLogs = new CapturingLogger(); ChapterLogs = new CapturingLogger(); BeatLogs = new CapturingLogger(); ArcLogs = new CapturingLogger(); QuestionLogs = new CapturingLogger(); GenreLogs = new CapturingLogger(); TrashLogs = new CapturingLogger(); Tags = new TagService(Db.Context, Access, ActivityLog, TagLogs, new CreateTagRequestValidator(), new UpdateTagRequestValidator()); Locations = new LocationService(Db.Context, Access, ActivityLog, LocationLogs, new CreateLocationRequestValidator(), new UpdateLocationRequestValidator()); Novels = new NovelService( Db.Context, Access, UserContext, ActivityLog, NovelLogs, new CreateNovelRequestValidator(), new UpdateNovelRequestValidator()); Characters = new CharacterService( Db.Context, Access, Tags, ActivityLog, CharacterLogs, new CreateCharacterRequestValidator(), new UpdateCharacterRequestValidator(), new CreateRelationshipRequestValidator(), new LinkCharacterIdentityRequestValidator()); ChapterLabels = new ChapterDisplayNumberLookup(Db.Context); Chapters = new ChapterService(Db.Context, Access, Tags, Locations, ChapterLabels, ActivityLog, ChapterLogs, new CreateChapterRequestValidator(), new UpdateChapterRequestValidator()); Beats = new BeatService( Db.Context, Access, Tags, ActivityLog, BeatLogs, new CreateBeatRequestValidator(), new UpdateBeatRequestValidator(), new ReorderBeatsRequestValidator(), new AssignCharacterToBeatsRequestValidator(), new MoveBeatsRequestValidator()); Arcs = new CharacterArcService( Db.Context, Access, ActivityLog, ArcLogs, new CreateArcStageRequestValidator(), new UpdateArcStageRequestValidator(), new ReorderArcStagesRequestValidator(), new SetArcStageBeatsRequestValidator()); Questions = new OpenQuestionService( Db.Context, Access, ActivityLog, QuestionLogs, new CreateOpenQuestionRequestValidator(), new UpdateOpenQuestionRequestValidator(), new ResolveOpenQuestionRequestValidator()); Genres = new GenreService(Db.Context, GenreLogs); TrashOptions = new TrashOptions(); Trash = new TrashService(Db.Context, Access, ActivityLog, Options.Create(TrashOptions), TrashLogs); OnSetUp(); } protected virtual void OnSetUp() { } [TearDown] public void TearDownFixture() => Db.Dispose(); }