@@ -62,9 +62,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_TransactionIs
6262 TestData . DeviceIdentifier ,
6363 CancellationToken . None ) ;
6464
65- response . ShouldNotBeNull ( ) ;
66- response . ResponseCode . ShouldBe ( TestData . ResponseCode ) ;
67- response . ResponseMessage . ShouldBe ( TestData . ResponseMessage ) ;
65+ this . ValidateLogonResponse ( response , TransactionResponseCode . Success ) ;
6866 }
6967
7068 [ Fact ]
@@ -105,9 +103,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_MerchantWithN
105103 TestData . DeviceIdentifier ,
106104 CancellationToken . None ) ;
107105
108- response . ShouldNotBeNull ( ) ;
109- response . ResponseCode . ShouldBe ( TestData . ResponseCode ) ;
110- response . ResponseMessage . ShouldBe ( TestData . ResponseMessage ) ;
106+ this . ValidateLogonResponse ( response , TransactionResponseCode . Success ) ;
111107 }
112108
113109 [ Fact ]
@@ -148,9 +144,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_MerchantWithN
148144 TestData . DeviceIdentifier ,
149145 CancellationToken . None ) ;
150146
151- response . ShouldNotBeNull ( ) ;
152- response . ResponseCode . ShouldBe ( TestData . ResponseCode ) ;
153- response . ResponseMessage . ShouldBe ( TestData . ResponseMessage ) ;
147+ this . ValidateLogonResponse ( response , TransactionResponseCode . Success ) ;
154148 }
155149
156150 [ Fact ]
@@ -168,7 +162,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_IncorrectDevi
168162 transactionAggregateRepository . SetupSequence ( t => t . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
169163 . ReturnsAsync ( TestData . GetEmptyTransactionAggregate )
170164 . ReturnsAsync ( TestData . GetStartedTransactionAggregate )
171- . ReturnsAsync ( TestData . GetLocallyAuthorisedTransactionAggregate )
165+ . ReturnsAsync ( TestData . GetLocallyDeclinedTransactionAggregate ( TransactionResponseCode . InvalidDeviceIdentifier ) )
172166 . ReturnsAsync ( TestData . GetCompletedTransactionAggregate ) ;
173167 transactionAggregateRepository . Setup ( t => t . SaveChanges ( It . IsAny < TransactionAggregate > ( ) , It . IsAny < CancellationToken > ( ) ) ) . Returns ( Task . CompletedTask ) ;
174168
@@ -191,13 +185,11 @@ public async Task TransactionDomainService_ProcessLogonTransaction_IncorrectDevi
191185 TestData . DeviceIdentifier1 ,
192186 CancellationToken . None ) ;
193187
194- response . ShouldNotBeNull ( ) ;
195- response . ResponseCode . ShouldBe ( TestData . ResponseCode ) ;
196- response . ResponseMessage . ShouldBe ( TestData . ResponseMessage ) ;
188+ this . ValidateLogonResponse ( response , TransactionResponseCode . InvalidDeviceIdentifier ) ;
197189 }
198190
199191 [ Fact ]
200- public async Task TransactionDomainService_ProcessLogonTransaction_InvlaidEstate_TransactionIsProcessed ( )
192+ public async Task TransactionDomainService_ProcessLogonTransaction_InvalidEstate_TransactionIsProcessed ( )
201193 {
202194 IConfigurationRoot configurationRoot = new ConfigurationBuilder ( ) . AddInMemoryCollection ( TestData . DefaultAppSettings ) . Build ( ) ;
203195 ConfigurationReader . Initialise ( configurationRoot ) ;
@@ -211,7 +203,7 @@ public async Task TransactionDomainService_ProcessLogonTransaction_InvlaidEstate
211203 transactionAggregateRepository . SetupSequence ( t => t . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
212204 . ReturnsAsync ( TestData . GetEmptyTransactionAggregate )
213205 . ReturnsAsync ( TestData . GetStartedTransactionAggregate )
214- . ReturnsAsync ( TestData . GetLocallyAuthorisedTransactionAggregate )
206+ . ReturnsAsync ( TestData . GetLocallyDeclinedTransactionAggregate ( TransactionResponseCode . InvalidEstateId ) )
215207 . ReturnsAsync ( TestData . GetCompletedTransactionAggregate ) ;
216208 transactionAggregateRepository . Setup ( t => t . SaveChanges ( It . IsAny < TransactionAggregate > ( ) , It . IsAny < CancellationToken > ( ) ) ) . Returns ( Task . CompletedTask ) ;
217209
@@ -234,10 +226,63 @@ public async Task TransactionDomainService_ProcessLogonTransaction_InvlaidEstate
234226 TestData . DeviceIdentifier1 ,
235227 CancellationToken . None ) ;
236228
237- response . ShouldNotBeNull ( ) ;
238- response . ResponseCode . ShouldBe ( TestData . ResponseCode ) ;
239- response . ResponseMessage . ShouldBe ( TestData . ResponseMessage ) ;
229+ this . ValidateLogonResponse ( response , TransactionResponseCode . InvalidEstateId ) ;
240230 }
241231
232+ [ Fact ]
233+ public async Task TransactionDomainService_ProcessLogonTransaction_InvalidMerchant_TransactionIsProcessed ( )
234+ {
235+ IConfigurationRoot configurationRoot = new ConfigurationBuilder ( ) . AddInMemoryCollection ( TestData . DefaultAppSettings ) . Build ( ) ;
236+ ConfigurationReader . Initialise ( configurationRoot ) ;
237+
238+ Logger . Initialise ( NullLogger . Instance ) ;
239+
240+ Mock < IAggregateRepositoryManager > aggregateRepositoryManager = new Mock < IAggregateRepositoryManager > ( ) ;
241+ Mock < IAggregateRepository < TransactionAggregate > > transactionAggregateRepository = new Mock < IAggregateRepository < TransactionAggregate > > ( ) ;
242+
243+ aggregateRepositoryManager . Setup ( x => x . GetAggregateRepository < TransactionAggregate > ( It . IsAny < Guid > ( ) ) ) . Returns ( transactionAggregateRepository . Object ) ;
244+ transactionAggregateRepository . SetupSequence ( t => t . GetLatestVersion ( It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
245+ . ReturnsAsync ( TestData . GetEmptyTransactionAggregate )
246+ . ReturnsAsync ( TestData . GetStartedTransactionAggregate )
247+ . ReturnsAsync ( TestData . GetLocallyDeclinedTransactionAggregate ( TransactionResponseCode . InvalidMerchantId ) )
248+ . ReturnsAsync ( TestData . GetCompletedTransactionAggregate ) ;
249+ transactionAggregateRepository . Setup ( t => t . SaveChanges ( It . IsAny < TransactionAggregate > ( ) , It . IsAny < CancellationToken > ( ) ) ) . Returns ( Task . CompletedTask ) ;
250+
251+ Mock < IEstateClient > estateClient = new Mock < IEstateClient > ( ) ;
252+ Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
253+
254+ securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
255+ estateClient . Setup ( e => e . GetEstate ( It . IsAny < String > ( ) , It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . GetEstateResponse ) ;
256+ estateClient . Setup ( e => e . GetMerchant ( It . IsAny < String > ( ) , It . IsAny < Guid > ( ) , It . IsAny < Guid > ( ) , It . IsAny < CancellationToken > ( ) ) )
257+ . ReturnsAsync ( TestData . GetEmptyMerchantResponse ) ;
258+
259+ TransactionDomainService transactionDomainService =
260+ new TransactionDomainService ( aggregateRepositoryManager . Object , estateClient . Object , securityServiceClient . Object ) ;
261+
262+ ProcessLogonTransactionResponse response = await transactionDomainService . ProcessLogonTransaction ( TestData . TransactionId ,
263+ TestData . EstateId ,
264+ TestData . MerchantId ,
265+ TestData . TransactionDateTime ,
266+ TestData . TransactionNumber ,
267+ TestData . DeviceIdentifier1 ,
268+ CancellationToken . None ) ;
269+
270+ this . ValidateLogonResponse ( response , TransactionResponseCode . InvalidMerchantId ) ;
271+ }
272+
273+ private void ValidateLogonResponse ( ProcessLogonTransactionResponse response ,
274+ TransactionResponseCode transactionResponseCode )
275+ {
276+ response . ShouldNotBeNull ( ) ;
277+ response . ResponseCode . ShouldBe ( TestData . GetResponseCodeAsString ( transactionResponseCode ) ) ;
278+
279+ String messageToValidate = TestData . GetResponseCodeMessage ( transactionResponseCode ) ;
280+ if ( transactionResponseCode == TransactionResponseCode . Success )
281+ {
282+ messageToValidate = messageToValidate . ToUpper ( ) ;
283+ }
284+
285+ response . ResponseMessage . ShouldBe ( messageToValidate ) ;
286+ }
242287 }
243288}
0 commit comments