예제 #1
0
        public async void Funnel_ValidTimeframe_Success()
        {
            var client = new KeenClient(settingsEnv);
            var filters = new List<QueryFilter>() { new QueryFilter("field1", QueryFilter.FilterOperator.GreaterThan(), "1") };

            var funnelColA = "FunnelTestA";
            var funnelColB = "FunnelTestB";
            var funnelColC = "FunnelTestC";

            try
            {
                if (!UseMocks)
                {
                    client.DeleteCollection(funnelColA);
                    client.DeleteCollection(funnelColB);
                    client.DeleteCollection(funnelColC);
                }
            }
            catch (Exception)
            {
            }

            var timeframe = new QueryAbsoluteTimeframe(DateTime.Now, DateTime.Now.AddSeconds(2));

            if (!UseMocks)
            {
                client.AddEvent(funnelColA, new { id = "1" });
                client.AddEvent(funnelColA, new { id = "2" });
                client.AddEvent(funnelColA, new { id = "3" });

                client.AddEvent(funnelColB, new { id = "1" });
                client.AddEvent(funnelColB, new { id = "2" });

                client.AddEvent(funnelColC, new { id = "1" });
            }
            IEnumerable<FunnelStep> funnelsteps = new List<FunnelStep>()
            {
                new FunnelStep(){ EventCollection = funnelColA, ActorProperty = "id" },
                new FunnelStep(){ EventCollection = funnelColB, ActorProperty = "id" },
                new FunnelStep(){ EventCollection = funnelColC, ActorProperty = "id" },
            };
            IEnumerable<int> result = new List<int>() { 3, 2, 1 };


            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Funnel(
                        It.IsAny<string>(),
                        It.Is<IEnumerable<FunnelStep>>(f => f == funnelsteps),
                        It.Is<QueryTimeframe>(t => t == null),
                        It.Is<string>(t => t == "")
                      ))
                  .Returns(Task.FromResult(result));

                client.Queries = queryMock.Object;
            }

            var reply = (await client.QueryFunnelAsync(testCol, funnelsteps, null)).ToList();

            if (null != queryMock)
                queryMock.VerifyAll();
        }
예제 #2
0
        public async void SelectUnique_ValidAbsoluteIntervalGroup_Success()
        {
            var client = new KeenClient(settingsEnv);
            var prop = "field1";
            var timeframe = new QueryAbsoluteTimeframe(DateTime.Now.AddDays(-1), DateTime.Now);
            var interval = QueryInterval.EveryNHours(4);
            var groupby = "field1";
            var resultl = "hello,goodbye,I'm late";

            IEnumerable<QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>> result =
                new List<QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>>() 
                { 
                    new QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>(
                        new List<QueryGroupValue<string>>(){
                            new QueryGroupValue<string>(resultl, "abc"),
                            new QueryGroupValue<string>(resultl, "def")
                        }, 
                        timeframe.Start, timeframe.End
                        ),
                    new QueryIntervalValue<IEnumerable<QueryGroupValue<string>>>(
                        new List<QueryGroupValue<string>>(){
                            new QueryGroupValue<string>(resultl, "abc"),
                            new QueryGroupValue<string>(resultl, "def")
                        }, 
                        timeframe.Start, timeframe.End
                        ),
                };

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Metric(
                        It.Is<QueryType>(q => q == QueryType.SelectUnique()),
                        It.Is<string>(c => c == testCol),
                        It.Is<string>(p => p == prop),
                        It.Is<string>(g => g == groupby),
                        It.Is<QueryAbsoluteTimeframe>(t => t == timeframe),
                        It.Is<QueryInterval>(i => i == interval),
                        It.Is<IEnumerable<QueryFilter>>(f => f == null),
                        It.Is<string>(t => t == "")
                        ))
                    .Returns(Task.FromResult(result));

                client.Queries = queryMock.Object;
            }

            var counts = (await client.QueryIntervalGroupAsync(QueryType.SelectUnique(), testCol, prop, groupby, timeframe, interval)).ToList();

            if (null != queryMock)
                queryMock.VerifyAll();
        }
예제 #3
0
        public async void ExtractResource_ValidAbsolute_Success()
        {
            var client = new KeenClient(settingsEnv);
            var timeframe = new QueryAbsoluteTimeframe(DateTime.Now.AddDays(-1), DateTime.Now);
            dynamic eo = new ExpandoObject();
            eo.field1 = "8888";
            IEnumerable<dynamic> result = new List<dynamic>() { eo, eo };

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Extract(
                        It.Is<string>(c => c == testCol),
                        It.Is<QueryAbsoluteTimeframe>(t => t == timeframe),
                        It.Is<IEnumerable<QueryFilter>>(f => f == null),
                        It.Is<int>( l => l == 0),
                        It.Is<string>(t => t == "")
                        ))
                    .Returns(Task.FromResult(result));

                client.Queries = queryMock.Object;
            }

            var reply = (await client.QueryExtractResourceAsync(testCol, timeframe)).ToList();

            if (null != queryMock)
                queryMock.VerifyAll();
        }
예제 #4
0
        public async void SelectUnique_ValidAbsolute_Success()
        {
            var client = new KeenClient(settingsEnv);
            var timeframe = new QueryAbsoluteTimeframe(DateTime.Now.AddDays(-1), DateTime.Now);
            var prop = "field1";
            var result = "hello,goodbye,I'm late";

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Metric(
                        It.Is<QueryType>(q => q == QueryType.SelectUnique()),
                        It.Is<string>(c => c == testCol),
                        It.Is<string>(p => p == prop),
                        It.Is<QueryAbsoluteTimeframe>(t => t == timeframe),
                        It.Is<IEnumerable<QueryFilter>>(f => f == null),
                        It.Is<string>(t => t == "")
                        ))
                    .Returns(Task.FromResult(result));

                client.Queries = queryMock.Object;
            }

            var reply = await client.QueryAsync(QueryType.SelectUnique(), testCol, prop, timeframe);

            if (null != queryMock)
                queryMock.VerifyAll();
        }
예제 #5
0
        public async void Query_ValidAbsoluteInterval_Success()
        {
            var client = new KeenClient(settingsEnv);
            var timeframe = new QueryAbsoluteTimeframe(DateTime.Now.AddDays(-1), DateTime.Now);
            var interval = QueryInterval.EveryNMinutes(5);
            IEnumerable<QueryIntervalValue<string>> result =
                new List<QueryIntervalValue<string>>() { new QueryIntervalValue<string>("0", timeframe.Start, timeframe.End) };

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Metric(
                        It.Is<QueryType>(q => q == QueryType.Count()),
                        It.Is<string>(c => c == testCol),
                        It.Is<string>(p => p == ""),
                        It.Is<QueryAbsoluteTimeframe>(t => t == timeframe),
                        It.Is<QueryInterval>(i => i == interval),
                        It.IsAny<IEnumerable<QueryFilter>>(),
                        It.Is<string>(z => z == "")))
                    .Returns(Task.FromResult(result));

                client.Queries = queryMock.Object;
            }

            var counts = (await client.QueryIntervalAsync(QueryType.Count(), testCol, "", timeframe, interval)).ToList();
            Assert.IsNotNull(counts);

            if (null != queryMock)
                queryMock.VerifyAll();
        }
예제 #6
0
        public async void Query_ValidAbsolute_Success()
        {
            var client = new KeenClient(settingsEnv);
            var timeframe = new QueryAbsoluteTimeframe(DateTime.Now.AddDays(-1), DateTime.Now);

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Metric(
                        It.Is<QueryType>(q => q == QueryType.Count()),
                        It.Is<string>(c => c == testCol),
                        It.Is<string>(p => p == ""),
                        It.Is<QueryAbsoluteTimeframe>(t => t == timeframe),
                        It.Is<IEnumerable<QueryFilter>>(f=>f==null),
                        It.Is<string>(z => z == "")))
                    .Returns(Task.FromResult("0"));

                client.Queries = queryMock.Object;
            }

            var count = await client.QueryAsync(QueryType.Count(), testCol, "", timeframe, null);
            Assert.IsNotNull(count, "expected valid count");

            if (null != queryMock)
                queryMock.VerifyAll();
        }
예제 #7
0
        public async void Average_ValidAbsoluteInterval_Success()
        {
            var client = new KeenClient(settingsEnv);
            var prop = "field1";
            var timeframe = new QueryAbsoluteTimeframe(DateTime.Now.AddDays(-1), DateTime.Now);
            var interval = QueryInterval.EveryNMinutes(5);
            IEnumerable<QueryIntervalValue<double?>> result =
                new List<QueryIntervalValue<double?>>() { new QueryIntervalValue<double?>(0.0, timeframe.Start, timeframe.End) };

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Metric<double?>(
                        It.Is<string>(me => me == "average"),
                        It.Is<string>(c => c == testCol),
                        It.Is<string>(p => p == prop),
                        It.Is<QueryAbsoluteTimeframe>(t => t == timeframe),
                        It.Is<QueryInterval>(i => i == interval),
                        It.Is<IEnumerable<QueryFilter>>(f => f == null),
                        It.Is<string>(t => t == "")
                        ))
                    .Returns(Task.FromResult(result));

                client.Queries = queryMock.Object;
            }

            var counts = await client.QueryAverageIntervalAsync(testCol, prop, timeframe, interval);

            if (null != queryMock)
                queryMock.VerifyAll();
        }
예제 #8
0
        public async void Average_ValidAbsolute_Success()
        {
            var client = new KeenClient(settingsEnv);
            var timeframe = new QueryAbsoluteTimeframe(DateTime.Now.AddDays(-1), DateTime.Now);
            var prop = "field1";

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Metric<double?>(
                        It.Is<string>(me => me == "average"),
                        It.Is<string>(c => c == testCol),
                        It.Is<string>(p => p == prop),
                        It.Is<QueryAbsoluteTimeframe>(t => t == timeframe),
                        It.Is<IEnumerable<QueryFilter>>(f => f == null),
                        It.Is<string>(t => t == "")
                        ))
                    .Returns(Task.FromResult((double?)0.0));

                client.Queries = queryMock.Object;
            }

            await client.QueryAverageAsync(testCol, prop, timeframe);

            if (null != queryMock)
                queryMock.VerifyAll();
        }