public void Test_1_8_GroupWithID_ExistsInCloud_NotRefresh_Delete() { // mock delete response MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; MockHttpClient client = (MockHttpClient)factory.Client; client.AddResponse(204, null); // create group. string groupId = "dummyId"; KiiGroup group = KiiGroup.GroupWithID(groupId); Assert.IsNull(group.Name); // delete group.Delete(); //check delete request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.DELETE, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.AreEqual("Bearer token1234", client.RequestHeader[0]["Authorization"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); }
public void Test_GetStatusWhenDisabledIsFalse() { // refresh response string response = @" { ""userID"" : ""dummyID"", ""internalUserID"" : 87442786592227328, ""loginName"" : ""kii_user01"", ""_disabled"" : ""false"" } "; client.AddResponse(200, response); KiiUser user = KiiUser.UserWithID("dummyID"); user.Refresh(); Assert.AreEqual("kii_user01", user.Username); Assert.IsFalse(user.Disabled); // verify request. string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users", "dummyID"); Assert.AreEqual(url, client.RequestUrl [0]); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]); MockHttpHeaderList headerList = client.RequestHeader [0]; Assert.AreEqual("appId", headerList ["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList ["X-Kii-AppKey"]); Assert.IsTrue(headerList ["X-Kii-SDK"].StartsWith("sn=cs;sv=")); }
public void Test_1_2_GroupWithID_ExistsInCloud_ListMembers() { // mock list members response. MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; MockHttpClient client = (MockHttpClient)factory.Client; client.AddResponse(200, "{" + "\"members\":[{" + "\"userID\" : \"dummyUser\"" + "}]" + "}"); // create group string groupId = "dummyId"; KiiGroup group = KiiGroup.GroupWithID(groupId); // list members IList <KiiUser> members = group.ListMembers(); Assert.AreEqual(1, members.Count); //check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId", "members"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.AreEqual("Bearer token1234", client.RequestHeader[0]["Authorization"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); }
public void Test_4_24_CreateWithQuery_InCloud_Patch_Overwrite_EtagNotMatch() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; client.AddResponse(201, "{" + "\"results\" : [" + "{" + "\"_created\" : 1," + "\"_modified\" : 1," + "\"key\" : \"value\"," + "\"_id\" : \"abcd-1234\"," + "\"_version\" : \"1\" " + "}]" + "}"); KiiQueryResult <KiiObject> result = Kii.Bucket("test").Query(null); Assert.AreEqual(1, result.Count); KiiObject obj = result[0]; string mockResponseBody = "{\"errorCode\" : \"OBJECT_VERSION_IN_STALE\"}"; client.AddResponse(new CloudException(409, mockResponseBody)); obj["key1"] = "value1"; CloudException exp = null; try { obj.Save(true); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(409, exp.Status); Assert.AreEqual(mockResponseBody, exp.Body); // check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", "abcd-1234"); Assert.AreEqual(url, client.RequestUrl[1]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[1]); MockHttpHeaderList headerList = client.RequestHeader[1]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.AreEqual("PATCH", headerList["X-HTTP-Method-Override"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); string reqBody = "{\"key1\" : \"value1\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void TestSDKInfoIncludedInRequestHeader() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; client.AddResponse(200, "{\"objectID\": 1, \"createdAt\": 1}"); string bucketName = "TestBucket"; KiiBucket bucket = Kii.Bucket(bucketName); KiiObject obj = bucket.NewKiiObject(); obj.Save(); // check request. MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); string sdkInfo = headerList["X-Kii-SDK"]; Assert.IsNotNull(sdkInfo); Assert.IsTrue(sdkInfo.StartsWith("sn=cs;sv=")); }
public void Test_1_5_GroupWithID_ExistsInCloud_Refresh() { // mock refresh response MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; MockHttpClient client = (MockHttpClient)factory.Client; client.AddResponse(200, "{" + "\"groupID\" : \"dummyId\"," + "\"name\" : \"MyGroup\"," + "\"owner\" : \"user1234\"" + "}"); // create group. string groupId = "dummyId"; KiiGroup group = KiiGroup.GroupWithID(groupId); Assert.IsNull(group.Name); // refresh. group.Refresh(); Assert.AreEqual("MyGroup", group.Name); //check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.AreEqual("Bearer token1234", client.RequestHeader[0]["Authorization"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); }
public void Test_PseudoUserDisabledStatus() { // refresh response string response = @" { ""userID"" : ""dummyID"", ""internalUserID"" : 87442786592227328, ""_accessToken"" : ""abcd1234"", ""_disabled"" : ""false"" } "; client.AddResponse(200, response); KiiUser user = KiiUser.RegisterAsPseudoUser(null); Assert.IsFalse(user.Disabled); // verify request. string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users"); Assert.AreEqual(url, client.RequestUrl [0]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod [0]); MockHttpHeaderList headerList = client.RequestHeader [0]; Assert.AreEqual("appId", headerList ["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList ["X-Kii-AppKey"]); Assert.IsTrue(headerList ["X-Kii-SDK"].StartsWith("sn=cs;sv=")); }
public void TestUserWithID_1_3_existsInCloud_refresh() { // mock refresh response MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; MockHttpClient client = factory.Client; client.AddResponse(201, "{" + "\"userID\" : \"dummyID\"," + "\"loginName\" : \"dummyName\"" + "}"); // create user with id KiiUser userWithId = KiiUser.UserWithID("dummyID"); Assert.IsNull(userWithId.Username); // refresh userWithId.Refresh(); Assert.AreEqual("dummyName", userWithId.Username); // verify request. string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users", "dummyID"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); }
public void Test_2_15_CreateWithUri_InCloud_NoPatch_NotOverwrite_EtagMatch() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // save object to cloud MockHttpClient client = factory.Client; client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/" + objId)); obj["key"] = "value"; obj.SaveAllFields(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); string etag = (string)SDKTestHack.GetField(obj, "mEtag"); Assert.AreEqual("1", etag); // server send error response (assume object already updated in server side) string mockResponseBody = "{\"errorCode\" : \"OBJECT_VERSION_IN_STALE\"}"; client.AddResponse(new CloudException(409, mockResponseBody)); obj["key1"] = "value1"; CloudException exp = null; try { obj.SaveAllFields(false); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(409, exp.Status); Assert.AreEqual(mockResponseBody, exp.Body); // request contains if-match string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId); Assert.AreEqual(url, client.RequestUrl[1]); Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod[1]); MockHttpHeaderList headerList = client.RequestHeader[1]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); Assert.AreEqual("1", headerList["If-Match"]); string reqBody = "{ \"key\" : \"value\", \"key1\" : \"value1\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_1_6_GroupWithID_ExistsInCloud_NotRefresh_ChangeName() { // mock change name response. MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; MockHttpClient client = (MockHttpClient)factory.Client; client.AddResponse(204, null); // create group string groupId = "dummyId"; KiiGroup group = KiiGroup.GroupWithID(groupId); Assert.IsNull(group.Name); // change name. string newGroupName = "MyGroupUpdate"; group.ChangeName(newGroupName); Assert.AreEqual(newGroupName, group.Name); //check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId", "name"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); }
public void Test_Login_With_TokenExpiration_Negative() { 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\" : -9223372036854775" + "}"); // set refresh response client.AddResponse(200, "{" + "\"id\" : \"efgh\"," + "\"username\" : \"dummyUser\"" + "}"); // set access token expiration to negative FieldInfo fieldInfo = typeof(Kii).GetField("INSTANCE", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); Kii kii = (Kii)fieldInfo.GetValue(null); SDKTestHack.SetField(kii, "mAccessTokenExpiration", -1L); Assert.AreEqual(-1L, Kii.AccessTokenExpiration); // perform login. Assert.IsNull(KiiUser.CurrentUser); KiiUser.LogIn("dummyUser", "111111"); Assert.IsNotNull(KiiUser.CurrentUser); IDictionary tokenBundle = KiiUser.CurrentUser.GetAccessTokenDictionary(); Assert.AreEqual("dummyToken", tokenBundle["access_token"]); Assert.AreEqual(DateTime.MinValue, tokenBundle["expires_at"]); // 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(2, requestBody.Length()); Assert.AreEqual("dummyUser", requestBody.GetString("username")); Assert.AreEqual("111111", requestBody.GetString("password")); }
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_2_6_CountWithUnsupportedQuery() { MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; string mockResponseBody = "{\"errorCode\" : \"QUERY_NOT_SUPPORTED\"}"; client.AddResponse(new CloudException(400, mockResponseBody)); string bucketName = "TestBucket"; KiiBucket bucket = Kii.Bucket(bucketName); KiiClause clause = KiiClause.Equals("key", "value"); KiiQuery query = new KiiQuery(clause); query.NextPaginationKey = "pkey"; CloudException exp = null; try { bucket.Count(query); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(400, exp.Status); Assert.AreEqual(mockResponseBody, exp.Body); // check request. string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "TestBucket", "query"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); String queryStr = "{ " + "\"bucketQuery\" : {" + "\"clause\" : {" + "\"type\" : \"eq\"," + "\"field\" : \"key\"," + "\"value\" : \"value\"" + "}," + "\"aggregations\" : [ {" + "\"type\" : \"COUNT\"," + "\"putAggregationInto\" : \"count_field\"" + "}]" + "}, " + "\"paginationKey\" : \"pkey\"" + "}"; JsonObject expectedBodyJson = new JsonObject(queryStr); JsonObject actualBodyJson = new JsonObject(client.RequestBody[0]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_2_5_CountWithOrQuery() { MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; client.AddResponse(200, "{\"aggregations\" : { \"count_field\" : 5 } }"); string bucketName = "TestBucket"; KiiBucket bucket = Kii.Bucket(bucketName); KiiClause clause1 = KiiClause.Equals("key1", "value1"); KiiClause clause2 = KiiClause.Equals("key2", "value2"); KiiClause clause = KiiClause.Or(clause1, clause2); KiiQuery query = new KiiQuery(clause); int count = bucket.Count(query); Assert.AreEqual(5, count); // check request. Console.WriteLine(client.RequestBody[0]); string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "TestBucket", "query"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); String queryStr = "{ " + "\"bucketQuery\" : {" + "\"clause\" : {" + "\"type\" : \"or\"," + "\"clauses\" :[ {" + "\"type\" : \"eq\"," + "\"field\" : \"key1\"," + "\"value\" : \"value1\"" + "}," + "{" + "\"type\" : \"eq\"," + "\"field\" : \"key2\"," + "\"value\" : \"value2\"" + "}]" + "}," + "\"aggregations\" : [ {" + "\"type\" : \"COUNT\"," + "\"putAggregationInto\" : \"count_field\"" + "}]" + "}" + "}"; JsonObject expectedBodyJson = new JsonObject(queryStr); JsonObject actualBodyJson = new JsonObject(client.RequestBody[0]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_LoginWithTokenAndExpiresAt_Async() { Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US); // mock http client MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.AsyncHttpClientFactory = factory; MockHttpClient client = factory.Client; // set refresh response client.AddResponse(200, "{" + "\"userID\" : \"dummyID\"," + "\"loginName\" : \"dummyUser\"" + "}"); // perform login. Assert.IsNull(KiiUser.CurrentUser); DateTime expiresAt = DateTime.UtcNow; CountDownLatch cd = new CountDownLatch(1); KiiUser loggedInUser = null; Exception exp = null; KiiUser.LoginWithToken("dummyToken", expiresAt, (KiiUser user, Exception e) => { loggedInUser = user; exp = e; cd.Signal(); }); if (!cd.Wait()) { Assert.Fail("Callback has not called."); } Assert.IsNull(exp); Assert.IsNotNull(loggedInUser); Assert.IsNotNull(KiiUser.CurrentUser); Assert.AreEqual(loggedInUser, KiiUser.CurrentUser); // verify token dictionary Dictionary <string, object> tokenBundle = KiiUser.CurrentUser.GetAccessTokenDictionary(); Assert.AreEqual("dummyToken", tokenBundle["access_token"]); Assert.AreEqual(expiresAt, tokenBundle["expires_at"]); // verify refresh request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", APP_ID, "users", "me"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.GET, 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=")); }
public void Test_LoginWithFacebookToken_With_TokenExpiration_MaxLong() { 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\" : 9223372036854775," + "\"new_user_created\" : false" + "}"); // set refresh response client.AddResponse(200, "{" + "\"id\" : \"efgh\"," + "\"username\" : \"dummyUser\"" + "}"); // set access token expiration Kii.AccessTokenExpiration = long.MaxValue; Assert.AreEqual(long.MaxValue, Kii.AccessTokenExpiration); // perform login. Assert.IsNull(KiiUser.CurrentUser); KiiUser.LoginWithFacebookToken("dummyFbToken"); Assert.IsNotNull(KiiUser.CurrentUser); IDictionary tokenBundle = KiiUser.CurrentUser.GetAccessTokenDictionary(); Assert.AreEqual("dummyToken", tokenBundle["access_token"]); Assert.AreEqual(DateTime.MaxValue, (DateTime)tokenBundle["expires_at"]); // verify login request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", APP_ID, "integration", "facebook"); 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(2, requestBody.Length()); Assert.AreEqual("dummyFbToken", requestBody.GetString("accessToken")); Assert.AreEqual(DateTimeMaxToUnixTimeMillis(), requestBody.GetLong("expiresAt")); }
public void Test_4_20_CreateWithQuery_InCloud_Patch_NotOverwrite_EtagMatch() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; client.AddResponse(201, "{" + "\"results\" : [" + "{" + "\"_created\" : 1," + "\"_modified\" : 1," + "\"key\" : \"value\"," + "\"_id\" : \"abcd-1234\"," + "\"_version\" : \"1\" " + "}]" + "}"); KiiQueryResult <KiiObject> result = Kii.Bucket("test").Query(null); Assert.AreEqual(1, result.Count); KiiObject obj = result[0]; client.AddResponse(201, "{\"_created\" : 1, \"_modified\" : 1, \"_id\" : \"abcd-1234\"}", "1"); obj["key1"] = "value1"; obj.Save(false); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); string etag = (string)SDKTestHack.GetField(obj, "mEtag"); Assert.AreEqual("1", etag); // check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", "abcd-1234"); Assert.AreEqual(url, client.RequestUrl[1]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[1]); MockHttpHeaderList headerList = client.RequestHeader[1]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.AreEqual("1", headerList["If-Match"]); Assert.AreEqual("PATCH", headerList["X-HTTP-Method-Override"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); Assert.AreEqual("1", headerList["If-Match"]); string reqBody = "{\"key1\" : \"value1\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_Login_Without_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\" : 9223372036854775" + "}"); // set refresh response client.AddResponse(200, "{" + "\"id\" : \"efgh\"," + "\"username\" : \"dummyUser\"" + "}"); // check expiresIn set to default. Assert.AreEqual(0, Kii.AccessTokenExpiration); // perform login. Assert.IsNull(KiiUser.CurrentUser); KiiUser.LogIn("dummyUser", "111111"); Assert.IsNotNull(KiiUser.CurrentUser); IDictionary tokenBundle = KiiUser.CurrentUser.GetAccessTokenDictionary(); Assert.AreEqual("dummyToken", tokenBundle["access_token"]); Assert.AreEqual(DateTime.MaxValue, tokenBundle["expires_at"]); // 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(2, requestBody.Length()); Assert.AreEqual("dummyUser", requestBody.GetString("username")); Assert.AreEqual("111111", requestBody.GetString("password")); }
public void Test_2_22_CreateWithUri_InCloud_Patch_Overwrite_EtagNone() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // prepare response MockHttpClient client = factory.Client; client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); // save object to cloud KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/" + objId)); obj["key"] = "value"; obj.SaveAllFields(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); string etag = (string)SDKTestHack.GetField(obj, "mEtag"); Assert.AreEqual("1", etag); // set etag to null SDKTestHack.SetField(obj, "mEtag", null); client.AddResponse(201, "{\"_created\" : 1, \"_modified\" : 1}"); obj["key1"] = "value1"; // object save successfully as Overwrite is true. obj.Save(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); // request contains x-http-method-override string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId); Assert.AreEqual(url, client.RequestUrl[1]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[1]); MockHttpHeaderList headerList = client.RequestHeader[1]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); Assert.AreEqual("PATCH", headerList["X-HTTP-Method-Override"]); string reqBody = "{\"key1\" : \"value1\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_1_4_CountWhenBucketParentNotExists() { MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; string mockResponseBody = "{\"errorCode\" : \"USER_NOT_FOUND\"}"; client.AddResponse(new CloudException(404, mockResponseBody)); string bucketName = "TestBucket"; KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/dummyUserId")); KiiBucket bucket = user.Bucket(bucketName); CloudException exp = null; try { bucket.Count(); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(404, exp.Status); Assert.AreEqual(mockResponseBody, exp.Body); // check request. string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users", "dummyUserId", "buckets", "TestBucket", "query"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); string queryStr = "{ " + "\"bucketQuery\" : {" + "\"clause\" : {" + "\"type\" : \"all\"" + "}," + "\"aggregations\" : [ {" + "\"type\" : \"COUNT\"," + "\"putAggregationInto\" : \"count_field\"" + "}]" + "}" + "}"; JsonObject expectedBodyJson = new JsonObject(queryStr); JsonObject actualBodyJson = new JsonObject(client.RequestBody[0]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_3_20_CreateWithNoId_InCloud_Patch_NoOverwrite_EtagMatch() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // prepare response MockHttpClient client = factory.Client; client.AddResponse(201, "{\"objectID\" : \"abcd-1234\", \"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["key"] = "value"; obj.SaveAllFields(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); string etag = (string)SDKTestHack.GetField(obj, "mEtag"); Assert.AreEqual("1", etag); client.AddResponse(201, "{\"_created\" : 1, \"_modified\" : 1}"); obj["key1"] = "value1"; obj.Save(false); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); // request contains x-http-method-override, if-match header string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId); Assert.AreEqual(url, client.RequestUrl[1]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[1]); MockHttpHeaderList headerList = client.RequestHeader[1]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); Assert.AreEqual("PATCH", headerList["X-HTTP-Method-Override"]); Assert.AreEqual("1", headerList["If-Match"]); string reqBody = "{\"key1\" : \"value1\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_1_16_CreateWithId_InCloud_NoPatch_Overwrite_EtagNone() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // prepare response MockHttpClient client = factory.Client; client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); // save object to cloud KiiObject obj = Kii.Bucket("test").NewKiiObject(objId); obj["key"] = "value"; obj.SaveAllFields(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); string etag = (string)SDKTestHack.GetField(obj, "mEtag"); Assert.AreEqual("1", etag); // Set Etag to null SDKTestHack.GetField(obj, "mEtag"); client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); // save successful as overwrite is true. obj.SaveAllFields(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); // check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId); Assert.AreEqual(url, client.RequestUrl[1]); Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod[1]); MockHttpHeaderList headerList = client.RequestHeader[1]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); string reqBody = "{ \"key\" : \"value\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_2_13_CreateWithUri_InCloud_NoPatch_NotOverwrite_EtagNone() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // set response MockHttpClient client = factory.Client; string mockResponseBody = "{" + "\"errorCode\" : \"OBJECT_ALREADY_EXISTS\"," + "\"message\" : \"The object with specified id already exists\" " + "}"; client.AddResponse(new CloudException(404, mockResponseBody)); KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/" + objId)); obj["key"] = "value"; CloudException exp = null; try { obj.SaveAllFields(false); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(404, exp.Status); Assert.AreEqual(mockResponseBody, exp.Body); // check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.AreEqual("*", headerList["If-None-Match"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); string reqBody = "{ \"key\" : \"value\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[0]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_1_10_CreateWithId_notInCloud_Patch_overwrite_etagNone() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // set response MockHttpClient client = factory.Client; string mockResponseBody = "{" + "\"errorCode\" : \"OBJECT_NOT_FOUND\"," + "\"message\" : \"The object with specified id not found\" " + "}"; client.AddResponse(new CloudException(404, mockResponseBody)); KiiObject obj = Kii.Bucket("test").NewKiiObject(objId); obj["key"] = "value"; CloudException exp = null; try { obj.Save(true); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(404, exp.Status); Assert.AreEqual(mockResponseBody, exp.Body); // check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); string reqBody = "{ \"key\" : \"value\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[0]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_2_14_CreateWithUri_InCloud_NoPatch_NotOverwrite_EtagMatch() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // save object to cloud MockHttpClient client = factory.Client; client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/" + objId)); obj["key"] = "value"; obj.SaveAllFields(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); string etag = (string)SDKTestHack.GetField(obj, "mEtag"); Assert.AreEqual("1", etag); // update object client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); obj["key1"] = "value1"; obj.SaveAllFields(false); // check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId); Assert.AreEqual(url, client.RequestUrl[1]); Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod[1]); MockHttpHeaderList headerList = client.RequestHeader[1]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); Assert.AreEqual("1", headerList["If-Match"]); string reqBody = "{ \"key\" : \"value\", \"key1\" : \"value1\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_1_3_CountAllWhenObjectExists() { MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; client.AddResponse(201, "{\"aggregations\" : { \"count_field\" : 10 } }"); string bucketName = "TestBucket"; KiiBucket bucket = Kii.Bucket(bucketName); int count = bucket.Count(); Assert.AreEqual(10, count); // check request. Console.WriteLine(client.RequestBody[0]); string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "TestBucket", "query"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.POST, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); string queryStr = "{ " + "\"bucketQuery\" : {" + "\"clause\" : {" + "\"type\" : \"all\"" + "}," + "\"aggregations\" : [ {" + "\"type\" : \"COUNT\"," + "\"putAggregationInto\" : \"count_field\"" + "}]" + "}" + "}"; JsonObject expectedBodyJson = new JsonObject(queryStr); JsonObject actualBodyJson = new JsonObject(client.RequestBody[0]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_LoginWithTokenAndExpiresAt() { Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US); // mock http client MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; MockHttpClient client = factory.Client; // set refresh response client.AddResponse(200, "{" + "\"userID\" : \"dummyID\"," + "\"loginName\" : \"dummyUser\"" + "}"); // perform login. Assert.IsNull(KiiUser.CurrentUser); DateTime expiresAt = DateTime.UtcNow; KiiUser.LoginWithToken("dummyToken", expiresAt); Assert.IsNotNull(KiiUser.CurrentUser); // verify token dictionary Dictionary <string, object> tokenBundle = KiiUser.CurrentUser.GetAccessTokenDictionary(); Assert.AreEqual("dummyToken", tokenBundle["access_token"]); Assert.AreEqual(expiresAt, tokenBundle["expires_at"]); // verify refresh request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", APP_ID, "users", "me"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.GET, 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=")); }
public void Test_1_11_GroupWithID_NotExistsInCloud_Refresh() { // mock response MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; MockHttpClient client = (MockHttpClient)factory.Client; client.AddResponse(new CloudException(404, "GROUP_NOT_FOUND")); // create group. string groupId = "dummyId"; KiiGroup group = KiiGroup.GroupWithID(groupId); Assert.IsNull(group.Name); // refresh. CloudException exp = null; try { group.Refresh(); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(404, exp.Status); //check request string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.AreEqual("Bearer token1234", client.RequestHeader[0]["Authorization"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); }
public void TestUserWithID_1_8_NotExistsInCloud_refresh() { // mock refresh response. MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; MockHttpClient client = factory.Client; client.AddResponse(new CloudException(404, "USER_NOT_FOUND")); // create user with id. KiiUser userWithId = KiiUser.UserWithID("dummyID"); Assert.IsNull(userWithId.Username); // refresh CloudException exp = null; try { userWithId.Refresh(); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(404, exp.Status); // verify request. string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users", "dummyID"); Assert.AreEqual(url, client.RequestUrl[0]); Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod[0]); MockHttpHeaderList headerList = client.RequestHeader[0]; Assert.AreEqual("appId", headerList["X-Kii-AppID"]); Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]); Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv=")); }
/// <summary> /// Sends the request. /// </summary> /// <returns> /// The response. /// </returns> public ApiResponse SendRequest() { // move request headers to list SetSDKClientInfo(); requestHeaderList.Add(headers); // If request body is empty, add null to requestBodyList. if (requestHeaderList.Count == requestBodyList.Count + 1) { requestBodyList.Add(null); } headers = new MockHttpHeaderList(); ApiResponse response = new ApiResponse(); if (responseQueue.Count == 0) { response.Status = 200; response.Body = "{}"; return(response); } MockResponse mockResponse = responseQueue.Dequeue(); Exception e = mockResponse.Ex; if (e != null) { throw e; } response.Status = mockResponse.Status; response.Body = mockResponse.Body; response.ETag = mockResponse.ETag; if (mockResponse.StepCount >= 0) { response.Headers["X-Step-count"] = "" + mockResponse.StepCount; } return(response); }