Exemplo n.º 1
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";
            IEnumerable<string> resultl = new List<string>() { "hello", "goodbye", "I'm late" };

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

            Mock<IQueries> queryMock = null;
            if (UseMocks)
            {
                queryMock = new Mock<IQueries>();
                queryMock.Setup(m => m.Metric<IEnumerable<string>>(
                        It.Is<string>(me => me == "select_unique"),
                        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.QuerySelectUniqueIntervalGroupAsync(testCol, prop, groupby, timeframe, interval);

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