Пример #1
0
        public void Test_0204_Refresh_broken_no_name()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(200, "{" +
                               "\"groupID\" : \"90def9aa-565e-4037-bde8-3a8704c7d806\"," +
                               "\"owner\" : \"e3137ebe-2874-4d02-b7ef-6780bf8ecc1d\"}");

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is IllegalKiiBaseObjectFormatException);
            Assert.IsNotNull(refreshedGroup);
            // We won't rollback the id change after the exception happens.
            Assert.AreEqual("90def9aa-565e-4037-bde8-3a8704c7d806", refreshedGroup.ID);
        }
Пример #2
0
        public void Test_0202_Refresh_broken_json()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(200, "broken");

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is IllegalKiiBaseObjectFormatException);
            Assert.IsNotNull(refreshedGroup);
            Assert.AreEqual("group1234", refreshedGroup.ID);
        }
Пример #3
0
        public void Test_0203_Refresh_broken_no_groupId()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(200, "{" +
                               "\"name\" : \"testing group\"," +
                               "\"owner\" : \"e3137ebe-2874-4d02-b7ef-6780bf8ecc1d\"}");

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is IllegalKiiBaseObjectFormatException);
            Assert.IsNotNull(refreshedGroup);
            Assert.AreEqual("group1234", refreshedGroup.ID);
        }
Пример #4
0
        public void Test_0200_Refresh()
        {
            this.LogIn();

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

            // set Response
            this.SetStandardRefreshResponse();

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(refreshedException);
            Assert.IsNotNull(refreshedGroup);

            Assert.AreEqual("testing group", group.Name);
            Assert.AreEqual("kiicloud://users/e3137ebe-2874-4d02-b7ef-6780bf8ecc1d", group.Owner.Uri.ToString());
        }
Пример #5
0
        public void Test_0201_Refresh_no_ID()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("newGroup");

            // set Response
            this.SetStandardRefreshResponse();

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is InvalidOperationException);
            Assert.IsNotNull(refreshedGroup);
            Assert.AreEqual("newGroup", refreshedGroup.Name);
        }
Пример #6
0
        public void Test_0206_Refresh_server_error()
        {
            this.LogIn();

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

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

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNotNull(refreshedException);
            Assert.IsTrue(refreshedException is CloudException);
            Assert.IsNotNull(refreshedGroup);
            Assert.AreEqual("group1234", refreshedGroup.ID);
        }
Пример #7
0
        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="));
        }
Пример #8
0
        public void Test_0205_Refresh_broken_no_owner()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(200, "{" +
                               "\"groupID\" : \"90def9aa-565e-4037-bde8-3a8704c7d806\"," +
                               "\"name\" : \"testing group\"}");

            bool      done               = false;
            KiiGroup  refreshedGroup     = null;
            Exception refreshedException = null;

            group.Refresh((KiiGroup retGroup, Exception retExp) =>
            {
                done               = true;
                refreshedGroup     = retGroup;
                refreshedException = retExp;
            });

            Assert.IsTrue(done);
            Assert.IsNull(refreshedException);
            Assert.IsNotNull(refreshedGroup);

            Assert.AreEqual("testing group", refreshedGroup.Name);
            Assert.AreEqual("90def9aa-565e-4037-bde8-3a8704c7d806", refreshedGroup.ID);
            Assert.IsNull(refreshedGroup.Owner);
        }
Пример #9
0
        public void Test_1_3_GroupWithID_ExistsInCloud_Refresh_AddMembers()
        {
            // mock refresh response
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;
            MockHttpClient client = (MockHttpClient)factory.Client;

            client.AddResponse(200, "{" +
                               "\"groupID\" : \"dummyId\"," +
                               "\"name\" : \"MyGroup\"," +
                               "\"owner\" : \"user1234\"" +
                               "}");

            // mock response for adding user
            client.AddResponse(201, "{}");

            // create group
            string   groupId = "dummyId";
            KiiGroup group   = KiiGroup.GroupWithID(groupId);

            Assert.IsNull(group.Name);

            // refresh
            group.Refresh();
            Assert.AreEqual("MyGroup", group.Name);

            // add member
            string  memberID = TextUtils.generateUUID();
            KiiUser member   = KiiUser.UserWithID(memberID);

            group.AddUser(member);

            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);

            // Save group
            group.Save();

            // Verify add member request
            string requestUrl = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId", "members", memberID);

            Assert.AreEqual(requestUrl, client.RequestUrl[1]);
            Assert.AreEqual("PUT", client.RequestMethod[1].ToString());
            Assert.AreEqual(AppConst.APP_ID, client.RequestHeader[1]["X-Kii-AppID"]);
            Assert.AreEqual(AppConst.APP_KEY, client.RequestHeader[1]["X-Kii-AppKey"]);
            Assert.AreEqual("Bearer token1234", client.RequestHeader[1]["Authorization"]);
            Assert.AreEqual(null, client.RequestBody[1]);

            // Verify local userList get empty.
            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);
        }
        private IEnumerator TestStep()
        {
            string  username = StringUtils.RandomAlphabetic(20);
            string  password = StringUtils.RandomAlphabetic(20);
            KiiUser user     = KiiUser.BuilderWithName(username).Build();
            var     task     = RegisterUser(user, password, (KiiUser u, Exception e) => {
                if (e != null)
                {
                    throw new TestFailException();
                }
                Debug.Log("Register user.");
            });

            yield return(StartCoroutine(task));

            // create group
            string   groupname = StringUtils.RandomAlphabetic(20);
            KiiGroup group     = Kii.Group(groupname);

            Exception        exp      = null;
            bool             endFlag  = false;
            KiiGroupCallback callback = (KiiGroup grp, Exception e) => {
                exp     = e;
                endFlag = true;
            };

            group.Save(callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }

            if (exp != null)
            {
                throw new TestFailException();
            }

            // refresh
            KiiGroup groupWithId = KiiGroup.GroupWithID(group.ID);

            exp     = null;
            endFlag = false;
            groupWithId.Refresh(callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (exp != null)
            {
                throw new TestFailException();
            }
            if (!groupname.Equals(groupWithId.Name))
            {
                throw new TestFailException();
            }
            resultFlag = true;
        }
        public void Test_0206_Refresh_server_error()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(new CloudException(400, "{}"));
            group.Refresh();
        }
        public void Test_0202_Refresh_broken_json()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(200, "broken");
            group.Refresh();
        }
        public void Test_0201_Refresh_no_ID()
        {
            this.LogIn();

            KiiGroup group = Kii.Group("newGroup");

            // set Response
            this.SetStandardRefreshResponse(client);
            group.Refresh();
        }
        public void Test_0204_Refresh_broken_no_name()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(200, "{" +
                               "\"groupID\" : \"90def9aa-565e-4037-bde8-3a8704c7d806\"," +
                               "\"owner\" : \"e3137ebe-2874-4d02-b7ef-6780bf8ecc1d\"}");

            group.Refresh();
        }
        public void Test_0203_Refresh_broken_no_groupId()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(200, "{" +
                               "\"name\" : \"testing group\"," +
                               "\"owner\" : \"e3137ebe-2874-4d02-b7ef-6780bf8ecc1d\"}");

            group.Refresh();
        }
        public void Test_0200_Refresh()
        {
            this.LogIn();

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

            // set Response
            this.SetStandardRefreshResponse(client);
            group.Refresh();

            Assert.AreEqual("testing group", group.Name);
            Assert.AreEqual("kiicloud://users/e3137ebe-2874-4d02-b7ef-6780bf8ecc1d", group.Owner.Uri.ToString());
        }
        public void Test_0205_Refresh_broken_no_owner()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(200, "{" +
                               "\"groupID\" : \"90def9aa-565e-4037-bde8-3a8704c7d806\"," +
                               "\"name\" : \"testing group\"}");
            group.Refresh();

            Assert.AreEqual("testing group", group.Name);
            Assert.AreEqual("90def9aa-565e-4037-bde8-3a8704c7d806", group.ID);
            Assert.IsNull(group.Owner);
        }
Пример #18
0
        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="));
        }
        private IEnumerator TestStep()
        {
            string  username = StringUtils.RandomAlphabetic(20);
            string  password = StringUtils.RandomAlphabetic(20);
            KiiUser user     = KiiUser.BuilderWithName(username).Build();
            var     task     = RegisterUser(user, password, (KiiUser u, Exception e) => {
                if (e != null)
                {
                    throw new TestFailException();
                }
                Debug.Log("Register user.");
            });

            yield return(StartCoroutine(task));

            // create group
            string   groupname = StringUtils.RandomAlphabetic(20);
            KiiGroup group     = Kii.Group(groupname);

            Exception        exp      = null;
            bool             endFlag  = false;
            KiiGroupCallback callback = (KiiGroup grp, Exception e) => {
                exp     = e;
                endFlag = true;
            };

            group.Save(callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }

            if (exp != null)
            {
                throw new TestFailException();
            }

            // refresh
            KiiGroup groupWithId = KiiGroup.GroupWithID(group.ID);

            exp     = null;
            endFlag = false;
            groupWithId.Refresh(callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (exp != null)
            {
                throw new TestFailException();
            }
            if (!groupname.Equals(groupWithId.Name))
            {
                throw new TestFailException();
            }

            // change name
            string newGroupName = StringUtils.RandomAlphabetic(20);

            exp     = null;
            endFlag = false;
            groupWithId.ChangeName(newGroupName, callback);
            while (!endFlag)
            {
                yield return(new WaitForSeconds(1));
            }
            if (!newGroupName.Equals(groupWithId.Name))
            {
                throw new TestFailException();
            }

            //check groupname changed in server.
            string     respString  = ApiHelper.get(SDKUtils.GetGroupUFEUri(groupWithId), Kii.AppId, Kii.AppKey, KiiUser.AccessToken);
            JsonObject groupJson   = new JsonObject(respString);
            string     updatedName = groupJson.GetString("name");

            if (!newGroupName.Equals(updatedName))
            {
                throw new TestFailException();
            }
            resultFlag = true;
        }