Example #1
0
        public void SimplPolymorphicCompositeFollowsTagNameConventions()
        {
            // case A: We have an ITC in the polymorphic class

            // Create the object
            var ourObjCaseA = new InternalPolymorphicCompositeTestClass(4, true);

            // Make sure that we created it correctly
            Assert.IsTrue(ourObjCaseA.polyMorph.GetType().Equals(typeof(InternalTestClass)), "Type should be internalTestClass");

            // Create the sts
            var ourSTS = new SimplTypesScope("CompositeWithPolymorph", new[] { typeof(InternalTestClass), typeof(InternalCompositeTestClass), typeof(InternalPolymorphicCompositeTestClass) });

            // Serialize it, get the XML representation, parse it
            var      resultStream = TestMethods.TestSerialization(ourObjCaseA, Format.Xml);
            string   xmlString    = resultStream.StringData;
            XElement xe           = XElement.Parse(xmlString);

            // polyMorph => poly_morph. And we should expect that element in our serialized representation.
            Assert.IsTrue(xe.Elements("poly_morph").Any(), "Should have an XML composite element \"poly_morph\"");

            // Okay, let's do case B, an Internal Composite inside. ;D
            var ourObjCaseB = new InternalPolymorphicCompositeTestClass(5, false);

            // Yes, I know this could probably be a seperate method. Just putting it here beacuse it fit in the moment.
            // Feel free to refactor if it tickles your fancy as such.

            // Serialize it, get the XML representation, parse it
            var      resultStreamCaseB = TestMethods.TestSerialization(ourObjCaseB, Format.Xml);
            string   xmlStringCaseB    = resultStreamCaseB.StringData;
            XElement xeCaseB           = XElement.Parse(xmlStringCaseB);

            // polyMorph => poly_morph. And we should expect that element in our serialized representation.
            Assert.IsTrue(xeCaseB.Elements("poly_morph").Any(), "Should have an XML composite element \"poly_morph\"");

            // We'll defer these tests to the end; if we have a failure earlier we'll end up getting a deserialized null
            // because we fail hard if we don't serialize the type name correctly.
            TestMethods.TestSimplObject(ourObjCaseA, ourSTS);
            TestMethods.TestSimplObject(ourObjCaseB, ourSTS);
        }
Example #2
0
        public void SimplPolymorphicCompositeFieldDescriptorFollowsTagNameConventions()
        {
            // The case below double covers this slightly, but this makes the issue a bit easier to uncover.


            var v = new InternalPolymorphicCompositeTestClass(3, true);

            ClassDescriptor cd = ClassDescriptor.GetClassDescriptor(v);

            var polymorphicField = cd.FieldDescriptorByFieldName["polyMorph"];

            Assert.AreEqual("polyMorph", polymorphicField.Name, "Name incorrect!");
            Assert.AreEqual("poly_morph", polymorphicField.TagName, "Tag name incorrect!");

            Assert.IsTrue(polymorphicField.IsPolymorphic, "Should be polymorphic!");


            var psuedoDescriptor = ClassDescriptor.GetClassDescriptor(v.polyMorph).PseudoFieldDescriptor;

            Assert.AreEqual("polyMorph", psuedoDescriptor.Name, "Psuedo Descriptor is wrecking life.");
            Assert.AreEqual("poly_morph", psuedoDescriptor.TagName, "Psuedo descriptor is again messing stuff up.");
        }
Example #3
0
        public void SimplPolymorphicCompositeFollowsTagNameConventions()
        {
            // case A: We have an ITC in the polymorphic class

            // Create the object
            var ourObjCaseA = new InternalPolymorphicCompositeTestClass(4, true);

            // Make sure that we created it correctly
            Assert.IsTrue(ourObjCaseA.polyMorph.GetType().Equals(typeof(InternalTestClass)), "Type should be internalTestClass");

            // Create the sts
            var ourSTS = new SimplTypesScope("CompositeWithPolymorph", new[] { typeof(InternalTestClass), typeof(InternalCompositeTestClass), typeof(InternalPolymorphicCompositeTestClass) });

            // Serialize it, get the XML representation, parse it
            var resultStream = TestMethods.TestSerialization(ourObjCaseA, Format.Xml);
            string xmlString = resultStream.StringData;
            XElement xe = XElement.Parse(xmlString);

            // polyMorph => poly_morph. And we should expect that element in our serialized representation.
            Assert.IsTrue(xe.Elements("poly_morph").Any(), "Should have an XML composite element \"poly_morph\"");

            // Okay, let's do case B, an Internal Composite inside. ;D
            var ourObjCaseB = new InternalPolymorphicCompositeTestClass(5, false);

            // Yes, I know this could probably be a seperate method. Just putting it here beacuse it fit in the moment.
            // Feel free to refactor if it tickles your fancy as such.

            // Serialize it, get the XML representation, parse it
            var resultStreamCaseB = TestMethods.TestSerialization(ourObjCaseB, Format.Xml);
            string xmlStringCaseB =  resultStreamCaseB.StringData;
            XElement xeCaseB = XElement.Parse(xmlStringCaseB);

            // polyMorph => poly_morph. And we should expect that element in our serialized representation.
            Assert.IsTrue(xeCaseB.Elements("poly_morph").Any(), "Should have an XML composite element \"poly_morph\"");

            // We'll defer these tests to the end; if we have a failure earlier we'll end up getting a deserialized null
            // because we fail hard if we don't serialize the type name correctly.
            TestMethods.TestSimplObject(ourObjCaseA, ourSTS);
            TestMethods.TestSimplObject(ourObjCaseB, ourSTS);
        }
Example #4
0
        public void SimplPolymorphicCompositeFieldDescriptorFollowsTagNameConventions()
        {
            // The case below double covers this slightly, but this makes the issue a bit easier to uncover.

            var v = new InternalPolymorphicCompositeTestClass(3,true);

            ClassDescriptor cd = ClassDescriptor.GetClassDescriptor(v);

            var polymorphicField = cd.FieldDescriptorByFieldName["polyMorph"];

            Assert.AreEqual("polyMorph", polymorphicField.Name, "Name incorrect!");
            Assert.AreEqual("poly_morph",polymorphicField.TagName,"Tag name incorrect!");

            Assert.IsTrue(polymorphicField.IsPolymorphic, "Should be polymorphic!");

            var psuedoDescriptor = ClassDescriptor.GetClassDescriptor(v.polyMorph).PseudoFieldDescriptor;

            Assert.AreEqual("polyMorph", psuedoDescriptor.Name, "Psuedo Descriptor is wrecking life.");
            Assert.AreEqual("poly_morph", psuedoDescriptor.TagName, "Psuedo descriptor is again messing stuff up.");
        }