Throw ObjectNotFoundException from FindRequired; add run-console wrappers

- DbBase.FindRequired / Client.FindByNameRequired now throw the
  domain-specific ObjectNotFoundException (NHibernate lineage; Rails
  equivalent: ActiveRecord::RecordNotFound) on a lookup miss; the
  no-context case stays InvalidOperationException (configuration error)
- Console demo catches the new type; tests (18)/(21) assert it,
  (19)/(23) keep InvalidOperationException with rationale comments
- scripts/run-console.sh delegates to dotnet.sh; run-console.ps1 is
  the Windows/PowerShell counterpart (mise-first, repo-root cd)

Yak: objectnotfoundexception-run-console-wrappers-3p8b
This commit is contained in:
2026-09-14 22:39:21 +01:00
parent 4b6e6f5a00
commit ec9586c316
8 changed files with 104 additions and 17 deletions
+2 -5
View File
@@ -44,9 +44,6 @@ foreach (var client in DbBase.Context!.Tracked.OfType<Client>())
// ----- find by name -------------------------------------------------------
Console.WriteLine("\n=== Find by Name (null-returning) ===");
// No context argument: FindByName falls back to the DbBase.Context singleton.
// This is the ActiveRecord ergonomic — call sites don't carry the context,
// but the null that comes back on a miss can't tell "no such client" from
// "nobody configured the context".
var found = Client.FindByName("Jane Doe");
if (found is not null)
{
@@ -66,7 +63,7 @@ try
Console.WriteLine($"Found: {required.Name} [{required.Id}]");
Console.WriteLine($" Orders: {required.Orders.Count}");
}
catch (InvalidOperationException ex)
catch (ObjectNotFoundException ex)
{
Console.WriteLine($"Not found: {ex.Message}");
}
@@ -79,7 +76,7 @@ try
{
Client.FindByNameRequired("Nobody Here");
}
catch (InvalidOperationException ex)
catch (ObjectNotFoundException ex)
{
var msg = ex.Message.ReplaceLineEndings(" ").Trim();
Console.WriteLine($"FindByNameRequired(\"Nobody Here\"): throws - {msg}");