Exemplo n.º 1
0
        public async Task UndefinedSinglePageAsync()
        {
            IReadOnlyList <IReadOnlyList <CosmosElement> > pages = new List <List <CosmosElement> >()
            {
                new List <CosmosElement>()
                {
                    CosmosElement.Parse("{\"payload\": {\"$1\": {}}}")
                }
            };

            List <CosmosElement> elements = await AggregateQueryPipelineStageTests.CreateAndDrain(
                pages : pages,
                executionEnvironment : ExecutionEnvironment.Compute,
                aggregates : new List <AggregateOperator>()
            {
                AggregateOperator.Sum
            },
                aliasToAggregateType : new Dictionary <string, AggregateOperator?>()
            {
                { "$1", AggregateOperator.Sum }
            },
                orderedAliases : new List <string>()
            {
                "$1"
            },
                hasSelectValue : false,
                continuationToken : null);

            Assert.AreEqual(1, elements.Count);
            Assert.AreEqual(0, (elements[0] as CosmosObject).Keys.Count());
        }
Exemplo n.º 2
0
        public async Task MultiplePagesAsync()
        {
            long[] values = new long[] { 42, 1337 };
            IReadOnlyList <IReadOnlyList <CosmosElement> > pages = values
                                                                   .Select(value => new List <CosmosElement>()
            {
                CosmosElement.Parse($"{{\"payload\": {{\"$1\": {{\"item\": {value}}}}}}}")
            })
                                                                   .ToList();

            List <CosmosElement> elements = await AggregateQueryPipelineStageTests.CreateAndDrain(
                pages : pages,
                executionEnvironment : ExecutionEnvironment.Compute,
                aggregates : new List <AggregateOperator>()
            {
                AggregateOperator.Sum
            },
                aliasToAggregateType : new Dictionary <string, AggregateOperator?>()
            {
                { "$1", AggregateOperator.Sum }
            },
                orderedAliases : new List <string>()
            {
                "$1"
            },
                hasSelectValue : false,
                continuationToken : null);

            Assert.AreEqual(1, elements.Count);
            Assert.AreEqual(values.Sum(), Number64.ToLong(((elements[0] as CosmosObject)["$1"] as CosmosNumber).Value));
        }