public void Test_0504_remove_member() { // Create test user for group owner string userID = TextUtils.generateUUID(); KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/" + userID)); SDKTestHack.SetField(Kii.Instance, "mLoginUser", user); string authToken = TextUtils.generateUUID(); KiiCloudEngine.UpdateAccessToken(authToken); // Prepare group string groupName = TextUtils.randomAlphaNumeric(10); string groupID = TextUtils.randomAlphaNumeric(26); KiiGroup group = Kii.Group(groupName); SDKTestHack.SetField(group, "mId", groupID); SDKTestHack.SetField(group, "mOwnerId", userID); // Prepare KiiUser for member string memberID = TextUtils.generateUUID(); KiiUser member = KiiUser.CreateByUri(new Uri("kiicloud://users/" + memberID)); group.RemoveUser(member); // Check value HashSet <KiiUser> addUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers"); HashSet <KiiUser> removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers"); Assert.AreEqual(0, addUsers.Count); Assert.AreEqual(1, removeUsers.Count); // Prepare mock response for adding user client.AddResponse(204, ""); // Save group group.Save(); // Verify request Assert.AreEqual(1, client.RequestUrl.Count); Assert.AreEqual(1, client.RequestHeader.Count); string requestUrl = AppUtil.getUrlOfSite(AppConst.APP_SITE, AppConst.APP_ID, "groups", groupID, "members", memberID); Assert.AreEqual(requestUrl, client.RequestUrl[0]); Assert.AreEqual("DELETE", client.RequestMethod[0].ToString()); IList <MockHttpHeaderList> headers = client.RequestHeader; Assert.AreEqual(AppConst.APP_ID, client.RequestHeader[0]["X-Kii-AppID"]); Assert.AreEqual(AppConst.APP_KEY, client.RequestHeader[0]["X-Kii-AppKey"]); Assert.AreEqual("Bearer " + authToken, client.RequestHeader[0]["Authorization"]); Assert.AreEqual(null, client.RequestBody[0]); // Verify Assert.AreEqual(groupID, group.ID); addUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers"); removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers"); Assert.AreEqual(0, addUsers.Count); Assert.AreEqual(0, removeUsers.Count); }
public void Test_0502_CreateGroup_with_member() { // Create test user for group owner string userID = TextUtils.generateUUID(); KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/" + userID)); SDKTestHack.SetField(Kii.Instance, "mLoginUser", user); string authToken = TextUtils.generateUUID(); KiiCloudEngine.UpdateAccessToken(authToken); // Prepare KiiUser for member string memberID = TextUtils.generateUUID(); KiiUser member = KiiUser.CreateByUri(new Uri("kiicloud://users/" + memberID)); // Prepare group string groupName = TextUtils.randomAlphaNumeric(10); KiiGroup group = Kii.Group(groupName, new List <KiiUser>() { member }); // Check value HashSet <KiiUser> addUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers"); HashSet <KiiUser> removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers"); Assert.AreEqual(1, addUsers.Count); Assert.AreEqual(0, removeUsers.Count); // Prepare mock response for creating group string groupID = TextUtils.randomAlphaNumeric(26); JsonObject resEntity = new JsonObject(new Dictionary <string, object>() { { "groupID", groupID }, { "notFoundUsers", new JsonArray() } }); client.AddResponse(201, resEntity.ToString()); // Save group group.Save(); // Verify request Assert.AreEqual(1, client.RequestUrl.Count); Assert.AreEqual(1, client.RequestHeader.Count); string requestUrl = AppUtil.getUrlOfSite(AppConst.APP_SITE, AppConst.APP_ID, "groups"); Assert.AreEqual(requestUrl, client.RequestUrl[0]); Assert.AreEqual("POST", client.RequestMethod[0].ToString()); IList <MockHttpHeaderList> headers = client.RequestHeader; Assert.AreEqual(AppConst.APP_ID, client.RequestHeader[0]["X-Kii-AppID"]); Assert.AreEqual(AppConst.APP_KEY, client.RequestHeader[0]["X-Kii-AppKey"]); Assert.AreEqual("Bearer " + authToken, client.RequestHeader[0]["Authorization"]); JsonObject requestBody = new JsonObject(client.RequestBody[0]); Assert.AreEqual(3, requestBody.Length()); Assert.AreEqual(groupName, requestBody.GetString("name")); Assert.AreEqual(userID, requestBody.GetString("owner")); Assert.AreEqual(1, requestBody.GetJsonArray("members").Length()); Assert.AreEqual(memberID, requestBody.GetJsonArray("members").GetString(0)); // Verify Assert.AreEqual(groupID, group.ID); Assert.AreEqual(user.ID, group.Owner.ID); addUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers"); removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers"); Assert.AreEqual(0, addUsers.Count); Assert.AreEqual(0, removeUsers.Count); }