Esempio n. 1
0
        public void OnlyReadDiff()
        {
            string xmlString = Framework.LoadInternalAsString <WithInclude>(XmlDiffData);

            var readData = new DataWithInclude()
            {
                Data = new DataWithInclude.DataImpl()
                {
                    PropertyNames = new Dictionary <string, string>()
                    {
                        { nameof(DataWithInclude.DataImpl.Name), "Login" },
                        { nameof(DataWithInclude.DataImpl.Note), "Info" },
                    }
                },
            };

            var readMapper = XmlMapper.Build(readData, "Data");

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments = true;
            settings.IgnoreProcessingInstructions = true;
            settings.IgnoreWhitespace             = true;

            using (XmlReader reader = XmlReader.Create(new StringReader(xmlString), settings))
            {
                readMapper.Read(reader);
            }

            Assert.That(readData.Data.Name, Is.EqualTo("Emiya"));
            Assert.That(readData.Data.Note, Is.EqualTo("simple"));
        }
        public void SetsElementFromComplexProperty()
        {
            var agencyMapper = new XmlMapper <Agency>
            {
                { "name", a => a.Name },
                { "country", a => a.Country },
            };

            var mapper = new XmlMapper <Spaceship>
            {
                { "agency", o => o.Owner, agencyMapper },
            };

            var spaceship = new Spaceship
            {
                Owner = new Agency
                {
                    Name    = "NASA",
                    Country = Country.USA
                }
            };

            var actual = mapper.ToXml(spaceship, "spaceship");

            var agency = actual.Element("agency");

            Assert.NotNull(agency);
            Assert.Equal("NASA", agency.Attribute("name").Value);
        }
        public void SetsAttributesFromCollectionItems()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "captainName", o => o.Crew[0].Name },
                { "pilotName", o => o.Crew[1].Name },
            };

            var spaceship = new Spaceship
            {
                Crew = new List <Astronaut>
                {
                    new Astronaut {
                        Name = "Neil Armstrong"
                    },
                    new Astronaut {
                        Name = "Michael Collins"
                    },
                }
            };

            var actual = mapper.ToXml(spaceship, "spaceship");

            Assert.Equal("Neil Armstrong", actual.Attribute("captainName").Value);
            Assert.Equal("Michael Collins", actual.Attribute("pilotName").Value);
        }
Esempio n. 4
0
        public IMapper CreateMapper(object data)
        {
            IMapper mapper;

            if (IsXml(data.ToString()))
            {
                mapper = new XmlMapper();
            }
            else if (IsJson(data.ToString()))
            {
                mapper = new JsonMapper();
            }
            else
            {
                if (data.GetType().IsPrimitive)
                {
                    mapper = new PocoMapper();
                }
                else
                {
                    mapper = new StringMapper();
                }
            }
            return(mapper);
        }
Esempio n. 5
0
        public void OnlyReadDiff()
        {
            string xmlString = Framework.LoadInternalAsString <WriteAndRead>(XmlDiffData);

            Data readData = new Data()
            {
                Self = new Person()
                {
                },
                Owner = new Person()
                {
                },
                Current = new Address()
                {
                },
                Notes = new List <Info>()
                {
                    new Info()
                    {
                    },
                    new Info()
                    {
                    },
                    new Info()
                    {
                    },
                    new Info()
                    {
                    },
                }
            };

            var readMapper = XmlMapper.Build(readData, nameof(Data));

            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreComments = true;
            settings.IgnoreProcessingInstructions = true;
            settings.IgnoreWhitespace             = true;

            using (XmlReader reader = XmlReader.Create(new StringReader(xmlString), settings))
            {
                readMapper.Read(reader);
            }

            Assert.That(readData.Self.Name, Is.EqualTo("Emiya"));
            Assert.That(readData.Self.Phone, Is.EqualTo("777"));
            Assert.That(readData.Owner.Name, Is.EqualTo("None"));
            Assert.That(readData.Owner.Phone, Is.EqualTo("*"));
            Assert.That(readData.Current.Data, Is.EqualTo("full address ..."));
            Assert.IsNotNull(readData.Notes);
            Assert.That(readData.Notes.Count, Is.EqualTo(4));
            Assert.That(readData.Notes[0].Note, Is.EqualTo("some 1"));
            Assert.That(readData.Notes[1].Note, Is.EqualTo("some 2"));
            Assert.That(readData.Notes[2].Note, Is.EqualTo("some 3"));
            Assert.That(readData.Notes[3].Note, Is.EqualTo("some 4"));
        }
Esempio n. 6
0
        public void MapXmlWithAttribute_Expected_PathToAttribute()
        {
            var xmlMapper = new XmlMapper();

            var xml   = Given();
            var paths = xmlMapper.Map(xml);

            Assert.IsTrue(paths.Any(p => p.ActualPath == "Company:Name"));
        }
        public IXmlSerializerConfiguration Apply()
        {
            if (_member == null && _target != null) _member = _target.Name;

            var map = new XmlMapper(_member, _targetType, _converter, _rootTarget);
            _mapper.Entries.Add(map);

            return _config;
        }
Esempio n. 8
0
        public void MapXmlWithScalarValue_Expected_PathToScalarValue()
        {
            var xmlMapper = new XmlMapper();

            var xml   = Given();
            var paths = xmlMapper.Map(xml);

            Assert.IsTrue(paths.Any(p => p.ActualPath == "Company.Motto"));
        }
Esempio n. 9
0
        public void MapXmlWithARecordsetAndAttributesOnTheRecordset_Expected_PathToAttributeOfRecordset()
        {
            XmlMapper xmlMapper = new XmlMapper();

            string xml = Given();
            IEnumerable <IPath> paths = xmlMapper.Map(xml);

            Assert.IsTrue(paths.Any(p => p.ActualPath == "Company.Departments:TestAttrib"));
        }
Esempio n. 10
0
        public void MapXmlWithARecordsetAndAttributesOnItemsInTheRecordset_Expected_PathToAttributeOfElementsInRecordset()
        {
            var xmlMapper = new XmlMapper();

            var xml   = Given();
            var paths = xmlMapper.Map(xml);

            Assert.IsTrue(paths.Any(p => p.ActualPath == "Company.Departments().Department:Name"));
        }
Esempio n. 11
0
        public void MapXmlWithAInlineRecordset_Expected_PathToItemsInInnerRecordset()
        {
            XmlMapper xmlMapper = new XmlMapper();

            string xml = Given();
            IEnumerable <IPath> paths = xmlMapper.Map(xml);

            Assert.IsTrue(paths.Any(p => p.ActualPath == "Company().InlineRecordSet"));
        }
Esempio n. 12
0
        public void MapXmlWithAttribute_Expected_PathToAttribute()
        {
            XmlMapper xmlMapper = new XmlMapper();

            string xml = Given();
            IEnumerable <IPath> paths = xmlMapper.Map(xml);

            Assert.IsTrue(paths.Any(p => p.ActualPath == "Company:Name"));
        }
Esempio n. 13
0
        public void MapXmlWithBlankScalarValue_Expected_PathToScalarValue()
        {
            XmlMapper xmlMapper = new XmlMapper();

            string xml = Given();
            IEnumerable <IPath> paths = xmlMapper.Map(xml);

            Assert.IsTrue(paths.Any(p => p.ActualPath == "Company.PreviousMotto"));
        }
Esempio n. 14
0
        public IXmlSerializerConfiguration Apply()
        {
            _member ??= _target.Name;

            var map = new XmlMapper(_member, _targetType, _converter, _root);

            _mapper.Entries.Add(map);

            return(_config);
        }
Esempio n. 15
0
        public void SetsDateTimePropertyUsingCustomConverter()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "launchDate", o => o.FirstLaunch, s => DateTime.Parse(s) },
            };
            var xml    = XElement.Parse(@"<spaceship launchDate=""16/7/1969""/>");
            var actual = mapper.ToObject(xml);

            Assert.Equal(new DateTime(1969, 7, 16), actual.FirstLaunch);
        }
Esempio n. 16
0
        public void OnlyWrite()
        {
            string xmlString = Framework.LoadInternalAsString <WriteAndRead>(XmlData);

            xmlString = Framework.ReplaceWhitespace(xmlString);

            var writeData = new Data()
            {
                Self = new Person()
                {
                    Name  = "Emiya",
                    Phone = "777",
                },
                Owner = new Person()
                {
                    Name  = "None",
                    Phone = "*",
                },
                Current = new Address()
                {
                    Data = "full address ...",
                },
                Notes = new List <Info>()
                {
                    new Info()
                    {
                        Note = "some 1"
                    },
                    new Info()
                    {
                        Note = "some 2"
                    },
                    new Info()
                    {
                        Note = "some 3"
                    },
                    new Info()
                    {
                        Note = "some 4"
                    },
                }
            };

            var writeMapper = XmlMapper.Build(writeData, nameof(Data));

            var builder = new StringBuilder();

            using (XmlWriter writer = XmlWriter.Create(builder))
            {
                writeMapper.Write(writer);
            }

            Assert.That(builder.ToString(), Is.EqualTo(xmlString));
        }
Esempio n. 17
0
    static void Main(string[] args)
    {
        XmlMapper xmlMapper = new XmlMapper("xml.xml");

        Console.WriteLine("TEST WITHOUT BLACKLIST:\n");
        xmlMapper.PrintMap();
        Console.WriteLine("\nTEST WITH BLACKLIST:\n");
        xmlMapper.PrintMap(new List <string>()
        {
            "P"
        });
    }
Esempio n. 18
0
        public void SetsStringProperty()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "name", o => o.Name },
            };

            var xml    = XElement.Parse(@"<spaceship name=""Apollo 11""/>");
            var actual = mapper.ToObject(xml);

            Assert.Equal("Apollo 11", actual.Name);
        }
Esempio n. 19
0
        public void SetsPropertyFromTwoElements()
        {
            var mapper = new XmlMapper <Astronaut>
            {
                { "fname", "lname", a => a.Name, (f, l) => string.Format("{0} {1}", f, l), s => Tuple.Create("", "") },
            };
            var xml = XElement.Parse(@"<astronaut fname=""Michael"" lname=""Collins""/>");

            var actual = mapper.ToObject(xml);

            Assert.Equal("Michael Collins", actual.Name);
        }
Esempio n. 20
0
        public void SetsInt32Property()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "year", o => o.Year },
            };

            var xml    = XElement.Parse(@"<spaceship year=""1969""/>");
            var actual = mapper.ToObject(xml);

            Assert.Equal(1969, actual.Year);
        }
        public void CreateElementFromNullObject()
        {
            var astronautMapper = new XmlMapper <Astronaut>
            {
                { "name", a => a.Name },
            };

            Astronaut astronaut = null;

            var actual = astronautMapper.ToXml(astronaut, "astronaut");

            Assert.Equal("<astronaut />", actual.ToString());
        }
Esempio n. 22
0
        public void SetsIndirectEnumProperty()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "agencyCountry", o => o.Owner.Country },
            };

            var xml = XElement.Parse(@"<spaceship agencyCountry=""USA""/>");

            var actual = mapper.ToObject(xml);

            Assert.Equal(Country.USA, actual.Owner.Country);
        }
        public void CreatesRootElement()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"name", o => o.Name},
                             };

            var obj = new Spaceship {Name = "Apollo 11"};

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal("spaceship", actual.Name);
        }
        public IXmlSerializerConfiguration Apply()
        {
            if (_member == null && _target != null)
            {
                _member = _target.Name;
            }

            var map = new XmlMapper(_member, _targetType, _converter, _rootTarget);

            _mapper.Entries.Add(map);

            return(_config);
        }
Esempio n. 25
0
        public void SetsIndirectStringProperty()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "agencyName", o => o.Owner.Name },
            };

            var xml = XElement.Parse(@"<spaceship agencyName=""NASA""/>");

            var actual = mapper.ToObject(xml);

            Assert.Equal("NASA", actual.Owner.Name);
        }
        public void CreateElementFromNullObject()
        {
            var astronautMapper = new XmlMapper<Astronaut>
                                      {
                                          {"name", a => a.Name},
                                      };

            Astronaut astronaut = null;

            var actual = astronautMapper.ToXml(astronaut, "astronaut");

            Assert.Equal("<astronaut />", actual.ToString());
        }
Esempio n. 27
0
        public void SelectEnumerableValuesAsRelatedUsingEnumerablePathFromXmlFromFoPrimitiveType()
        {
            var xmlDocument = new XmlDocument();

            xmlDocument.LoadXml("<boolean xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">false</boolean>");
            var testData     = Scrubber.Scrub(xmlDocument.InnerXml);
            var xmlMapper    = new XmlMapper();
            var paths        = xmlMapper.Map(testData).ToList();
            var path         = paths.FirstOrDefault();
            var xmlNavigator = new XmlNavigator(testData);
            var dat2         = xmlNavigator.SelectScalar(path);

            Assert.AreEqual("false", dat2);
        }
        public void CreatesRootElement()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "name", o => o.Name },
            };

            var obj = new Spaceship {
                Name = "Apollo 11"
            };

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal("spaceship", actual.Name);
        }
        public void SetsStringAttribute()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "name", o => o.Name },
            };

            var obj = new Spaceship {
                Name = "Apollo 11"
            };

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal("Apollo 11", actual.Attribute("name").Value);
        }
        public void SetsDateTimeAttributeWithJustCustomParser()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "firstLaunch", o => o.FirstLaunch, s => DateTime.Parse(s), p => p.ToString("yyyy-MM-dd") },
            };

            var obj = new Spaceship {
                FirstLaunch = new DateTime(1969, 7, 16)
            };

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal("1969-07-16", actual.Attribute("firstLaunch").Value);
        }
        public void SetsDateTimeAttribute()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "firstLaunch", o => o.FirstLaunch },
            };

            var obj = new Spaceship {
                FirstLaunch = new DateTime(1969, 7, 16)
            };

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal(obj.FirstLaunch.ToString(CultureInfo.CurrentCulture), actual.Attribute("firstLaunch").Value);
        }
        public void SetsIntAttribute()
        {
            var mapper = new XmlMapper <Spaceship>
            {
                { "year", o => o.Year },
            };

            var obj = new Spaceship {
                Year = 1969
            };

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal("1969", actual.Attribute("year").Value);
        }
        public void DoesNotOverwriteExistingObject()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"agencyName", o => o.Owner.Name},
                             };

            var xml = XElement.Parse(@"<spaceship agencyName=""NASA""/>");

            var original = new Spaceship {Owner = new Agency {Country = Country.USA}};
            var actual = mapper.ToObject(xml, original);

            Assert.Equal("NASA", actual.Owner.Name);
            Assert.Equal(Country.USA, actual.Owner.Country);
        }
Esempio n. 34
0
        private string ReplaceSql(string sql, object param)
        {
            string result = XmlMapper.GetCommandSql(sql);
            object order  = TypeUtility.GetPropertyValue(param, "Order");
            object group  = TypeUtility.GetPropertyValue(param, "Group");

            if (order != null)
            {
                result = result.Replace("{{ORDER}}", TypeUtility.ToString(order));
            }
            if (group != null)
            {
                result = result.Replace("{{GROUP}}", TypeUtility.ToString(group));
            }
            return(string.IsNullOrEmpty(result) ? sql : result);
        }
        public void SetsCollectionItemFromElement()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"captainName", o => o.Crew[0].Name},
                                 {"pilotName", o => o.Crew[1].Name},
                             };

            var xml = XElement.Parse(@"<spaceship captainName=""Neil Armstrong"" pilotName=""Michael Collins""/>");

            var actual = mapper.ToObject(xml);

            Assert.Equal(2, actual.Crew.Count);
            Assert.Equal("Neil Armstrong", actual.Crew[0].Name);
            Assert.Equal("Michael Collins", actual.Crew[1].Name);
        }
        public void SetsCollectionFromElement()
        {
            var astronautMapper = new XmlMapper<Astronaut>
                                      {
                                          {"name", a => a.Name},
                                      };

            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"crew/member", o => o.Crew, astronautMapper},
                             };

            var xml = XElement.Parse(@"<spaceship><crew><member name=""Buzz Aldrin""/><member name=""Neil Armstrong""/></crew></spaceship>");

            var actual = mapper.ToObject(xml);

            Assert.Equal(2, actual.Crew.Count);
            Assert.Contains("Buzz Aldrin", actual.Crew.Select(c => c.Name));
            Assert.Contains("Neil Armstrong", actual.Crew.Select(c => c.Name));
        }
        public void CreateElementFromNullCollection()
        {
            var astronautMapper = new XmlMapper<Astronaut>
                                      {
                                          {"name", a => a.Name},
                                      };

            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"crew/member", o => o.Crew, astronautMapper},
                             };

            var spaceship = new Spaceship
            {
                Crew = null,
            };

            var actual = mapper.ToXml(spaceship, "spaceship");

            Assert.Equal("<crew />", actual.Element("crew").ToString());
        }
        public void SetsAttributesFromCollectionItems()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"captainName", o => o.Crew[0].Name},
                                 {"pilotName", o => o.Crew[1].Name},
                             };

            var spaceship = new Spaceship
                                {
                                    Crew = new List<Astronaut>
                                               {
                                                   new Astronaut {Name = "Neil Armstrong"},
                                                   new Astronaut {Name = "Michael Collins"},
                                               }
                                };

            var actual = mapper.ToXml(spaceship, "spaceship");

            Assert.Equal("Neil Armstrong", actual.Attribute("captainName").Value);
            Assert.Equal("Michael Collins", actual.Attribute("pilotName").Value);
        }
        public void SetsStringProperty()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"name", o => o.Name},
                             };

            var xml = XElement.Parse(@"<spaceship name=""Apollo 11""/>");
            var actual = mapper.ToObject(xml);

            Assert.Equal("Apollo 11", actual.Name);
        }
        public void SetsStringAndInt32AndDateTimeProperty()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"name", o => o.Name},
                                 {"year", o => o.Year},
                                 {"launchDate", o => o.FirstLaunch, s => DateTime.Parse(s)},
                             };

            var xml = XElement.Parse(@"<spaceship name=""Apollo 11"" year=""1969"" launchDate=""16/7/1969""/>");

            var actual = mapper.ToObject(xml);

            Assert.Equal("Apollo 11", actual.Name);
            Assert.Equal(1969, actual.Year);
            Assert.Equal(new DateTime(1969,7,16), actual.FirstLaunch);
        }
Esempio n. 41
0
 public void Setup()
 {
     this.mapper = ConstructMapper();
 }
        public void SetsInt32Property()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"year", o => o.Year},
                             };

            var xml = XElement.Parse(@"<spaceship year=""1969""/>");
            var actual = mapper.ToObject(xml);

            Assert.Equal(1969, actual.Year);
        }
        public void SetsElementFromComplexProperty()
        {
            var agencyMapper = new XmlMapper<Agency>
                                   {
                                       {"name", a => a.Name},
                                       {"country", a => a.Country},
                                   };

            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"agency", o => o.Owner, agencyMapper},
                             };

            var spaceship = new Spaceship
                                {
                                    Owner = new Agency
                                                {
                                                    Name = "NASA",
                                                    Country = Country.USA
                                                }
                                };

            var actual = mapper.ToXml(spaceship, "spaceship");

            var agency = actual.Element("agency");
            Assert.NotNull(agency);
            Assert.Equal("NASA", agency.Attribute("name").Value);
        }
        public void SetsDateTimeAttributeWithJustCustomParser()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"firstLaunch", o => o.FirstLaunch, s => DateTime.Parse(s), p => p.ToString("yyyy-MM-dd")},
                             };

            var obj = new Spaceship { FirstLaunch = new DateTime(1969, 7, 16) };

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal("1969-07-16", actual.Attribute("firstLaunch").Value);
        }
        public void SetsDateTimePropertyUsingCustomConverter()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"launchDate", o => o.FirstLaunch, s => DateTime.Parse(s)},
                             };
            var xml = XElement.Parse(@"<spaceship launchDate=""16/7/1969""/>");
            var actual = mapper.ToObject(xml);

            Assert.Equal(new DateTime(1969,7,16), actual.FirstLaunch);
        }
        public void SetsElementsFromCollection()
        {
            var astronautMapper = new XmlMapper<Astronaut>
                                      {
                                          {"name", a => a.Name},
                                      };

            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"crew/member", o => o.Crew, astronautMapper},
                             };

            var spaceship = new Spaceship
                                {
                                    Crew = new List<Astronaut>
                                               {
                                                   new Astronaut {Name = "Buzz Aldrin"},
                                                   new Astronaut {Name = "Neil Armstrong"},
                                               }
                                };

            var actual = mapper.ToXml(spaceship, "spaceship");

            var crew = actual.Element("crew");
            Assert.NotNull(crew);
            Assert.Equal(2, crew.Elements("member").Count());

            Assert.Contains("Buzz Aldrin", crew.Elements("member").Select(x => x.Attribute("name").Value));
            Assert.Contains("Neil Armstrong", crew.Elements("member").Select(x => x.Attribute("name").Value));
        }
        public void SetsIntAttribute()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"year", o => o.Year},
                             };

            var obj = new Spaceship {Year = 1969};

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal("1969", actual.Attribute("year").Value);
        }
        public void SetsIndirectEnumProperty()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"agencyCountry", o => o.Owner.Country},
                             };

            var xml = XElement.Parse(@"<spaceship agencyCountry=""USA""/>");

            var actual = mapper.ToObject(xml);

            Assert.Equal(Country.USA, actual.Owner.Country);
        }
        public void SetsIndirectStringProperty()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"agencyName", o => o.Owner.Name},
                             };

            var xml = XElement.Parse(@"<spaceship agencyName=""NASA""/>");

            var actual = mapper.ToObject(xml);

            Assert.Equal("NASA", actual.Owner.Name);
        }
        public void SetsAttributeFromIndirectStringProperty()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"agencyName", o => o.Owner.Name},
                             };

            var spaceship = new Spaceship
                                {
                                    Owner = new Agency
                                                {
                                                    Name = "NASA"
                                                }
                                };

            var actual = mapper.ToXml(spaceship, "spaceship");

            Assert.Equal("NASA", actual.Attribute("agencyName").Value);
        }
        public void SetsStringAttribute()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"name", o => o.Name},
                             };

            var obj = new Spaceship {Name = "Apollo 11"};

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal("Apollo 11", actual.Attribute("name").Value);
        }
        public void SetsTwoAttributesFromProperty()
        {
            var mapper = new XmlMapper<Astronaut>
                             {
                                 {"fname", "lname", a => a.Name, (f,l) => string.Format("{0} {1}", f, l), s => Split(s)},
                             };

            var astronaut = new Astronaut {Name = "Michael Collins"};

            var actual = mapper.ToXml(astronaut, "astronaut");

            Assert.Equal("Michael", actual.Attribute("fname").Value);
            Assert.Equal("Collins", actual.Attribute("lname").Value);
        }
        public void SetsPropertyFromTwoElements()
        {
            var mapper = new XmlMapper<Astronaut>
                             {
                                 {"fname", "lname", a => a.Name, (f,l) => string.Format("{0} {1}", f, l), s => Tuple.Create("","")},
                             };
            var xml = XElement.Parse(@"<astronaut fname=""Michael"" lname=""Collins""/>");

            var actual = mapper.ToObject(xml);

            Assert.Equal("Michael Collins", actual.Name);
        }
        public void SetsComplexPropertyFromElement()
        {
            var agencyMapper = new XmlMapper<Agency>
                                   {
                                       {"name", a => a.Name},
                                       {"country", a => a.Country},
                                   };

            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"agency", o => o.Owner, agencyMapper},
                             };

            var xml = XElement.Parse(@"<spaceship><agency name=""NASA"" country=""USA""/></spaceship>");

            var actual = mapper.ToObject(xml);

            Assert.Equal(Country.USA, actual.Owner.Country);
        }
        public void SetsDateTimeAttribute()
        {
            var mapper = new XmlMapper<Spaceship>
                             {
                                 {"firstLaunch", o => o.FirstLaunch},
                             };

            var obj = new Spaceship { FirstLaunch = new DateTime(1969, 7, 16) };

            var actual = mapper.ToXml(obj, "spaceship");

            Assert.Equal(obj.FirstLaunch.ToString(CultureInfo.CurrentCulture), actual.Attribute("firstLaunch").Value);
        }