public void ReadWriteDatavalueWithStringStream()
        {
            // Create dummy
            var expected = new DataValue(new Variant("TestTestTestTest"
                                                     + Guid.NewGuid()));
            var count = 10000;

            byte[] buffer;
            var    context = new ServiceMessageContext();

            using (var stream = new MemoryStream()) {
                using (var encoder = new JsonEncoderEx(stream, context,
                                                       JsonEncoderEx.JsonEncoding.Array)) {
                    for (var i = 0; i < count; i++)
                    {
                        encoder.WriteDataValue(null, expected);
                    }
                }
                buffer = stream.ToArray();
            }
            using (var stream = new MemoryStream(buffer)) {
                using (var decoder = new JsonDecoderEx(stream, context)) {
                    for (var i = 0; i < count; i++)
                    {
                        var result = decoder.ReadDataValue(null);
                        Assert.Equal(expected, result);
                    }
                    var eof = decoder.ReadDataValue(null);
                    Assert.Null(eof);
                }
            }
        }
        public void ReadWriteDataValueDictionary()
        {
            // Create dummy
            var expected = new Dictionary <string, DataValue> {
                ["abcd"] = new DataValue(new Variant(1234), StatusCodes.Good, DateTime.Now, DateTime.UtcNow),
                ["http://microsoft.com"]      = new DataValue(new Variant(-222222222), StatusCodes.Bad, DateTime.MinValue, DateTime.Now),
                ["1111111111111111111111111"] = new DataValue(new Variant(false), StatusCodes.Bad, DateTime.UtcNow, DateTime.MinValue),
                ["@#$%^&*()_+~!@#$%^*(){}"]   = new DataValue(new Variant(new byte[] { 0, 2, 4, 6 }), StatusCodes.Good),
                ["1245"] = new DataValue(new Variant("hello"), StatusCodes.Bad, DateTime.Now, DateTime.MinValue),
                ["..."]  = new DataValue(new Variant(new Variant("imbricated"))),
            };

            var count = 10000;

            byte[] buffer;
            var    context = new ServiceMessageContext();

            using (var stream = new MemoryStream()) {
                using (var encoder = new JsonEncoderEx(stream, context,
                                                       JsonEncoderEx.JsonEncoding.Array)) {
                    for (var i = 0; i < count; i++)
                    {
                        encoder.WriteDataValueDictionary(null, expected);
                    }
                }
                buffer = stream.ToArray();
            }
            // convert DataValue timestamps to OpcUa Utc
            var expectedResult = new Dictionary <string, DataValue>();

            foreach (var entry in expected)
            {
                expectedResult[entry.Key] = new DataValue(entry.Value).ToOpcUaUniversalTime();
            }
            using (var stream = new MemoryStream(buffer)) {
                using (var decoder = new JsonDecoderEx(stream, context)) {
                    for (var i = 0; i < count; i++)
                    {
                        var result = decoder.ReadDataValueDictionary(null);
                        Assert.Equal(expectedResult, result);
                    }
                    var eof = decoder.ReadDataValue(null);
                    Assert.Null(eof);
                }
            }
        }