public void EncodeDecodeNodeId()
        {
            var codec = new VariantEncoderFactory().Default;

            var expected = new Variant(new NodeId(2354));

            var encoded = codec.Encode(expected);
            var variant = codec.Decode(encoded, BuiltInType.NodeId);

            Assert.Equal(expected, variant);
        }
Exemplo n.º 2
0
        public void DecodeEncodeDoubleArrayFromString()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "-123.123, 124.124, 0.0";
            var variant  = codec.Decode(str, BuiltInType.Double);
            var expected = new Variant(new double[] { -123.123, 124.124, 0.0 });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JArray(-123.123, 124.124, 0.0).ToString(Formatting.Indented),
                         encoded.ToString(Formatting.Indented));
        }
Exemplo n.º 3
0
        public void DecodeEncodeDoubleFromJValueTypeNullIsDouble()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = new JValue(-123.123);
            var variant  = codec.Decode(str, BuiltInType.Null);
            var expected = new Variant(-123.123);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(str.ToString(Formatting.Indented),
                         encoded.ToString(Formatting.Indented));
        }
Exemplo n.º 4
0
        public void DecodeEncodeDoubleFromSinglyQuotedString()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "  '-123.123'";
            var variant  = codec.Decode(str, BuiltInType.Double);
            var expected = new Variant(-123.123);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JValue(-123.123).ToString(Formatting.Indented),
                         encoded.ToString(Formatting.Indented));
        }
Exemplo n.º 5
0
        public void DecodeEncodeDoubleArrayFromQuotedString2()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = " [\"-123.123\",'124.124',\"0.0\"] ";
            var variant  = codec.Decode(str, BuiltInType.Double);
            var expected = new Variant(new double[] { -123.123, 124.124, 0.0 });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromArray(-123.123, 124.124, 0.0),
                         encoded);
        }
Exemplo n.º 6
0
        public void DecodeEncodeDoubleFromSinglyQuotedString()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "  '-123.123'";
            var variant  = codec.Decode(str, BuiltInType.Double);
            var expected = new Variant(-123.123);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromObject(-123.123),
                         encoded);
        }
Exemplo n.º 7
0
        public void DecodeEncodeDoubleArrayFromStringTypeNullIsDouble2()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "[-123.123, 124.124, 0.0]";
            var variant  = codec.Decode(str, BuiltInType.Null);
            var expected = new Variant(new double[] { -123.123, 124.124, 0.0 });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromArray(-123.123, 124.124, 0.0),
                         encoded);
        }
Exemplo n.º 8
0
        public void DecodeEncodeDoubleFromStringTypeNullIsDouble()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "-123.123";
            var variant  = codec.Decode(str, BuiltInType.Null);
            var expected = new Variant(-123.123);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromObject(-123.123),
                         encoded);
        }
        public void DecodeEncodeFloatArrayFromString2()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "[-123.123, 124.124, 0.0]";
            var variant  = codec.Decode(str, BuiltInType.Float);
            var expected = new Variant(new float[] { -123.123f, 124.124f, 0.0f });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromArray(-123.123f, 124.124f, 0.0f),
                         encoded);
        }
        public void DecodeEmptyShortArray()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "[]";
            var variant  = codec.Decode(str, BuiltInType.Int16);
            var expected = new Variant(new short[0]);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.True(encoded.Equals(str));
            Assert.Equal(str, encoded);
        }
        public void DecodeEncodeStringAsUInt32()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "123";
            var context  = new ServiceMessageContext();
            var variant  = codec.Decode(str, BuiltInType.UInt32);
            var expected = new Variant(123u);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(str, encoded);
        }
        public void DecodeEncodeFloatArrayFromJArrayTypeNullIsDouble()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = _serializer.FromArray(-123.123f, 124.124f, 0.0f);
            var variant  = codec.Decode(str, BuiltInType.Null);
            var expected = new Variant(new double[] { -123.123, 124.124, 0.0 });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(str,
                         encoded);
        }
Exemplo n.º 13
0
        public void DecodeEncodeFloatFromString2()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "-123";
            var variant  = codec.Decode(str, BuiltInType.Float);
            var expected = new Variant(-123f);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JValue(-123f).ToString(Formatting.Indented),
                         encoded.ToString(Formatting.Indented));
        }
        public void DecodeEncodeFloatFromString2()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "-123";
            var variant  = codec.Decode(str, BuiltInType.Float);
            var expected = new Variant(-123f);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromObject(-123f),
                         encoded);
        }
Exemplo n.º 15
0
        public void DecodeEncodeFloatArrayFromJArrayTypeNullIsDouble()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = new JArray(-123.123f, 124.124f, 0.0f);
            var variant  = codec.Decode(str, BuiltInType.Null);
            var expected = new Variant(new double[] { -123.123, 124.124, 0.0 });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(str.ToString(Formatting.Indented),
                         encoded.ToString(Formatting.Indented));
        }
Exemplo n.º 16
0
        public void DecodeEncodeFloatArrayFromQuotedString2()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = " [\"-123.123\",'124.124',\"0.0\"] ";
            var variant  = codec.Decode(str, BuiltInType.Float);
            var expected = new Variant(new float[] { -123.123f, 124.124f, 0.0f });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JArray(-123.123f, 124.124f, 0.0f).ToString(Formatting.Indented),
                         encoded.ToString(Formatting.Indented));
        }
Exemplo n.º 17
0
        public void DecodeEncodeUInt64ArrayFromStringTypeNumberIsInt641()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "[123, 124, 125]";
            var variant  = codec.Decode(str, BuiltInType.Number);
            var expected = new Variant(new Variant[] {
                new Variant(123L), new Variant(124L), new Variant(125L)
            });
            var encoded = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JArray(123Lu, 124Lu, 125Lu), encoded);
        }
        public void DecodeEncodeByteArrayFromStringTypeIntegerIsInt641()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "[123, 124, 125]";
            var variant  = codec.Decode(str, BuiltInType.Integer);
            var expected = new Variant(new Variant[] {
                new Variant(123L), new Variant(124L), new Variant(125L)
            });
            var encoded = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromArray((byte)123, (byte)124, (byte)125), encoded);
        }
        public void DecodeEncodeStringArrayFromQuotedString3()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = " [\"\\\"test\\\"\",'\\\"test\\\"',\"\\\"test\\\"\"] ";
            var variant  = codec.Decode(str, BuiltInType.String);
            var expected = new Variant(new string[] { "test", "test", "test" });
            // TODO: var expected = new Variant(new string[] { "\"test\"", "\"test\"", "\"test\"" });
            var encoded = codec.Encode(variant);

            Assert.Equal(expected, variant);
            // TODO: Assert.Equal(_serializer.FromArray("\"test\"", "\"test\"", "\"test\""), encoded);
            Assert.Equal(_serializer.FromArray("test", "test", "test"), encoded);
        }
        public void DecodeEncodeInt16ArrayFromStringTypeIntegerIsInt641()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "[-123, -124, -125]";
            var variant  = codec.Decode(str, BuiltInType.Integer);
            var expected = new Variant(new Variant[] {
                new Variant(-123L), new Variant(-124L), new Variant(-125L)
            });
            var encoded = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JArray((short)-123, (short)-124, (short)-125), encoded);
        }
        public void DecodeEncodeInt64ArrayFromStringTypeNumberIsInt641()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "[-123, -124, -125]";
            var variant  = codec.Decode(str, BuiltInType.Number);
            var expected = new Variant(new Variant[] {
                new Variant(-123L), new Variant(-124L), new Variant(-125L)
            });
            var encoded = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromArray(-123L, -124L, -125L), encoded);
        }
        public void DecodeEncodeInt16FromVariantJsonStringTypeVariantMsftEncoding()
        {
            var codec = new VariantEncoderFactory().Default;
            var str   = JToken.FromObject(new {
                DataType = "Int16",
                Value    = (short)-123
            }).ToString();
            var variant  = codec.Decode(str, BuiltInType.Variant);
            var expected = new Variant((short)-123);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JValue(-123), encoded);
        }
Exemplo n.º 23
0
        public void DecodeEncodeUInt64ArrayFromVariantJsonTokenTypeNull2()
        {
            var codec = new VariantEncoderFactory().Default;
            var str   = JToken.FromObject(new {
                Type = "UInt64",
                Body = new ulong[0]
            });
            var variant  = codec.Decode(str, BuiltInType.Null);
            var expected = new Variant(new ulong[0]);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JArray(), encoded);
        }
        public void DecodeEncodeFloatArrayFromVariantJsonTokenTypeNull2()
        {
            var codec = new VariantEncoderFactory().Default;
            var str   = _serializer.FromObject(new {
                Type = "Float",
                Body = new float[0]
            });
            var variant  = codec.Decode(str, BuiltInType.Null);
            var expected = new Variant(new float[0]);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromArray(), encoded);
        }
        public void DecodeEncodeInt16ArrayFromVariantJsonTokenTypeVariantMsftEncoding()
        {
            var codec = new VariantEncoderFactory().Default;
            var str   = JToken.FromObject(new {
                dataType = "Int16",
                value    = new short[] { -123, -124, -125 }
            });
            var variant  = codec.Decode(str, BuiltInType.Variant);
            var expected = new Variant(new short[] { -123, -124, -125 });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JArray((short)-123, (short)-124, (short)-125), encoded);
        }
        public void DecodeEncodeFloatArrayFromStringTypeNumberIsDouble1()
        {
            var codec    = new VariantEncoderFactory().Default;
            var str      = "[-123.123, 124.124, 0.0]";
            var variant  = codec.Decode(str, BuiltInType.Number);
            var expected = new Variant(new Variant[] {
                new Variant(-123.123), new Variant(124.124), new Variant(0.0)
            });
            var encoded = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(_serializer.FromArray(-123.123, 124.124, 0.0),
                         encoded);
        }
Exemplo n.º 27
0
        public void DecodeEncodeUInt64FromVariantJsonTokenTypeNull()
        {
            var codec = new VariantEncoderFactory().Default;
            var str   = JToken.FromObject(new {
                Type = "UInt64",
                Body = 123Lu
            });
            var variant  = codec.Decode(str, BuiltInType.Null);
            var expected = new Variant(123Lu);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JValue(123Lu), encoded);
        }
Exemplo n.º 28
0
        public void DecodeEncodeUInt64ArrayFromVariantJsonTokenTypeVariantMsftEncoding()
        {
            var codec = new VariantEncoderFactory().Default;
            var str   = JToken.FromObject(new {
                dataType = "UInt64",
                value    = new ulong[] { 123Lu, 124Lu, 125Lu }
            });
            var variant  = codec.Decode(str, BuiltInType.Variant);
            var expected = new Variant(new ulong[] { 123Lu, 124Lu, 125Lu });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JArray(123Lu, 124Lu, 125Lu), encoded);
        }
Exemplo n.º 29
0
        public void DecodeEncodeUInt64FromVariantJsonStringTypeVariantMsftEncoding()
        {
            var codec = new VariantEncoderFactory().Default;
            var str   = JToken.FromObject(new {
                DataType = "UInt64",
                Value    = 123Lu
            }).ToString();
            var variant  = codec.Decode(str, BuiltInType.Variant);
            var expected = new Variant(123Lu);
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JValue(123Lu), encoded);
        }
Exemplo n.º 30
0
        public void DecodeEncodeUInt64ArrayFromVariantJsonStringTypeNull()
        {
            var codec = new VariantEncoderFactory().Default;
            var str   = JToken.FromObject(new {
                type = "UInt64",
                body = new ulong[] { 123Lu, 124Lu, 125Lu }
            }).ToString();
            var variant  = codec.Decode(str, BuiltInType.Null);
            var expected = new Variant(new ulong[] { 123Lu, 124Lu, 125Lu });
            var encoded  = codec.Encode(variant);

            Assert.Equal(expected, variant);
            Assert.Equal(new JArray(123Lu, 124Lu, 125Lu), encoded);
        }