4
4
using Amazon . DynamoDBv2 . DataModel ;
5
5
using Amazon . StepFunctions ;
6
6
using Amazon . StepFunctions . Model ;
7
- using Moq ;
7
+ using NSubstitute ;
8
8
using Xunit ;
9
9
using Xunit . Abstractions ;
10
10
@@ -39,33 +39,31 @@ public void StatusIsDraftSyncShouldNotSendTaskSuccess()
39
39
// Setup
40
40
var ddbEvent = TestHelpers . LoadDynamoDbEventSource ( "./events/StreamEvents/contract_status_changed_draft.json" ) ;
41
41
42
- var retContractStatusItem = new ContractStatusItem
43
- {
44
- PropertyId = "usa/anytown/main-street/999" ,
45
- ContractId = Guid . NewGuid ( ) ,
46
- ContractStatus = "DRAFT" ,
47
- ContractLastModifiedOn = DateTime . Today ,
48
- SfnWaitApprovedTaskToken = null
49
- } ;
50
-
51
- var mockDynamoDbContext = new Mock < IDynamoDBContext > ( ) ;
52
-
53
- mockDynamoDbContext
54
- . Setup ( x => x . LoadAsync < ContractStatusItem > ( It . IsAny < string > ( ) , CancellationToken . None ) . Result )
55
- . Returns ( retContractStatusItem ) ;
56
-
57
- var mockStepFunctionsClient = new Mock < AmazonStepFunctionsClient > ( ) ;
58
-
42
+ var mockDynamoDbContext = Substitute . For < IDynamoDBContext > ( ) ;
43
+
44
+ mockDynamoDbContext . LoadAsync < ContractStatusItem > ( Arg . Any < string > ( ) , Arg . Is ( CancellationToken . None ) )
45
+ . Returns ( new ContractStatusItem
46
+ {
47
+ PropertyId = "usa/anytown/main-street/999" ,
48
+ ContractId = Guid . NewGuid ( ) ,
49
+ ContractStatus = "DRAFT" ,
50
+ ContractLastModifiedOn = DateTime . Today ,
51
+ SfnWaitApprovedTaskToken = null
52
+ } ) ;
53
+
54
+ var mockStepFunctionsClient = Substitute . ForPartsOf < AmazonStepFunctionsClient > ( ) ;
55
+ mockStepFunctionsClient . Received ( 0 )
56
+ . SendTaskSuccessAsync ( Arg . Any < SendTaskSuccessRequest > ( ) ,
57
+ Arg . Any < CancellationToken > ( ) ) ;
58
+
59
59
var context = TestHelpers . NewLambdaContext ( ) ;
60
60
61
61
var function =
62
- new PropertiesApprovalSyncFunction ( mockStepFunctionsClient . Object , mockDynamoDbContext . Object ) ;
62
+ new PropertiesApprovalSyncFunction ( mockStepFunctionsClient , mockDynamoDbContext ) ;
63
+
64
+ var handler = function . FunctionHandler ( ddbEvent , context ) ;
63
65
64
- function . FunctionHandler ( ddbEvent , context ) ;
65
66
66
- mockStepFunctionsClient . Verify (
67
- client => client . SendTaskSuccessAsync ( It . IsAny < SendTaskSuccessRequest > ( ) ,
68
- It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
69
67
}
70
68
71
69
@@ -75,32 +73,32 @@ public Task StatusIsApprovedNoTokenSyncShouldNotSendTaskSuccess()
75
73
var ddbEvent =
76
74
TestHelpers . LoadDynamoDbEventSource ( "./events/StreamEvents/contract_status_changed_approved.json" ) ;
77
75
78
- var retContractStatusItem = new ContractStatusItem
79
- {
80
- PropertyId = "usa/anytown/main-street/999" ,
81
- ContractId = Guid . NewGuid ( ) ,
82
- ContractStatus = "APPROVED " ,
83
- ContractLastModifiedOn = DateTime . Today ,
84
- SfnWaitApprovedTaskToken = null
85
- } ;
86
-
87
- var mockDynamoDbContext = new Mock < IDynamoDBContext > ( ) ;
88
- mockDynamoDbContext
89
- . Setup ( x => x . LoadAsync < ContractStatusItem > ( It . IsAny < string > ( ) , CancellationToken . None ) . Result )
90
- . Returns ( retContractStatusItem ) ;
91
-
92
- var mockStepFunctionsClient = new Mock < AmazonStepFunctionsClient > ( ) ;
93
-
76
+ var mockDynamoDbContext = Substitute . For < IDynamoDBContext > ( ) ;
77
+ mockDynamoDbContext . LoadAsync < ContractStatusItem > ( Arg . Any < string > ( ) , Arg . Any < CancellationToken > ( ) )
78
+ . Returns ( new ContractStatusItem
79
+ {
80
+ PropertyId = "usa/anytown/main-street/999 " ,
81
+ ContractId = Guid . NewGuid ( ) ,
82
+ ContractStatus = "APPROVED" ,
83
+ ContractLastModifiedOn = DateTime . Today ,
84
+ SfnWaitApprovedTaskToken = null
85
+ } ) ;
86
+
87
+ var mockStepFunctionsClient = Substitute . ForPartsOf < AmazonStepFunctionsClient > ( ) ;
88
+ mockStepFunctionsClient . Received ( 0 ) .
89
+ SendTaskSuccessAsync ( Arg . Any < SendTaskSuccessRequest > ( ) ,
90
+ Arg . Any < CancellationToken > ( ) ) ;
91
+
94
92
var context = TestHelpers . NewLambdaContext ( ) ;
95
93
96
94
var function =
97
- new PropertiesApprovalSyncFunction ( mockStepFunctionsClient . Object , mockDynamoDbContext . Object ) ;
95
+ new PropertiesApprovalSyncFunction ( mockStepFunctionsClient , mockDynamoDbContext ) ;
98
96
99
97
function . FunctionHandler ( ddbEvent , context ) ;
100
98
101
- mockStepFunctionsClient . Verify (
102
- client => client . SendTaskSuccessAsync ( It . IsAny < SendTaskSuccessRequest > ( ) ,
103
- It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
99
+ mockStepFunctionsClient . Received ( 0 ) .
100
+ SendTaskSuccessAsync ( Arg . Any < SendTaskSuccessRequest > ( ) ,
101
+ Arg . Any < CancellationToken > ( ) ) ;
104
102
105
103
return Task . CompletedTask ;
106
104
}
@@ -113,32 +111,30 @@ public Task StatusIsDraftWithTokenSyncShouldNotSendTaskSuccess()
113
111
TestHelpers . LoadDynamoDbEventSource (
114
112
"./events/StreamEvents/contract_status_draft_waiting_for_approval.json" ) ;
115
113
116
- var retContractStatusItem = new ContractStatusItem
117
- {
118
- PropertyId = "usa/anytown/main-street/999" ,
119
- ContractId = Guid . NewGuid ( ) ,
120
- ContractStatus = "DRAFT" ,
121
- ContractLastModifiedOn = DateTime . Today ,
122
- SfnWaitApprovedTaskToken = Token
123
- } ;
124
-
125
- var mockDynamoDbContext = new Mock < IDynamoDBContext > ( ) ;
126
- mockDynamoDbContext
127
- . Setup ( x => x . LoadAsync < ContractStatusItem > ( It . IsAny < string > ( ) , CancellationToken . None ) . Result )
128
- . Returns ( retContractStatusItem ) ;
114
+ var mockDynamoDbContext = Substitute . For < IDynamoDBContext > ( ) ;
115
+
116
+ mockDynamoDbContext . LoadAsync < ContractStatusItem > ( Arg . Any < string > ( ) , CancellationToken . None )
117
+ . Returns ( new ContractStatusItem
118
+ {
119
+ PropertyId = "usa/anytown/main-street/999" ,
120
+ ContractId = Guid . NewGuid ( ) ,
121
+ ContractStatus = "DRAFT" ,
122
+ ContractLastModifiedOn = DateTime . Today ,
123
+ SfnWaitApprovedTaskToken = Token
124
+ } ) ;
129
125
130
- var mockStepFunctionsClient = new Mock < AmazonStepFunctionsClient > ( ) ;
126
+ var mockStepFunctionsClient = Substitute . ForPartsOf < AmazonStepFunctionsClient > ( ) ;
131
127
132
128
var context = TestHelpers . NewLambdaContext ( ) ;
133
129
134
130
var function =
135
- new PropertiesApprovalSyncFunction ( mockStepFunctionsClient . Object , mockDynamoDbContext . Object ) ;
131
+ new PropertiesApprovalSyncFunction ( mockStepFunctionsClient , mockDynamoDbContext ) ;
136
132
137
133
var handler = function . FunctionHandler ( ddbEvent , context ) ;
138
134
139
- mockStepFunctionsClient . Verify (
140
- client => client . SendTaskSuccessAsync ( It . IsAny < SendTaskSuccessRequest > ( ) ,
141
- It . IsAny < CancellationToken > ( ) ) , Times . Never ) ;
135
+ mockStepFunctionsClient . Received ( 0 ) .
136
+ SendTaskSuccessAsync ( Arg . Any < SendTaskSuccessRequest > ( ) ,
137
+ Arg . Any < CancellationToken > ( ) ) ;
142
138
143
139
return Task . CompletedTask ;
144
140
}
@@ -151,31 +147,27 @@ public Task StatusIsApprovedWithTokenSyncShouldSendTaskSuccess()
151
147
TestHelpers . LoadDynamoDbEventSource (
152
148
"./events/StreamEvents/contract_status_changed_approved_waiting_for_approval.json" ) ;
153
149
154
- var retContractStatusItem = new ContractStatusItem
155
- {
156
- PropertyId = "usa/anytown/main-street/999" ,
157
- ContractId = Guid . NewGuid ( ) ,
158
- ContractStatus = "APPROVED" ,
159
- ContractLastModifiedOn = DateTime . Today ,
160
- SfnWaitApprovedTaskToken = Token
161
- } ;
162
-
163
- var mockStepFunctionsClient = new Mock < AmazonStepFunctionsClient > ( ) ;
164
- var mockDynamoDbContext = new Mock < IDynamoDBContext > ( ) ;
165
- mockDynamoDbContext
166
- . Setup ( x =>
167
- x . LoadAsync < ContractStatusItem > ( It . IsAny < string > ( ) ,
168
- CancellationToken . None ) . Result )
169
- . Returns ( retContractStatusItem ) ;
150
+ var mockStepFunctionsClient = Substitute . ForPartsOf < AmazonStepFunctionsClient > ( ) ;
151
+ var mockDynamoDbContext = Substitute . For < IDynamoDBContext > ( ) ;
152
+
153
+ mockDynamoDbContext . LoadAsync < ContractStatusItem > ( Arg . Any < string > ( ) , Arg . Is ( CancellationToken . None ) )
154
+ . Returns ( new ContractStatusItem
155
+ {
156
+ PropertyId = "usa/anytown/main-street/999" ,
157
+ ContractId = Guid . NewGuid ( ) ,
158
+ ContractStatus = "APPROVED" ,
159
+ ContractLastModifiedOn = DateTime . Today ,
160
+ SfnWaitApprovedTaskToken = Token
161
+ } ) ;
170
162
var context = TestHelpers . NewLambdaContext ( ) ;
171
163
172
164
var function =
173
- new PropertiesApprovalSyncFunction ( mockStepFunctionsClient . Object , mockDynamoDbContext . Object ) ;
165
+ new PropertiesApprovalSyncFunction ( mockStepFunctionsClient , mockDynamoDbContext ) ;
174
166
var handler = function . FunctionHandler ( ddbEvent , context ) ;
175
167
176
- mockStepFunctionsClient . Verify (
177
- client => client . SendTaskSuccessAsync ( It . IsAny < SendTaskSuccessRequest > ( ) ,
178
- It . IsAny < CancellationToken > ( ) ) , Times . Once ) ;
168
+ mockStepFunctionsClient . Received ( 1 ) .
169
+ SendTaskSuccessAsync ( Arg . Any < SendTaskSuccessRequest > ( ) ,
170
+ Arg . Any < CancellationToken > ( ) ) ;
179
171
180
172
return Task . CompletedTask ;
181
173
}
0 commit comments