예제 #1
0
        public void DeserializeVerifyElementOrdering()
        {
            var serializer = MessageSerializer.Get(typeof(Mocks.TestDerivedMessage));
            Dictionary <string, string> fields = new Dictionary <string, string>(StringComparer.Ordinal);

            // We deliberately do this OUT of order,
            // since DataContractSerializer demands elements to be in
            // 1) inheritance then 2) alphabetical order.
            // Proper xml element order would be: Name, age, Second..., TheFirst...
            fields["TheFirstDerivedElement"] = "first";
            fields["age"]  = "15";
            fields["Name"] = "Andrew";
            fields["SecondDerivedElement"] = "second";
            fields["explicit"]             = "explicitValue";
            fields["private"] = "privateValue";
            var actual = new Mocks.TestDerivedMessage();

            serializer.Deserialize(fields, this.MessageDescriptions.GetAccessor(actual));
            Assert.AreEqual(15, actual.Age);
            Assert.AreEqual("Andrew", actual.Name);
            Assert.AreEqual("first", actual.TheFirstDerivedElement);
            Assert.AreEqual("second", actual.SecondDerivedElement);
            Assert.AreEqual("explicitValue", ((Mocks.IBaseMessageExplicitMembers)actual).ExplicitProperty);
            Assert.AreEqual("privateValue", actual.PrivatePropertyAccessor);
        }
 public void DeserializeVerifyElementOrdering()
 {
     var serializer = MessageSerializer.Get(typeof(Mocks.TestDerivedMessage));
     Dictionary<string, string> fields = new Dictionary<string, string>(StringComparer.Ordinal);
     // We deliberately do this OUT of order,
     // since DataContractSerializer demands elements to be in
     // 1) inheritance then 2) alphabetical order.
     // Proper xml element order would be: Name, age, Second..., TheFirst...
     fields["TheFirstDerivedElement"] = "first";
     fields["age"] = "15";
     fields["Name"] = "Andrew";
     fields["SecondDerivedElement"] = "second";
     fields["explicit"] = "explicitValue";
     fields["private"] = "privateValue";
     var actual = new Mocks.TestDerivedMessage();
     serializer.Deserialize(fields, this.MessageDescriptions.GetAccessor(actual));
     Assert.AreEqual(15, actual.Age);
     Assert.AreEqual("Andrew", actual.Name);
     Assert.AreEqual("first", actual.TheFirstDerivedElement);
     Assert.AreEqual("second", actual.SecondDerivedElement);
     Assert.AreEqual("explicitValue", ((Mocks.IBaseMessageExplicitMembers)actual).ExplicitProperty);
     Assert.AreEqual("privateValue", actual.PrivatePropertyAccessor);
 }