public object SettingsFor(Type settingsType)
        {
            IBindingContext context = new BindingContext(new AppSettingsRequestData(), _locator)
                                      .PrefixWith(settingsType.Name + ".");

            BindResult result = _resolver.BindModel(settingsType, context);

            result.AssertNoProblems(settingsType);

            return(result.Value);
        }
Beispiel #2
0
        public void should_throw_bind_result_assertion_exception_on_problems()
        {
            var problem = new ConvertProblem {
                Properties = new List <PropertyInfo> {
                    typeof(PropertyHolder).GetProperty("SomeProperty")
                }, Value = "some value"
            };

            result.Problems.Add(problem);

            var ex = typeof(BindResultAssertionException).ShouldBeThrownBy(
                () => result.AssertNoProblems(typeof(string))) as BindResultAssertionException;

            ex.ShouldNotBeNull();
            ex.Message.ShouldEqual("Failure while trying to bind object of type '{0}'".ToFormat(ex.Type) +
                                   "Property: {0}, Value: '{1}', Exception:{2}{3}{2}".ToFormat(problem.PropertyName()
                                                                                               , problem.Value, Environment.NewLine, problem.ExceptionText));
            ex.Type.ShouldEqual(typeof(string));
            ex.Problems.ShouldContain(problem);
        }