public void ReadWriteProgramDiagnostic2DataTypeStream()
        {
            // Create dummy type
            var expected = new ProgramDiagnostic2DataType {
                CreateClientName         = "Testname",
                CreateSessionId          = new NodeId(Guid.NewGuid()),
                InvocationCreationTime   = DateTime.UtcNow,
                LastMethodCall           = "swappido",
                LastMethodCallTime       = DateTime.UtcNow,
                LastMethodInputArguments = new ArgumentCollection {
                    new Argument("something1",
                                 new NodeId(2354), -1, "somedesciroeioi")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("something2",
                                 new NodeId(23), -1, "fdsadfsdaf")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("something3",
                                 new NodeId(44), 1, "fsadf  sadfsdfsadfsd")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("something4",
                                 new NodeId(23), 1, "dfad  sdafdfdf  fasdf")
                    {
                        ArrayDimensions = new uint[0]
                    }
                },
                LastMethodInputValues = new VariantCollection {
                    new Variant(4L),
                    new Variant("test"),
                    new Variant(new long[] { 1, 2, 3, 4, 5 }),
                    new Variant(new string[] { "1", "2", "3", "4", "5" })
                },
                LastMethodOutputArguments = new ArgumentCollection {
                    new Argument("foo1",
                                 new NodeId(2354), -1, "somedesciroeioi")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("foo2",
                                 new NodeId(33), -1, "fdsadfsdaf")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("adfsdafsdsdsafdsfa",
                                 new NodeId("absc"), 1, "fsadf  sadfsdfsadfsd")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("ddddd",
                                 new NodeId(25), 1, "dfad  sdafdfdf  fasdf")
                    {
                        ArrayDimensions = new uint[0]
                    }
                },
                LastMethodOutputValues = new VariantCollection {
                    new Variant(4L),
                    new Variant("test"),
                    new Variant(new long[] { 1, 2, 3, 4, 5 }),
                    new Variant(new string[] { "1", "2", "3", "4", "5" })
                },
                LastMethodReturnStatus =
                    StatusCodes.BadAggregateConfigurationRejected,
                LastMethodSessionId = new NodeId(
                    Utils.Nonce.CreateNonce(32)),
                LastTransitionTime = DateTime.UtcNow - TimeSpan.FromDays(23)
            };

            var count = 100;

            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.WriteEncodeable(null, expected, expected.GetType());
                    }
                }
                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.ReadEncodeable(null, expected.GetType());
                        Assert.True(result.IsEqual(expected));
                    }
                    var eof = decoder.ReadEncodeable(null, expected.GetType());
                    Assert.Null(eof);
                }
            }
        }
        public void ReadWriteProgramDiagnostic2DataType(string encoderType, string decoderType)
        {
            // Create dummy type
            var expected = new ProgramDiagnostic2DataType {
                CreateClientName         = "Testname",
                CreateSessionId          = new NodeId(Guid.NewGuid()),
                InvocationCreationTime   = DateTime.UtcNow,
                LastMethodCall           = "swappido",
                LastMethodCallTime       = DateTime.UtcNow,
                LastMethodInputArguments = new ArgumentCollection {
                    new Argument("something1",
                                 new NodeId(2354), -1, "somedesciroeioi")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("something2",
                                 new NodeId(23), -1, "fdsadfsdaf")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("something3",
                                 new NodeId(44), 1, "fsadf  sadfsdfsadfsd")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("something4",
                                 new NodeId(23), 1, "dfad  sdafdfdf  fasdf")
                    {
                        ArrayDimensions = new uint[0]
                    }
                },
                LastMethodInputValues = new VariantCollection {
                    new Variant(4L),
                    new Variant("test"),
                    new Variant(new long[] { 1, 2, 3, 4, 5 }),
                    new Variant(new string[] { "1", "2", "3", "4", "5" })
                },
                LastMethodOutputArguments = new ArgumentCollection {
                    new Argument("foo1",
                                 new NodeId(2354), -1, "somedesciroeioi")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("foo2",
                                 new NodeId(33), -1, "fdsadfsdaf")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("adfsdafsdsdsafdsfa",
                                 new NodeId("absc"), 1, "fsadf  sadfsdfsadfsd")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("ddddd",
                                 new NodeId(25), 1, "dfad  sdafdfdf  fasdf")
                    {
                        ArrayDimensions = new uint[0]
                    }
                },
                LastMethodOutputValues = new VariantCollection {
                    new Variant(4L),
                    new Variant("test"),
                    new Variant(new long[] { 1, 2, 3, 4, 5 }),
                    new Variant(new string[] { "1", "2", "3", "4", "5" })
                },
                LastMethodReturnStatus = new StatusResult(
                    StatusCodes.BadAggregateConfigurationRejected),
                LastMethodSessionId = new NodeId(
                    Utils.Nonce.CreateNonce(32)),
                LastTransitionTime = DateTime.UtcNow - TimeSpan.FromDays(23)
            };

            CreateSerializers(out var encoder, out var decoder);

            var buffer = encoder.Encode(encoderType, e => e.WriteEncodeable("test", expected, typeof(ProgramDiagnostic2DataType)));
            var result = decoder.Decode(decoderType, buffer, d => d.ReadEncodeable("test", typeof(ProgramDiagnostic2DataType)));

            Assert.True(result.IsEqual(expected));
        }
        public void ReadWriteProgramDiagnostic2DataTypeAsExtensionObject()
        {
            // Create dummy type
            var type = new ProgramDiagnostic2DataType {
                CreateClientName         = "Testname",
                CreateSessionId          = new NodeId(Guid.NewGuid()),
                InvocationCreationTime   = DateTime.UtcNow,
                LastMethodCall           = "swappido",
                LastMethodCallTime       = DateTime.UtcNow,
                LastMethodInputArguments = new ArgumentCollection {
                    new Argument("something1",
                                 new NodeId(2354), -1, "somedesciroeioi")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("something2",
                                 new NodeId(23), -1, "fdsadfsdaf")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("something3",
                                 new NodeId(44), 1, "fsadf  sadfsdfsadfsd")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("something4",
                                 new NodeId(23), 1, "dfad  sdafdfdf  fasdf")
                    {
                        ArrayDimensions = new uint[0]
                    }
                },
                LastMethodInputValues = new VariantCollection {
                    new Variant(4L),
                    new Variant("test"),
                    new Variant(new long[] { 1, 2, 3, 4, 5 }),
                    new Variant(new string[] { "1", "2", "3", "4", "5" })
                },
                LastMethodOutputArguments = new ArgumentCollection {
                    new Argument("foo1",
                                 new NodeId(2354), -1, "somedesciroeioi")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("foo2",
                                 new NodeId(33), -1, "fdsadfsdaf")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("adfsdafsdsdsafdsfa",
                                 new NodeId("absc"), 1, "fsadf  sadfsdfsadfsd")
                    {
                        ArrayDimensions = new uint[0]
                    },
                    new Argument("ddddd",
                                 new NodeId(25), 1, "dfad  sdafdfdf  fasdf")
                    {
                        ArrayDimensions = new uint[0]
                    }
                },
                LastMethodOutputValues = new VariantCollection {
                    new Variant(4L),
                    new Variant("test"),
                    new Variant(new long[] { 1, 2, 3, 4, 5 }),
                    new Variant(new string[] { "1", "2", "3", "4", "5" })
                },
                LastMethodReturnStatus = new StatusResult(
                    StatusCodes.BadAggregateConfigurationRejected),
                LastMethodSessionId = new NodeId(
                    Opc.Ua.Utils.Nonce.CreateNonce(32)),
                LastTransitionTime = DateTime.UtcNow - TimeSpan.FromDays(23)
            };
            var expected = new ExtensionObject(type);
            var json     = Serializer.SerializeObject(expected);
            var result   = Serializer.DeserializeObject <ExtensionObject>(json);

            Assert.Equal(result, expected);
        }