diff --git a/ModelFirst/Library/README.md b/ModelFirst/Library/README.md index 409f7e7b..d52b9fa1 100644 --- a/ModelFirst/Library/README.md +++ b/ModelFirst/Library/README.md @@ -25,13 +25,13 @@ AddBook command BookAddedToCatalog event ``` -The same file contains one accepted example and one rejected example. Screenplay compiles the model; Stage runs those examples as model-level specifications. +The same file contains one accepted example and two rejected examples: an empty title and an empty author name. Screenplay compiles the model; Stage runs those examples as model-level specifications. ```mermaid flowchart LR model[library.play] --> compiler[Screenplay compiler] compiler --> stage[Stage specification runner] - stage --> result[2 model specifications] + stage --> result[3 model specifications] ``` ## What is in the model @@ -39,9 +39,9 @@ flowchart LR - `BookId`, `BookTitle`, and `AuthorName` concepts; - an `AddBook` state-change slice; - required title and author rules; -- the `BookAddedToCatalog` fact; +- the `BookAddedToCatalog` fact, declared inline with `produces event`, with typed payload mappings and the command identifier as its default event source; - one successful scenario; -- one expected validation rejection. +- two expected validation rejections. Open [`library.play`](./library.play) before running anything—the complete behavior fits on one screen. @@ -67,12 +67,12 @@ dotnet run --no-build --no-restore \ cat "$RESULTS_PATH" ``` -The current model compiles without diagnostics and produces two passing specification results. +The current model compiles without diagnostics and produces three passing specification results. ## Make it yours - Add an ISBN concept and require it on `AddBook`. -- Add a second rejection for an empty author name. +- Add a specification for a book with both title and author name empty. - Introduce a read model after exploring the focused state-change slice. - Change an expected event value and watch the specification catch it. diff --git a/ModelFirst/Library/library.play b/ModelFirst/Library/library.play index 87b9e983..5e970d7c 100644 --- a/ModelFirst/Library/library.play +++ b/ModelFirst/Library/library.play @@ -1,7 +1,7 @@ // Copyright (c) Cratis. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -// A deliberately small model-first sample: one command, one fact, and two model specifications. +// A deliberately small model-first sample: one command, one inline fact, and three model specifications. domain Library concept BookId : Uuid @@ -26,14 +26,9 @@ module Library title not empty message "A title is required" authorName not empty message "An author name is required" - produces BookAddedToCatalog - for bookId - title = title - authorName = authorName - - event BookAddedToCatalog - title BookTitle - authorName AuthorName + produces event BookAddedToCatalog + title BookTitle = title + authorName AuthorName = authorName specification AddingABook when AddBook @@ -50,3 +45,10 @@ module Library title = "" authorName = "Mara North" then error "A title is required" + + specification RejectingABookWithoutAnAuthorName + when AddBook + bookId = "69064f39-6a76-458a-8a34-088eb4752650" + title = "The Quiet Archive" + authorName = "" + then error "An author name is required"