public void Test_0508_AddAndRemoveUser_null_KiiUser_instance()
        {
            // Prepare KiiUser for member
            KiiUser memberUser1 = KiiUser.CreateByUri(new Uri("kiicloud://users/" + TextUtils.generateUUID()));
            KiiUser memberUser2 = KiiUser.CreateByUri(new Uri("kiicloud://users/" + TextUtils.generateUUID()));
            KiiUser nullUser    = null;

            // 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", TextUtils.generateUUID());
            group.AddUser(memberUser1);
            group.RemoveUser(memberUser2);
            // 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(1, removeUsers.Count);

            // Add user
            try
            {
                group.AddUser(nullUser);
                Assert.Fail("Should throw ArgumentException");
            }
            catch (ArgumentException)
            {
                // Pass
            }
            // Check value
            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(1, addUsers.Count);
            Assert.AreEqual(1, removeUsers.Count);

            // Remove user
            try
            {
                group.RemoveUser(nullUser);
                Assert.Fail("Should throw ArgumentException");
            }
            catch (ArgumentException)
            {
                // Pass
            }
            // Check value
            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(1, addUsers.Count);
            Assert.AreEqual(1, removeUsers.Count);
        }
Beispiel #2
0
        public void Test_0012_Save_update_delete()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.RemoveUser(user);


            // set Response
            client.RequestUrl.Clear();
            this.SetStandardSaveResponse();

            bool      done           = false;
            KiiGroup  savedGroup     = null;
            Exception savedException = null;

            group.Save((KiiGroup retGroup, Exception retExp) =>
            {
                done           = true;
                savedGroup     = retGroup;
                savedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(savedException);
            Assert.IsNotNull(savedGroup);

            Assert.AreEqual(1, client.RequestUrl.Count);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/groups/group1234/members/user1234", client.RequestUrl [0]);
        }
        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_0023_Save_update_add_remove_server_error_partial()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.RemoveUser(user);

            user = KiiUser.CreateByUri(new Uri("kiicloud://users/user5678"));
            group.AddUser(user);

            // set Response
            client.RequestUrl.Clear();
            this.SetStandardSaveResponse(client);
            client.AddResponse(new CloudException(400, "{}"));

            try
            {
                group.Save();
            }
            catch (GroupOperationException e)
            {
                Assert.AreEqual(0, e.AddFailedUsers.Count);
                Assert.AreEqual(1, e.RemoveFailedUsers.Count);
            }
        }
        public void Test_0509_AddAndRemoveUser_notsaved_group()
        {
            // Prepare KiiUser for member
            KiiUser memberUser1 = KiiUser.CreateByUri(new Uri("kiicloud://users/" + TextUtils.generateUUID()));
            KiiUser memberUser2 = KiiUser.CreateByUri(new Uri("kiicloud://users/" + TextUtils.generateUUID()));

            // Prepare group
            string   groupName = TextUtils.randomAlphaNumeric(10);
            string   groupID   = TextUtils.randomAlphaNumeric(26);
            KiiGroup group     = Kii.Group(groupName);
            // 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(0, removeUsers.Count);

            // Add user
            group.AddUser(memberUser1);
            // Check value
            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(1, addUsers.Count);
            Assert.AreEqual(0, removeUsers.Count);

            // Remove user
            group.RemoveUser(memberUser2);
            // Check value
            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(1, addUsers.Count);
            Assert.AreEqual(0, removeUsers.Count);

            // Remove user for user1
            group.RemoveUser(memberUser1);
            // Check value
            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_0013_Save_update_delete_2()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.RemoveUser(user);

            user = KiiUser.CreateByUri(new Uri("kiicloud://users/user5678"));
            group.RemoveUser(user);

            // set Response
            client.RequestUrl.Clear();
            this.SetStandardSaveResponse(client);

            group.Save();

            Assert.AreEqual(2, client.RequestUrl.Count);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/groups/group1234/members/user1234", client.RequestUrl[0]);
            Assert.AreEqual("https://api.kii.com/api/apps/appId/groups/group1234/members/user5678", client.RequestUrl[1]);
        }
Beispiel #7
0
        public void Test_0023_Save_update_add_remove_server_error_partial()
        {
            this.LogIn();

            KiiGroup group = KiiGroup.CreateByUri(new Uri("kiicloud://groups/group1234"));

            KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/user1234"));

            group.RemoveUser(user);

            user = KiiUser.CreateByUri(new Uri("kiicloud://users/user5678"));
            group.AddUser(user);

            // set Response
            client.RequestUrl.Clear();
            this.SetStandardSaveResponse();
            client.AddResponse(new CloudException(400, "{ \"errorCode\" : \"INVALID_INPUT_DATA\", \"message\" : \"There are validation errors\", \"suppressed\" : [ ]}"));

            bool      done           = false;
            KiiGroup  savedGroup     = null;
            Exception savedException = null;

            group.Save((KiiGroup retGroup, Exception retExp) =>
            {
                done           = true;
                savedGroup     = retGroup;
                savedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(savedException);
            Assert.IsTrue(savedException is GroupOperationException);
            Assert.IsNotNull(savedGroup);
            Assert.AreEqual("group1234", savedGroup.ID);

            GroupOperationException groupExp = (GroupOperationException)savedException;

            Assert.AreEqual(0, groupExp.AddFailedUsers.Count);
            Assert.AreEqual(1, groupExp.RemoveFailedUsers.Count);
        }
Beispiel #8
0
        public void Test_0101_RemoveMyself_FromGroupMember()
        {
            // Create KiiUser for group member
            long    milliseconds = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
            string  memberName   = "kiiGroupMember-" + milliseconds;
            KiiUser member       = KiiUser.BuilderWithName(memberName).Build();

            member.Register("pass1234");
            string memberToken = KiiUser.AccessToken;

            // Create KiiUser for group member
            string  ownerName = "kiiGroupOwner-" + milliseconds;
            KiiUser owner     = KiiUser.BuilderWithName(ownerName).Build();

            owner.Register("pass1234");

            // Create group
            KiiGroup group = Kii.Group("testGroup");

            // Add member and save
            group.AddUser(member);
            group.Save();

            // Auth as member
            KiiUser.LogOut();
            KiiUser.LoginWithToken(memberToken);

            // Try to remove myself from the group
            group.RemoveUser(KiiUser.CurrentUser);
            group.Save();

            // 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(0, removeUsers.Count);
        }
        public void Test_0506_AddAndRemoveUser_different_KiiUser_instance()
        {
            // Prepare KiiUser for member
            KiiUser memberUser1 = KiiUser.CreateByUri(new Uri("kiicloud://users/" + TextUtils.generateUUID()));
            KiiUser memberUser2 = KiiUser.CreateByUri(new Uri("kiicloud://users/" + TextUtils.generateUUID()));
            KiiUser memberUser3 = KiiUser.CreateByUri(new Uri("kiicloud://users/" + TextUtils.generateUUID()));

            // 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", TextUtils.generateUUID());
            group.AddUser(memberUser1);
            group.RemoveUser(memberUser2);
            // 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(1, removeUsers.Count);

            // Add user
            group.AddUser(memberUser3);
            // Check value
            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(2, addUsers.Count);
            Assert.AreEqual(1, removeUsers.Count);

            // Add user again
            KiiUser memberUser3a = KiiUser.CreateByUri(memberUser3.Uri);

            group.AddUser(memberUser3a);
            // Check value
            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(2, addUsers.Count);
            Assert.AreEqual(1, removeUsers.Count);

            // Remove user
            group.RemoveUser(memberUser1);
            // Check value
            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(1, addUsers.Count);
            Assert.AreEqual(2, removeUsers.Count);

            // Remove user again
            KiiUser memberUser1a = KiiUser.CreateByUri(memberUser1.Uri);

            group.RemoveUser(memberUser1a);
            // Check value
            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(1, addUsers.Count);
            Assert.AreEqual(2, removeUsers.Count);

            // Add user
            KiiUser memberUser2a = KiiUser.CreateByUri(memberUser2.Uri);

            group.AddUser(memberUser2a);
            // Check value
            addUsers    = (HashSet <KiiUser>)SDKTestHack.GetField(group, "addUsers");
            removeUsers = (HashSet <KiiUser>)SDKTestHack.GetField(group, "removeUsers");
            Assert.AreEqual(2, addUsers.Count);
            Assert.AreEqual(1, removeUsers.Count);
        }