public void CanProcessRequestOk() { var refundResponse = "{\r\n \"refundId\": \"S01-5105180-3221187-R022311\",\r\n \"chargeId\": \"S01-5105180-3221187-C056351\",\r\n \"refundAmount\": {\r\n \"amount\": \"14.00\",\r\n \"currencyCode\": \"USD\"\r\n },\r\n \"softDescriptor\": \"Descriptor\",\r\n \"creationTimestamp\": \"20190714T155300Z\",\r\n \"statusDetails\": {\r\n \"state\": \"RefundInitiated\",\r\n \"reasonCode\": null,\r\n \"reasonDescription\": null,\r\n \"lastUpdatedTimestamp\": \"20190714T155300Z\"\r\n },\r\n \"releaseEnvironment\": \"Sandbox\"\r\n}"; var mockTestClient = new Mock <TestClient>(payConfig) { CallBase = true }; mockTestClient.Protected().As <ITestClientMapping>() .Setup(c => c.SendRequest(It.IsAny <ApiRequest>(), It.IsAny <Dictionary <string, string> >())) .Returns((ApiRequest request, Dictionary <string, string> postSignedHeaders) => AssertPreSendRequestFlow(request, postSignedHeaders, HttpStatusCode.OK, refundResponse)); var testRequest = new Amazon.Pay.API.InStore.Refund.CreateRefundRequest("123456789", 10, Currency.USD, "referenceID"); var apiUrlBuilder = new ApiUrlBuilder(payConfig); var apiPath = apiUrlBuilder.BuildFullApiPath(Constants.ApiServices.Default, Constants.Resources.InStore.Refund); var apiRequest = new ApiRequest(apiPath, HttpMethod.POST, testRequest, null); var result = mockTestClient.Object.Invoke <RefundResponse>(apiRequest, new Dictionary <string, string>()); Assert.NotNull(result); Assert.AreEqual(refundResponse, result.RawResponse); Assert.AreEqual(testRequest.ToJson(), result.RawRequest); Assert.AreEqual("S01-5105180-3221187-R022311", result.RefundId); Assert.AreEqual(true, result.Success); Assert.NotNull(result.RequestId); Assert.AreEqual(0, result.Retries); Assert.AreEqual(HttpMethod.POST, result.Method); Assert.AreEqual(apiPath, result.Url); Assert.True(result.Duration > 0); }
public void CanRefund() { mockClient.Protected().As <IClientMapping>() .Setup(c => c.ProcessRequest <RefundResponse>(It.IsAny <ApiRequest>(), It.IsAny <Dictionary <string, string> >())) .Returns((ApiRequest request, Dictionary <string, string> headers) => AssertPreProcessRequestFlow <RefundResponse>(request, headers, HttpMethod.POST, $"{Constants.Resources.InStore.Refund}")); var testRequest = new Amazon.Pay.API.InStore.Refund.CreateRefundRequest("123456789", 10, Currency.USD, "referenceID"); var result = mockClient.Object.Refund(testRequest); }