コード例 #1
0
        public async void Caching_SendEvents_Success()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());

            if (UseMocks)
            {
                client.Event = new EventMock(SettingsEnv,
                                             addEvents: new Func <JObject, IProjectSettings, IEnumerable <CachedEvent> >((e, p) =>
                {
                    if ((p == SettingsEnv) &&
                        (null != e.Property("CachedEventTest")) &&
                        (e.Property("CachedEventTest").Value.Children().Count() == 3))
                    {
                        return(new List <CachedEvent>());
                    }
                    else
                    {
                        throw new Exception("Unexpected value");
                    }
                }));
            }

            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });

            Assert.DoesNotThrow(() => client.SendCachedEvents());
            Assert.Null(await client.EventCache.TryTake(), "Cache is empty");
        }
コード例 #2
0
ファイル: KeenClientTest.cs プロジェクト: 5ag1/keen-sdk-net
        public void AddGlobalProperty_DelegateValueProviderNullReturn_Throws()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Value <string>() == "value"))
                    {
                        return;
                    }
                    throw new Exception("Unexpected value");
                });
            }

            var i = 0;

            // return valid for the first two tests, then null
            client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => i++ > 1 ? null : "value"));
            // This is the second test (AddGlobalProperty runs the first)
            Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
            // Third test should fail.
            Assert.Throws <KeenException>(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
        }
コード例 #3
0
ファイル: KeenClientTest.cs プロジェクト: 5ag1/keen-sdk-net
        public void AddGlobalProperty_DelegateSimpleValue_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"] != null))
                    {
                        return;
                    }
                    throw new Exception("Unexpected value");
                });
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => DateTime.Now.Millisecond));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
コード例 #4
0
ファイル: KeenClientTest.cs プロジェクト: 5ag1/keen-sdk-net
        public void Caching_SendEvents_Success()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());

            if (UseMocks)
            {
                client.Event = new EventMock(SettingsEnv,
                                             addEvents: (e, p) =>
                {
                    if ((p == SettingsEnv) &&
                        (null != e.Property("CachedEventTest")) &&
                        (e.Property("CachedEventTest").Value.Children().Count() == 3))
                    {
                        return(new List <CachedEvent>());
                    }
                    throw new Exception("Unexpected value");
                });
            }

            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });

            Assert.DoesNotThrow(client.SendCachedEvents);
            Assert.Null(client.EventCache.TryTake(), "Cache is empty");
        }
コード例 #5
0
ファイル: KeenClientTest.cs プロジェクト: 5ag1/keen-sdk-net
        public void Caching_AddEvents_Success()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());

            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
        }
コード例 #6
0
        public void CachingPCL_AddEvents_Success(IEventCache cache)
        {
            var client = new KeenClient(settingsEnv, cache);

            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
        }
コード例 #7
0
        public void AddEvent_ScopedKeyWrite_Success()
        {
            const string scope     = "{\"timestamp\": \"2014-02-25T22:09:27.320082\", \"allowed_operations\": [\"write\"]}";
            var          scopedKey = ScopedKey.EncryptString(SettingsEnv.MasterKey, scope);
            var          settings  = new ProjectSettingsProvider(masterKey: SettingsEnv.MasterKey, projectId: SettingsEnv.ProjectId, writeKey: scopedKey);

            var client = new KeenClient(settings);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(settings,
                                                                 addEvent: (c, e, p) =>
                {
                    var key = JObject.Parse(ScopedKey.Decrypt(p.MasterKey, p.WriteKey));

                    if ((key["allowed_operations"].Values <string>().First() == "write") && (p == settings) && (c == "AddEventTest") && (e["AProperty"].Value <string>() == "CustomKey"))
                    {
                        return;
                    }

                    throw new Exception("Unexpected value");
                });
            }

            Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", new { AProperty = "CustomKey" }));
        }
コード例 #8
0
        public void Roundtrip_RndIV_Success()
        {
            const string vendor_guid = "abc";
            const bool   isRead      = false;

            var str = "{\"filters\": [{\"property_name\": \"vendor_id\",\"operator\": \"eq\",\"property_value\": \"VENDOR_GUID\"}],\"allowed_operations\": [ \"READ_OR_WRITE\" ]}";

            str = str.Replace("VENDOR_GUID", vendor_guid);

            if (isRead)
            {
                str = str.Replace("READ_OR_WRITE", "read");
            }
            else
            {
                str = str.Replace("READ_OR_WRITE", "write");
            }

            var rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();

            byte[] bytes = new byte[16];
            rnd.GetBytes(bytes);

            var IV = String.Concat(bytes.Select(b => b.ToString("X2"))); Trace.WriteLine("IV: " + IV);

            var scopedKey = ScopedKey.EncryptString(SettingsEnv.MasterKey, str, IV); //System.Text.Encoding.Default.GetString(bytes));
            var decrypted = ScopedKey.Decrypt(SettingsEnv.MasterKey, scopedKey);

            Trace.WriteLine("decrypted: " + decrypted);

            var settings = new ProjectSettingsProvider(SettingsEnv.ProjectId, writeKey: scopedKey);
            var client   = new KeenClient(settings);

            client.AddEvent("X", new { vendor_id = "abc", X = "123" });
        }
コード例 #9
0
ファイル: KeenClientTest.cs プロジェクト: 5ag1/keen-sdk-net
        public void AddGlobalProperty_DelegateArrayValue_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Values <int>().All(x => (x == 1) || (x == 2) || (x == 3))))
                    {
                        return;
                    }
                    throw new Exception("Unexpected value");
                });
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => new[] { 1, 2, 3 }));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
コード例 #10
0
ファイル: KeenClientTest.cs プロジェクト: 5ag1/keen-sdk-net
        public void AddGlobalProperty_DelegateObjectValue_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Value <JObject>()["SubProp1"].Value <string>() == "Value"))
                    {
                        return;
                    }
                    throw new Exception("Unexpected value");
                });
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => new { SubProp1 = "Value", SubProp2 = "Value" }));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
コード例 #11
0
ファイル: KeenClientTest.cs プロジェクト: 5ag1/keen-sdk-net
        public void Caching_SendManyEvents_Success()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());
            var total  = 0;

            if (UseMocks)
            {
                client.Event = new EventMock(SettingsEnv,
                                             addEvents: (e, p) =>
                {
                    if ((p == SettingsEnv) &&
                        (null != e.Property("CachedEventTest")) &&
                        ((e.Property("CachedEventTest").Value.Children().Count() == KeenConstants.BulkBatchSize)))
                    {
                        total += e.Property("CachedEventTest").Value.Children().Count();
                        return(new List <CachedEvent>());
                    }
                    throw new Exception("Unexpected value");
                });
            }

            for (int i = 0; i < KeenConstants.BulkBatchSize; i++)
            {
                client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            }

            Assert.DoesNotThrow(client.SendCachedEvents);
            Assert.Null(client.EventCache.TryTake(), "Cache is empty");
            Assert.True(!UseMocks || (total == KeenConstants.BulkBatchSize));
        }
コード例 #12
0
        public void AddGlobalProperty_SimpleValue_Success()
        {
            var client = new KeenClient(settingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(settingsEnv,
                                                                 AddEvent: new Action <string, JObject, IProjectSettings>((c, e, p) =>
                {
                    if ((p == settingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Value <string>() == "AValue"))
                    {
                        return;
                    }
                    else
                    {
                        throw new Exception("Unexpected value");
                    }
                }));
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", "AValue");
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
コード例 #13
0
ファイル: AddOnsTest.cs プロジェクト: quxiaoshan/keen-sdk-net
        public void UrlParser_Send_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if (!e["keen"].ToString().Contains("keen:url_parser"))
                    {
                        throw new Exception("Unexpected values");
                    }
                });
            }

            var a = AddOn.UrlParser("url", "url_parsed");

            Assert.DoesNotThrow(
                () =>
                client.AddEvent("AddOnTest",
                                new { url = "https://keen.io/docs/data-collection/data-enrichment/#anchor" }, new List <AddOn> {
                a
            }));
        }
コード例 #14
0
ファイル: AddOnsTest.cs プロジェクト: quxiaoshan/keen-sdk-net
        public void UserAgentParser_Send_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if (!e["keen"].ToString().Contains("keen:ua_parser"))
                    {
                        throw new Exception("Unexpected values");
                    }
                });
            }

            var a = AddOn.UserAgentParser("user_agent_string", "user_agent_parsed");

            Assert.DoesNotThrow(
                () =>
                client.AddEvent("AddOnTest",
                                new
            {
                user_agent_string =
                    "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
            }, new List <AddOn> {
                a
            }));
        }
コード例 #15
0
        public void AddGlobalProperty_CollectionValue_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: new Action <string, JObject, IProjectSettings>((c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") &&
                        (e["AProperty"].Value <string>() == "AValue") &&
                        (e["AGlobal"].Values <int>().All((x) => (x == 1) || (x == 2) || (x == 3))))
                    {
                        return;
                    }
                    else
                    {
                        throw new Exception("Unexpected value");
                    }
                }));
            }

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new[] { 1, 2, 3, });
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
コード例 #16
0
        public void AddEvent_InvalidKeenNamespaceProperty_Throws()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: new Action <string, JObject, IProjectSettings>((c, e, p) =>
                {
                    if ((p == SettingsEnv) &&
                        (c == "X") &&
                        (null != e.Property("keen")) &&
                        (e.Property("keen").Value.GetType() == typeof(JObject)) &&
                        (null != ((JObject)e.Property("keen").Value).Property("AProperty")))
                    {
                        throw new KeenInvalidKeenNamespacePropertyException();
                    }
                    else
                    {
                        throw new Exception("Unexpected value");
                    }
                }));
            }

            Assert.Throws <KeenInvalidKeenNamespacePropertyException>(() => client.AddEvent("X", new { keen = new { AProperty = "AValue" } }));
        }
コード例 #17
0
        public async Task DefaultHeaders_Success()
        {
            object responseData = new[] { new { result = 2 } };

            var handler = new FuncHandler()
            {
                PreProcess = (req, ct) =>
                {
                    // Make sure the default headers are in place
                    Assert.IsTrue(req.Headers.Contains("Keen-Sdk"));
                    Assert.AreEqual(KeenUtil.GetSdkVersion(), req.Headers.GetValues("Keen-Sdk").Single());

                    Assert.IsTrue(req.Headers.Contains("Authorization"));

                    var key = req.Headers.GetValues("Authorization").Single();
                    Assert.IsTrue(SettingsEnv.ReadKey == key ||
                                  SettingsEnv.WriteKey == key ||
                                  SettingsEnv.MasterKey == key);
                },
                ProduceResultAsync = (req, ct) =>
                {
                    return(CreateJsonStringResponseAsync(responseData));
                },
                DeferToDefault = false
            };

            var client = new KeenClient(SettingsEnv, new TestKeenHttpClientProvider()
            {
                ProvideKeenHttpClient =
                    (url) => KeenHttpClientFactory.Create(url,
                                                          new HttpClientCache(),
                                                          null,
                                                          new DelegatingHandlerMock(handler))
            });

            // Try out all the endpoints
            Assert.DoesNotThrow(() => client.GetSchemas());

            // Remaining operations expect an object, not an array of objects
            responseData = new { result = 2 };

            var @event = new { AProperty = "AValue" };

            Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", @event));
            Assert.DoesNotThrow(() => client.AddEvents("AddEventTest", new[] { @event }));

            Assert.DoesNotThrow(() => client.DeleteCollection("DeleteColTest"));
            Assert.IsNotNull(client.GetSchema("AddEventTest"));

            // Currently all the queries/extraction go through the same KeenWebApiRequest() call.
            var count = await client.QueryAsync(
                QueryType.Count(),
                "testCollection",
                "",
                QueryRelativeTimeframe.ThisMonth());

            Assert.IsNotNull(count);
            Assert.AreEqual("2", count);
        }
コード例 #18
0
        public void Caching_SendInvalidEvents_Throws()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());

            if (UseMocks)
            {
                client.Event = new EventMock(SettingsEnv,
                                             addEvents: new Func <JObject, IProjectSettings, IEnumerable <CachedEvent> >((e, p) =>
                {
                    if (p == SettingsEnv)
                    {
                        throw new KeenBulkException("Mock exception",
                                                    new List <CachedEvent>()
                        {
                            new CachedEvent("CachedEventTest", e, new Exception())
                        });
                    }
                    else
                    {
                        throw new Exception("Unexpected value");
                    }
                }));
            }

            var anEvent = new JObject();

            anEvent.Add("AProperty", "AValue");
            client.AddEvent("CachedEventTest", anEvent);

            anEvent.Add("keen", JObject.FromObject(new { invalidPropName = "value" }));
            client.AddEvent("CachedEventTest", anEvent);
            Assert.DoesNotThrow(() =>
            {
                try
                {
                    client.SendCachedEvents();
                }
                catch (KeenBulkException ex)
                {
                    if (ex.FailedEvents.Count() != 1)
                    {
                        throw new Exception("Expected 1 failed event.");
                    }
                }
            });
        }
コード例 #19
0
        public async void Notify()
        {
            var text = await Request.Content.ReadAsStringAsync();

            var projSettings = new ProjectSettingsProvider("5a402d20c9e77c0001ff1a04", writeKey: "EF4BE1AF9688F1B19D207932A0E6F1726EDA4E0E17F523F23953EE2D2BAEAE0213F1EC16A1D4CD32D5DE570F259FFFDAC0ED5639866329B98FC7B1C63D4B7F8675C56E6437F574E64B40B45120846C8637FADD43F34F2E4B77FB5EC4FDB82DDF");
            var cli          = new KeenClient(projSettings);

            cli.AddEvent("Notify", new {
                data = text
            });
        }
コード例 #20
0
        public override void Setup()
        {
            base.Setup();

            // If not using mocks, set up conditions on the server
            if (!UseMocks)
            {
                var client = new KeenClient(SettingsEnv);

                client.DeleteCollection(FunnelColA);
                client.DeleteCollection(FunnelColB);
                client.DeleteCollection(FunnelColC);

                client.AddEvent(FunnelColA, new { id = 1, name = new { first = "sam", last = "w" } });
                client.AddEvent(FunnelColA, new { id = 2, name = new { first = "dean", last = "w" } });
                client.AddEvent(FunnelColA, new { id = 3, name = new { first = "crowly", last = "" } });

                client.AddEvent(FunnelColB, new { id = 1, name = new { first = "sam", last = "w" } });
                client.AddEvent(FunnelColB, new { id = 2, name = new { first = "dean", last = "w" } });

                client.AddEvent(FunnelColC, new { id = 1, name = new { first = "sam", last = "w" } });

                Thread.Sleep(8000); // Give it a moment to show up. Queries will fail if run too soon.
            }
        }
コード例 #21
0
        public async Task Async_Caching_SendEvents_Success()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());

            if (UseMocks)
            {
                client.Event = new EventMock(SettingsEnv,
                                             addEvents: new Func <JObject, IProjectSettings, IEnumerable <CachedEvent> >((e, p) =>
                {
                    Assert.AreEqual(p, SettingsEnv, "Unexpected settings object");
                    Assert.AreEqual(e.Property("CachedEventTest").Value.AsEnumerable().Count(), 3, "Expected exactly 3 collection members");
                    return(new List <CachedEvent>());
                }));
            }

            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });

            await client.SendCachedEventsAsync();

            Assert.Null(await client.EventCache.TryTake(), "Cache should be empty");
        }
コード例 #22
0
ファイル: AddOnsTest.cs プロジェクト: iturpablo/keen-sdk-net
        public void IpToGeo_Send_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if (!e["keen"].ToString().Contains("keen:ip_to_geo"))
                            throw new Exception("Unexpected values");
                    });

            var a = AddOn.IpToGeo("an_ip", "geocode");

            Assert.DoesNotThrow(() => client.AddEvent("AddOnTest", new {an_ip = "70.187.8.97"}, new List<AddOn> {a}));
        }
コード例 #23
0
ファイル: AddOnsTest.cs プロジェクト: iturpablo/keen-sdk-net
        public void IpToGeo_MissingInput_Throws()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if (!e["keen"].ToString().Contains("\"ip\": \"an_ip\""))
                            throw new KeenException("Unexpected values");
                    });

            var a = AddOn.IpToGeo("wrong_field", "geocode");

            Assert.Throws<KeenException>(
                () => client.AddEvent("AddOnTest", new {an_ip = "70.187.8.97"}, new List<AddOn> {a}));
        }
コード例 #24
0
        static void Main(string[] args)
        {
            // Loading Keen.IO Keys and Misc. from Config File
            _keenIOProjectID = ConfigurationManager.AppSettings["keenIOProjectID"];
            _keenIOMasterKey = ConfigurationManager.AppSettings["keenIOMasterKey"];
            _keenIOWriteKey  = ConfigurationManager.AppSettings["keenIOWriteKey"];
            _keenIOReadKey   = ConfigurationManager.AppSettings["keenIOReadKey"];
            _bucketName      = ConfigurationManager.AppSettings["keenIOBucketName"];

            // Configuring MongoDB Wrapper for connection and queries
            MongoDBWrapper mongoDB           = new MongoDBWrapper();
            string         fullServerAddress = String.Join(":", Consts.MONGO_SERVER, Consts.MONGO_PORT);

            mongoDB.ConfigureDatabase(Consts.MONGO_USER, Consts.MONGO_PASS, Consts.MONGO_AUTH_DB, fullServerAddress, Consts.MONGO_TIMEOUT, Consts.MONGO_DATABASE, Consts.MONGO_COLLECTION);

            // Creating Keen.IO Variables
            var projectSettings = new ProjectSettingsProvider(_keenIOProjectID, _keenIOMasterKey, _keenIOWriteKey, _keenIOReadKey);
            var keenClient      = new KeenClient(projectSettings);

            // From This point on, you can change your code to reflect your own "Reading" logic
            // What I've done is simply read the records from the MongoDB database and Upload them to Keen.IO
            foreach (var currentApp in mongoDB.FindMatch <AppModel> (Query.NE("Uploaded", true)))
            {
                try
                {
                    // Adding Event to Keen.IO
                    keenClient.AddEvent("PlayStore2014", currentApp);

                    // Incrementing Counter
                    _appsCounter++;

                    // Console feedback Every 100 Processed Apps
                    if (_appsCounter % 100 == 0)
                    {
                        Console.WriteLine("Uploaded : " + _appsCounter);
                    }

                    mongoDB.SetUpdated(currentApp.Url);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("\n\t" + ex.Message);
                }
            }
        }
コード例 #25
0
ファイル: KeenClientTest.cs プロジェクト: 5ag1/keen-sdk-net
        public void AddEvent_ValidProjectIdInvalidWriteKey_Throws()
        {
            var settings = new ProjectSettingsProvider(projectId: SettingsEnv.ProjectId, writeKey: "X");
            var client   = new KeenClient(settings);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(settings,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == settings) && (c == "X") && (e["X"].Value <string>() == "X"))
                    {
                        throw new KeenInvalidApiKeyException(c);
                    }
                });
            }
            Assert.Throws <KeenInvalidApiKeyException>(() => client.AddEvent("X", new { X = "X" }));
        }
コード例 #26
0
ファイル: KeenClientTest.cs プロジェクト: 5ag1/keen-sdk-net
        public void AddEvent_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if ((p == SettingsEnv) && (c == "AddEventTest") && (e["AProperty"].Value <string>() == "AValue"))
                    {
                        return;
                    }
                    throw new Exception("Unexpected values");
                });
            }
            Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
        }
コード例 #27
0
        public void No_AddOn_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if (e["keen"].ToString().Contains("keen:ip_to_geo"))
                    {
                        throw new Exception("Unexpected values");
                    }
                });
            }

            Assert.DoesNotThrow(() => client.AddEvent("AddOnTest", new { an_ip = "70.187.8.97" }));
        }
コード例 #28
0
        public void AddEvent_InvalidProjectId_Throws()
        {
            var settings = new ProjectSettingsProvider(projectId: "X", writeKey: SettingsEnv.WriteKey);
            var client   = new KeenClient(settings);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(settings,
                                                                 addEvent: new Action <string, JObject, IProjectSettings>((c, e, p) =>
                {
                    if ((p == settings) && (c == "X") && (e["X"].Value <string>() == "X"))
                    {
                        throw new KeenResourceNotFoundException(c);
                    }
                }));
            }

            Assert.Throws <KeenResourceNotFoundException>(() => client.AddEvent("X", new { X = "X" }));
        }
コード例 #29
0
        public async Task CachingPCL_SendEventsParallel_Success(IEventCache cache)
        {
            await cache.Clear();

            var client = new KeenClient(SettingsEnv, cache);

            if (UseMocks)
            {
                client.Event = new EventMock(SettingsEnv,
                                             addEvents: (e, p) => new List <CachedEvent>());
            }

            (from i in Enumerable.Range(1, 100)
             select new { AProperty = "AValue" })
            .AsParallel()
            .ForAll(e => client.AddEvent("CachedEventTest", e));

            await client.SendCachedEventsAsync();

            Assert.Null(await client.EventCache.TryTake(), "Cache is empty");
        }
コード例 #30
0
ファイル: AddOnsTest.cs プロジェクト: iturpablo/keen-sdk-net
        public void UserAgentParser_Send_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if (!e["keen"].ToString().Contains("keen:ua_parser"))
                            throw new Exception("Unexpected values");
                    });

            var a = AddOn.UserAgentParser("user_agent_string", "user_agent_parsed");

            Assert.DoesNotThrow(
                () =>
                    client.AddEvent("AddOnTest",
                        new
                        {
                            user_agent_string =
                                "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"
                        }, new List<AddOn> {a}));
        }
コード例 #31
0
        public void IpToGeo_MissingInput_Throws()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if (!e["keen"].ToString().Contains("\"ip\": \"an_ip\""))
                    {
                        throw new KeenException("Unexpected values");
                    }
                });
            }

            var a = AddOn.IpToGeo("wrong_field", "geocode");

            Assert.Throws <KeenException>(() => client.AddEvent("AddOnTest", new { an_ip = "70.187.8.97" }, new List <AddOn> {
                a
            }));
        }
コード例 #32
0
        public void IpToGeo_Send_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if (!e["keen"].ToString().Contains("keen:ip_to_geo"))
                    {
                        throw new Exception("Unexpected values");
                    }
                });
            }

            var a = AddOn.IpToGeo("an_ip", "geocode");

            Assert.DoesNotThrow(() => client.AddEvent("AddOnTest", new { an_ip = "70.187.8.97" }, new List <AddOn> {
                a
            }));
        }
コード例 #33
0
        public void ReferrerParser_Send_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 addEvent: (c, e, p) =>
                {
                    if (!e["keen"].ToString().Contains("keen:referrer_parser"))
                    {
                        throw new Exception("Unexpected values");
                    }
                });
            }

            var a = AddOn.ReferrerParser("referrer", "page", "referrer_parsed");

            Assert.DoesNotThrow(() => client.AddEvent("AddOnTest", new { page = "", referrer = "" }, new List <AddOn> {
                a
            }));
        }
コード例 #34
0
        public void AddEvent_InvalidKeenNamespaceProperty_Throws()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c,e,p) =>
                    {
                        if ((p == SettingsEnv) 
                            && (c == "X") 
                            && (null != e.Property("keen"))
                            && (e.Property("keen").Value.GetType()==typeof(JObject))
                            && (null!=((JObject)e.Property("keen").Value).Property("AProperty")))
                            throw new KeenInvalidKeenNamespacePropertyException();
                        throw new Exception("Unexpected value");
                    });

            Assert.Throws<KeenInvalidKeenNamespacePropertyException>(() => client.AddEvent("X", new { keen = new { AProperty = "AValue" } }));
        }
コード例 #35
0
 public void AddEvent_Success()
 {
     var client = new KeenClient(SettingsEnv);
     if (UseMocks)
         client.EventCollection = new EventCollectionMock(SettingsEnv,
             addEvent: (c, e, p) =>
             {
                 if ((p == SettingsEnv) && (c == "AddEventTest") && (e["AProperty"].Value<string>()=="AValue"))
                     return;
                 throw new Exception("Unexpected values");
             });
     Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
 }
コード例 #36
0
        public void AddEvent_ScopedKeyWrite_Success()
        {
            const string scope = "{\"timestamp\": \"2014-02-25T22:09:27.320082\", \"allowed_operations\": [\"write\"]}";
            var scopedKey = ScopedKey.EncryptString(SettingsEnv.MasterKey, scope);
            var settings = new ProjectSettingsProvider(masterKey: SettingsEnv.MasterKey, projectId: SettingsEnv.ProjectId, writeKey: scopedKey);

            var client = new KeenClient(settings);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(settings,
                    addEvent: (c, e, p) =>
                    {
                        var key = JObject.Parse(ScopedKey.Decrypt(p.MasterKey, p.WriteKey));
                        if ((key["allowed_operations"].Values<string>().First()=="write") && (p == settings) && (c == "AddEventTest") && (e["AProperty"].Value<string>()=="CustomKey"))
                            return;
                        throw new Exception("Unexpected value");
                    });

            Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", new { AProperty = "CustomKey" }));
        }
コード例 #37
0
        public void AddGlobalProperty_DelegateSimpleValue_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if ((p == SettingsEnv) && (c == "AddEventTest")
                            && (e["AProperty"].Value<string>() == "AValue")
                            && (e["AGlobal"]!=null))
                            return;
                        throw new Exception("Unexpected value");
                    });

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => DateTime.Now.Millisecond));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
コード例 #38
0
        public void Caching_SendManyEvents_Success()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());
            var total = 0;
            if (UseMocks)
                client.Event = new EventMock(SettingsEnv,
                    addEvents: (e, p) =>
                    {
                        if ((p == SettingsEnv)
                            && (null != e.Property("CachedEventTest"))
                            && ((e.Property("CachedEventTest").Value.Children().Count() == KeenConstants.BulkBatchSize)))
                        {
                            total += e.Property("CachedEventTest").Value.Children().Count();
                            return new List<CachedEvent>();
                        }
                        throw new Exception("Unexpected value");
                    });

            for (int i = 0; i < KeenConstants.BulkBatchSize; i++)
                client.AddEvent("CachedEventTest", new { AProperty = "AValue" });

            Assert.DoesNotThrow(client.SendCachedEvents);
            Assert.Null(client.EventCache.TryTake(), "Cache is empty");
            Assert.True( !UseMocks || ( total == KeenConstants.BulkBatchSize));
        }
コード例 #39
0
ファイル: AddOnsTest.cs プロジェクト: iturpablo/keen-sdk-net
        public void UrlParser_Send_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if (!e["keen"].ToString().Contains("keen:url_parser"))
                            throw new Exception("Unexpected values");
                    });

            var a = AddOn.UrlParser("url", "url_parsed");

            Assert.DoesNotThrow(
                () =>
                    client.AddEvent("AddOnTest",
                        new {url = "https://keen.io/docs/data-collection/data-enrichment/#anchor"}, new List<AddOn> {a}));
        }
コード例 #40
0
        public void AddGlobalProperty_DelegateArrayValue_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if ((p == SettingsEnv) && (c == "AddEventTest") 
                            && (e["AProperty"].Value<string>() == "AValue")
                            && (e["AGlobal"].Values<int>().All(x => (x == 1) || (x == 2) || (x == 3))))
                            return;
                        throw new Exception("Unexpected value");
                    });

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => new[] { 1, 2, 3 }));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
コード例 #41
0
ファイル: AddOnsTest.cs プロジェクト: iturpablo/keen-sdk-net
        public void ReferrerParser_Send_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if (!e["keen"].ToString().Contains("keen:referrer_parser"))
                            throw new Exception("Unexpected values");
                    });

            var a = AddOn.ReferrerParser("referrer", "page", "referrer_parsed");

            Assert.DoesNotThrow(() => client.AddEvent("AddOnTest", new {page = "", referrer = ""}, new List<AddOn> {a}));
        }
コード例 #42
0
        public void Caching_SendEvents_Success()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());
            if (UseMocks)
                client.Event = new EventMock(SettingsEnv,
                    addEvents: (e, p) =>
                    {
                        if ((p == SettingsEnv) 
                            && (null!=e.Property("CachedEventTest"))
                            && (e.Property("CachedEventTest").Value.Children().Count()==3))
                            return new List<CachedEvent>();
                        throw new Exception("Unexpected value");
                    });

            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });
            client.AddEvent("CachedEventTest", new { AProperty = "AValue" });

            Assert.DoesNotThrow(client.SendCachedEvents);
            Assert.Null(client.EventCache.TryTake(), "Cache is empty");
        }
コード例 #43
0
 public void AddEvent_ValidProjectIdInvalidWriteKey_Throws()
 {
     var settings = new ProjectSettingsProvider(projectId: SettingsEnv.ProjectId, writeKey: "X");
     var client = new KeenClient(settings);
     if (UseMocks)
         client.EventCollection = new EventCollectionMock(settings,
             addEvent: (c, e, p) =>
             {
                 if ((p == settings) && (c == "X") && (e["X"].Value<string>() == "X"))
                     throw new KeenInvalidApiKeyException(c);
             });
     Assert.Throws<KeenInvalidApiKeyException>(() => client.AddEvent("X", new { X = "X" }));
 }
コード例 #44
0
 public void AddEvent_InvalidCollectionNameTooLong_Throws()
 {
     var client = new KeenClient(SettingsEnv);
     Assert.Throws<KeenException>(() => client.AddEvent(new String('X', 257), new { AProperty = "AValue" }));
 }
コード例 #45
0
        public void Caching_SendInvalidEvents_Throws()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());
            if (UseMocks)
                client.Event = new EventMock(SettingsEnv,
                    addEvents: (e, p) =>
                    {
                        if (p == SettingsEnv)
                            throw new KeenBulkException("Mock exception", 
                                new List<CachedEvent> {new CachedEvent("CachedEventTest", e, new Exception())});
                        throw new Exception("Unexpected value");
                    });

            var anEvent = new JObject {{"AProperty", "AValue"}};
            client.AddEvent("CachedEventTest", anEvent);
            
            anEvent.Add("keen", JObject.FromObject(new {invalidPropName = "value"} ));
            client.AddEvent("CachedEventTest", anEvent);
            Assert.DoesNotThrow(() => 
                {
                    try
                    {
                        client.SendCachedEvents();
                    } 
                    catch (KeenBulkException ex)
                    {
                        if (ex.FailedEvents.Count() != 1)
                            throw new Exception("Expected 1 failed event.");
                    }
                });
        }
コード例 #46
0
 public void AddEvent_InvalidCollectionNameDollarSign_Throws()
 {
     var client = new KeenClient(SettingsEnv);
     Assert.Throws<KeenException>(() => client.AddEvent("$Invalid", new { AProperty = "AValue" }));
 }
コード例 #47
0
        public void AddGlobalProperty_DelegateValueProviderNullReturn_Throws()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if ((p == SettingsEnv) && (c == "AddEventTest") 
                            && (e["AProperty"].Value<string>() == "AValue")
                            && (e["AGlobal"].Value<string>() == "value"))
                            return;
                        throw new Exception("Unexpected value");
                    });

            var i = 0;
            // return valid for the first two tests, then null
            client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => i++ > 1 ? null : "value"));
            // This is the second test (AddGlobalProperty runs the first)
            Assert.DoesNotThrow(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
            // Third test should fail.
            Assert.Throws<KeenException>(() => client.AddEvent("AddEventTest", new { AProperty = "AValue" }));
        }
コード例 #48
0
        public void AddGlobalProperty_DelegateObjectValue_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    addEvent: (c, e, p) =>
                    {
                        if ((p == SettingsEnv) && (c == "AddEventTest") 
                            && (e["AProperty"].Value<string>() == "AValue") 
                            && (e["AGlobal"].Value<JObject>()["SubProp1"].Value<string>() == "Value"))
                            return;
                        throw new Exception("Unexpected value");
                    });

            Assert.DoesNotThrow(() =>
            {
                client.AddGlobalProperty("AGlobal", new DynamicPropertyValue(() => new { SubProp1 = "Value", SubProp2 = "Value" }));
                client.AddEvent("AddEventTest", new { AProperty = "AValue" });
            });
        }
コード例 #49
0
        public void Caching_AddEvents_Success()
        {
            var client = new KeenClient(SettingsEnv, new EventCacheMemory());

            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
            Assert.DoesNotThrow(() => client.AddEvent("CachedEventTest", new { AProperty = "AValue" }));
        }