public void VerifyThatSerializationofOperationsWorks()
        {
            this.serializer = new Cdp4JsonSerializer(this.metadataprovider, new Version(1, 1, 0));

            var postoperation = new TestPostOperation();

            this.engModel           = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri);
            this.book1              = new Book(Guid.NewGuid(), this.cache, this.uri);
            this.book2              = new Book(Guid.NewGuid(), this.cache, this.uri);
            this.section1           = new Section(Guid.NewGuid(), this.cache, this.uri);
            this.section1.ShortName = "SS1";

            this.engModel.Book.Add(this.book1);
            this.engModel.Book.Add(this.book2);
            this.book2.Section.Add(this.section1);

            var iteration             = new Iteration(Guid.NewGuid(), this.cache, this.uri);
            var ed                    = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri);
            var parameter             = new Parameter(Guid.NewGuid(), this.cache, this.uri);
            var parameterSubscription = new ParameterSubscription(Guid.NewGuid(), this.cache, this.uri);
            var valueset              = new ParameterValueSet(Guid.NewGuid(), this.cache, this.uri);
            var subscriptionValueset  = new ParameterSubscriptionValueSet(Guid.NewGuid(), this.cache, this.uri);
            var valuearrayvalues      = new[] { "123", "456", "789.0" };

            valueset.Manual    = new ValueArray <string>(valuearrayvalues);
            valueset.Reference = new ValueArray <string>(valuearrayvalues);
            valueset.Computed  = new ValueArray <string>(valuearrayvalues);
            valueset.Formula   = new ValueArray <string>(valuearrayvalues);
            valueset.Published = new ValueArray <string>(valuearrayvalues);

            subscriptionValueset.Manual             = new ValueArray <string>(valuearrayvalues);
            subscriptionValueset.SubscribedValueSet = valueset;

            this.engModel.Iteration.Add(iteration);
            iteration.Element.Add(ed);
            ed.Parameter.Add(parameter);
            parameter.ValueSet.Add(valueset);
            parameter.ParameterSubscription.Add(parameterSubscription);
            parameterSubscription.ValueSet.Add(subscriptionValueset);

            postoperation.Update.Add(ClasslessDtoFactory.FullFromThing(this.metadataprovider, subscriptionValueset.ToDto()));
            postoperation.Update.Add(ClasslessDtoFactory.FullFromThing(this.metadataprovider, parameterSubscription.ToDto()));
            postoperation.Create.Add(valueset.ToDto());
            postoperation.Delete.Add(ClasslessDtoFactory.FullFromThing(this.metadataprovider, ed.ToDto()));

            using (var memoryStream = new MemoryStream())
            {
                this.serializer.SerializeToStream(postoperation, memoryStream);

                // necessary
                memoryStream.Position = 0;

                var result = this.serializer.Deserialize <TestPostOperation>(memoryStream);
                Assert.AreEqual(1, result.Delete.Count);
                Assert.AreEqual(1, result.Create.Count);
                Assert.AreEqual(2, result.Update.Count);

                var subscriptionValueSetClasslessDto =
                    result.Update.Single(x => x["Iid"].ToString() == subscriptionValueset.Iid.ToString());

                var valueArray = (ValueArray <string>)subscriptionValueSetClasslessDto["Manual"];
                Assert.IsTrue(subscriptionValueSetClasslessDto["Iid"] is Guid);
                Assert.IsTrue(subscriptionValueSetClasslessDto["ClassKind"] is ClassKind);
                Assert.AreEqual(3, valueArray.Count());
                Assert.AreEqual("123", valueArray[0]);
                Assert.AreEqual("456", valueArray[1]);
                Assert.AreEqual("789.0", valueArray[2]);
            }
        }
        public void VerifyThatSerializationOfDtosWorks()
        {
            this.serializer = new Cdp4JsonSerializer(this.metadataprovider, new Version(1, 1, 0));

            this.engModel           = new EngineeringModel(Guid.NewGuid(), this.cache, this.uri);
            this.book1              = new Book(Guid.NewGuid(), this.cache, this.uri);
            this.book2              = new Book(Guid.NewGuid(), this.cache, this.uri);
            this.section1           = new Section(Guid.NewGuid(), this.cache, this.uri);
            this.section1.ShortName = "SS1";

            this.engModel.Book.Add(this.book1);
            this.engModel.Book.Add(this.book2);
            this.book2.Section.Add(this.section1);

            var iteration             = new Iteration(Guid.NewGuid(), this.cache, this.uri);
            var ed                    = new ElementDefinition(Guid.NewGuid(), this.cache, this.uri);
            var parameter             = new Parameter(Guid.NewGuid(), this.cache, this.uri);
            var parameterSubscription = new ParameterSubscription(Guid.NewGuid(), this.cache, this.uri);
            var valueset              = new ParameterValueSet(Guid.NewGuid(), this.cache, this.uri);
            var subscriptionValueset  = new ParameterSubscriptionValueSet(Guid.NewGuid(), this.cache, this.uri);
            var valuearrayvalues      = new[] { "123", "456", "789.0" };

            valueset.Manual    = new ValueArray <string>(valuearrayvalues);
            valueset.Reference = new ValueArray <string>(valuearrayvalues);
            valueset.Computed  = new ValueArray <string>(valuearrayvalues);
            valueset.Formula   = new ValueArray <string>(valuearrayvalues);
            valueset.Published = new ValueArray <string>(valuearrayvalues);

            subscriptionValueset.Manual = new ValueArray <string>(valuearrayvalues);

            this.engModel.Iteration.Add(iteration);
            iteration.Element.Add(ed);
            ed.Parameter.Add(parameter);
            parameter.ValueSet.Add(valueset);
            parameter.ParameterSubscription.Add(parameterSubscription);
            parameterSubscription.ValueSet.Add(subscriptionValueset);

            var list = new List <Dto.Thing>
            {
                this.engModel.ToDto(),
                this.book1.ToDto(),
                this.book2.ToDto(),
                this.section1.ToDto(),
                iteration.ToDto(),
                ed.ToDto(),
                parameter.ToDto(),
                parameterSubscription.ToDto(),
                valueset.ToDto(),
                subscriptionValueset.ToDto()
            };

            using (var memoryStream = new MemoryStream())
            {
                this.serializer.SerializeToStream(list, memoryStream);

                // necessary
                memoryStream.Position = 0;

                var resDtos = this.serializer.Deserialize(memoryStream).ToList();

                Assert.AreEqual(10, resDtos.Count);
                var resEngineeringModel     = resDtos.OfType <Dto.EngineeringModel>().Single();
                var resBook1                = resDtos.OfType <Dto.Book>().Single(x => x.Iid == this.book1.Iid);
                var resBook2                = resDtos.OfType <Dto.Book>().Single(x => x.Iid == this.book2.Iid);
                var resSection              = resDtos.OfType <Dto.Section>().Single();
                var resSubscriptionValueset = resDtos.OfType <Dto.ParameterSubscriptionValueSet>().Single();

                Assert.AreEqual(resSection.ShortName, this.section1.ShortName);
                Assert.IsTrue(resBook2.Section.Any(x => x.V.ToString() == this.section1.Iid.ToString()));
                Assert.IsTrue(resEngineeringModel.Book.Any(x => x.V.ToString() == this.book1.Iid.ToString()));
                Assert.IsTrue(resEngineeringModel.Book.Any(x => x.V.ToString() == this.book2.Iid.ToString()));

                Assert.AreEqual(resSubscriptionValueset.Manual, new ValueArray <string>(valuearrayvalues));
            }
        }