public Site()
 {
     PrimaryAddress = new Address();
 }
        public void register_a_string_conversion_for_a_class()
        {
            stringifier.IfIsType<Address>(a => "{0}, {1}".ToFormat(a.Address1, a.City));

            var address = new Address
            {
                Address1 = "2050 Ozark",
                City = "Joplin"
            };

            stringifier.GetString(address).ShouldEqual("2050 Ozark, Joplin");
        }
        public void register_a_property_override_for_a_string_conversion_passing_raw_value()
        {
            object passedRawValue = null;

            configure(x =>
            {
                //specific override formatting for Address objects named Shipping
                x.IfPropertyMatches<Address>(prop => prop.Name == "Shipping").ConvertBy((req, value) =>
                {
                    passedRawValue = req.RawValue;
                    return "{1}-{0}".ToFormat(value.Address1, value.City);
                });

                //default formatting for Address objects
                x.IfIsType<Address>().ConvertBy(a => "{0}, {1}".ToFormat(a.Address1, a.City));

            });

            var address = new Address();

            var shippingRequest = new GetStringRequest(ReflectionHelper.GetAccessor<FakeSite>(s => s.Shipping), address, locator);

            stringifier.GetString(shippingRequest);

            passedRawValue.ShouldBeTheSameAs(address);
        }
        public void register_a_property_override_for_a_string_conversion()
        {
            //default formatting for Address objects
            stringifier.IfIsType<Address>(a => "{0}, {1}".ToFormat(a.Address1, a.City));
            //specific override formatting for Address objects named Shipping
            stringifier.IfPropertyMatches<Address>(prop => prop.Name == "Shipping", a => "{1}-{0}".ToFormat(a.Address1, a.City));

            var address = new Address
            {
                Address1 = "2050 Ozark",
                City = "Joplin"
            };

            const string expectedDefaultFormatting = "2050 Ozark, Joplin";
            const string expectedOverrideFormatting = "Joplin-2050 Ozark";
            stringifier.GetString(ReflectionHelper.GetProperty<FakeSite>(s => s.Billing), address).ShouldEqual(expectedDefaultFormatting);
            stringifier.GetString(ReflectionHelper.GetProperty<FakeSite>(s => s.Shipping), address).ShouldEqual(expectedOverrideFormatting);
        }
        public void register_a_property_override_for_a_string_conversion()
        {
            configure(x =>
            {
                //specific override formatting for Address objects named Shipping
                x.IfPropertyMatches<Address>(prop => prop.Name == "Shipping").ConvertBy(a => "{1}-{0}".ToFormat(a.Address1, a.City));

                //default formatting for Address objects
                x.IfIsType<Address>().ConvertBy(a => "{0}, {1}".ToFormat(a.Address1, a.City));
            });

            var address = new Address
            {
                Address1 = "2050 Ozark",
                City = "Joplin"
            };

            const string expectedDefaultFormatting = "2050 Ozark, Joplin";
            const string expectedOverrideFormatting = "Joplin-2050 Ozark";
            var billingRequest = new GetStringRequest(ReflectionHelper.GetAccessor<FakeSite>(s => s.Billing), address, locator);
            var shippingRequest = new GetStringRequest(ReflectionHelper.GetAccessor<FakeSite>(s => s.Shipping), address, locator);
            stringifier.GetString(billingRequest).ShouldEqual(expectedDefaultFormatting);
            stringifier.GetString(shippingRequest).ShouldEqual(expectedOverrideFormatting);
        }