Beispiel #1
0
        public void Test_remove_KiiObject()
        {
            // Do initialize
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // Set response
            MockHttpClient client = factory.Client;

            this.SetStandardSaveResponse(client);

            // Set KiiObject
            KiiObject obj = Kii.Bucket("test").NewKiiObject();

            obj["name"] = "Kii";
            obj["age"]  = 18;

            // Do save
            obj.Save();

            // Assert
            Assert.AreEqual("d8dc9f29-0fb9-48be-a80c-ec60fddedb54", obj.ID);
            Assert.AreEqual(1337039114613, obj.CreatedTime);
            Assert.AreEqual(1337039114613, obj.ModifedTime);

            // Set response
            this.SetStandardRefreshResponse(client);

            // Create and refresh KiiObject from URI
            KiiObject obj2 = KiiObject.CreateByUri(obj.Uri);

            obj2.Refresh();

            // Assert
            Assert.IsTrue(obj2.Has("name"));
            Assert.AreEqual("Kii", obj2.GetString("name"));
            Assert.IsTrue(obj2.Has("age"));
            Assert.AreEqual(18, obj2.GetInt("age"));

            // Remove age key
            obj2.Remove("age");

            // Assert
            Assert.IsTrue(obj2.Has("name"));
            Assert.AreEqual("Kii", obj2.GetString("name"));
            Assert.IsFalse(obj2.Has("age"));

            // Remove age key once more
            obj2.Remove("age");

            // Assert
            Assert.IsTrue(obj2.Has("name"));
            Assert.AreEqual("Kii", obj2.GetString("name"));
            Assert.IsFalse(obj2.Has("age"));
        }
        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_0211_double_fallback_null()
        {
            KiiObject obj = Kii.Bucket("test").NewKiiObject();

            obj["score"] = 12.345;

            Assert.AreEqual((double)12.345, obj.GetDouble("score", 45.6789));
            Assert.AreEqual((double)45.6789, obj.GetDouble(null, 45.6789));
        }
        public void Test_AppScope404Sync()
        {
            LogIn("test-user-00001");
            client.AddResponse(new NotFoundException("", null, "", NotFoundException.Reason.ACL_NOT_FOUND));
            string   topicName = "test_topic";
            KiiTopic topic     = Kii.Topic(topicName);

            topic.ListAclEntries();
        }
        public void Test_1001_Remove_null()
        {
            KiiObject obj = Kii.Bucket("test").NewKiiObject();

            obj["name"]  = "kii";
            obj["score"] = 100;

            obj.Remove(null);
        }
        public void SetUp()
        {
            Kii.Initialize(AppConst.APP_ID, AppConst.APP_KEY, AppConst.APP_SITE);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            client = (MockHttpClient)factory.Client;
        }
        public void Test_0900_Has()
        {
            KiiObject obj = Kii.Bucket("test").NewKiiObject();

            obj["score"] = 100;

            Assert.IsTrue(obj.Has("score"));
            Assert.IsFalse(obj.Has("name"));
        }
        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_0311_bool_fallback_null()
        {
            KiiObject obj = Kii.Bucket("test").NewKiiObject();

            obj["enable"] = true;

            Assert.AreEqual(true, obj.GetBoolean("enable", false));
            Assert.AreEqual(false, obj.GetBoolean(null, false));
        }
Beispiel #10
0
        public void Test_0401_Group_name_null()
        {
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.Site.US);
            List <KiiUser> members = new List <KiiUser>();

            members.Add(KiiUser.CreateByUri(new Uri("kiicloud://users/abcd")));
            members.Add(KiiUser.CreateByUri(new Uri("kiicloud://users/efgh")));
            Kii.Group(null, members);
        }
        public void Test_0111_long_fallback_null()
        {
            KiiObject obj = Kii.Bucket("test").NewKiiObject();

            obj["score"] = (long)1234567890123;

            Assert.AreEqual((long)1234567890123, obj.GetLong("score", -1));
            Assert.AreEqual(-1, obj.GetLong(null, -1));
        }
Beispiel #12
0
        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_Status403Sync()
        {
            LogIn("test-user-00001");
            client.AddResponse(new ForbiddenException("", null, ""));
            string   topicName = "test_topic";
            KiiTopic topic     = Kii.Topic(topicName);

            topic.Exists();
        }
        public void SetUp()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.AsyncHttpClientFactory = factory;

            client = (MockHttpClient)factory.Client;
        }
        public void Test_AppScopeWithPaginationASync()
        {
            LogIn("test-user-00001");
            AddMockResponse(200, new string[] { "Topic1", "Topic2" }, "ab=12/12+");
            AddMockResponse(200, new string[] { "Topic3" }, null);
            CountDownLatch           cd     = new CountDownLatch(1);
            KiiListResult <KiiTopic> topics = null;
            Exception exception             = null;

            Kii.ListTopics((KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }

            Assert.IsNull(exception);
            Assert.IsTrue(topics.HasNext);
            Assert.AreEqual("ab=12/12+", topics.PaginationKey);
            Assert.AreEqual(2, topics.Result.Count);
            Assert.AreEqual("Topic1", topics.Result[0].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("topics", "Topic1"), topics.Result[0].Uri.ToString());
            Assert.AreEqual("Topic2", topics.Result[1].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("topics", "Topic2"), topics.Result[1].Uri.ToString());

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [0]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics"), client.RequestUrl [0]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [0]["Authorization"]);

            string paginationKey = topics.PaginationKey;

            cd        = new CountDownLatch(1);
            topics    = null;
            exception = null;

            Kii.ListTopics(paginationKey, (KiiListResult <KiiTopic> t, Exception e) => {
                topics    = t;
                exception = e;
                cd.Signal();
            });
            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.IsFalse(topics.HasNext);
            Assert.IsNull(topics.PaginationKey);
            Assert.AreEqual(1, topics.Result.Count);
            Assert.AreEqual("Topic3", topics.Result[0].Name);
            Assert.AreEqual("kiicloud://" + Utils.Path("topics", "Topic3"), topics.Result[0].Uri.ToString());

            Assert.AreEqual(KiiHttpMethod.GET, client.RequestMethod [1]);
            Assert.AreEqual(Utils.Path(Kii.BaseUrl, "apps", Kii.AppId, "topics") + "?paginationKey=" + Uri.EscapeUriString("ab=12/12+"), client.RequestUrl [1]);
            Assert.AreEqual("Bearer " + KiiUser.AccessToken, client.RequestHeader [1]["Authorization"]);
        }
        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_0304_Uri_GroupScope_endWith_shash()
        {
            Kii.Initialize("abbId", "appKey", Kii.Site.JP);

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

            Assert.AreEqual("kiicloud://groups/group1234/buckets/name1234", bucket.Uri.ToString());
        }
        public void Test_0302_Uri_UserScope_endWith_slash()
        {
            Kii.Initialize("abbId", "appKey", Kii.Site.JP);

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

            Assert.AreEqual("kiicloud://users/user1234/buckets/name1234", bucket.Uri.ToString());
        }
        public void Test_0011_int_fallback_null()
        {
            KiiObject obj = Kii.Bucket("test").NewKiiObject();

            obj["score"] = 100;

            Assert.AreEqual(100, obj.GetInt("score", -1));
            Assert.AreEqual(-1, obj.GetInt(null, -1));
        }
        public void Test_0411_string_fallback_null()
        {
            KiiObject obj = Kii.Bucket("test").NewKiiObject();

            obj["name"] = "kii";

            Assert.AreEqual("kii", obj.GetString("name", "fallback"));
            Assert.AreEqual("fallback", obj.GetString(null, "fallback"));
        }
        public void Test_3_15_CreateWithNoId_InCloud_NoPatch_NotOverwrite_EtagNotMatch()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set 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(false);
            Assert.AreEqual("abcd-1234", obj.ID);
            Assert.AreEqual(1, obj.CreatedTime);
            Assert.AreEqual(1, obj.ModifedTime);

            // 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", "abcd-1234");

            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);
        }
Beispiel #22
0
        public override void SetUp()
        {
            EUApp app = new EUApp();

            Kii.Initialize(app.AppId, app.AppKey, app.BaseUrl);
            Kii.Logger = new TestLogger();
            string uname = "Test-" + CurrentTimeMillis();

            AppUtil.CreateNewUser(uname, "password");
        }
        public void Test_Delete_By_Anonymous()
        {
            this.LogIn();
            ClearClientRequest();
            client.AddResponse(200, null);
            KiiTopic topic = KiiUser.CurrentUser.Topic("my_topic");

            Kii.LogOut();
            topic.Delete();
        }
Beispiel #24
0
        public void Test_GetAccessTokenDictionary_WhenUserIsNotLoggedIn()
        {
            Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US);
            KiiUser user = KiiUser.BuilderWithName("dummyName").Build();

            Assert.IsNull(KiiUser.CurrentUser);
            IDictionary dict = user.GetAccessTokenDictionary();

            Assert.IsNull(dict);
        }
Beispiel #25
0
        public void SetUp()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);

            MockHttpClientFactory mockFactory = new MockHttpClientFactory();

            Kii.AsyncHttpClientFactory = mockFactory;

            mockClient = mockFactory.Client;
        }
        public void Test_0402_ChangeName_no_id()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(204, "");
            group.ChangeName("newGroupName");
        }
        public void Test_0301_Delete_no_ID()
        {
            this.LogIn();

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

            // set Response
            client.AddResponse(204, "");
            group.Delete();
        }
        public void Test_0201_Refresh_no_ID()
        {
            this.LogIn();

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

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

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

            // set Response
            this.SetStandardListResponse(client);
            group.ListMembers();
        }
Beispiel #30
0
        public void SetUp()
        {
            Kii.Initialize(AppID, AppKey, Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory      = factory;
            Kii.AsyncHttpClientFactory = factory;
            client = (MockHttpClient)factory.Client;
            LogIn(Guid.NewGuid().ToString());
        }