private static PartitionKey CosmosElementToPartitionKeyObject(IReadOnlyList <CosmosElement> cosmosElementList)
        {
            PartitionKeyBuilder partitionKeyBuilder = new PartitionKeyBuilder();

            foreach (CosmosElement cosmosElement in cosmosElementList)
            {
                if (cosmosElement == null)
                {
                    partitionKeyBuilder.AddNoneType();
                }
                else
                {
                    _ = cosmosElement switch
                    {
                        CosmosString cosmosString => partitionKeyBuilder.Add(cosmosString.Value),
                        CosmosNumber cosmosNumber => partitionKeyBuilder.Add(Number64.ToDouble(cosmosNumber.Value)),
                        CosmosBoolean cosmosBoolean => partitionKeyBuilder.Add(cosmosBoolean.Value),
                        CosmosNull _ => partitionKeyBuilder.AddNullValue(),
                        _ => throw new ArgumentException(
                                  string.Format(
                                      CultureInfo.InvariantCulture,
                                      RMResources.UnsupportedPartitionKeyComponentValue,
                                      cosmosElement)),
                    };
                }
            }

            return(partitionKeyBuilder.Build());
        }
        public static CosmosElement ToCosmosElement(OrderByContinuationToken orderByContinuationToken)
        {
            CosmosElement        compositeContinuationToken = ParallelContinuationToken.ToCosmosElement(orderByContinuationToken.ParallelContinuationToken);
            List <CosmosElement> orderByItemsRaw            = new List <CosmosElement>();

            foreach (OrderByItem orderByItem in orderByContinuationToken.OrderByItems)
            {
                orderByItemsRaw.Add(OrderByItem.ToCosmosElement(orderByItem));
            }

            CosmosArray orderByItems = CosmosArray.Create(orderByItemsRaw);

            CosmosElement filter = orderByContinuationToken.Filter == null?CosmosNull.Create() : (CosmosElement)CosmosString.Create(orderByContinuationToken.Filter);

            CosmosObject cosmosObject = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { PropertyNames.CompositeToken, compositeContinuationToken },
                { PropertyNames.OrderByItems, orderByItems },
                { PropertyNames.Rid, CosmosString.Create(orderByContinuationToken.Rid) },
                { PropertyNames.SkipCount, CosmosNumber64.Create(orderByContinuationToken.SkipCount) },
                { PropertyNames.Filter, filter },
            });

            return(cosmosObject);
        }
Exemple #3
0
        public static CosmosElement ToCosmosElement(FeedRangeState <ReadFeedState> feedRangeState)
        {
            Dictionary <string, CosmosElement> dictionary = new Dictionary <string, CosmosElement>()
            {
                {
                    PropertyNames.FeedRange,
                    FeedRangeCosmosElementSerializer.ToCosmosElement(feedRangeState.FeedRange)
                }
            };

            if (feedRangeState.State is ReadFeedBeginningState)
            {
                dictionary[PropertyNames.State] = CosmosNull.Create();
            }
            else if (feedRangeState.State is ReadFeedContinuationState readFeedContinuationState)
            {
                dictionary[PropertyNames.State] = readFeedContinuationState.ContinuationToken;
            }
            else
            {
                throw new InvalidOperationException("Unknown FeedRange State.");
            }

            return(CosmosObject.Create(dictionary));
        }
        public void SqlLiteralScalarExpressionTest()
        {
            SqlLiteralScalarExpression numberLiteral = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(1));

            AssertEvaluation(CosmosNumber64.Create(1), numberLiteral);

            SqlLiteralScalarExpression stringLiteral = SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("Hello"));

            AssertEvaluation(CosmosString.Create("Hello"), stringLiteral);

            SqlLiteralScalarExpression trueLiteral = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.True);

            AssertEvaluation(CosmosBoolean.Create(true), trueLiteral);

            SqlLiteralScalarExpression falseLiteral = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.False);

            AssertEvaluation(CosmosBoolean.Create(false), falseLiteral);

            SqlLiteralScalarExpression nullLiteral = SqlLiteralScalarExpression.Create(SqlNullLiteral.Singleton);

            AssertEvaluation(CosmosNull.Create(), nullLiteral);

            SqlLiteralScalarExpression undefinedLiteral = SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create());

            AssertEvaluation(Undefined, undefinedLiteral);
        }
            public TryCatch <object> Visit(CosmosNull cosmosNull, Type type)
            {
                if (type.IsValueType && !(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)))
                {
                    return(TryCatch <object> .FromException(Visitor.Exceptions.ExpectedReferenceOrNullableType));
                }

                return(TryCatch <object> .FromResult(default));
            public UInt128 Visit(CosmosNull cosmosNull, UInt128 seed)
            {
                if (seed == RootHashSeed)
                {
                    return(RootCache.Null);
                }

                return(MurmurHash3.Hash128(HashSeeds.Null, seed));
            }
            public TryCatch <object> Visit(CosmosArray cosmosArray, Type type)
            {
                bool isReadOnlyList = type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(IReadOnlyList <>));

                if (!isReadOnlyList)
                {
                    return(TryCatch <object> .FromException(Visitor.Exceptions.ExpectedArray));
                }

                Type genericArgumentType = type.GenericTypeArguments.First();

                Type  listType = typeof(List <>).MakeGenericType(genericArgumentType);
                IList list     = (IList)Activator.CreateInstance(listType);

                foreach (CosmosElement arrayItem in cosmosArray)
                {
                    TryCatch <object> tryGetMaterializedArrayItem;
                    if (genericArgumentType == typeof(object))
                    {
                        Type dotNetType = arrayItem switch
                        {
                            CosmosArray _ => typeof(IReadOnlyList <object>),
                            CosmosBoolean _ => typeof(bool),
                            CosmosNull _ => typeof(object),
                            CosmosNumber _ => typeof(Number64),
                            CosmosObject _ => typeof(object),
                            CosmosString _ => typeof(string),
                            CosmosGuid _ => typeof(Guid),
                            CosmosBinary _ => typeof(ReadOnlyMemory <byte>),
                            _ => throw new ArgumentOutOfRangeException($"Unknown cosmos element type."),
                        };

                        tryGetMaterializedArrayItem = arrayItem.Accept(this, dotNetType);
                    }
                    else
                    {
                        tryGetMaterializedArrayItem = arrayItem.Accept(this, genericArgumentType);
                    }

                    if (tryGetMaterializedArrayItem.Failed)
                    {
                        return(tryGetMaterializedArrayItem);
                    }

                    list.Add(tryGetMaterializedArrayItem.Result);
                }

                return(TryCatch <object> .FromResult(list));
            }
Exemple #8
0
 /// <summary>
 /// Adds a JToken to this map if it hasn't already been added.
 /// </summary>
 /// <param name="cosmosElement">The element to add.</param>
 /// <param name="hash">The hash of the token.</param>
 /// <returns>Whether or not the item was added to this Distinct Map.</returns>
 public override bool Add(CosmosElement cosmosElement, out UInt128 hash)
 {
     // Unordered distinct does not need to return a valid hash.
     // Since it doesn't need the last hash for a continuation.
     hash = default;
     return(cosmosElement switch
     {
         CosmosArray cosmosArray => this.AddArrayValue(cosmosArray),
         CosmosBoolean cosmosBoolean => this.AddSimpleValue(cosmosBoolean.Value ? SimpleValues.True : SimpleValues.False),
         CosmosNull _ => this.AddSimpleValue(SimpleValues.Null),
         CosmosNumber cosmosNumber => this.AddNumberValue(cosmosNumber.Value),
         CosmosObject cosmosObject => this.AddObjectValue(cosmosObject),
         CosmosString cosmosString => this.AddStringValue(cosmosString.Value),
         _ => throw new ArgumentOutOfRangeException($"Unexpected {nameof(CosmosElement)}: {cosmosElement}"),
     });
Exemple #9
0
        private static IReadOnlyList <(string serializedToken, CosmosElement element)> TokenTestData()
        {
            Guid guid = Guid.Parse("69D5AB17-C94A-4173-A278-B59D0D9C7C37");

            byte[] randomBytes = guid.ToByteArray();
            string hexString   = PartitionKeyInternal.HexConvert.ToHex(randomBytes, 0, randomBytes.Length);

            return(new List <(string, CosmosElement)>
            {
                ("[42, 37]", CosmosArray.Parse("[42, 37]")),
                ($@"{{C_Binary(""0x{hexString}"")}}", CosmosBinary.Create(new ReadOnlyMemory <byte>(randomBytes))),
                ("false", CosmosBoolean.Create(false)),
                ($@"{{C_Guid(""{guid}"")}}", CosmosGuid.Create(guid)),
                ("null", CosmosNull.Create()),
                ("1", CosmosInt64.Create(1)),
                ("{\"foo\": false}", CosmosObject.Parse("{\"foo\": false}")),
                ("asdf", CosmosString.Create("asdf"))
            });
Exemple #10
0
 public override string ToString()
 {
     return(CosmosObject.Create(new Dictionary <string, CosmosElement>()
     {
         {
             PipelineContinuationToken.VersionPropertyName,
             CosmosString.Create(this.Version.ToString())
         },
         {
             PipelineContinuationTokenV1_1.QueryPlanPropertyName,
             this.QueryPlan == null ? (CosmosElement)CosmosNull.Create() : (CosmosElement)CosmosString.Create(this.QueryPlan.ToString())
         },
         {
             PipelineContinuationTokenV1_1.SourceContinuationTokenPropertyName,
             CosmosString.Create(this.SourceContinuationToken)
         },
     }).ToString());
 }
        public static CosmosElement ToCosmosElement(CompositeContinuationToken compositeContinuationToken)
        {
            CosmosElement token = compositeContinuationToken.Token == null?CosmosNull.Create() : (CosmosElement)CosmosString.Create(compositeContinuationToken.Token);

            return(CosmosObject.Create(
                       new Dictionary <string, CosmosElement>()
            {
                { CompositeContinuationToken.PropertyNames.Token, token },
                {
                    CompositeContinuationToken.PropertyNames.Range,
                    CosmosObject.Create(
                        new Dictionary <string, CosmosElement>()
                    {
                        { PropertyNames.Min, CosmosString.Create(compositeContinuationToken.Range.Min) },
                        { PropertyNames.Max, CosmosString.Create(compositeContinuationToken.Range.Max) }
                    })
                },
            }));
        }
        public void SqlCoalesceScalarExpressionTest()
        {
            SqlLiteralScalarExpression nullLiteral      = SqlLiteralScalarExpression.Create(SqlNullLiteral.Singleton);
            SqlLiteralScalarExpression undefinedLiteral = SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create());
            SqlLiteralScalarExpression five             = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(5));
            SqlLiteralScalarExpression three            = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3));

            SqlCoalesceScalarExpression nullCoalesceFive = SqlCoalesceScalarExpression.Create(nullLiteral, five);

            AssertEvaluation(CosmosNull.Create(), nullCoalesceFive);

            SqlCoalesceScalarExpression undefinedCoalesceFive = SqlCoalesceScalarExpression.Create(undefinedLiteral, five);

            AssertEvaluation(CosmosNumber64.Create(5), undefinedCoalesceFive);

            SqlCoalesceScalarExpression threeCoalesceFive = SqlCoalesceScalarExpression.Create(three, five);

            AssertEvaluation(CosmosNumber64.Create(3), threeCoalesceFive);
        }
Exemple #13
0
        public void Singletons()
        {
            List <Input> inputs = new List <Input>()
            {
                new Input(
                    description: "Undefined",
                    partitionKeyValue: null),
                new Input(
                    description: "null",
                    partitionKeyValue: CosmosNull.Create()),
                new Input(
                    description: "true",
                    partitionKeyValue: CosmosBoolean.Create(true)),
                new Input(
                    description: "false",
                    partitionKeyValue: CosmosBoolean.Create(false)),
            };

            this.ExecuteTestSuite(inputs);
        }
 public bool Visit(CosmosNull cosmosNull)
 {
     return(true);
 }
Exemple #15
0
 public bool Visit(CosmosNull cosmosNull) => false;
Exemple #16
0
 public JsonType Visit(CosmosNull cosmosNull) => JsonType.Null;
Exemple #17
0
 public CosmosElement Visit(CosmosNull cosmosNull, CosmosElement indexer) => Undefined;
Exemple #18
0
 public override CosmosElement Visit(SqlNullLiteral literal) => CosmosNull.Create();
Exemple #19
0
 public UInt128 Visit(CosmosNull cosmosNull, UInt128 seed)
 {
     return(MurmurHash3.Hash128(CosmosElementHasher.NullHashSeed, seed));
 }
Exemple #20
0
 public int Visit(CosmosNull cosmosNull, CosmosElement input)
 {
     return(cosmosNull.CompareTo((CosmosNull)input));
 }
        public void TestOrderByQueryLiterals()
        {
            StringBuilder sb      = new StringBuilder();
            CosmosElement element = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { "item", CosmosString.Create("asdf") }
            });

            element.Accept(new CosmosElementToQueryLiteral(sb));
            Assert.AreEqual(
                @"{""item"":""asdf""}",
                sb.ToString());

            element = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { "item", CosmosBoolean.Create(true) }
            });
            sb.Clear();
            element.Accept(new CosmosElementToQueryLiteral(sb));
            Assert.AreEqual(
                @"{""item"":true}",
                sb.ToString());

            element = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { "item", CosmosBoolean.Create(false) }
            });
            sb.Clear();
            element.Accept(new CosmosElementToQueryLiteral(sb));
            Assert.AreEqual(
                @"{""item"":false}",
                sb.ToString());

            element = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { "item", CosmosNull.Create() }
            });
            sb.Clear();
            element.Accept(new CosmosElementToQueryLiteral(sb));
            Assert.AreEqual(
                @"{""item"":null}",
                sb.ToString());

            element = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { "item", CosmosNumber64.Create(1.0) }
            });
            sb.Clear();
            element.Accept(new CosmosElementToQueryLiteral(sb));
            Assert.AreEqual(
                @"{""item"":1}",
                sb.ToString());

            element = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { "item", CosmosNumber64.Create(1L) }
            });
            sb.Clear();
            element.Accept(new CosmosElementToQueryLiteral(sb));
            Assert.AreEqual(
                @"{""item"":1}",
                sb.ToString());

            element = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { "item", CosmosInt8.Create(3) },
                { "item2", CosmosInt16.Create(4) },
                { "item3", CosmosInt32.Create(5) },
                { "item5", CosmosUInt32.Create(7) },
                { "item6", CosmosInt64.Create(8) },
                { "item7", CosmosFloat32.Create(9.1f) },
                { "item8", CosmosFloat64.Create(10.2) },
            });
            sb.Clear();
            element.Accept(new CosmosElementToQueryLiteral(sb));
            Assert.AreEqual(
                @"{""item"":C_Int8(3),""item2"":C_Int16(4),""item3"":C_Int32(5),""item5"":C_UInt32(7),""item6"":C_Int64(8)," +
                @"""item7"":C_Float32(9.1),""item8"":C_Float64(10.2)}",
                sb.ToString());

            Guid guid = Guid.NewGuid();

            byte[] randomBytes = Guid.NewGuid().ToByteArray();
            string hexString   = PartitionKeyInternal.HexConvert.ToHex(randomBytes, 0, randomBytes.Length);

            element = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { "item", CosmosGuid.Create(guid) },
                { "item2", CosmosBinary.Create(new ReadOnlyMemory <byte>(randomBytes)) },
            });
            sb.Clear();
            element.Accept(new CosmosElementToQueryLiteral(sb));
            Assert.AreEqual(
                $@"{{""item"":C_Guid(""{guid.ToString()}""),""item2"":C_Binary(""0x{hexString}"")}}",
                sb.ToString());

            // deeply nested arrays and objects
            element = CosmosObject.Create(
                new Dictionary <string, CosmosElement>()
            {
                { "item", CosmosGuid.Create(guid) },

                // empty array
                { "item2", CosmosArray.Create(new CosmosElement[] { }) },

                // empty object
                { "item3", CosmosObject.Create(new Dictionary <string, CosmosElement>()) },

                // array of objects with numbers
                { "item4", CosmosArray.Create(new CosmosElement[]
                    {
                        CosmosObject.Create(new Dictionary <string, CosmosElement>()
                        {
                            { "a", CosmosInt8.Create(3) },
                            { "b", CosmosString.Create("adf") },
                        }),
                        CosmosInt16.Create(25)
                    }) },
            });
            sb.Clear();
            element.Accept(new CosmosElementToQueryLiteral(sb));
            Assert.AreEqual(
                $@"{{""item"":C_Guid(""{guid.ToString()}""),""item2"":[],""item3"":{{}},""item4"":[{{""a"":C_Int8(3),""b"":""adf""}},C_Int16(25)]}}",
                sb.ToString());
        }
 private static void VisitCosmosNull(CosmosNull cosmosNull, IJsonWriter jsonWriter)
 {
     jsonWriter.WriteNullValue();
 }
 public int Visit(CosmosNull cosmosNull, CosmosElement input) => cosmosNull.CompareTo((CosmosNull)input);
 public int Visit(CosmosNull cosmosNull) => 0;
Exemple #25
0
        public string ToString(int lengthLimitInBytes)
        {
            string queryPlanString = this.QueryPlan?.ToString();
            bool   shouldSerializeQueryPlan;

            if (queryPlanString == null)
            {
                shouldSerializeQueryPlan = false;
            }
            else
            {
                shouldSerializeQueryPlan = (queryPlanString.Length + this.SourceContinuationToken.ToString().Length) < lengthLimitInBytes;
            }

            return(CosmosObject.Create(new Dictionary <string, CosmosElement>()
            {
                {
                    PipelineContinuationToken.VersionPropertyName,
                    CosmosString.Create(this.Version.ToString())
                },
                {
                    PipelineContinuationTokenV1_1.QueryPlanPropertyName,
                    shouldSerializeQueryPlan ? CosmosString.Create(queryPlanString) : (CosmosElement)CosmosNull.Create()
                },
                {
                    PipelineContinuationTokenV1_1.SourceContinuationTokenPropertyName,
                    this.SourceContinuationToken
                },
            }).ToString());
        }
        public void SqlBinaryScalarExpressionTest()
        {
            SqlLiteralScalarExpression five             = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(5));
            SqlLiteralScalarExpression three            = SqlLiteralScalarExpression.Create(SqlNumberLiteral.Create(3));
            SqlLiteralScalarExpression hello            = SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("Hello"));
            SqlLiteralScalarExpression world            = SqlLiteralScalarExpression.Create(SqlStringLiteral.Create("World"));
            SqlLiteralScalarExpression trueBoolean      = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.True);
            SqlLiteralScalarExpression falseBoolean     = SqlLiteralScalarExpression.Create(SqlBooleanLiteral.False);
            SqlLiteralScalarExpression nullLiteral      = SqlLiteralScalarExpression.Create(SqlNullLiteral.Singleton);
            SqlLiteralScalarExpression undefinedLiteral = SqlLiteralScalarExpression.Create(SqlUndefinedLiteral.Create());

            SqlArrayCreateScalarExpression  arrayCreateScalarExpresion1  = SqlArrayCreateScalarExpression.Create();
            SqlArrayCreateScalarExpression  arrayCreateScalarExpresion2  = SqlArrayCreateScalarExpression.Create(five);
            SqlObjectCreateScalarExpression objectCreateScalarExpression = SqlObjectCreateScalarExpression.Create();

            SqlBinaryScalarExpression fivePlusThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Add, five, three);

            AssertEvaluation(CosmosNumber64.Create(3 + 5), fivePlusThree);

            SqlBinaryScalarExpression trueAndFalse = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.And, trueBoolean, falseBoolean);

            AssertEvaluation(CosmosBoolean.Create(true && false), trueAndFalse);

            SqlBinaryScalarExpression falseAndUndefined = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.And, falseBoolean, undefinedLiteral);

            AssertEvaluation(CosmosBoolean.Create(false), falseAndUndefined);

            SqlBinaryScalarExpression trueAndUndefined = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.And, trueBoolean, undefinedLiteral);

            AssertEvaluation(Undefined, trueAndUndefined);

            try
            {
                SqlBinaryScalarExpression threeBitwiseAndFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.BitwiseAnd, three, five);
                AssertEvaluation(CosmosNumber64.Create(1), threeBitwiseAndFive);
            }
            catch (Exception)
            {
            }

            try
            {
                SqlBinaryScalarExpression threeBitwiseOrFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.BitwiseOr, three, five);
                AssertEvaluation(CosmosNumber64.Create(7), threeBitwiseOrFive);
            }
            catch (Exception)
            {
            }

            try
            {
                SqlBinaryScalarExpression threeBitwiseXorFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.BitwiseXor, three, five);
                AssertEvaluation(CosmosNumber64.Create(7), threeBitwiseXorFive);
            }
            catch (Exception)
            {
            }

            SqlBinaryScalarExpression nullCoalesceFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Coalesce, nullLiteral, five);

            AssertEvaluation(CosmosNull.Create(), nullCoalesceFive);

            SqlBinaryScalarExpression fiveDivideFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Divide, five, five);

            AssertEvaluation(CosmosNumber64.Create(5 / 5), fiveDivideFive);

            SqlBinaryScalarExpression fiveEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Equal, five, five);

            AssertEvaluation(CosmosBoolean.Create(5 == 5), fiveEqualFive);

            SqlBinaryScalarExpression threeEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Equal, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 == 5), threeEqualFive);

            AssertEvaluation(
                CosmosBoolean.Create(true),
                SqlBinaryScalarExpression.Create(
                    SqlBinaryScalarOperatorKind.Equal,
                    arrayCreateScalarExpresion1,
                    arrayCreateScalarExpresion1));

            AssertEvaluation(
                CosmosBoolean.Create(false),
                SqlBinaryScalarExpression.Create(
                    SqlBinaryScalarOperatorKind.Equal,
                    arrayCreateScalarExpresion1,
                    arrayCreateScalarExpresion2));

            AssertEvaluation(
                CosmosBoolean.Create(false),
                SqlBinaryScalarExpression.Create(
                    SqlBinaryScalarOperatorKind.Equal,
                    arrayCreateScalarExpresion1,
                    objectCreateScalarExpression));

            SqlBinaryScalarExpression threeGreaterThanFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.GreaterThan, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 > 5), threeGreaterThanFive);

            SqlBinaryScalarExpression fiveGreaterThanThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.GreaterThan, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 > 3), fiveGreaterThanThree);

            SqlBinaryScalarExpression threeGreaterThanOrEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.GreaterThanOrEqual, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 >= 5), threeGreaterThanOrEqualFive);

            SqlBinaryScalarExpression fiveGreaterThanOrEqualThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.GreaterThanOrEqual, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 >= 3), fiveGreaterThanOrEqualThree);

            SqlBinaryScalarExpression threeLessThanFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.LessThan, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 < 5), threeLessThanFive);

            SqlBinaryScalarExpression fiveLessThanThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.LessThan, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 < 3), fiveLessThanThree);

            SqlBinaryScalarExpression threeLessThanOrEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.LessThanOrEqual, three, five);

            AssertEvaluation(CosmosBoolean.Create(3 <= 5), threeLessThanOrEqualFive);

            SqlBinaryScalarExpression fiveLessThanOrEqualThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.LessThanOrEqual, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 <= 3), fiveLessThanOrEqualThree);

            SqlBinaryScalarExpression fiveModThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Modulo, five, three);

            AssertEvaluation(CosmosNumber64.Create(5 % 3), fiveModThree);

            SqlBinaryScalarExpression fiveMultiplyThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Multiply, five, three);

            AssertEvaluation(CosmosNumber64.Create(5 * 3), fiveMultiplyThree);

            SqlBinaryScalarExpression fiveNotEqualThree = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.NotEqual, five, three);

            AssertEvaluation(CosmosBoolean.Create(5 != 3), fiveNotEqualThree);

            SqlBinaryScalarExpression fiveNotEqualFive = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.NotEqual, five, five);

            AssertEvaluation(CosmosBoolean.Create(5 != 5), fiveNotEqualFive);

            SqlBinaryScalarExpression trueOrFalse = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Or, trueBoolean, falseBoolean);

            AssertEvaluation(CosmosBoolean.Create(true || false), trueOrFalse);

            SqlBinaryScalarExpression trueOrUndefined = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Or, trueBoolean, undefinedLiteral);

            AssertEvaluation(CosmosBoolean.Create(true), trueOrUndefined);

            SqlBinaryScalarExpression falseOrUndefined = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Or, falseBoolean, undefinedLiteral);

            AssertEvaluation(Undefined, falseOrUndefined);

            SqlBinaryScalarExpression helloConcatWorld = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.StringConcat, hello, world);

            AssertEvaluation(CosmosString.Create("Hello" + "World"), helloConcatWorld);

            SqlBinaryScalarExpression fiveSubtract3 = SqlBinaryScalarExpression.Create(SqlBinaryScalarOperatorKind.Subtract, five, three);

            AssertEvaluation(CosmosNumber64.Create(5 - 3), fiveSubtract3);
        }
Exemple #27
0
 public void Visit(CosmosNull cosmosNull)
 {
     this.stringBuilder.Append("null");
 }
Exemple #28
0
 public void TestNull()
 {
     ReadOnlyMemory <byte> result     = JsonSerializer.Serialize((object)null);
     CosmosNull            cosmosNull = (CosmosNull)CosmosElement.CreateFromBuffer(result);
 }
Exemple #29
0
 public int Visit(CosmosNull cosmosNull)
 {
     return(0);
 }