-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
BankAccountTests.fs
114 lines (102 loc) · 2.94 KB
/
BankAccountTests.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
module BankAccountTests
open System
open Deciders.BankAccount
open Deciders.BankAccountPrimitives
open Deciders.BankAccountDecider
open Ogooreck.BusinessLogic
open FsCheck.Xunit
let random = Random()
let spec =
Specification.For(decide, evolve, Initial)
let BankAccountOpenedWith bankAccountId now version =
let accountNumber =
AccountNumber.parse (Guid.NewGuid().ToString())
let clientId = ClientId.newId ()
let currencyISOCode =
CurrencyIsoCode.parse "USD"
BankAccountOpened
{ BankAccountId = bankAccountId
AccountNumber = accountNumber
ClientId = clientId
CurrencyIsoCode = currencyISOCode
CreatedAt = now
Version = version }
let BankAccountClosedWith bankAccountId now version =
BankAccountClosed
{ BankAccountId = bankAccountId
Reason = Guid.NewGuid().ToString()
ClosedAt = now
Version = version }
[<Property>]
let ``GIVEN non existing bank account WHEN open with valid params THEN bank account is opened``
bankAccountId
accountNumber
clientId
currencyISOCode
now
=
let notExistingAccount = Array.empty
spec
.Given(notExistingAccount)
.When(
OpenBankAccount
{ BankAccountId = bankAccountId
AccountNumber = accountNumber
ClientId = clientId
CurrencyIsoCode = currencyISOCode
Now = now }
)
.Then(
BankAccountOpened
{ BankAccountId = bankAccountId
AccountNumber = accountNumber
ClientId = clientId
CurrencyIsoCode = currencyISOCode
CreatedAt = now
Version = 1 }
)
|> ignore
[<Property>]
let ``GIVEN open bank account WHEN record deposit with valid params THEN deposit is recorded``
bankAccountId
amount
cashierId
now
=
spec
.Given(BankAccountOpenedWith bankAccountId now 1)
.When(
RecordDeposit
{ Amount = amount
CashierId = cashierId
Now = now }
)
.Then(
DepositRecorded
{ BankAccountId = bankAccountId
Amount = amount
CashierId = cashierId
RecordedAt = now
Version = 2 }
)
|> ignore
[<Property>]
let ``GIVEN closed bank account WHEN record deposit with valid params THEN fails with invalid operation exception``
bankAccountId
amount
cashierId
now
=
spec
.Given(
BankAccountOpenedWith bankAccountId now 1,
BankAccountClosedWith bankAccountId now 2
)
.When(
RecordDeposit
{ Amount = amount
CashierId = cashierId
Now = now }
)
.ThenThrows<InvalidOperationException>
|> ignore