using Novelly.Api.Beats;
using Novelly.Api.Chapters;
using Novelly.Api.Characters;
using Novelly.Api.Projects;
using Novelly.Api.Questions;
using Novelly.Api.Scenes;
using Novelly.Api.Tags;
namespace Novelly.Api.Tests;
///
/// Shared plumbing for the service tests: a fresh in-memory database and a matching set
/// of services per test.
///
///
/// The setup lives in [SetUp] rather than a constructor or field initialisers
/// because NUnit builds one fixture instance for the whole class — anything created once
/// would leak state from one test into the next.
///
public abstract class ServiceTestFixture
{
protected TestDatabase Db { get; private set; } = null!;
protected TagService Tags { get; private set; } = null!;
protected ProjectService Projects { get; private set; } = null!;
protected CharacterService Characters { get; private set; } = null!;
protected ChapterService Chapters { get; private set; } = null!;
protected SceneService Scenes { 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 CapturingLogger ProjectLogs { get; private set; } = null!;
protected CapturingLogger CharacterLogs { get; private set; } = null!;
protected CapturingLogger ChapterLogs { get; private set; } = null!;
protected CapturingLogger SceneLogs { get; private set; } = null!;
protected CapturingLogger BeatLogs { get; private set; } = null!;
protected CapturingLogger TagLogs { get; private set; } = null!;
protected CapturingLogger ArcLogs { get; private set; } = null!;
protected CapturingLogger QuestionLogs { get; private set; } = null!;
[SetUp]
public void SetUpFixture()
{
Db = new TestDatabase();
TagLogs = new CapturingLogger();
ProjectLogs = new CapturingLogger();
CharacterLogs = new CapturingLogger();
ChapterLogs = new CapturingLogger();
SceneLogs = new CapturingLogger();
BeatLogs = new CapturingLogger();
ArcLogs = new CapturingLogger();
QuestionLogs = new CapturingLogger();
Tags = new TagService(Db.Context, TagLogs, new CreateTagRequestValidator(), new UpdateTagRequestValidator());
Projects = new ProjectService(Db.Context, ProjectLogs, new CreateProjectRequestValidator(), new UpdateProjectRequestValidator());
Characters = new CharacterService(
Db.Context, Tags, CharacterLogs,
new CreateCharacterRequestValidator(), new UpdateCharacterRequestValidator(), new CreateRelationshipRequestValidator());
Chapters = new ChapterService(Db.Context, Tags, ChapterLogs, new CreateChapterRequestValidator(), new UpdateChapterRequestValidator());
Scenes = new SceneService(Db.Context, SceneLogs, new CreateSceneRequestValidator(), new UpdateSceneRequestValidator());
Beats = new BeatService(
Db.Context, Tags, BeatLogs,
new CreateBeatRequestValidator(), new UpdateBeatRequestValidator(), new ReorderBeatsRequestValidator());
Arcs = new CharacterArcService(
Db.Context, ArcLogs,
new CreateArcStageRequestValidator(), new UpdateArcStageRequestValidator(), new ReorderArcStagesRequestValidator());
Questions = new OpenQuestionService(
Db.Context, QuestionLogs,
new CreateOpenQuestionRequestValidator(), new UpdateOpenQuestionRequestValidator(), new ResolveOpenQuestionRequestValidator());
OnSetUp();
}
/// Runs after the services exist, for per-class seed data.
protected virtual void OnSetUp()
{
}
[TearDown]
public void TearDownFixture() => Db.Dispose();
}