public void SetOnContainer_ShouldWriteToContainer()
        {
            var person = new Person();
            var mapping = new ChildElementMapping<Person, Address>(Ns + "Address", x => x.Address);
            var expected = new Address {StreetName = "231 Queen Street", City = "Auckland"};

            mapping.SetOnContainer(person, expected);

            person.Address.ShouldBe(expected);
        }
        public void Build_ShouldCreateValidMapping()
        {
            var person = new Person();
            var address = new Address {StreetName = "231 Queen Street", City = "Auckland"};
            var builder = new ChildElementMappingBuilder<Person, Address, object>(null, Ns + "Address", x => x.Address);

            builder.Attribute(Ns + "City", x => x.City, x => x, x => x);
            builder.Element(Ns + "PostCode", x => x.PostCode);
            builder.CollectionElement(Ns + "AreaCode", x => x.AreaCodes);

            var actual = (ChildElementMapping<Person, Address>)builder.Build();

            actual.SetOnContainer(person, address);
            actual.GetFromContainer(person).ShouldBe(address);
            person.Address.ShouldBe(address);
            actual.Attributes.Length.ShouldBe(1);
            actual.ChildElements.Length.ShouldBe(2);
            actual.ChildElements[0].ShouldBeTypeOf(typeof(ChildElementMapping<Address, PostCode>));
            actual.ChildElements[1].ShouldBeTypeOf(typeof(CollectionChildElementMapping<Address, AreaCode>));
        }
Example #3
0
        public void SerializeFragment_ShouldSucceed()
        {
            var stream = new MemoryStream();
            var address = new Address {StreetName = "231 Queen Street", City = "Auckland"};
            var serializer = new Serializer(FullSchema());

            serializer.Serialize(stream, address);

            var expected = XDocument.Parse(@"<Address StreetName='231 Queen Street' City='Auckland' xmlns='http://test.com' />");

            XAssert.AreEqual(expected, stream.ToXDocument());
        }
Example #4
0
 static string PackAddressForAttribute(Address address)
 {
     return address.StreetName + ";" + address.City;
 }