/// <summary> /// Creates mock test client /// </summary> /// <param name="fileName">The file that is returned</param> /// <returns>IClient implementation</returns> protected Client CreateMockTestClientRecurringRequest(string fileName) { var mockPath = GetMockFilePath(fileName); var response = MockFileToString(mockPath); //Create a mock interface var clientInterfaceMock = new Mock <IClient>(); var confMock = MockPaymentData.CreateConfingMock(); clientInterfaceMock.Setup(x => x.Request(It.IsAny <string>(), It.IsAny <string>(), confMock)).Returns(response); var clientMock = new Client(It.IsAny <Config>()) { HttpClient = clientInterfaceMock.Object, Config = confMock }; return(clientMock); }
/// <summary> /// Creates mock test client /// </summary> /// <param name="fileName">The file that is returned</param> /// <returns>IClient implementation</returns> protected Client CreateMockTestClientNullRequiredFieldsRequest(string fileName) { var mockPath = GetMockFilePath(fileName); var response = MockFileToString(mockPath); //Create a mock interface var clientInterfaceMock = new Mock <IClient>(); var confMock = MockPaymentData.CreateConfingMock(); clientInterfaceMock.Setup(x => x.Request(It.IsAny <string>(), It.IsAny <string>(), confMock)).Returns(response); clientInterfaceMock.Setup(x => x.Request(It.IsAny <string>(), It.IsAny <string>(), confMock, It.IsAny <bool>(), It.IsAny <RequestOptions>())).Returns(response); clientInterfaceMock.Setup(x => x.RequestAsync(It.IsAny <string>(), It.IsAny <string>(), confMock, It.IsAny <bool>(), It.IsAny <RequestOptions>())).Returns(Task.FromResult(response)); var clientMock = new Client(It.IsAny <Config>()) { HttpClient = clientInterfaceMock.Object, Config = confMock }; return(clientMock); }
/// <summary> /// Creates mock test client errors /// </summary> /// <param name="status"></param> /// <param name="fileName"></param> /// <returns></returns> protected Client CreateMockTestClientForErrors(int status, string fileName) { var mockPath = GetMockFilePath(fileName); var response = MockFileToString(mockPath); //Create a mock interface var clientInterfaceMock = new Mock <IClient>(); var confMock = MockPaymentData.CreateConfingMock(); var httpClientException = new HttpClientException(status, "An error occured", new WebHeaderCollection(), response); clientInterfaceMock.Setup(x => x.Request(It.IsAny <string>(), It.IsAny <string>(), confMock)).Throws(httpClientException); var clientMock = new Client(It.IsAny <Config>()) { HttpClient = clientInterfaceMock.Object, Config = confMock }; return(clientMock); }
public void BasicAuthenticationHeadersTest() { var httpWebRequest = _httpUrlConnectionClient.GetHttpWebRequest(_endpoint, MockPaymentData.CreateConfingMock(), false); Assert.IsNotNull(httpWebRequest.UserAgent); Assert.AreEqual(httpWebRequest.Address, _endpoint); Assert.AreEqual(httpWebRequest.Headers["Accept-Charset"], "UTF-8"); Assert.AreEqual(httpWebRequest.Headers["Cache-Control"], "no-cache"); Assert.AreEqual(httpWebRequest.ContentType, "application/json"); Assert.IsNotNull(httpWebRequest.Headers["Authorization"]); Assert.IsTrue(httpWebRequest.UseDefaultCredentials); Assert.AreEqual(httpWebRequest.Headers["Cache-Control"], "no-cache"); Assert.IsNull(httpWebRequest.Headers["x-api-key"]); }