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 UpdateByDeletedPseudoUserTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);
            Exception      e  = null;

            KiiUser.RegisterAsPseudoUser(null, (KiiUser registeredUser, Exception e1) => {
                string currentUserId          = Kii.CurrentUser.ID;
                string currentUserAccessToken = KiiUser.AccessToken;
                KiiUser.CurrentUser.Delete();
                Kii.CurrentUser = KiiUser.GetById(currentUserId);
                KiiCloudEngine.UpdateAccessToken(currentUserAccessToken);

                UserFields userFields  = new UserFields();
                userFields.Displayname = "disp";
                userFields.Country     = "JP";
                userFields["age"]      = 30;
                userFields.RemoveFromServer("birthday");

                Kii.CurrentUser.Update(null, userFields, (KiiUser updatedUser, Exception e2) => {
                    e = e2;
                    cd.Signal();
                });
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(e);
            Assert.IsInstanceOfType(typeof(ForbiddenException), e);
        }
        public void PutIdentityByDeletedUserTest_Async()
        {
            CountDownLatch cd = new CountDownLatch(1);

            string    unixTime = CurrentTimeMillis().ToString();
            string    username = "******" + unixTime;
            string    email    = username + "@kii.com";
            string    phone    = "+874" + unixTime.Substring(unixTime.Length - 9, 9);
            Exception e        = null;

            KiiUser.RegisterAsPseudoUser(null, (KiiUser registeredUser, Exception e1) => {
                IdentityData.Builder builder = IdentityData.Builder.CreateWithName(username);
                builder.WithEmail(email);
                builder.WithPhone(phone);
                IdentityData identityData = builder.Build();

                string currentUserId          = Kii.CurrentUser.ID;
                string currentUserAccessToken = KiiUser.AccessToken;
                KiiUser.CurrentUser.Delete();
                Kii.CurrentUser = KiiUser.GetById(currentUserId);
                KiiCloudEngine.UpdateAccessToken(currentUserAccessToken);

                Kii.CurrentUser.PutIdentity(identityData, null, "123ABC", (KiiUser user, Exception e2) => {
                    e = e2;
                    cd.Signal();
                });
            });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 10)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsNotNull(e);
            Assert.IsInstanceOfType(typeof(ForbiddenException), e);
        }
Пример #4
0
        public void SetUp()
        {
            Kii.Initialize(AppConst.APP_ID, AppConst.APP_KEY, AppConst.APP_SITE);
            KiiUser user = KiiUser.UserWithID("user1234");

            SDKTestHack.SetField(Kii.Instance, "mLoginUser", user);
            KiiCloudEngine.UpdateAccessToken("token1234");
        }
Пример #5
0
        public void Test_0107_initialize_id_key_Url_2times_url_change()
        {
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", "https://api.kii.com/api");
            Assert.AreEqual("ee573743", Kii.AppId);
            Assert.AreEqual("5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.AppKey);
            Assert.AreEqual("https://api.kii.com/api", Kii.BaseUrl);

            KiiCloudEngine.UpdateAccessToken("accesstoken");

            // 2 times
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", "https://api-jp.kii.com/api");

            Assert.IsNull(KiiCloudEngine.AccessToken);
        }
Пример #6
0
        public void Test_0006_initialize_2times_Site_change()
        {
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.Site.US);
            Assert.AreEqual("ee573743", Kii.AppId);
            Assert.AreEqual("5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.AppKey);
            Assert.AreEqual("https://api.kii.com/api", Kii.BaseUrl);

            KiiCloudEngine.UpdateAccessToken("accesstoken");

            // same id and key
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.Site.JP);

            Assert.IsNull(KiiCloudEngine.AccessToken);
        }
Пример #7
0
        public void Test_0003_initialize_2times_same()
        {
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.Site.US);
            Assert.AreEqual("ee573743", Kii.AppId);
            Assert.AreEqual("5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.AppKey);
            Assert.AreEqual("https://api.kii.com/api", Kii.BaseUrl);

            KiiUser user = KiiUser.UserWithID("dummyID");

            _KiiInternalUtils.SetCurrentUser(user);
            KiiCloudEngine.UpdateAccessToken("accesstoken");

            // same id and key
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.Site.US);
            Assert.AreEqual("ee573743", Kii.AppId);
            Assert.AreEqual("5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.AppKey);
            Assert.AreEqual("https://api.kii.com/api", Kii.BaseUrl);
            Assert.AreEqual(user, KiiUser.CurrentUser);
            Assert.AreEqual("accesstoken", KiiCloudEngine.AccessToken);
        }
        public void UpdateByDeletedPseudoUserTest()
        {
            KiiUser.RegisterAsPseudoUser(null);

            UserFields userFields = new UserFields();

            userFields.Displayname = "disp";
            userFields.Country     = "JP";
            userFields["age"]      = 30;
            userFields.RemoveFromServer("birthday");

            string currentUserId          = Kii.CurrentUser.ID;
            string currentUserAccessToken = KiiUser.AccessToken;

            KiiUser.CurrentUser.Delete();
            Kii.CurrentUser = KiiUser.GetById(currentUserId);
            KiiCloudEngine.UpdateAccessToken(currentUserAccessToken);

            KiiUser.CurrentUser.Update(userFields);
        }
        public void PutIdentityByDeletedUserTest()
        {
            string unixTime = CurrentTimeMillis().ToString();
            string username = "******" + unixTime;
            string email    = username + "@kii.com";
            string phone    = "+874" + unixTime.Substring(unixTime.Length - 9, 9);

            KiiUser.RegisterAsPseudoUser(null);
            IdentityData.Builder builder = IdentityData.Builder.CreateWithName(username);
            builder.WithEmail(email);
            builder.WithPhone(phone);
            IdentityData identityData = builder.Build();

            string currentUserId          = Kii.CurrentUser.ID;
            string currentUserAccessToken = KiiUser.AccessToken;

            KiiUser.CurrentUser.Delete();
            Kii.CurrentUser = KiiUser.GetById(currentUserId);
            KiiCloudEngine.UpdateAccessToken(currentUserAccessToken);

            KiiUser.CurrentUser.PutIdentity(identityData, null, "123ABC");
        }
Пример #10
0
 /// <summary>
 /// Updates the access token.
 /// </summary>
 /// <param name="accessToken">Access token.</param>
 /// <remarks>Do not use it from your application.</remarks>
 public static void UpdateAccessToken(string accessToken)
 {
     KiiCloudEngine.UpdateAccessToken(accessToken);
 }
        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);
        }