public void CallGetTransaction_TransactionPresent_SuccessfulResult() { var responseMessage = "APPROVED"; var transactionId = "111222"; var mockCallResult = $@"<transactions> <transaction> <id>{transactionId}</id> <status>{responseMessage}</status> <responseMessage>{responseMessage}</responseMessage> </transaction> </transactions>"; var mockClient = new Mock <IHelcimClient>(); mockClient .Setup(x => x.MakeRequest(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >())) .Returns((string endpint, Dictionary <string, string> values) => mockCallResult); var paymentService = new HelcimPaymentService("testendpoint", mockClient.Object); var result = paymentService.GetTransaction(new HelcimCheckTransactionRequest()); Assert.False(result.Error); Assert.Equal(responseMessage, result.ResponseMessage); Assert.Equal(transactionId, result.Transaction.Id); }
public void CallGetTransaction_CommunicationError_ExceptionCaptured() { var message = "Exception message"; var mockClient = new Mock <IHelcimClient>(); mockClient .Setup(x => x.MakeRequest(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >())) .Throws(new Exception(message)); var paymentService = new HelcimPaymentService("testendpoint", mockClient.Object); var result = paymentService.GetTransaction(new HelcimCheckTransactionRequest()); Assert.True(result.Error); Assert.Equal(message, result.ResponseMessage); Assert.Null(result.Transaction); }
public void CallGetTransaction_TransactionNotPresent_ErrorResult() { var response = "0"; var responseMessage = "Invalid Transaction ID"; var mockCallResult = $@"<message> <response>{response}</response> <responseMessage>{responseMessage}</responseMessage> </message>"; var mockClient = new Mock <IHelcimClient>(); mockClient .Setup(x => x.MakeRequest(It.IsAny <string>(), It.IsAny <Dictionary <string, string> >())) .Returns((string endpint, Dictionary <string, string> values) => mockCallResult); var paymentService = new HelcimPaymentService("testendpoint", mockClient.Object); var result = paymentService.GetTransaction(new HelcimCheckTransactionRequest()); Assert.True(result.Error); Assert.Equal(responseMessage, result.ResponseMessage); Assert.Null(result.Transaction); }