Stop throwing for not-found; add Guard and request validation
Not-found lookups return null/false instead of throwing NotFoundException across all services — a missing row is expected control flow, not an exceptional condition. NotFoundException stays for embedded precondition checks inside mutations (missing parent, invalid foreign reference). Guard (copied from mic-check) enforces required arguments at the top of every service method. A ported IModelValidator<T> framework validates every request DTO at the API layer via a new ValidationEndpointFilter, returning a 400 with field-level messages; services re-run the same validator and throw for direct callers that bypass the API. Endpoints translate null/false into 404 via a new ToApiResult() helper. The agent toolset boundary translates the same nullable/bool results into the tool-error text the model already expected.
This commit is contained in:
@@ -28,8 +28,8 @@ public class CharacterArcTests : ServiceTestFixture
|
||||
|
||||
Assert.That(mara.Importance, Is.EqualTo(CharacterImportance.Supporting));
|
||||
|
||||
var promoted = await Characters.UpdateAsync(
|
||||
mara.Id, new UpdateCharacterRequest(Importance: CharacterImportance.Main));
|
||||
var promoted = (await Characters.UpdateAsync(
|
||||
mara.Id, new UpdateCharacterRequest(Importance: CharacterImportance.Main)))!;
|
||||
|
||||
Assert.That(promoted.Importance, Is.EqualTo(CharacterImportance.Main));
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class CharacterArcTests : ServiceTestFixture
|
||||
await Arcs.CreateAsync(_characterId, new CreateArcStageRequest(
|
||||
"She trusts the map", Description: "Because her mother drew it."));
|
||||
|
||||
var character = await Characters.GetAsync(_characterId);
|
||||
var character = (await Characters.GetAsync(_characterId))!;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -163,7 +163,7 @@ public class CharacterArcTests : ServiceTestFixture
|
||||
await Chapters.DeleteAsync(chapter.Id);
|
||||
|
||||
// How a character changes outlives a decision about where the chapter break falls.
|
||||
var survivor = await Arcs.GetAsync(stage.Id);
|
||||
var survivor = (await Arcs.GetAsync(stage.Id))!;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -201,7 +201,7 @@ public class CharacterArcTests : ServiceTestFixture
|
||||
await Beats.CreateAsync(first.Id, new CreateBeatRequest("Mara lies", CharacterId: mara.Id));
|
||||
await Beats.CreateAsync(first.Id, new CreateBeatRequest("Nobody's beat"));
|
||||
|
||||
var beats = await Beats.ListForCharacterAsync(_characterId);
|
||||
var beats = (await Beats.ListForCharacterAsync(_characterId))!;
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -213,8 +213,6 @@ public class CharacterArcTests : ServiceTestFixture
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Asking_for_the_beats_of_a_character_who_does_not_exist_reports_not_found() =>
|
||||
Assert.That(
|
||||
async () => await Beats.ListForCharacterAsync(Guid.NewGuid()),
|
||||
Throws.TypeOf<NotFoundException>());
|
||||
public async Task Asking_for_the_beats_of_a_character_who_does_not_exist_returns_null_rather_than_throwing() =>
|
||||
Assert.That(await Beats.ListForCharacterAsync(Guid.NewGuid()), Is.Null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user