void BucketCreatedCallback(KiiObject obj, System.Exception exc) { if (exc != null && exc as System.NullReferenceException == null) { // Error handling setErrText = "BUCKET FAILURE: " + exc.Message; return; } setErrText = "BUCKET SUCCESS " + obj.ToString(); loggedIn = true; }
public void Test_0000_int() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["score"] = 100; Assert.AreEqual("{\"score\":100}", obj.mJSON.ToString()); Assert.AreEqual("{\"score\":100}", obj.mJSONPatch.ToString()); Assert.AreEqual(100, obj["score"]); Assert.AreEqual(100, obj.GetInt("score")); }
public void Test_3_22_CreateWithNoId_InCloud_Patch_Overwrite_EtagNone() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // prepare 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(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); string etag = (string)SDKTestHack.GetField(obj, "mEtag"); Assert.AreEqual("1", etag); // set etag to null SDKTestHack.SetField(obj, "mEtag", null); client.AddResponse(201, "{\"_created\" : 1, \"_modified\" : 1}"); obj["key1"] = "value1"; // object save successfully as Overwrite is true. obj.Save(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); // request contains x-http-method-override string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId); Assert.AreEqual(url, client.RequestUrl[1]); Assert.AreEqual(KiiHttpMethod.POST, 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("PATCH", headerList["X-HTTP-Method-Override"]); string reqBody = "{\"key1\" : \"value1\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_0301_bool_false() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["enable"] = false; Assert.AreEqual("{\"enable\":false}", obj.mJSON.ToString()); Assert.AreEqual("{\"enable\":false}", obj.mJSONPatch.ToString()); Assert.AreEqual(false, obj["enable"]); Assert.AreEqual(false, obj.GetBoolean("enable")); }
public void Test_0400_string() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["name"] = "kii"; Assert.AreEqual("{\"name\":\"kii\"}", obj.mJSON.ToString()); Assert.AreEqual("{\"name\":\"kii\"}", obj.mJSONPatch.ToString()); Assert.AreEqual("kii", obj["name"]); Assert.AreEqual("kii", obj.GetString("name")); }
public void Test_0121_Save_Update_No_Overwrite_No_Etag() { // set response client.AddResponse(201, "{" + "\"objectID\" : \"d8dc9f29-0fb9-48be-a80c-ec60fddedb54\"," + "\"createdAt\" : 1337039114613," + "\"dataType\" : \"application/vnd.sandobx.mydata+json\"" + "}", null); KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["name"] = "Kii"; obj["age"] = 18; bool done = false; KiiObject outObj = null; Exception exception = null; obj.Save((KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNull(exception); Assert.AreEqual("d8dc9f29-0fb9-48be-a80c-ec60fddedb54", obj.ID); Assert.AreEqual(1337039114613, obj.CreatedTime); Assert.AreEqual(1337039114613, obj.ModifedTime); // update obj["age"] = 19; // set Response client.AddResponse(200, "{\"_created\": 1234,\"_modified\": 3456}"); done = false; outObj = null; exception = null; obj.SaveAllFields(false, (KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNotNull(exception); Assert.IsTrue(exception is InvalidOperationException); }
public void Test_0100_long() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["score"] = (long)1234567890123; Assert.AreEqual("{\"score\":1234567890123}", obj.mJSON.ToString()); Assert.AreEqual("{\"score\":1234567890123}", obj.mJSONPatch.ToString()); Assert.AreEqual((long)1234567890123, obj["score"]); Assert.AreEqual((long)1234567890123, obj.GetLong("score")); }
public void Test_0200_double() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["score"] = 12.345; Assert.AreEqual("{\"score\":12.345}", obj.mJSON.ToString()); Assert.AreEqual("{\"score\":12.345}", obj.mJSONPatch.ToString()); Assert.AreEqual((double)12.345, obj["score"]); Assert.AreEqual((double)12.345, obj.GetDouble("score")); }
public void Test_0020_Save_Update_No_Overwrite() { // set response this.SetStandardSaveResponse(); KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["name"] = "Kii"; obj["age"] = 18; bool done = false; KiiObject outObj = null; Exception exception = null; obj.Save((KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNull(exception); Assert.AreEqual("d8dc9f29-0fb9-48be-a80c-ec60fddedb54", outObj.ID); Assert.AreEqual(1337039114613, outObj.CreatedTime); Assert.AreEqual(1337039114613, outObj.ModifedTime); // update obj["age"] = 19; // set Response client.AddResponse(200, "{\"_created\": 1234,\"_modified\": 3456}"); done = false; outObj = null; exception = null; obj.Save(false, (KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNull(exception); Assert.AreEqual(1234, outObj.CreatedTime); Assert.AreEqual(3456, outObj.ModifedTime); }
public void Test_0003_Save_2times() { // set response this.SetStandardSaveResponse(); KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["name"] = "Kii"; obj["age"] = 18; bool done = false; KiiObject outObj = null; Exception exception = null; obj.Save((KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNull(exception); Assert.AreEqual("d8dc9f29-0fb9-48be-a80c-ec60fddedb54", outObj.ID); Assert.AreEqual(1337039114613, outObj.CreatedTime); Assert.AreEqual(1337039114613, outObj.ModifedTime); // clear stub client.RequestBody.Clear(); // set Response client.AddResponse(200, "{\"_created\": 1234,\"_modified\": 3456}"); obj["score"] = 80; done = false; outObj = null; exception = null; obj.Save((KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNull(exception); Assert.AreEqual("{\"score\":80}", client.RequestBody[0]); }
public void Test_0004_GeoDistanceQuery_sort_asc() { KiiBucket bucket = testUser.Bucket("aBucket"); KiiObject obj1 = bucket.NewKiiObject(); KiiGeoPoint point1 = new KiiGeoPoint(35.672568, 139.723606); obj1.SetGeoPoint("myLoc", point1); obj1.Save(); KiiObject obj2 = bucket.NewKiiObject(); KiiGeoPoint point2 = new KiiGeoPoint(35.667983, 139.739356); obj2.SetGeoPoint("myLoc", point2); obj2.Save(); // not in radius KiiObject obj3 = bucket.NewKiiObject(); KiiGeoPoint point3 = new KiiGeoPoint(); obj3.SetGeoPoint("myLoc", point3); obj3.Save(); KiiGeoPoint center = new KiiGeoPoint(35.677379, 139.702148); KiiClause clause = KiiClause.GeoDistance("myloc", center, 4000, "distanceToMyLoc"); KiiQuery query = new KiiQuery(clause); query.SortByAsc("_calculated.distanceToMyLoc"); KiiQueryResult <KiiObject> result = bucket.Query(query); Assert.AreEqual(result.Count, 2); KiiObject retObj1 = result [0]; KiiGeoPoint retPoint1 = retObj1.GetGeoPoint("myLoc"); Assert.AreEqual(point1.Latitude, retPoint1.Latitude); Assert.AreEqual(point1.Longitude, retPoint1.Longitude); JsonObject jObj1 = retObj1.GetJsonObject("_calculated"); KiiObject retObj2 = result [1]; KiiGeoPoint retPoint2 = retObj2.GetGeoPoint("myLoc"); Assert.AreEqual(point2.Latitude, retPoint2.Latitude); Assert.AreEqual(point2.Longitude, retPoint2.Longitude); JsonObject jObj2 = retObj2.GetJsonObject("_calculated"); double retDistance1 = jObj1.GetDouble("distanceToMyLoc"); double retDistance2 = jObj2.GetDouble("distanceToMyLoc"); double expectedDistance1 = distanceInMeter(point1, center); double expectedDistance2 = distanceInMeter(point2, center); Assert.IsTrue(approximateEqual(expectedDistance1, retDistance1, 0.00001)); Assert.IsTrue(approximateEqual(expectedDistance2, retDistance2, 0.00001)); }
public void Test_2_20_CreateWithUri_InCloud_Patch_NoOverwrite_EtagMatch() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // prepare response MockHttpClient client = factory.Client; client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); // save object to cloud KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/" + objId)); obj["key"] = "value"; obj.SaveAllFields(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); string etag = (string)SDKTestHack.GetField(obj, "mEtag"); Assert.AreEqual("1", etag); client.AddResponse(201, "{\"_created\" : 1, \"_modified\" : 1}"); obj["key1"] = "value1"; obj.Save(false); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); // request contains x-http-method-override, if-match header string url = Utils.Path(ConstantValues.DEFAULT_BASE_URL, "apps", "appId", "buckets", "test", "objects", objId); Assert.AreEqual(url, client.RequestUrl[1]); Assert.AreEqual(KiiHttpMethod.POST, 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("PATCH", headerList["X-HTTP-Method-Override"]); Assert.AreEqual("1", headerList["If-Match"]); string reqBody = "{\"key1\" : \"value1\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_1101_Keys_empty() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); IEnumerable <string> keys = obj.Keys(); List <string> list = new List <string>(); foreach (string k in keys) { list.Add(k); } Assert.AreEqual(0, list.Count); }
public void Test_1_7_CreateWithId_NotInCloud_Patch_NotOverwrite_EtagNone() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; KiiObject obj = Kii.Bucket("test").NewKiiObject(objId); obj["key"] = "value"; obj.Save(false); }
public void KiiNotSavedObjectAclTest() { KiiObject objectA = Kii.Bucket("app_bucket").NewKiiObject(); KiiObjectAcl acl1 = null; KiiObjectAcl acl2 = null; acl1 = new KiiObjectAcl(objectA); acl2 = new KiiObjectAcl(objectA); Assert.IsFalse(acl1.Equals(acl2)); Assert.IsTrue(acl1.GetHashCode() == acl2.GetHashCode()); Assert.IsFalse(acl1 == acl2); }
public void Test_0002_PutAclEntry_server_error() { // set response client.AddResponse(new CloudException(400, "{}")); KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/abcd")); KiiObjectAcl acl = obj.Acl(ObjectAction.READ_EXISTING_OBJECT); // user KiiUser user = KiiUser.CreateByUri(new Uri("kiicloud://users/id1234")); acl.Subject(user).Save(ACLOperation.GRANT); }
public void Test_2_7_CreateWithUri_NotInCloud_Patch_NotOverwrite_EtagNone() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/" + objId)); obj["key"] = "value"; obj.Save(false); }
void OnGUI() { ScalableGUI gui = new ScalableGUI(); gui.Label(5, 5, 310, 20, "Push2App scene"); if (gui.Button(200, 5, 120, 35, "-> Push2User")) { this.kiiPushPlugin.OnPushMessageReceived -= this.receivedCallback; Application.LoadLevel("push2user"); } this.payload = gui.TextField(0, 45, 320, 50, this.payload); if (gui.Button(0, 100, 160, 50, "Create Object")) { KiiBucket bucket = KiiUser.CurrentUser.Bucket(BUCKET_NAME); KiiObject obj = bucket.NewKiiObject(); obj["payload"] = this.payload; obj.Save((KiiObject o, Exception e) => { if (e != null) { Debug.Log("#####" + e.Message); Debug.Log("#####" + e.StackTrace); this.ShowException("Failed to save object", e); return; } this.message = "#####creating object is successful!!"; }); } if (gui.Button(160, 100, 160, 50, "Clear Log")) { this.message = ""; } if (gui.Button(0, 150, 160, 50, "Register Push")) { Invoke("registerPush", 0); } if (gui.Button(160, 150, 160, 50, "Unregister Push")) { this.kiiPushPlugin.UnregisterPush((Exception e) => { if (e != null) { Debug.Log("#####" + e.Message); Debug.Log("#####" + e.StackTrace); this.ShowException("#####Unregister push is failed!!", e); return; } this.message = "#####Unregister push is successful!!"; }); } gui.Label(5, 210, 310, 270, this.message, 10); }
public void Test_2_16_CreateWithUri_InCloud_NoPatch_Overwrite_EtagNone() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; string objId = "abcd-1234"; // prepare response MockHttpClient client = factory.Client; client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); // save object to cloud KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/" + objId)); obj["key"] = "value"; obj.SaveAllFields(true); Assert.AreEqual("abcd-1234", obj.ID); Assert.AreEqual(1, obj.CreatedTime); Assert.AreEqual(1, obj.ModifedTime); string etag = (string)SDKTestHack.GetField(obj, "mEtag"); Assert.AreEqual("1", etag); // Set Etag to null SDKTestHack.GetField(obj, "mEtag"); client.AddResponse(201, "{\"createdAt\" : 1, \"modifiedAt\" : 1}", "1"); // save successful as overwrite is true. obj.SaveAllFields(true); 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[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=")); string reqBody = "{ \"key\" : \"value\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[1]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_2_13_CreateWithUri_InCloud_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; string mockResponseBody = "{" + "\"errorCode\" : \"OBJECT_ALREADY_EXISTS\"," + "\"message\" : \"The object with specified id already exists\" " + "}"; client.AddResponse(new CloudException(404, mockResponseBody)); KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/test/objects/" + objId)); obj["key"] = "value"; CloudException exp = null; try { obj.SaveAllFields(false); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(404, exp.Status); Assert.AreEqual(mockResponseBody, exp.Body); // 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); }
public void Test_0700_ByteArray() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); byte[] array = new byte[] { 1, 2, 3, 4 }; obj["data"] = array; Assert.AreEqual("{\"data\":\"AQIDBA==\"}", obj.mJSON.ToString()); Assert.AreEqual("{\"data\":\"AQIDBA==\"}", obj.mJSONPatch.ToString()); Assert.AreEqual("AQIDBA==", (string)obj["data"]); byte[] outArray = obj.GetByteArray("data"); Assert.AreEqual(array, outArray); }
public void Test_0500_JsonObject() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); JsonObject json = new JsonObject(); json.Put("name", "kii"); obj["attr"] = json; Assert.AreEqual("{\"attr\":{\"name\":\"kii\"}}", obj.mJSON.ToString()); Assert.AreEqual("{\"attr\":{\"name\":\"kii\"}}", obj.mJSONPatch.ToString()); Assert.AreEqual("kii", ((JsonObject)obj["attr"]).GetString("name")); Assert.AreEqual("kii", obj.GetJsonObject("attr").GetString("name")); }
public void Test_0012_Save_Update_broken_json() { // set response this.SetStandardSaveResponse(); KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["name"] = "Kii"; obj["age"] = 18; bool done = false; KiiObject outObj = null; Exception exception = null; obj.Save((KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNull(exception); Assert.AreEqual("d8dc9f29-0fb9-48be-a80c-ec60fddedb54", outObj.ID); Assert.AreEqual(1337039114613, outObj.CreatedTime); Assert.AreEqual(1337039114613, outObj.ModifedTime); // update obj["age"] = 19; // set Response client.AddResponse(200, "{}"); done = false; outObj = null; exception = null; obj.Save((KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNotNull(exception); Assert.IsTrue(exception is IllegalKiiBaseObjectFormatException); }
public void Test_1_10_CreateWithId_notInCloud_Patch_overwrite_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; string mockResponseBody = "{" + "\"errorCode\" : \"OBJECT_NOT_FOUND\"," + "\"message\" : \"The object with specified id not found\" " + "}"; client.AddResponse(new CloudException(404, mockResponseBody)); KiiObject obj = Kii.Bucket("test").NewKiiObject(objId); obj["key"] = "value"; CloudException exp = null; try { obj.Save(true); Assert.Fail("Exception not thrown"); } catch (CloudException e) { exp = e; } Assert.IsNotNull(exp); Assert.AreEqual(404, exp.Status); Assert.AreEqual(mockResponseBody, exp.Body); // 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.POST, 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=")); string reqBody = "{ \"key\" : \"value\"}"; JsonObject expectedBodyJson = new JsonObject(reqBody); JsonObject actualBodyJson = new JsonObject(client.RequestBody[0]); KiiAssertion.AssertJson(expectedBodyJson, actualBodyJson); }
public void Test_0200_Delete() { // set response this.SetStandardSaveResponse(); KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["name"] = "Kii"; obj["age"] = 18; bool done = false; KiiObject outObj = null; Exception exception = null; obj.Save((KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNull(exception); Assert.AreEqual("d8dc9f29-0fb9-48be-a80c-ec60fddedb54", obj.ID); Assert.AreEqual(1337039114613, obj.CreatedTime); Assert.AreEqual(1337039114613, obj.ModifedTime); // set Response client.AddResponse(204, ""); done = false; outObj = null; exception = null; obj.Delete((KiiObject deletedObj, Exception e) => { done = true; outObj = deletedObj; exception = e; }); Console.WriteLine(exception); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNull(exception); Assert.AreEqual(-1, outObj.CreatedTime); Assert.AreEqual(-1, outObj.ModifedTime); Assert.AreEqual(null, outObj.Uri); }
public void Test_0800_Uri() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); Uri uri = new Uri("kiicloud://users/abcd"); obj["id"] = uri; Assert.AreEqual("{\"id\":\"kiicloud:\\/\\/users\\/abcd\"}", obj.mJSON.ToString()); Assert.AreEqual("{\"id\":\"kiicloud:\\/\\/users\\/abcd\"}", obj.mJSONPatch.ToString()); Assert.AreEqual("kiicloud://users/abcd", (string)obj["id"]); Uri outUri = obj.GetUri("id"); Assert.AreEqual(uri, outUri); }
public ObjectBodyPage(MainCamera camera, KiiObject obj) : base(camera) { this.obj = obj; this.body = ""; this.upBodyContentType = ""; this.expireIn = ""; DateTime now = DateTime.Now; this.expireAtYear = "" + now.Year; this.expireAtMonth = "" + now.Month; this.expireAtDay = "" + now.Day; this.expireAtHour = "" + now.Hour; this.expireAtMinute = "" + now.Minute; this.expireAtSecond = "" + now.Second; }
public void Test_0600_JsonArray() { KiiObject obj = Kii.Bucket("test").NewKiiObject(); JsonArray array = new JsonArray(); array.Put("Kaa"); array.Put("Kii"); obj["names"] = array; Assert.AreEqual("{\"names\":[\"Kaa\",\"Kii\"]}", obj.mJSON.ToString()); Assert.AreEqual("{\"names\":[\"Kaa\",\"Kii\"]}", obj.mJSONPatch.ToString()); Assert.AreEqual("Kaa", ((JsonArray)obj["names"]).GetString(0)); Assert.AreEqual("Kii", obj.GetJsonArray("names").GetString(1)); }
public void Test_0111_SaveAllFields_Update_server_error() { // set response this.SetStandardSaveResponse(); KiiObject obj = Kii.Bucket("test").NewKiiObject(); obj["name"] = "Kii"; obj["age"] = 18; bool done = false; KiiObject outObj = null; Exception exception = null; obj.Save((KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNull(exception); Assert.AreEqual("d8dc9f29-0fb9-48be-a80c-ec60fddedb54", outObj.ID); Assert.AreEqual(1337039114613, outObj.CreatedTime); Assert.AreEqual(1337039114613, outObj.ModifedTime); // update obj["age"] = 19; // set Response client.AddResponse(new CloudException(400, "{}")); done = false; outObj = null; exception = null; obj.SaveAllFields(true, (KiiObject createdObj, Exception e) => { done = true; outObj = createdObj; exception = e; }); Assert.IsTrue(done); Assert.IsNotNull(outObj); Assert.IsNotNull(exception); Assert.IsTrue(exception is CloudException); }
public void Test_0012_Publish_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, "broken"); KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/images/objects/object1234")); obj.PublishBody(); }
public void Test_0011_Publish_not_found() { Kii.Initialize("appId", "appKey", Kii.Site.US); MockHttpClientFactory factory = new MockHttpClientFactory(); Kii.HttpClientFactory = factory; // set response MockHttpClient client = factory.Client; client.AddResponse(new NotFoundException("object not found", null, "{}", NotFoundException.Reason.OBJECT_NOT_FOUND)); KiiObject obj = KiiObject.CreateByUri(new Uri("kiicloud://buckets/images/objects/object1234")); obj.PublishBody(); }
// Use this for initialization void Start() { RecalcPlayerPrestige(); System.DateTime queryStart = System.DateTime.UtcNow; KiiClause recentClause = KiiClause.GreaterThan("expires", queryStart.Ticks); KiiClause mineClause = KiiClause.Equals("owner", Login.User.Username); KiiQuery recentQuery = new KiiQuery(KiiClause.And(recentClause, mineClause)); KiiQueryResult<KiiObject> result = Kii.Bucket("worlds").Query(recentQuery); if (result.Count == 0) { Debug.Log("Creating new world."); World = GenerateNewLevel(); } else { KiiObject latest = result[0]; World = latest; Debug.Log("Successfully loaded world."); PopulateWorld(latest.GetJsonArray("objects")); Village.RecalculateAll(); } FindObjectOfType<AlienMgr>().ClearAliens(); }
void ShowObjectPage(KiiObject obj) { camera.PushPage(new ObjectPage(camera, obj)); }
void SetContent(KiiObject obj) { content = ""; IEnumerable<string> keys = obj.Keys(); foreach (string key in keys) { content += key + " = " + obj[key] + "\n"; } }
void SaveWorldCallback(KiiObject worldObj, System.Exception e) { if (e != null && e as System.NullReferenceException == null) { Debug.LogError("Could not save the world: " + e.Message); return; } }
public ObjectPage(MainCamera camera, KiiObject obj) : base(camera) { this.obj = obj; }
public void Travel(bool goHome) { RecalcPlayerPrestige(); System.DateTime queryStart = System.DateTime.UtcNow; KiiClause recentClause = KiiClause.GreaterThan("expires", queryStart.Ticks); KiiQuery worldsQuery; if (goHome) { KiiClause mineClause = KiiClause.Equals("owner", Login.User.Username); worldsQuery = new KiiQuery(KiiClause.And(recentClause, mineClause)); } else { KiiClause notMineClause = KiiClause.NotEquals("owner", Login.User.Username); worldsQuery = new KiiQuery(KiiClause.And(recentClause, notMineClause)); } KiiQueryResult<KiiObject> result = Kii.Bucket("worlds").Query(worldsQuery); targ.Deselect(); if (goHome && result.Count == 0) { Debug.LogError("Could not find home! Making a new one."); ClearSpawnedObjects(); World = GenerateNewLevel(); } else if (!goHome && result.Count < MIN_WORLDS) { Debug.Log("Traveling to new anonymous world."); ClearSpawnedObjects(); World = GenerateNewLevel(true); } else { ClearSpawnedObjects(); int i = Mathf.FloorToInt(Random.value * result.Count); KiiObject latest = result[i]; World = latest; Debug.Log("Successfully travelled " + (goHome ? "home." : "away.")); PopulateWorld(latest.GetJsonArray("objects")); Village.RecalculateAll(); } player.FindStartPos(); FindObjectOfType<AlienMgr>().ClearAliens(); AudioSource audio = GetComponent<AudioSource>(); audio.clip = travelSound; audio.Play(); }