Skip to content

Commit bd287d8

Browse files
author
Leif Battermann
committed
ex1 readme updated
1 parent f5ac2ce commit bd287d8

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

ex1/README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ let item = itemId,book
1818
let qty = Quantity.Create 10
1919
2020
Given defaultPreconditions
21-
|> When (aggId, RegisterInventoryItem (item, qty))
21+
|> When (aggId, RegisterInventoryItem { Item = item; Quantity = qty })
2222
|> Then ([ItemRegistered(item, qty)] |> ok)
2323
```
2424

@@ -51,7 +51,11 @@ We use single discriminated union for `Title`, `Author` and `Quantity`, this wil
5151
After we have the basic type we can add the command to the `Commands` module in the `Contracts` project. Replace the `RegisterInventoryItem` with the following
5252

5353
```fsharp
54-
| RegisterInventoryItem of Item * Quantity
54+
| RegisterInventoryItem of RegisterInventoryItem
55+
56+
and RegisterInventoryItem = {
57+
Item:Item
58+
Quantity:Quantity }
5559
```
5660

5761
The last type we need to add is the event used in the test. So add that to the `Events` module. The `EventData` definition should look like this when done:
@@ -72,14 +76,12 @@ In the `Inventory` module we have skeleton implementation of what we need. The m
7276
If you add a break point in the `executeCommand` function you'll see that the `State` is `ItemInit`. That state is defined in `DomainTypes`, and is the state we are interested in right now since nothing has happened and the `Item` should be in its initial stage. To get the test green we need to handle the command, and to address that you need to change the implementation to this:
7377

7478
```fsharp
75-
let handleAtInit (id, command) =
76-
match command with
77-
| RegisterInventoryItem(item, quantity) -> [ItemRegistered(item, quantity)] |> ok
78-
| _ -> raise (exn "Implement me")
79+
let handleAtInit (id, (command:RegisterInventoryItem)) =
80+
[ItemRegistered(command.Item, command.Quantity)] |> ok
7981
8082
let executeCommand state command =
81-
match state with
82-
| ItemInit -> handleAtInit command
83+
match state, command with
84+
| ItemInit, (id, RegisterInventoryItem cmd) -> handleAtInit (id, cmd)
8385
| _ -> raise (exn "Implement me")
8486
```
8587

0 commit comments

Comments
 (0)