public async Task GetDimensionValuesForAllFilteredDimensionInDataProvidesExpectedValues()
        {
            var          anyTimestamp        = DateTime.Now;
            const string firstDimSecondValue = AnyDimValue + "2";
            var          dimValues           = new DimensionSpecification(AnyDimensions);

            var counter = await this.dataManager.CreateHitCounter(AnyCounterName, AnyKeys);

            counter.Increment(dimValues, anyTimestamp);

            dimValues[AnyKeys.Dimensions.First().Name] = firstDimSecondValue;
            counter.Increment(dimValues, anyTimestamp);

            dimValues.Remove(AnyKeys.Dimensions.First().Name);
            counter.DataSet.Flush();
            var values = counter.GetDimensionValues(AnyKeys.Dimensions.First().Name, dimValues).ToList();

            Assert.AreEqual(2, values.Count);
            Assert.IsTrue(values.Contains(AnyDimValue));
            Assert.IsTrue(values.Contains(firstDimSecondValue));

            dimValues[AnyKeys.Dimensions.First().Name] = firstDimSecondValue;
            counter.Increment(dimValues, anyTimestamp);

            const string lastDimSecondValue = AnyDimValue + "2";

            dimValues[AnyKeys.Dimensions.Last().Name] = lastDimSecondValue;
            counter.Increment(dimValues, anyTimestamp);

            var secondKey = AnyKeys.Dimensions.Skip(1).First();

            dimValues.Remove(secondKey.Name);
            counter.DataSet.Flush();
            values = counter.GetDimensionValues(AnyKeys.Dimensions.First().Name, dimValues).ToList();
            Assert.AreEqual(1, values.Count);
            Assert.IsTrue(values.Contains(firstDimSecondValue));

            values = counter.GetDimensionValues(secondKey.Name, dimValues).ToList();
            Assert.AreEqual(1, values.Count);
            Assert.IsTrue(values.Contains(AnyDimValue));
        }
        private DataSample CombinedDataQuery(Counter counter, DimensionSpecification queryParams)
        {
            if (queryParams != null)
            {
                queryParams[ReservedDimensions.AggregateSamplesDimension] = "true";
            }

            counter.DataSet.Flush();
            var queryResults = counter.Query(queryParams).ToList();

            queryParams.Remove(ReservedDimensions.AggregateSamplesDimension);

            return(queryResults.Count > 0 ? queryResults[0] : null);
        }
        public async Task GetCombinedDataCombinesDataAcrossDimensionValuesIfFilterValueIsNotProvided()
        {
            var          anyTimestamp        = DateTime.Now;
            const string firstDimSecondValue = AnyDimValue + "2";
            var          dimValues           = new DimensionSpecification(AnyDimensions);

            var counter = await this.dataManager.CreateHitCounter(AnyCounterName, AnyKeys);

            counter.Increment(dimValues, anyTimestamp);

            dimValues[AnyKeys.Dimensions.First().Name] = firstDimSecondValue;
            counter.Increment(dimValues, anyTimestamp);

            dimValues.Remove(AnyKeys.Dimensions.First().Name);
            var sample = this.CombinedDataQuery(counter, dimValues);

            Assert.AreEqual(DataSampleType.HitCount, sample.SampleType);
            Assert.AreEqual((ulong)2, sample.HitCount);
        }
        private IEnumerable <DataSample> BucketedDataQuery(Counter counter, DimensionSpecification queryParams,
                                                           int expectedCount = 1)
        {
            if (queryParams != null)
            {
                queryParams[ReservedDimensions.AggregateSamplesDimension] = "false";
            }

            counter.DataSet.Flush();
            var queryResult = counter.Query(queryParams);

            if (queryResult == null)
            {
                return(null);
            }
            var bucketedSamplesList = counter.Query(queryParams).ToList();

            Assert.AreEqual(expectedCount, bucketedSamplesList.Count);
            queryParams.Remove(ReservedDimensions.AggregateSamplesDimension);
            return(bucketedSamplesList);
        }
        public async Task GetCombinedDataCombinesDataAcrossDimensionValuesIfFilterValueIsNotProvided()
        {
            var anyTimestamp = DateTime.Now;
            const string firstDimSecondValue = AnyDimValue + "2";
            var dimValues = new DimensionSpecification(AnyDimensions);

            var counter = await this.dataManager.CreateHitCounter(AnyCounterName, AnyKeys);
            counter.Increment(dimValues, anyTimestamp);

            dimValues[AnyKeys.Dimensions.First().Name] = firstDimSecondValue;
            counter.Increment(dimValues, anyTimestamp);

            dimValues.Remove(AnyKeys.Dimensions.First().Name);
            var sample = this.CombinedDataQuery(counter, dimValues);
            Assert.AreEqual(DataSampleType.HitCount, sample.SampleType);
            Assert.AreEqual((ulong)2, sample.HitCount);
        }
        private IEnumerable<DataSample> BucketedDataQuery(Counter counter, DimensionSpecification queryParams,
                                                          int expectedCount = 1)
        {
            if (queryParams != null)
            {
                queryParams[ReservedDimensions.AggregateSamplesDimension] = "false";
            }

            counter.DataSet.Flush();
            var queryResult = counter.Query(queryParams);
            if (queryResult == null)
            {
                return null;
            }
            var bucketedSamplesList = counter.Query(queryParams).ToList();
            Assert.AreEqual(expectedCount, bucketedSamplesList.Count);
            queryParams.Remove(ReservedDimensions.AggregateSamplesDimension);
            return bucketedSamplesList;
        }
        private DataSample CombinedDataQuery(Counter counter, DimensionSpecification queryParams)
        {
            if (queryParams != null)
            {
                queryParams[ReservedDimensions.AggregateSamplesDimension] = "true";
            }

            counter.DataSet.Flush();
            var queryResults = counter.Query(queryParams).ToList();
            queryParams.Remove(ReservedDimensions.AggregateSamplesDimension);

            return queryResults.Count > 0 ? queryResults[0] : null;
        }
        public async Task GetDimensionValuesForAllFilteredDimensionInDataProvidesExpectedValues()
        {
            var anyTimestamp = DateTime.Now;
            const string firstDimSecondValue = AnyDimValue + "2";
            var dimValues = new DimensionSpecification(AnyDimensions);

            var counter = await this.dataManager.CreateHitCounter(AnyCounterName, AnyKeys);
            counter.Increment(dimValues, anyTimestamp);

            dimValues[AnyKeys.Dimensions.First().Name] = firstDimSecondValue;
            counter.Increment(dimValues, anyTimestamp);

            dimValues.Remove(AnyKeys.Dimensions.First().Name);
            counter.DataSet.Flush();
            var values = counter.GetDimensionValues(AnyKeys.Dimensions.First().Name, dimValues).ToList();
            Assert.AreEqual(2, values.Count);
            Assert.IsTrue(values.Contains(AnyDimValue));
            Assert.IsTrue(values.Contains(firstDimSecondValue));

            dimValues[AnyKeys.Dimensions.First().Name] = firstDimSecondValue;
            counter.Increment(dimValues, anyTimestamp);

            const string lastDimSecondValue = AnyDimValue + "2";
            dimValues[AnyKeys.Dimensions.Last().Name] = lastDimSecondValue;
            counter.Increment(dimValues, anyTimestamp);

            var secondKey = AnyKeys.Dimensions.Skip(1).First();
            dimValues.Remove(secondKey.Name);
            counter.DataSet.Flush();
            values = counter.GetDimensionValues(AnyKeys.Dimensions.First().Name, dimValues).ToList();
            Assert.AreEqual(1, values.Count);
            Assert.IsTrue(values.Contains(firstDimSecondValue));

            values = counter.GetDimensionValues(secondKey.Name, dimValues).ToList();
            Assert.AreEqual(1, values.Count);
            Assert.IsTrue(values.Contains(AnyDimValue));
        }