Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ModelFirst/Library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ 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

- `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.

Expand All @@ -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.

Expand Down
20 changes: 11 additions & 9 deletions ModelFirst/Library/library.play
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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"
Loading