Ejemplo n.º 1
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.
            }
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public void DeleteCollection_Success()
        {
            var client = new KeenClient(SettingsEnv);

            if (UseMocks)
            {
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                                                                 deleteCollection: (c, p) =>
                {
                    if ((p == SettingsEnv) && (c == "DeleteColTest"))
                    {
                        return;
                    }
                    throw new Exception("Unexpected value");
                });
            }

            // Idempotent, does not matter if collection does not exist.
            Assert.DoesNotThrow(() => client.DeleteCollection("DeleteColTest"));
        }
Ejemplo n.º 4
0
        public void DeleteCollection_Success()
        {
            var client = new KeenClient(SettingsEnv);
            if (UseMocks)
                client.EventCollection = new EventCollectionMock(SettingsEnv,
                    deleteCollection: (c, p) =>
                    {
                        if ((p == SettingsEnv) && (c == "DeleteColTest"))
                            return;
                        throw new Exception("Unexpected value");
                    });

            // Idempotent, does not matter if collection does not exist.
            Assert.DoesNotThrow(() => client.DeleteCollection("DeleteColTest"));
        }