public void Attributes_ShouldBeMapped() { var builder = new ElementMappingBuilder<Person>(Ns + "Person"); builder.Attribute("Id", x => x.Id); builder.Attribute("FirstName", x => x.FirstName); builder.Attribute("LastName", x => x.LastName); builder.Attribute("IsEnabled", x => x.IsEnabled, x => bool.Parse(x), x => x.ToString().ToLowerInvariant()); builder.CollectionElement(Ns + "ContactMethod", x => x.ContactMethods) .Attribute("Type", x => x.Type) .Attribute("Value", x => x.Value); var mapping = (ElementMapping<Person>)builder.Build(); mapping.LocalName.ShouldBe("Person"); mapping.NamespaceUri.ShouldBe(Ns.NamespaceName); mapping.Attributes.Length.ShouldBe(4); mapping.Attributes[0].ShouldBeTypeOf(typeof(AttributeMapping<Person, long?>)); mapping.Attributes[1].ShouldBeTypeOf(typeof(AttributeMapping<Person, string>)); mapping.Attributes[2].ShouldBeTypeOf(typeof(AttributeMapping<Person, string>)); mapping.Attributes[3].ShouldBeTypeOf(typeof(AttributeMapping<Person, bool>)); mapping.ChildElements.Length.ShouldBe(1); mapping.ChildElements[0].ShouldBeTypeOf(typeof(CollectionChildElementMapping<Person, ContactMethod>)); }
public void Elements_ShouldBeMapped() { var builder = new ElementMappingBuilder<Person>(Ns + "Person"); builder.Element(Ns + "Address", x => x.Address); var mapping = (ElementMapping<Person>)builder.Build(); mapping.ChildElements.Length.ShouldBe(1); mapping.ChildElements[0].ShouldBeTypeOf(typeof(ElementMapping<Address>)); }