public void Test_0304_Upload_float_min()
        {
            KiiAnalytics.Initialize("appID004", "appKey", KiiAnalytics.Site.JP, "dev004");
            KiiEvent ev = KiiAnalytics.NewEvent("type1");

            ev["page"]  = float.MinValue;
            ev["label"] = "OK";

            // set mock
            KiiAnalytics.HttpClientFactory = new MockHttpClientFactory();
            MockHttpClient client = ((MockHttpClientFactory)KiiAnalytics.HttpClientFactory).Client;

            client.AddResponse(204, "");

            KiiAnalytics.Upload(ev);

            Assert.AreEqual("https://api-jp.kii.com/api/apps/appID004/events", client.RequestUrl[0]);
            Assert.AreEqual("application/vnd.kii.EventRecordList+json", client.RequestContentType[0]);
            JsonArray  array = new JsonArray(client.RequestBody[0]);
            JsonObject json  = array.GetJsonObject(0);
            int        count = ToCount(json.Keys());

            Assert.AreEqual(6, count);
            Assert.AreEqual(float.MinValue, json.GetDouble("page"));
            Assert.AreEqual("OK", json.GetString("label"));
            Assert.AreEqual("dev004", json.GetString("_deviceID"));
            Assert.AreEqual("type1", json.GetString("_type"));
            Assert.IsTrue(json.Has("_triggeredAt"));
            Assert.IsTrue(json.Has("_uploadedAt"));
        }
        public void Test_1_3_Upload_EventListLength_Large()
        {
            KiiEvent ev        = KiiAnalytics.NewEvent("type1");
            var      eventList = Enumerable.Repeat <KiiEvent> (ev, 51);

            KiiAnalytics.Upload((Exception e) => {}, eventList.Cast <KiiEvent>().ToArray());
        }
        public void Test_1_6_Upload_NullCallback()
        {
            KiiAnalytics.Initialize("appID004", "appKey", KiiAnalytics.Site.JP, "dev004");
            KiiEvent ev = KiiAnalytics.NewEvent("type1");

            ev["page"]  = 1;
            ev["label"] = "OK";
            Assert.IsFalse(ev.Sent);

            // set mock
            MockHttpClientFactory factory = new MockHttpClientFactory();

            KiiAnalytics.AsyncHttpClientFactory = factory;
            MockHttpClient client = factory.Client;

            client.AddResponse(204, "");

            // async upload
            KiiEventCallback callback = null;

            KiiAnalytics.Upload(callback, ev);

            // verify event uploaded
            Assert.IsTrue(ev.Sent);
        }
        public void Test_0311_Upload_null()
        {
            KiiAnalytics.Initialize("appID005", "appKey", KiiAnalytics.Site.JP, "dev005");
            KiiEvent ev = null;

            KiiAnalytics.Upload(ev);
        }
        public void Test_1_5_Upload_AllEvents_AlreadySent()
        {
            KiiAnalytics.Initialize("appID005", "appKey", KiiAnalytics.Site.JP, "dev005");
            KiiEvent ev = KiiAnalytics.NewEvent("type1");

            ev.Sent = true;
            KiiAnalytics.Upload((Exception e) => {}, new KiiEvent[] { ev, null });
        }
        public void Test_0311_Upload_null_2()
        {
            KiiAnalytics.Initialize("appID005", "appKey", KiiAnalytics.Site.JP, "dev005");

            KiiEvent ev1 = KiiAnalytics.NewEvent("type1");

            ev1["page"]  = 1;
            ev1["label"] = "OK";

            KiiAnalytics.Upload(ev1, null);
        }
Exemplo n.º 7
0
 private void CheckKey(string key)
 {
     if (key == null)
     {
         throw new ArgumentNullException(ErrorInfo.KIIEVENT_KEY_NULL);
     }
     if (!KiiEvent.IsValidKey(key))
     {
         throw new ArgumentException(ErrorInfo.KIIEVENT_KEY_INVALID);
     }
 }
Exemplo n.º 8
0
        public void Test_0007_floatArrayValue()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["selected"] = new float[] { (float)1.23, (float)3.57 };

            JsonObject json = ev.ConvertToJsonObject("dev001");

            AssertAndRemoveTimes(json);

            Assert.AreEqual("{\"selected\":[1.23,3.57],\"_deviceID\":\"dev001\",\"_type\":\"testType\"}", json.ToString());
        }
Exemplo n.º 9
0
        public void Test_0006_longArrayValue()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["selected"] = new long[] { 1234567890123, 987654321098765 };

            JsonObject json = ev.ConvertToJsonObject("dev001");

            AssertAndRemoveTimes(json);

            Assert.AreEqual("{\"selected\":[1234567890123,987654321098765],\"_deviceID\":\"dev001\",\"_type\":\"testType\"}", json.ToString());
        }
Exemplo n.º 10
0
        public void Test_0009_stringArrayValue()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["selected"] = new string[] { "item1", "item3", "item6" };

            JsonObject json = ev.ConvertToJsonObject("dev001");

            AssertAndRemoveTimes(json);

            Assert.AreEqual("{\"selected\":[\"item1\",\"item3\",\"item6\"],\"_deviceID\":\"dev001\",\"_type\":\"testType\"}", json.ToString());
        }
Exemplo n.º 11
0
        public void Test_0021_key_len1()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["a"] = 1;

            JsonObject json = ev.ConvertToJsonObject("dev001");

            AssertAndRemoveTimes(json);

            Assert.AreEqual("{\"a\":1,\"_deviceID\":\"dev001\",\"_type\":\"testType\"}", json.ToString());
        }
Exemplo n.º 12
0
        public void Test_0005_intArrayValue()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["selected"] = new int[] { 2, 5, 8 };

            JsonObject json = ev.ConvertToJsonObject("dev001");

            AssertAndRemoveTimes(json);

            Assert.AreEqual("{\"selected\":[2,5,8],\"_deviceID\":\"dev001\",\"_type\":\"testType\"}", json.ToString());
        }
Exemplo n.º 13
0
        public void Test_0001_longValue()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["time"] = (long)12345678901234;

            JsonObject json = ev.ConvertToJsonObject("dev001");

            AssertAndRemoveTimes(json);

            Assert.AreEqual("{\"time\":12345678901234,\"_deviceID\":\"dev001\",\"_type\":\"testType\"}", json.ToString());
        }
Exemplo n.º 14
0
        public void Test_0004_stringValue()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["label"] = "KiiButton";

            JsonObject json = ev.ConvertToJsonObject("dev001");

            AssertAndRemoveTimes(json);

            Assert.AreEqual("{\"label\":\"KiiButton\",\"_deviceID\":\"dev001\",\"_type\":\"testType\"}", json.ToString());
        }
Exemplo n.º 15
0
        public void Test_0002_floatValue()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["score"] = (float)1.34;

            JsonObject json = ev.ConvertToJsonObject("dev001");

            AssertAndRemoveTimes(json);

            Assert.AreEqual("{\"score\":1.34,\"_deviceID\":\"dev001\",\"_type\":\"testType\"}", json.ToString());
        }
        public void Test_1_9_Upload_FailByCloudException()
        {
            KiiAnalytics.Initialize("appID004", "appKey", KiiAnalytics.Site.JP, "dev004");
            KiiEvent[] events = CreateEvents();

            // set mock
            MockHttpClientFactory factory = new MockHttpClientFactory();

            KiiAnalytics.AsyncHttpClientFactory = factory;
            MockHttpClient client = factory.Client;

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

            // async upload
            Exception      exp = null;
            CountDownLatch cd  = new CountDownLatch(1);

            KiiAnalytics.Upload((Exception e) => {
                exp = e;
                cd.Signal();
            }, events);

            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.NotNull(exp);
            Assert.That(exp, Is.InstanceOf <EventUploadException> ());
            EventUploadException ue        = (EventUploadException)exp;
            IList <KiiEvent>     errorList = ue.ErrorEvents;

            Assert.IsFalse(events [0].Sent);
            Assert.IsFalse(events [1].Sent);
            Assert.IsFalse(events [2].Sent);
            Assert.AreEqual(3, errorList.Count);

            KiiEvent error1 = errorList [0];

            Assert.AreEqual(1, error1 ["page"]);
            Assert.AreEqual("OK", error1 ["label"]);

            KiiEvent error2 = errorList [1];

            Assert.AreEqual(2, error2 ["page"]);
            Assert.AreEqual("Cancel", error2 ["label"]);

            KiiEvent error3 = errorList [2];

            Assert.AreEqual(3, error3 ["page"]);
            Assert.AreEqual("Next", error3 ["label"]);
        }
        public void Test_0314_Upload_51()
        {
            KiiAnalytics.Initialize("appID005", "appKey", KiiAnalytics.Site.JP, "dev005");

            KiiEvent[] eventList = new KiiEvent[51];
            for (int i = 0; i < eventList.Length; ++i)
            {
                KiiEvent ev = KiiAnalytics.NewEvent("type1");
                ev["page"]   = i;
                eventList[i] = ev;
            }

            KiiAnalytics.Upload(eventList);
        }
        public void Test_0000_Initialize_CN()
        {
            KiiAnalytics.Initialize("appId", "appKey", KiiAnalytics.Site.CN, "dev001");
            KiiEvent ev = KiiAnalytics.NewEvent("type");

            // set mock
            KiiAnalytics.HttpClientFactory = new MockHttpClientFactory();
            MockHttpClient client = ((MockHttpClientFactory)KiiAnalytics.HttpClientFactory).Client;

            client.AddResponse(204, "");

            KiiAnalytics.Upload(ev);

            Assert.AreEqual("https://api-cn2.kii.com/api/apps/appId/events", client.RequestUrl[0]);
        }
        public void Test_0320_Upload_sent()
        {
            KiiAnalytics.Initialize("appID004", "appKey", KiiAnalytics.Site.JP, "dev004");
            KiiEvent ev = KiiAnalytics.NewEvent("type1");

            ev["page"]  = 1;
            ev["label"] = "OK";

            // set mock
            KiiAnalytics.HttpClientFactory = new MockHttpClientFactory();
            MockHttpClient client = ((MockHttpClientFactory)KiiAnalytics.HttpClientFactory).Client;

            client.AddResponse(204, "");

            KiiAnalytics.Upload(ev);
            // set sent event
            KiiAnalytics.Upload(ev);
        }
        public void Test_1_7_Upload()
        {
            KiiAnalytics.Initialize("appID004", "appKey", KiiAnalytics.Site.JP, "dev004");
            KiiEvent ev = KiiAnalytics.NewEvent("type1");

            ev["page"]  = 1;
            ev["label"] = "OK";

            // set mock
            MockHttpClientFactory factory = new MockHttpClientFactory();

            KiiAnalytics.AsyncHttpClientFactory = factory;
            MockHttpClient client = factory.Client;

            client.AddResponse(204, "");

            // async upload
            Exception      exp = null;
            CountDownLatch cd  = new CountDownLatch(1);

            KiiAnalytics.Upload((Exception e) => {
                exp = e;
                cd.Signal();
            }, ev);

            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.Null(exp);
            Assert.AreEqual("https://api-jp.kii.com/api/apps/appID004/events", client.RequestUrl[0]);
            Assert.AreEqual("application/vnd.kii.EventRecordList+json", client.RequestContentType[0]);
            JsonArray  array = new JsonArray(client.RequestBody[0]);
            JsonObject json  = array.GetJsonObject(0);
            int        count = ToCount(json.Keys());

            Assert.AreEqual(6, count);
            Assert.AreEqual(1, json.GetInt("page"));
            Assert.AreEqual("OK", json.GetString("label"));
            Assert.AreEqual("dev004", json.GetString("_deviceID"));
            Assert.AreEqual("type1", json.GetString("_type"));
            Assert.IsTrue(json.Has("_triggeredAt"));
            Assert.IsTrue(json.Has("_uploadedAt"));
        }
        public void Test_1_2_AsyncUpload_PartialSuccess()
        {
            // create events
            KiiEvent ev1 = KiiAnalytics.NewEvent("type1");

            ev1 ["page"]  = 1;
            ev1 ["label"] = "OK";

            KiiEvent ev2 = KiiAnalytics.NewEvent("type2");

            ev1 ["page"]   = 1;
            ev1 ["labels"] = new string[] {};

            // async upload
            Exception      exp = null;
            CountDownLatch cd  = new CountDownLatch(1);

            KiiAnalytics.Upload((Exception e) => {
                Interlocked.Exchange(ref exp, e);
                cd.Signal();
            }, new KiiEvent[] { ev1, ev2 });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.NotNull(exp);
            Assert.That(exp, Is.InstanceOf <EventUploadException> ());
            EventUploadException ue = (EventUploadException)exp;

            Assert.AreEqual(200, ue.Status);

            // check response body
            JsonObject json = new JsonObject(ue.Body);

            Assert.AreEqual("PARTIAL_SUCCESS", json.GetString("errorCode"));
            JsonArray invalidEvents = json.GetJsonArray("invalidEvents");
            int       length        = invalidEvents.Length();

            Assert.AreEqual(1, length);
            JsonObject invalidEvent = invalidEvents.GetJsonObject(0);

            Assert.AreEqual(0, invalidEvent.GetInt("index"));
        }
        private KiiEvent[] CreateEvents()
        {
            KiiEvent ev1 = KiiAnalytics.NewEvent("type1");

            ev1["page"]  = 1;
            ev1["label"] = "OK";

            KiiEvent ev2 = KiiAnalytics.NewEvent("type1");

            ev2["page"]  = 2;
            ev2["label"] = "Cancel";

            KiiEvent ev3 = KiiAnalytics.NewEvent("type1");

            ev3["page"]  = 3;
            ev3["label"] = "Next";

            return(new KiiEvent[] { ev1, ev2, ev3 });
        }
        public void Test_0313_Upload_50()
        {
            KiiAnalytics.Initialize("appID005", "appKey", KiiAnalytics.Site.JP, "dev005");

            KiiEvent[] eventList = new KiiEvent[50];
            for (int i = 0; i < eventList.Length; ++i)
            {
                KiiEvent ev = KiiAnalytics.NewEvent("type1");
                ev["page"]   = i;
                eventList[i] = ev;
            }

            // set mock
            KiiAnalytics.HttpClientFactory = new MockHttpClientFactory();
            MockHttpClient client = ((MockHttpClientFactory)KiiAnalytics.HttpClientFactory).Client;

            client.AddResponse(204, "");

            KiiAnalytics.Upload(eventList);
        }
        public void Test_0332_Upload_Partial_last()
        {
            KiiAnalytics.Initialize("appID004", "appKey", KiiAnalytics.Site.JP, "dev004");
            KiiEvent[] events = CreateEvents();

            // set mock
            KiiAnalytics.HttpClientFactory = new MockHttpClientFactory();
            MockHttpClient client = ((MockHttpClientFactory)KiiAnalytics.HttpClientFactory).Client;

            client.AddResponse(200,
                               "{" +
                               "\"errorCode\" : \"PARTIAL_SUCCESS\"," +
                               "\"message\" : \"There are some errors in event data\"," +
                               "\"invalidEvents\" : [ {" +
                               "\"index\" : 2," +
                               "\"errorDetails\" : [ {" +
                               "\"fieldName\" : \"_uploadedAt\"," +
                               "\"errorCode\" : \"UPLOADED_AT_MISSING\"," +
                               "\"message\" : \"You must provide event upload time\"}]" +
                               "}]" +
                               "}");

            try
            {
                KiiAnalytics.Upload(events);
                Assert.Fail("Exception must be thrown");
            }
            catch (EventUploadException e)
            {
                IList <KiiEvent> errorList = e.ErrorEvents;
                Assert.IsTrue(events[0].Sent);
                Assert.IsTrue(events[1].Sent);
                Assert.IsFalse(events[2].Sent);
                Assert.AreEqual(1, errorList.Count);
                KiiEvent error1 = errorList[0];
                Assert.AreEqual(3, error1["page"]);
                Assert.AreEqual("Next", error1["label"]);
            }
        }
        public void Test_1_1_AsyncUpload()
        {
            // create events
            KiiEvent ev1 = KiiAnalytics.NewEvent("type1");

            ev1 ["page"]  = 1;
            ev1 ["label"] = "OK";

            // async upload
            Exception      exp = null;
            CountDownLatch cd  = new CountDownLatch(1);

            KiiAnalytics.Upload((Exception e) => {
                Interlocked.Exchange(ref exp, e);
                cd.Signal();
            }, new KiiEvent[] { ev1 });

            if (!cd.Wait(new TimeSpan(0, 0, 0, 3)))
            {
                Assert.Fail("Callback not fired.");
            }
            Assert.Null(exp);
        }
Exemplo n.º 26
0
        public void Test_0031_value_empty_string()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["key"] = "";
        }
Exemplo n.º 27
0
        public void Test_0020_key_null()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev[null] = 1;
        }
Exemplo n.º 28
0
        public void Test_0030_value_null()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["key"] = null;
        }
Exemplo n.º 29
0
        public void Test_0022_key_underscore()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["_"] = 1;
        }
Exemplo n.º 30
0
        public void Test_0003_doubleValue()
        {
            KiiEvent ev = KiiAnalytics.NewEvent("testType");

            ev["score"] = (double)1.3456;
        }