public void should_convert_nonnull_values_for_nullable_types()
 {
     PropertyInfo nullIntProp = ReflectionHelper.GetProperty<Target>(x => x.NullInt);
     var reg = new ValueConverterRegistry(new IConverterFamily[0]);
     var value = new InMemoryBindingContext().WithPropertyValue("99");
     value.ForProperty(nullIntProp, c =>
     {
         reg.FindConverter(nullIntProp).Convert(c).ShouldEqual(99);
     });
 }
Esempio n. 2
0
        public void can_accept_the_property_name_and_treat_it_as_true()
        {
            PropertyInfo property = ReflectionHelper.GetProperty<DummyClass>(c => c.Hungry);
            var context = new InMemoryBindingContext();
            context["Hungry"] = "Hungry";

            ValueConverter converter = new BooleanFamily().Build(null, property);
            context.ForProperty(property, x =>
            {
                converter.Convert(context).As<bool>().ShouldBeTrue();
            });
        }
Esempio n. 3
0
        public void can_accept_the_property_name_and_treat_it_as_true()
        {
            PropertyInfo property = ReflectionHelper.GetProperty <DummyClass>(c => c.Hungry);
            var          context  = new InMemoryBindingContext();

            context["Hungry"] = "Hungry";

            ValueConverter converter = new BooleanFamily().Build(null, property);

            context.ForProperty(property, x =>
            {
                converter(context).As <bool>().ShouldBeTrue();
            });
        }
        public void expand_environment_variables_for_settings_marked_for_expansion()
        {
            string expandedVariable = Environment.GetEnvironmentVariable("SystemRoot");
            var context = new InMemoryBindingContext();
            context[expandProp.Name] = "%SystemRoot%\\foo";

            bool wasCalled = false;
            ValueConverter converter = _family.Build(null, expandProp);
            context.ForProperty(expandProp, x =>
            {
                wasCalled = true;

                converter.Convert(context).ShouldEqual(expandedVariable + @"\foo");
            });

            wasCalled.ShouldBeTrue();
        }
Esempio n. 5
0
        private bool WithValue(string value)
        {
            PropertyInfo property = ReflectionHelper.GetProperty <BooleanFamilyTester.DummyClass>(c => c.Hungry);
            var          context  = new InMemoryBindingContext();

            context["Hungry"] = value;

            var convertedValue = false;

            ValueConverter converter = new BooleanFamily().Build(null, property);

            context.ForProperty(property, x =>
            {
                convertedValue = converter(context).As <bool>();
            });

            return(convertedValue);
        }
Esempio n. 6
0
        public void expand_environment_variables_for_settings_marked_for_expansion()
        {
            string expandedVariable = Environment.GetEnvironmentVariable("SystemRoot");
            var    context          = new InMemoryBindingContext();

            context[expandProp.Name] = "%SystemRoot%\\foo";

            bool           wasCalled = false;
            ValueConverter converter = _family.Build(null, expandProp);

            context.ForProperty(expandProp, () =>
            {
                wasCalled = true;

                converter(context).ShouldEqual(expandedVariable + @"\foo");
            });

            wasCalled.ShouldBeTrue();
        }
Esempio n. 7
0
        private bool WithValue(string value)
        {
            PropertyInfo property = ReflectionHelper.GetProperty<BooleanFamilyTester.DummyClass>(c => c.Hungry);
            var context = new InMemoryBindingContext();
            context["Hungry"] = value;

            var convertedValue = false;

            ValueConverter converter = new BooleanFamily().Build(null, property);
            context.ForProperty(property, x =>
            {
                convertedValue = converter.Convert(context).As<bool>();
            });

            return convertedValue;
        }