public void TestGetToken() { TokenSingleRequest req = new TokenSingleRequest() { PAN = this.testPan, ExpMonth = this.testExpMonth, ExpYear = this.testExpYear, TokenLifetime = 20 }; RPGClient client = new RPGClient(this.config.AppSettings.Settings["PrivateToken"].Value, this.uri); TokenSingleResponse response = client.TokenSingle.CreateAsync(req).Result; Assert.IsNotNull(response.Token); Assert.IsFalse(String.IsNullOrEmpty(response.Token.Token)); TokenSingleResponse tokenResponse = client.TokenSingle.GetAsync(response.Token.Token).Result; Assert.AreEqual((int)HttpStatusCode.OK, tokenResponse.StatusCode); Assert.IsNotNull(tokenResponse.Token); Assert.AreEqual(response.Token.Token, tokenResponse.Token.Token); tokenResponse = client.TokenSingle.GetAsync("InvalidToken").Result; Assert.AreEqual((int)HttpStatusCode.BadRequest, tokenResponse.StatusCode); tokenResponse = client.TokenSingle.GetAsync("ts_invalidtoken").Result; Assert.AreEqual((int)HttpStatusCode.NotFound, tokenResponse.StatusCode); client = new RPGClient("InvalidKey", this.uri); tokenResponse = client.TokenSingle.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.Unauthorized, tokenResponse.StatusCode); }
public void TestDisable() { RPGClient client = new RPGClient("myKey", "http://www.borgun.is/", new HttpMessageHandlerMock()); TokenSingleResponse response = client.TokenSingle.DisableAsync("testtoken").Result; Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode); Assert.IsNull(response.Token); }
public async Task <TokenSingleResponse> DisableAsync(string token) { TokenSingleResponse tokenRes = new TokenSingleResponse(); HttpResponseMessage httpRes = await this.client.PutAsync("api/token/single/" + token + "/disable", null); tokenRes.StatusCode = (int)httpRes.StatusCode; return(tokenRes); }
public void TestCreate() { TokenSingleRequest req = new TokenSingleRequest() { PAN = "4242424242424242", ExpMonth = "01", ExpYear = "20", TokenLifetime = 20 }; RPGClient client = new RPGClient("myKey", "http://www.borgun.is/", new HttpMessageHandlerMock()); TokenSingleResponse response = client.TokenSingle.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.Created, response.StatusCode); Assert.IsFalse(String.IsNullOrEmpty(response.Uri)); Assert.IsNotNull(response.Token); Assert.AreEqual("TestTokenSingle", response.Token.Token); }
public async Task <TokenSingleResponse> CreateAsync(TokenSingleRequest req) { var tokenRes = new TokenSingleResponse(); var resp = await DefaultPolly.Policy() .ExecuteAsync(() => _client.PostAsJsonAsync("token/single", req)) .ConfigureAwait(false); await HandleErrorResponseAsync(resp).ConfigureAwait(false); tokenRes.Token = await resp.Content.ReadAsAsync <TokenSingleInfo>() .ConfigureAwait(false); if (resp.Headers.Location != null) { tokenRes.Uri = resp.Headers.Location.AbsoluteUri; } return(tokenRes); }
public async Task <TokenSingleResponse> GetAsync(string token) { TokenSingleResponse tokenRes = new TokenSingleResponse(); HttpResponseMessage httpRes = await this.client.GetAsync("api/token/single/" + token); tokenRes.StatusCode = (int)httpRes.StatusCode; if (httpRes.IsSuccessStatusCode) { TokenSingleInfo info = await httpRes.Content.ReadAsAsync <TokenSingleInfo>(); tokenRes.Token = info; } else { tokenRes.Message = await httpRes.Content.ReadAsStringAsync(); } return(tokenRes); }
public void TestCreateToken() { TokenSingleRequest req = new TokenSingleRequest() { PAN = this.testPan, ExpMonth = this.testExpMonth, ExpYear = this.testExpYear, TokenLifetime = 20 }; RPGClient client = new RPGClient(this.config.AppSettings.Settings["PrivateToken"].Value, this.uri); TokenSingleResponse response = client.TokenSingle.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.Created, response.StatusCode); Assert.IsFalse(String.IsNullOrEmpty(response.Uri)); Assert.IsNotNull(response.Token); Assert.IsTrue(!String.IsNullOrEmpty(response.Token.Token)); Assert.AreEqual(this.uri + "api/token/single/" + response.Token.Token, response.Uri); req.PAN = "1234567890123456"; response = client.TokenSingle.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.BadRequest, response.StatusCode); Assert.IsNull(response.Token); Assert.IsFalse(String.IsNullOrEmpty(response.Message)); Assert.AreEqual("{\"Message\":\"PAN: InvalidFormat\"}", response.Message); req.PAN = null; req.ExpMonth = null; req.ExpYear = null; req.TokenLifetime = 0; response = client.TokenSingle.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.BadRequest, response.StatusCode); Assert.IsNull(response.Token); Assert.IsFalse(String.IsNullOrEmpty(response.Message)); Assert.AreEqual("{\"Message\":\"PAN: InvalidFormat; ExpMonth: Invalid expiration date; TokenLifetime: 'Token Lifetime' must be greater than '0'.\"}", response.Message); client = new RPGClient("InvalidKey", this.uri); response = client.TokenSingle.CreateAsync(req).Result; Assert.AreEqual((int)HttpStatusCode.Unauthorized, response.StatusCode); }
public async Task <TokenSingleResponse> CreateAsync(TokenSingleRequest req) { TokenSingleResponse tokenRes = new TokenSingleResponse(); HttpResponseMessage httpRes = await this.client.PostAsJsonAsync("api/token/single", req); tokenRes.StatusCode = (int)httpRes.StatusCode; if (httpRes.IsSuccessStatusCode) { tokenRes.Token = await httpRes.Content.ReadAsAsync <TokenSingleInfo>(); if (httpRes.Headers.Location != null) { tokenRes.Uri = httpRes.Headers.Location.AbsoluteUri; } } else { tokenRes.Message = await httpRes.Content.ReadAsStringAsync(); } return(tokenRes); }