public void VerifyExistanceOfExplicitUserAgent() { var customAgent = new List<ProductInfoHeaderValue>() { new ProductInfoHeaderValue("TEST", "123") }; var testHandler = new TestHandler( (request, cancelation) => { // Ensure User-Agent is sent Assert.That(request.Headers.UserAgent, Is.Not.Null.Or.Empty); Assert.That(request.Headers.UserAgent.Count, Is.EqualTo(2)); Assert.That(request.Headers.UserAgent, Has.Exactly(1).Matches<ProductInfoHeaderValue>(a => a.Product.Name == "TEST")); return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)); }); var clientWrapper = new HttpClientWrapper(customAgent, _versionHandler, _authorizationHandlerhandler, testHandler); var client = clientWrapper.HttpClient; // ReSharper disable once MethodSupportsCancellation var response = client.GetAsync("http://lodididki"); Assert.AreEqual(HttpStatusCode.OK, response.Result.StatusCode); }
private static JudoPayApi Create(Credentials credentials, JudoEnvironment environment) { string baseUrl = null; switch (environment) { case JudoEnvironment.Live: baseUrl = LIVE_URL; break; case JudoEnvironment.Sandbox: baseUrl = SANDBOX_URL; break; } IHttpClientHelper httpClientHelper = DependencyService.Get<IHttpClientHelper>(); IClientService clientService = DependencyService.Get<IClientService>(); var nh = new NativeHandler(httpClientHelper.MessageHandler, credentials, XamarinLoggerFactory.Create(typeof(AuthorizationHandler)), Apiversionheader, API_VERSION, clientService); HttpClientWrapper httpClient = new HttpClientWrapper(nh); var connection = new Connection(httpClient, XamarinLoggerFactory.Create, baseUrl); var client = new Client(connection); return new JudoPayApi(XamarinLoggerFactory.Create, client); }
public static JudoPayApi Create(string token, string secret, string address) { var credentials = new Credentials(token, secret); var httpClient = new HttpClientWrapper(); var connection = new Connection(httpClient, WindowsPhoneLoggerFactory.Create(typeof(Connection)), address); var client = new Client(connection); return new JudoPayApi(credentials, client); }
public static JudoPayments Create(string token, string secret, string address) { Credentials credentials = new Credentials(token, secret); HttpClientWrapper httpClient = new HttpClientWrapper(); Connection connection = new Connection(httpClient, AndroidLoggerFactory.Create(typeof(Connection)), address); Client client = new Client(connection); return new JudoPayments(credentials, client); }
/// <summary> /// Factory method for the benefit of platform tests that need to have finer grained control of the API version /// </summary> /// <param name="credentials">The api token and secret to use</param> /// <param name="baseUrl">Base URL for the host</param> /// <param name="apiVersion">The api version to use</param> /// <param name="userAgent">User-Agent details to set in the header for each request</param> /// <returns>Initialized instance of the Judopay api client</returns> internal static JudoPayApi Create(Credentials credentials, string baseUrl, string apiVersion, ProductInfoHeaderValue userAgent) { var userAgentCollection = new List<ProductInfoHeaderValue>(); userAgentCollection.Add(new ProductInfoHeaderValue("DotNetCLR", Environment.Version.ToString())); userAgentCollection.Add(new ProductInfoHeaderValue(Environment.OSVersion.Platform.ToString(), Environment.OSVersion.Version.ToString())); if (userAgent != null) userAgentCollection.Add(userAgent); var httpClient = new HttpClientWrapper( userAgentCollection, new AuthorizationHandler(credentials, DotNetLoggerFactory.Create(typeof(AuthorizationHandler))), new VersioningHandler(apiVersion)); var connection = new Connection(httpClient, DotNetLoggerFactory.Create, baseUrl); var client = new Client(connection); return new JudoPayApi(DotNetLoggerFactory.Create, client); }
public void VerifyExistanceOfDefaultHeaders() { var testHandler = new TestHandler( (request, cancelation) => { // Ensure User-Agent is sent Assert.That(request.Headers.UserAgent, Is.Not.Null.Or.Empty); Assert.That(request.Headers.UserAgent.First().Product.Name, Is.EqualTo("DotNetSDK")); Assert.That(request.Headers.UserAgent.First().Product.Version, Is.EqualTo(ProductVersion)); return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)); }); var clientWrapper = new HttpClientWrapper(_versionHandler, _authorizationHandlerhandler, testHandler); var client = clientWrapper.HttpClient; // ReSharper disable once MethodSupportsCancellation var response = client.GetAsync("http://lodididki"); Assert.AreEqual(HttpStatusCode.OK, response.Result.StatusCode); }
private static JudoPayApi Create(Credentials credentials, Environment environment) { string baseUrl = null; switch (environment) { case Environment.Live: baseUrl = LIVE_URL; break; case Environment.Sandbox: baseUrl = SANDBOX_URL; break; } var httpClient = new HttpClientWrapper(new AuthorizationHandler(credentials, XamarinLoggerFactory.Create(typeof(AuthorizationHandler))), new VersioningHandler(Apiversionheader, API_VERSION)); var connection = new Connection(httpClient, XamarinLoggerFactory.Create, baseUrl); var client = new Client(connection); return new JudoPayApi(XamarinLoggerFactory.Create, client); }
public void VerifyTheExistanceOfApiVersioning() { var testHandler = new TestHandler( (request, cancelation) => { var requestVersionHeader = request.Headers.FirstOrDefault(h => h.Key == VersioningHandler.API_VERSION_HEADER); // Ensure API version header is sent Assert.IsNotNull(requestVersionHeader); Assert.That(requestVersionHeader.Value.FirstOrDefault(), Is.Not.Null.Or.Empty); Assert.AreEqual(API_VERSION, requestVersionHeader.Value.FirstOrDefault()); return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)); }); var clientWrapper = new HttpClientWrapper(_versionHandler, _authorizationHandlerhandler, testHandler); var client = clientWrapper.HttpClient; // ReSharper disable once MethodSupportsCancellation var response = client.GetAsync("http://lodididki"); Assert.AreEqual(HttpStatusCode.OK, response.Result.StatusCode); }
public void VerifyTheExistanceOfAuthenticationHeader() { var testHandler = new TestHandler( (request, cancelation) => { // Ensure that authentication header is sent Assert.AreEqual("Bearer", request.Headers.Authorization.Scheme); Assert.AreEqual("ABC", request.Headers.Authorization.Parameter); return Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK)); }); var clientWrapper = new HttpClientWrapper(_versionHandler, _authorizationHandlerhandler, testHandler); var client = clientWrapper.HttpClient; // ReSharper disable once MethodSupportsCancellation var response = client.GetAsync("http://lodididki"); Assert.AreEqual(HttpStatusCode.OK, response.Result.StatusCode); }