Ejemplo n.º 1
0
        public void TestToXml()
        {
            Envelop envelop = new Envelop()
            {
                Created = new DateTime(2012, 11, 18, 13, 0, 0),
                Message = new Person()
                {
                    Id        = 123,
                    FirstName = "Hugh",
                    LastName  = "Laurie"
                }
            };

            string xml = envelop.ToXml(emitTypeInfo: true);

            var doc = XDocument.Parse(xml);

            var resolver = new XmlNamespaceManager(new NameTable());

            resolver.AddNamespace("t", "http://Transport");
            resolver.AddNamespace("b", "http://Business");

            var elementInner = doc.XPathSelectElement("/t:Envelop/t:Message/b:Person/b:LastName", resolver);

            Assert.AreEqual("Laurie", elementInner.Value);
        }
Ejemplo n.º 2
0
        public void TestLoadFromXml()
        {
            string xml = @"<Envelop p1:created='2012-11-18T13:00:00.0000000' xmlns:p1='http://Transport' xmlns='http://Transport'>
  <p1:Message p3:__type='Artemkv.Transformation.XmlToObject.Test.Examples.Namespaces.Person, Artemkv.Transformation.XmlToObject.Test, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' xmlns:p3='http://xmltoobject.codeplex.com'>
    <Person p1:id='123' xmlns='http://Business'>
      <FirstName p3:__type='System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>Hugh</FirstName>
      <LastName p3:__type='System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>Laurie</LastName>
    </Person>
  </p1:Message>
</Envelop>";

            Envelop envelop = XmlSerialization.LoadFromXml <Envelop>(xml);

            Assert.AreEqual("Laurie", (envelop.Message as Person).LastName);
        }