44
55namespace TransactionProcessorACL . BusinesssLogic . Tests
66{
7+ using System . Net . Http ;
78 using System . Threading ;
89 using System . Threading . Tasks ;
910 using BusinessLogic . Services ;
@@ -64,14 +65,14 @@ public async Task TransactionProcessorACLApplicationService_ProcessLogonTransact
6465 }
6566
6667 [ Fact ]
67- public async Task TransactionProcessorACLApplicationService_ProcessLogonTransaction_ErrorInLogon_TransactionIsNotSuccessful ( )
68+ public async Task TransactionProcessorACLApplicationService_ProcessLogonTransaction_InvalidOperationExceptionErrorInLogon_TransactionIsNotSuccessful ( )
6869 {
6970 IConfigurationRoot configuration = this . SetupMemoryConfiguration ( ) ;
7071 ConfigurationReader . Initialise ( configuration ) ;
7172
7273 Mock < ITransactionProcessorClient > transactionProcessorClient = new Mock < ITransactionProcessorClient > ( ) ;
7374 transactionProcessorClient . Setup ( t => t . PerformTransaction ( It . IsAny < String > ( ) , It . IsAny < SerialisedMessage > ( ) , It . IsAny < CancellationToken > ( ) ) )
74- . ThrowsAsync ( new Exception ( "Error" , new InvalidOperationException ( TestData . ErrorResponseMessage ) ) ) ;
75+ . ThrowsAsync ( new Exception ( "Error" , new InvalidOperationException ( TestData . InvalidOperationErrorResponseMessage ) ) ) ;
7576 Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
7677 securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
7778
@@ -86,8 +87,62 @@ public async Task TransactionProcessorACLApplicationService_ProcessLogonTransact
8687 CancellationToken . None ) ;
8788
8889 logonResponse . ShouldNotBeNull ( ) ;
89- logonResponse . ResponseMessage . ShouldBe ( TestData . ErrorResponseMessage ) ;
90- logonResponse . ResponseCode . ShouldBe ( TestData . ErrorResponseCode ) ;
90+ logonResponse . ResponseMessage . ShouldBe ( TestData . InvalidOperationErrorResponseMessage ) ;
91+ logonResponse . ResponseCode . ShouldBe ( TestData . InvalidOperationErrorResponseCode ) ;
92+ }
93+
94+ [ Fact ]
95+ public async Task TransactionProcessorACLApplicationService_ProcessLogonTransaction_HttpRequestExceptionErrorInLogon_TransactionIsNotSuccessful ( )
96+ {
97+ IConfigurationRoot configuration = this . SetupMemoryConfiguration ( ) ;
98+ ConfigurationReader . Initialise ( configuration ) ;
99+
100+ Mock < ITransactionProcessorClient > transactionProcessorClient = new Mock < ITransactionProcessorClient > ( ) ;
101+ transactionProcessorClient . Setup ( t => t . PerformTransaction ( It . IsAny < String > ( ) , It . IsAny < SerialisedMessage > ( ) , It . IsAny < CancellationToken > ( ) ) )
102+ . ThrowsAsync ( new Exception ( "Error" , new HttpRequestException ( TestData . HttpRequestErrorResponseMessage ) ) ) ;
103+ Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
104+ securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
105+
106+ ITransactionProcessorACLApplicationService applicationService =
107+ new TransactionProcessorACLApplicationService ( transactionProcessorClient . Object , securityServiceClient . Object ) ;
108+
109+ ProcessLogonTransactionResponse logonResponse = await applicationService . ProcessLogonTransaction ( TestData . EstateId ,
110+ TestData . MerchantId ,
111+ TestData . TransactionDateTime ,
112+ TestData . TransactionNumber ,
113+ TestData . DeviceIdentifier ,
114+ CancellationToken . None ) ;
115+
116+ logonResponse . ShouldNotBeNull ( ) ;
117+ logonResponse . ResponseMessage . ShouldBe ( TestData . HttpRequestErrorResponseMessage ) ;
118+ logonResponse . ResponseCode . ShouldBe ( TestData . HttpRequestErrorResponseCode ) ;
119+ }
120+
121+ [ Fact ]
122+ public async Task TransactionProcessorACLApplicationService_ProcessLogonTransaction_OtherExceptionErrorInLogon_TransactionIsNotSuccessful ( )
123+ {
124+ IConfigurationRoot configuration = this . SetupMemoryConfiguration ( ) ;
125+ ConfigurationReader . Initialise ( configuration ) ;
126+
127+ Mock < ITransactionProcessorClient > transactionProcessorClient = new Mock < ITransactionProcessorClient > ( ) ;
128+ transactionProcessorClient . Setup ( t => t . PerformTransaction ( It . IsAny < String > ( ) , It . IsAny < SerialisedMessage > ( ) , It . IsAny < CancellationToken > ( ) ) )
129+ . ThrowsAsync ( new Exception ( "Error" , new Exception ( TestData . GeneralErrorResponseMessage ) ) ) ;
130+ Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
131+ securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
132+
133+ ITransactionProcessorACLApplicationService applicationService =
134+ new TransactionProcessorACLApplicationService ( transactionProcessorClient . Object , securityServiceClient . Object ) ;
135+
136+ ProcessLogonTransactionResponse logonResponse = await applicationService . ProcessLogonTransaction ( TestData . EstateId ,
137+ TestData . MerchantId ,
138+ TestData . TransactionDateTime ,
139+ TestData . TransactionNumber ,
140+ TestData . DeviceIdentifier ,
141+ CancellationToken . None ) ;
142+
143+ logonResponse . ShouldNotBeNull ( ) ;
144+ logonResponse . ResponseMessage . ShouldBe ( TestData . GeneralErrorResponseMessage ) ;
145+ logonResponse . ResponseCode . ShouldBe ( TestData . GeneralErrorResponseCode ) ;
91146 }
92147
93148 [ Fact ]
@@ -124,14 +179,80 @@ public async Task TransactionProcessorACLApplicationService_ProcessSaleTransacti
124179 }
125180
126181 [ Fact ]
127- public async Task TransactionProcessorACLApplicationService_ProcessSaleTransaction_ErrorInSale_TransactionIsNotSuccessful ( )
182+ public async Task TransactionProcessorACLApplicationService_ProcessSaleTransaction_InvalidOperationExceptionErrorInSale_TransactionIsNotSuccessful ( )
183+ {
184+ IConfigurationRoot configuration = this . SetupMemoryConfiguration ( ) ;
185+ ConfigurationReader . Initialise ( configuration ) ;
186+
187+ Mock < ITransactionProcessorClient > transactionProcessorClient = new Mock < ITransactionProcessorClient > ( ) ;
188+ transactionProcessorClient . Setup ( t => t . PerformTransaction ( It . IsAny < String > ( ) , It . IsAny < SerialisedMessage > ( ) , It . IsAny < CancellationToken > ( ) ) )
189+ . ThrowsAsync ( new Exception ( "Error" , new InvalidOperationException ( TestData . InvalidOperationErrorResponseMessage ) ) ) ;
190+ Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
191+ securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
192+
193+ ITransactionProcessorACLApplicationService applicationService =
194+ new TransactionProcessorACLApplicationService ( transactionProcessorClient . Object , securityServiceClient . Object ) ;
195+
196+ ProcessSaleTransactionResponse saleResponse = await applicationService . ProcessSaleTransaction ( TestData . EstateId ,
197+ TestData . MerchantId ,
198+ TestData . TransactionDateTime ,
199+ TestData . TransactionNumber ,
200+ TestData . DeviceIdentifier ,
201+ TestData . OperatorIdentifier ,
202+ TestData . SaleAmount ,
203+ TestData . CustomerAccountNumber ,
204+ TestData . CustomerEmailAddress ,
205+ TestData . ContractId ,
206+ TestData . ProductId ,
207+ CancellationToken . None ) ;
208+
209+ saleResponse . ShouldNotBeNull ( ) ;
210+ saleResponse . ResponseMessage . ShouldBe ( TestData . InvalidOperationErrorResponseMessage ) ;
211+ saleResponse . ResponseCode . ShouldBe ( TestData . InvalidOperationErrorResponseCode ) ;
212+ }
213+
214+ [ Fact ]
215+ public async Task TransactionProcessorACLApplicationService_ProcessSaleTransaction_HttpRequestExceptionErrorInSale_TransactionIsNotSuccessful ( )
216+ {
217+ IConfigurationRoot configuration = this . SetupMemoryConfiguration ( ) ;
218+ ConfigurationReader . Initialise ( configuration ) ;
219+
220+ Mock < ITransactionProcessorClient > transactionProcessorClient = new Mock < ITransactionProcessorClient > ( ) ;
221+ transactionProcessorClient . Setup ( t => t . PerformTransaction ( It . IsAny < String > ( ) , It . IsAny < SerialisedMessage > ( ) , It . IsAny < CancellationToken > ( ) ) )
222+ . ThrowsAsync ( new Exception ( "Error" , new HttpRequestException ( TestData . HttpRequestErrorResponseMessage ) ) ) ;
223+ Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
224+ securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
225+
226+ ITransactionProcessorACLApplicationService applicationService =
227+ new TransactionProcessorACLApplicationService ( transactionProcessorClient . Object , securityServiceClient . Object ) ;
228+
229+ ProcessSaleTransactionResponse saleResponse = await applicationService . ProcessSaleTransaction ( TestData . EstateId ,
230+ TestData . MerchantId ,
231+ TestData . TransactionDateTime ,
232+ TestData . TransactionNumber ,
233+ TestData . DeviceIdentifier ,
234+ TestData . OperatorIdentifier ,
235+ TestData . SaleAmount ,
236+ TestData . CustomerAccountNumber ,
237+ TestData . CustomerEmailAddress ,
238+ TestData . ContractId ,
239+ TestData . ProductId ,
240+ CancellationToken . None ) ;
241+
242+ saleResponse . ShouldNotBeNull ( ) ;
243+ saleResponse . ResponseMessage . ShouldBe ( TestData . HttpRequestErrorResponseMessage ) ;
244+ saleResponse . ResponseCode . ShouldBe ( TestData . HttpRequestErrorResponseCode ) ;
245+ }
246+
247+ [ Fact ]
248+ public async Task TransactionProcessorACLApplicationService_ProcessSaleTransaction_OtherExceptionErrorInSale_TransactionIsNotSuccessful ( )
128249 {
129250 IConfigurationRoot configuration = this . SetupMemoryConfiguration ( ) ;
130251 ConfigurationReader . Initialise ( configuration ) ;
131252
132253 Mock < ITransactionProcessorClient > transactionProcessorClient = new Mock < ITransactionProcessorClient > ( ) ;
133254 transactionProcessorClient . Setup ( t => t . PerformTransaction ( It . IsAny < String > ( ) , It . IsAny < SerialisedMessage > ( ) , It . IsAny < CancellationToken > ( ) ) )
134- . ThrowsAsync ( new Exception ( "Error" , new InvalidOperationException ( TestData . ErrorResponseMessage ) ) ) ;
255+ . ThrowsAsync ( new Exception ( "Error" , new Exception ( TestData . GeneralErrorResponseMessage ) ) ) ;
135256 Mock < ISecurityServiceClient > securityServiceClient = new Mock < ISecurityServiceClient > ( ) ;
136257 securityServiceClient . Setup ( s => s . GetToken ( It . IsAny < String > ( ) , It . IsAny < String > ( ) , It . IsAny < CancellationToken > ( ) ) ) . ReturnsAsync ( TestData . TokenResponse ) ;
137258
@@ -152,8 +273,8 @@ public async Task TransactionProcessorACLApplicationService_ProcessSaleTransacti
152273 CancellationToken . None ) ;
153274
154275 saleResponse . ShouldNotBeNull ( ) ;
155- saleResponse . ResponseMessage . ShouldBe ( TestData . ErrorResponseMessage ) ;
156- saleResponse . ResponseCode . ShouldBe ( TestData . ErrorResponseCode ) ;
276+ saleResponse . ResponseMessage . ShouldBe ( TestData . GeneralErrorResponseMessage ) ;
277+ saleResponse . ResponseCode . ShouldBe ( TestData . GeneralErrorResponseCode ) ;
157278 }
158279 }
159280}
0 commit comments