예제 #1
0
        public void MutlilevelObjectsWithNamespacesSerializationTest()
        {
            const string result =
                @"<MutlilevelObjectsWithNamespaces xmlns:ch1=""http://namespace.org/ch1"" xmlns:ch2=""http://namespace.org/ch2"" xmlns=""http://namespace.org/default"">
  <Parent1>
    <ch1:Child1 ch2:Value3=""Value3"">
      <ch1:Field1>Field1</ch1:Field1>
      <ch1:Field2>Field2</ch1:Field2>
      <ch2:Value1>Value1</ch2:Value1>
      <ch2:Value2>Value2</ch2:Value2>
    </ch1:Child1>
  </Parent1>
  <Parent2>
    <ch2:Child2>
      <ch2:Value4>Value4</ch2:Value4>
    </ch2:Child2>
  </Parent2>
</MutlilevelObjectsWithNamespaces>";

            var serializer = new YAXSerializer(typeof(MutlilevelObjectsWithNamespaces),
                                               YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning,
                                               YAXSerializationOptions.SerializeNullObjects);
            var got = serializer.Serialize(MutlilevelObjectsWithNamespaces.GetSampleInstance());

            Assert.That(got, Is.EqualTo(result));
        }
예제 #2
0
        public void MutlilevelObjectsWithNamespacesDeserializationTest()
        {
            var    serializer   = new YAXSerializer(typeof(MutlilevelObjectsWithNamespaces), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects);
            string got          = serializer.Serialize(MutlilevelObjectsWithNamespaces.GetSampleInstance());
            var    deserialized = serializer.Deserialize(got) as MutlilevelObjectsWithNamespaces;

            Assert.That(deserialized, Is.Not.Null);
            Assert.That(serializer.ParsingErrors, Has.Count.EqualTo(0));
        }