public void Test_LoginWithLocalPhone_With_TokenExpiration() { Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US); // mock http client MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; MockHttpClient client = factory.Client; // set login response client.AddResponse(200, "{" + "\"id\" : \"efgh\"," + "\"access_token\" : \"dummyToken\"," + "\"expires_in\" : 3600" + "}"); // set refresh response client.AddResponse(200, "{" + "\"id\" : \"efgh\"," + "\"username\" : \"PHONE: JP-123456\"" + "}"); // set access token expiration Kii.AccessTokenExpiration = 3600; Assert.AreEqual(3600, Kii.AccessTokenExpiration); // perform login. Assert.IsNull(KiiUser.CurrentUser); KiiUser.LogInWithLocalPhone("123456", "111111", "JP"); Assert.IsNotNull(KiiUser.CurrentUser); IDictionary tokenBundle = KiiUser.CurrentUser.GetAccessTokenDictionary(); Assert.AreEqual("dummyToken", tokenBundle["access_token"]); DateTime expiresAt = (DateTime)tokenBundle["expires_at"]; Assert.IsTrue(DateTime.Compare(expiresAt, DateTime.UtcNow) > 0); // verify login request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "oauth2", "token"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual(APP_ID, headerList["X-Kii-AppID"]); Assert.AreEqual(APP_KEY, headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); // verify body. JsonObject requestBody = new JsonObject(client.RequestBody[0]); Assert.AreEqual(3, requestBody.Length()); Assert.AreEqual("PHONE:JP-123456", requestBody.GetString("username")); Assert.AreEqual("111111", requestBody.GetString("password")); Assert.IsTrue(requestBody.GetLong("expiresAt") >= CurrentTimeMillis()); }
public void Test_0203_LogInWithLocalPhone_country_null() { this.setStandardResponse(); KiiUser target = null; Exception exp = null; KiiUser.LogInWithLocalPhone("09011112222", "pass1111", null, (KiiUser user, Exception e) => { target = user; exp = e; }); Assert.IsNull(target); Assert.IsInstanceOfType(typeof(ArgumentException), exp); }
public void Test_0200_LogInWithLocalPhone_OK() { this.setStandardResponse(); // LogIn KiiUser target = null; Exception exp = null; KiiUser.LogInWithLocalPhone("09011112222", "pass1111", "JP", (KiiUser user, Exception e) => { target = user; exp = e; }); Assert.AreEqual("abcd", target.ID); Assert.IsNull(exp); }
public void Test_0203_LogInWithLocalPhone_country_null() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; this.setStandardResponse(client); // LogIn KiiUser.LogInWithLocalPhone("09011112222", "pass1111", null); }
public void Test_0200_LogInWithLocalPhone_OK() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; this.setStandardResponse(client); // LogIn KiiUser user = KiiUser.LogInWithLocalPhone("09011112222", "pass1111", "JP"); Assert.AreEqual("abcd", user.ID); }