public void Test_3_14_CreateWithNoId_InCloud_NoPatch_NotOverwrite_EtagMatch()
        {
            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);

            // update object
            client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1");
            obj["key1"] = "value1";
            obj.SaveAllFields(false);

            // check request
            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);
        }
Ejemplo n.º 2
0
        public void Test_0002_Save_broken_json()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            client.AddResponse(200, "{}");

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

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

            obj.Save();
        }
Ejemplo n.º 3
0
        public void Test_0001_Save_server_error()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            client.AddResponse(new CloudException(400, "{}"));

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

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

            obj.Save();
        }
Ejemplo n.º 4
0
        public void Test_0201_Delete_No_ID()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.SetStandardSaveResponse(client);

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

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

            obj.Delete();
        }
        public void Test_1_3_CountAllWhenObjectExists()
        {
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            client.AddResponse(201, "{\"aggregations\" : { \"count_field\" : 10 } }");

            string    bucketName = "TestBucket";
            KiiBucket bucket     = Kii.Bucket(bucketName);
            int       count      = bucket.Count();

            Assert.AreEqual(10, 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\" : \"all\"" +
                              "}," +
                              "\"aggregations\" : [ {" +
                              "\"type\" : \"COUNT\"," +
                              "\"putAggregationInto\" : \"count_field\"" +
                              "}]" +
                              "}" +
                              "}";
            JsonObject expectedBodyJson = new JsonObject(queryStr);
            JsonObject actualBodyJson   = new JsonObject(client.RequestBody[0]);

            KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson);
        }
Ejemplo n.º 6
0
        public void Test_0101_query_all()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = (MockHttpClient)factory.Client;

            this.SetDefaultQueryResult(client);

            KiiBucket bucket = Kii.Bucket("test");
            KiiQuery  query  = new KiiQuery();
            KiiQueryResult <KiiObject> result = bucket.Query(query);

            Assert.AreEqual(1, result.Count);
            Assert.IsFalse(result.HasNext);
        }
Ejemplo n.º 7
0
        public void Test_1101_ServerCodeEntry_Execute_null()
        {
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.AsyncHttpClientFactory = factory;

            // set Response
            MockHttpClient client = factory.Client;

            client.AddResponse(200, "{\"returnedValue\":\"testResult\"}", 10);

            KiiServerCodeEntry entry = Kii.ServerCodeEntry("myFunc");

            KiiServerCodeEntryArgument args2  = null;
            KiiServerCodeExecResult    result = null;
            Exception exception = null;

            entry.Execute(null, (KiiServerCodeEntry entry2, KiiServerCodeEntryArgument outArgs, KiiServerCodeExecResult outResult, Exception e) =>
            {
                args2     = outArgs;
                result    = outResult;
                exception = e;
            });

            // Assertion
            Assert.IsNotNull(args2);
            Assert.IsNotNull(result);
            Assert.IsNull(exception);

            Assert.AreEqual(10, result.ExecutedSteps);
            JsonObject json = result.ReturnedValue;

            Assert.AreEqual(1, json.Length());
            Assert.IsTrue(json.Has("returnedValue"));
            Assert.AreEqual("testResult", json.GetString("returnedValue"));

            // Assertion request
            Assert.AreEqual("https://api.kii.com/api/apps/appId/server-code/versions/current/myFunc", client.RequestUrl[0]);
            JsonObject requestJson = new JsonObject(client.RequestBody[0]);

            Assert.AreEqual(0, requestJson.Length());
        }
Ejemplo n.º 8
0
        public void Test_1_4_GroupWithID_ExistsInCloud_Refresh_Delete()
        {
            // 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 delete response
            client.AddResponse(204, null);

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

            Assert.IsNull(group.Name);

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

            // delete
            group.Delete();

            //check request
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "groups", "dummyId");

            Assert.AreEqual(url, client.RequestUrl[1]);
            Assert.AreEqual(KiiHttpMethod.DELETE, client.RequestMethod[1]);
            MockHttpHeaderList headerList = client.RequestHeader[1];

            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="));
        }
Ejemplo n.º 9
0
        public void Test_0000_Publish()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.SetStandardResponse(client);

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/images/objects/object1234"));
            string    url = obj.PublishBody();

            Assert.AreEqual("http://api-jp.kii.com/a/1234", url);
            IList <string> body = client.RequestBody;

            Assert.AreEqual(null, body[0]);
        }
Ejemplo n.º 10
0
        public void Test_0300_Refresh()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.SetStandardRefreshResponse(client);

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));

            obj.Refresh();

            Assert.AreEqual("abcd", obj.ID);
            Assert.AreEqual(2345, obj.CreatedTime);
            Assert.AreEqual(6789, obj.ModifedTime);
        }
Ejemplo n.º 11
0
 private void setRefreshResponse(MockHttpClient client)
 {
     client.AddResponse(200,
                        "{" +
                        "\"userID\" : \"user22222\"," +
                        "\"internalUserID\" : 2222222222222222," +
                        "\"loginName\" : \"u.a1629a40-4cb2-4f56-b007-59e652a40f8d\"," +
                        "\"displayName\" : \"User 2\"," +
                        "\"locale\" : \"ja_JP\"," +
                        "\"_hasPassword\" : true," +
                        "\"_disabled\" : false," +
                        "\"_thirdPartyAccounts\" : {" +
                        "\"facebook\" : {" +
                        "\"id\" : \"100000188475423\"," +
                        "\"type\" : \"facebook\"," +
                        "\"createdAt\" : 1418290423360" +
                        "}" +
                        "}" +
                        "}");
 }
        public void Test_LoginWithTokenAndExpiresAt()
        {
            Kii.Initialize(APP_ID, APP_KEY, Kii.Site.US);

            // mock http client
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = 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;

            KiiUser.LoginWithToken("dummyToken", expiresAt);
            Assert.IsNotNull(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="));
        }
Ejemplo n.º 13
0
        public void TestRequestUrl()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.CN3);
            MockHttpClientFactory factory = new MockHttpClientFactory();

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

            // send request
            client.AddResponse(200, "{" +
                               "\"id\" : \"user1234\"," +
                               "\"access_token\" : \"cdef\"," +
                               "\"expires_in\" : 9223372036854775}");
            KiiUser.LogIn("kii1234", "pass1234");

            // check request url
            Assert.AreEqual("https://api-cn3.kii.com/api/oauth2/token", client.RequestUrl [0]);

            Assert.AreEqual("https://appId.cn3.kiiapps.com/api", Kii.KiiAppsBaseUrl);
        }
        public void TestGetIDAfterSave()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // prepare response
            MockHttpClient client = factory.Client;

            client.AddResponse(201, "{\"userID\" : \"dummyID\", \"loginName\" : \"dummyName\"}");
            client.AddResponse(201, "{\"id\" : \"dummyID\", \"expires_in\" : 148478248144076800, \"access_token\" : \"dummyToken\"}");
            client.AddResponse(201, "{\"userID\" : \"dummyID\"}");

            KiiUser user = KiiUser.BuilderWithName("dummyName").Build();

            Assert.IsNull(user.ID);
            user.Register("pass");
            Assert.IsNotNull(user.ID);
            Assert.AreEqual("dummyID", user.ID);
        }
Ejemplo n.º 15
0
        public void Test_1010_ServerCodeEntry_Execute_BadRequest()
        {
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set Response
            MockHttpClient client = factory.Client;

            client.AddResponse(new BadRequestException("", null, "{}", BadRequestException.Reason.__UNKNOWN__));

            JsonObject rawArgs = new JsonObject();

            rawArgs.Put("name", "kii");
            rawArgs.Put("score", 100);
            KiiServerCodeEntryArgument args = KiiServerCodeEntryArgument.NewArgument(rawArgs);

            KiiServerCodeEntry entry = Kii.ServerCodeEntry("myFunc");

            entry.Execute(args);
        }
Ejemplo n.º 16
0
        public void Test_1011_ServerCodeEntry_Execute_broken_JSON()
        {
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set Response
            MockHttpClient client = factory.Client;

            client.AddResponse(200, "broken", 10);

            JsonObject rawArgs = new JsonObject();

            rawArgs.Put("name", "kii");
            rawArgs.Put("score", 100);
            KiiServerCodeEntryArgument args = KiiServerCodeEntryArgument.NewArgument(rawArgs);

            KiiServerCodeEntry entry = Kii.ServerCodeEntry("myFunc");

            entry.Execute(args);
        }
Ejemplo n.º 17
0
        public void Test_LoginWithFacebookToken()
        {
            // setup mock http client
            MockHttpClientFactory factory = new MockHttpClientFactory();

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

            // set response
            this.setFBLoginResponse(client);
            this.setRefreshResponse(client);

            // verify properties for return logged in user.
            KiiUser user = KiiUser.LoginWithFacebookToken("fbtoken-dummy");

            Assert.AreEqual("user22222", user.ID);
            Assert.AreEqual("dummyAccessToken2", user.GetAccessTokenDictionary() ["access_token"]);
            Assert.AreEqual("User 2", user.Displayname);

            // verify social access token dictionary.
            Dictionary <string, object> dict = user.GetSocialAccessTokenDictionary();

            Assert.AreEqual(true, dict["kii_new_user"]);
            Assert.AreEqual("100000188475423", dict["provider_user_id"]);
            Assert.AreEqual(KiiCorp.Cloud.Storage.Connector.Provider.FACEBOOK, dict["provider"]);
            Assert.AreEqual("fbtoken-dummy", dict["oauth_token"]);

            // verify properties for current user.
            user = KiiUser.CurrentUser;
            Assert.AreEqual("user22222", user.ID);
            Assert.AreEqual("dummyAccessToken2", user.GetAccessTokenDictionary() ["access_token"]);
            Assert.AreEqual("User 2", user.Displayname);

            // verify social access token dictionary.
            dict = user.GetSocialAccessTokenDictionary();
            Assert.AreEqual(true, dict["kii_new_user"]);
            Assert.AreEqual("100000188475423", dict["provider_user_id"]);
            Assert.AreEqual(KiiCorp.Cloud.Storage.Connector.Provider.FACEBOOK, dict["provider"]);
            Assert.AreEqual("fbtoken-dummy", dict["oauth_token"]);
        }
        public void Test_2_1_CreateWithUri_NotInCloud_NoPatch_NotOverwrite_EtagNone()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;
            string objId = "abcd-1234";

            // set response
            MockHttpClient client = factory.Client;

            client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1");

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/" + objId));

            obj["key"] = "value";
            obj.SaveAllFields(false);

            Assert.AreEqual("abcd-1234", obj.ID);
            Assert.AreEqual(1, obj.CreatedTime);
            Assert.AreEqual(1, obj.ModifedTime);

            // check request
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId);

            Assert.AreEqual(url, client.RequestUrl[0]);
            Assert.AreEqual(KiiHttpMethod.PUT, client.RequestMethod[0]);
            MockHttpHeaderList headerList = client.RequestHeader[0];

            Assert.AreEqual("appId", headerList["X-Kii-AppID"]);
            Assert.AreEqual("appKey", headerList["X-Kii-AppKey"]);
            Assert.AreEqual("*", headerList["If-None-Match"]);
            Assert.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv="));

            string     reqBody          = "{ \"key\" : \"value\"}";
            JsonObject expectedBodyJson = new JsonObject(reqBody);
            JsonObject actualBodyJson   = new JsonObject(client.RequestBody[0]);

            KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson);
        }
Ejemplo n.º 19
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="));
        }
        public void Test_1_6_DeleteBody()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.SetStandardResponse(client);

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/images/objects/object1234"));

            // set body content-type
            SDKTestHack.SetField(obj, "mBodyContentType", "text/plain");

            obj.DeleteBody();

            // check body content-type is cleared.
            Assert.IsNull(obj.BodyContentType);
        }
Ejemplo n.º 21
0
        public void Test_0200_Bucket()
        {
            Kii.Initialize("ee573743", "5eb7b8bc1b4e4c98e659431c69cef8d4", Kii.Site.US);
            KiiBucket bucket = Kii.Bucket("appBucket");

            Assert.AreEqual("kiicloud://buckets/appBucket", bucket.Uri.ToString());

            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.SetStandardSaveResponse(client);

            KiiObject obj = bucket.NewKiiObject();

            obj.Save();

            Assert.AreEqual("kiicloud://buckets/appBucket/objects/d8dc9f29-0fb9-48be-a80c-ec60fddedb54", obj.Uri.ToString());
        }
        public void Test_0001_GetGeoPoint_valid_param()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.SetGeoRefreshResponse(client);

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));

            obj.Refresh();
            KiiGeoPoint expectedResult = new KiiGeoPoint(72.00, 100.00);

            Assert.AreEqual("abcd", obj.ID);
            Assert.AreEqual(2345, obj.CreatedTime);
            Assert.AreEqual(6789, obj.ModifedTime);
            Assert.AreEqual(expectedResult, obj.GetGeoPoint("location"));
        }
 private void SetStandardOwnerResponse(MockHttpClient client)
 {
     client.AddResponse(200,
                        @"
         {
           ""groups"" : [ {
             ""groupID"" : ""3hj8w3592z8ex1lm9le4gp2u9"",
             ""name"" : ""testing group1"",
             ""owner"" : ""dfa848a00022-040a-4e11-1305-0d46f973"",
             ""createdAt"" : 1412913781542,
             ""modifiedAt"" : 1412913781542
           }, {
             ""groupID"" : ""esv505f6e9h6rjt8h4fxyrqu9"",
             ""name"" : ""testing group2"",
             ""owner"" : ""dfa848a00022-040a-4e11-1305-0d46f973"",
             ""createdAt"" : 1412913542835,
             ""modifiedAt"" : 1412913542835
           } ]
         }
          "
                        );
 }
Ejemplo n.º 24
0
        public void Test_1201_PublishExpiresAt_epock()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.AsyncHttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.SetStandardResponse(client);

            KiiObject obj       = KiiObject.CreateByUri(new Uri("kiicloud://buckets/images/objects/object1234"));
            bool      done      = false;
            string    outUrl    = null;
            Exception exception = null;

            obj.PublishBodyExpiresAt(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc),
                                     (KiiObject obj2, string url, Exception e) =>
            {
                done      = true;
                outUrl    = url;
                exception = e;
            });
            Assert.IsTrue(done);
            Assert.IsNotNull(outUrl);
            Assert.IsNull(exception);

            Assert.AreEqual("http://api-jp.kii.com/a/1234", outUrl);
            IList <string> body = client.RequestBody;

            Assert.AreEqual(1, body.Count);
            JsonObject argsJson = new JsonObject(body[0]);

            Assert.AreEqual(1, argsJson.Length());
            Assert.IsTrue(argsJson.Has("expiresAt"));
            Assert.AreEqual(0, argsJson.GetLong("expiresAt"));
        }
        public void TestUserWithID_1_8_NotExistsInCloud_refresh()
        {
            // mock refresh response.
            MockHttpClientFactory factory = new MockHttpClientFactory();

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

            client.AddResponse(new CloudException(404, "USER_NOT_FOUND"));

            // create user with id.
            KiiUser userWithId = KiiUser.UserWithID("dummyID");

            Assert.IsNull(userWithId.Username);

            // refresh
            CloudException exp = null;

            try {
                userWithId.Refresh();
                Assert.Fail("Exception not thrown");
            } catch (CloudException e) {
                exp = e;
            }
            Assert.IsNotNull(exp);
            Assert.AreEqual(404, exp.Status);

            // verify request.
            string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "users", "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.IsTrue(headerList["X-Kii-SDK"].StartsWith("sn=cs;sv="));
        }
Ejemplo n.º 26
0
        public void Test_0101_SaveAllField_false()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.SetStandardSaveResponse(client);

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

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

            obj.SaveAllFields(false);

            Assert.AreEqual("d8dc9f29-0fb9-48be-a80c-ec60fddedb54", obj.ID);
            Assert.AreEqual(1337039114613, obj.CreatedTime);
            Assert.AreEqual(1337039114613, obj.ModifedTime);
        }
        public void Test_0008_GetGeoPoint_fallback_notfound_key()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.SetGeoRefreshResponse(client);

            KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd"));

            obj.Refresh();

            KiiGeoPoint fallBack = new KiiGeoPoint(50.00, 100.00);

            Assert.AreEqual("abcd", obj.ID);
            Assert.AreEqual(2345, obj.CreatedTime);
            Assert.AreEqual(6789, obj.ModifedTime);
            Assert.AreEqual(fallBack, obj.GetGeoPoint("notfound", fallBack));
        }
        public void Test_0100_Refresh()
        {
            Kii.Initialize("appId", "appKey", Kii.Site.US);
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.HttpClientFactory = factory;

            // set response
            MockHttpClient client = factory.Client;

            this.setStandardResponseForRefresh(client);

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

            user.Refresh();
            Assert.AreEqual("abcd", user.ID);
            Assert.AreEqual("person test000", user.Displayname);
            Assert.AreEqual("JP", user.Country);
            Assert.AreEqual("*****@*****.**", user.Email);
            Assert.AreEqual(true, user.EmailVerified);
            Assert.AreEqual("+819098439211", user.Phone);
            Assert.AreEqual(true, user.PhoneVerified);
        }
Ejemplo n.º 29
0
        public void Test_FBLogin_After_PseudoUserCreation()
        {
            // setup mock http client
            MockHttpClientFactory factory = new MockHttpClientFactory();

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

            // set response
            this.setPseudoUserCreationResponse(client);
            this.setFBLoginResponse(client);
            this.setRefreshResponse(client);

            KiiUser user = KiiUser.RegisterAsPseudoUser(null);

            Assert.AreEqual("user11111", user.ID);
            Assert.AreEqual("dummyAccessToken1", user.GetAccessTokenDictionary() ["access_token"]);

            KiiUser.LoginWithFacebookToken("fbtoken-dummy");
            System.Collections.Generic.IList <MockHttpHeaderList> l = client.RequestHeader;
            string auth = l[2]["Authorization"];

            Assert.AreEqual("Bearer " + "dummyAccessToken2", auth);

            user = KiiUser.CurrentUser;
            Assert.AreEqual("user22222", user.ID);
            Assert.AreEqual("dummyAccessToken2", user.GetAccessTokenDictionary() ["access_token"]);
            Assert.AreEqual("User 2", user.Displayname);

            // verify social access token dictionary.
            Dictionary <string, object> dict = user.GetSocialAccessTokenDictionary();

            Assert.AreEqual(true, dict["kii_new_user"]);
            Assert.AreEqual("100000188475423", dict["provider_user_id"]);
            Assert.AreEqual(KiiCorp.Cloud.Storage.Connector.Provider.FACEBOOK, dict["provider"]);
            Assert.AreEqual("fbtoken-dummy", dict["oauth_token"]);
        }
Ejemplo n.º 30
0
        public void Test_1111_ServerCodeEntry_Execute_broken_JSON()
        {
            MockHttpClientFactory factory = new MockHttpClientFactory();

            Kii.AsyncHttpClientFactory = factory;

            // set Response
            MockHttpClient client = factory.Client;

            client.AddResponse(200, "broken", 10);

            JsonObject rawArgs = new JsonObject();

            rawArgs.Put("name", "kii");
            rawArgs.Put("score", 100);
            KiiServerCodeEntryArgument args = KiiServerCodeEntryArgument.NewArgument(rawArgs);

            KiiServerCodeEntry entry = Kii.ServerCodeEntry("myFunc");

            KiiServerCodeEntryArgument args2  = null;
            KiiServerCodeExecResult    result = null;
            Exception exception = null;

            entry.Execute(args, (KiiServerCodeEntry entry2, KiiServerCodeEntryArgument outArgs, KiiServerCodeExecResult outResult, Exception e) =>
            {
                args2     = outArgs;
                result    = outResult;
                exception = e;
            });

            // Assertion
            Assert.IsNotNull(args2);
            Assert.IsNull(result);
            Assert.IsNotNull(exception);
            Assert.IsTrue(exception is IllegalKiiBaseObjectFormatException);
        }