public void can_accept_the_property_name_and_treat_it_as_true()
 {
     BindingScenario <DummyClass> .For(x =>
     {
         x.Data(o => o.Hungry, "Hungry");
     }).Model.Hungry.ShouldBeTrue();
 }
 public void will_convert_comma_delimited_list_into_string_array()
 {
     BindingScenario <HerpDerp> .For(setup =>
     {
         setup.Data("Strings=herp, derp");
     }).Model.Strings.ShouldHaveTheSameElementsAs("herp", "derp");
 }
Пример #3
0
 public void do_a_primitive_list()
 {
     BindingScenario <HybridHolder> .Build(x =>
     {
         x.Data("Ages", "38,8,32");
     }).Ages.ShouldHaveTheSameElementsAs(38, 8, 32);
 }
Пример #4
0
 private bool WithValue(string value)
 {
     return(BindingScenario <BooleanTarget> .For(x =>
     {
         x.Data(o => o.IsTrue, value);
     }).Model.IsTrue);
 }
 public void will_convert_comma_delimited_list_into_int_array()
 {
     BindingScenario <HerpDerp> .For(setup =>
     {
         setup.Data("Numbers=1, 2, 3");
     }).Model.Numbers.ShouldHaveTheSameElementsAs(1, 2, 3);
 }
Пример #6
0
 public void return_the_original_value_if_the_connection_string_doesnt_exist()
 {
     BindingScenario <TestSettings> .Build(x =>
     {
         x.Data(o => o.DefaultPath, "foo");
     }).DefaultPath.ShouldEqual("foo");
 }
Пример #7
0
 public void should_convert_nonnull_values_for_nullable_types()
 {
     BindingScenario <Target> .Build(x =>
     {
         x.Data(o => o.NullInt, 99);
     }).NullInt.ShouldEqual(99);
 }
 public void convert_returns_the_context_property_value()
 {
     BindingScenario <MyModel> .Build(x =>
     {
         x.Data(o => o.ObjectProperty, "123");
     }).ObjectProperty.ShouldEqual("123");
 }
Пример #9
0
 public void set_a_property_correctly_against_a_binding_context()
 {
     BindingScenario <Address> .For(x =>
     {
         x.Data(o => o.Address1, "2035 Ozark");
     }).Model.Address1.ShouldEqual("2035 Ozark");
 }
Пример #10
0
 public void return_the_value_from_the_connectionStrings_section()
 {
     BindingScenario <TestSettings> .Build(x =>
     {
         x.Data(o => o.DefaultPath, connectionStringKey);
     }).DefaultPath.ShouldEqual(actualConnectionString);
 }
        public void log_for_nested_array()
        {
            var report = BindingScenario <ClassWithTargetArray> .For(x =>
            {
                x.Data(@"
Targets[0]Name=Jeremy
Targets[0]Age=38
Targets[0]EyeColor=Blue
Targets[1]Name=Lindsey
Targets[1]Age=29
Targets[1]EyeColor=Hazel


");
            }).Report;


            report.WriteToConsole(true);

            var array = report.For <ClassWithTargetArray>(x => x.Targets);

            array.Elements.ShouldHaveCount(2);

            var age0 = array.Elements.First().For <Target>(x => x.Age);

            age0.Binder.ShouldBeOfType <ConversionPropertyBinder>();
            age0.Converter.ShouldBeOfType <NumericTypeFamily>();
            age0.Values.Single().RawValue.ShouldEqual("38");

            var age1 = array.Elements.Last().For <Target>(x => x.Age);

            age1.Binder.ShouldBeOfType <ConversionPropertyBinder>();
            age1.Converter.ShouldBeOfType <NumericTypeFamily>();
            age1.Values.Single().RawValue.ShouldEqual("29");
        }
        public void captures_details_for_a_nested_object()
        {
            var scenario = BindingScenario <ClassThatNestsTarget> .For(x =>
            {
                x.Data(@"
TargetName=Jeremy
TargetAge=38
TargetEyeColor=Blue
");
            });


            scenario.Model.Target.Name.ShouldEqual("Jeremy");

            var report = scenario.Report;



            var nestedPropReport = report.LastProperty;

            nestedPropReport.Nested.ShouldNotBeNull();

            var age   = nestedPropReport.Nested.For <Target>(x => x.Age);
            var value = age.Values.Single();

            value.RawKey.ShouldEqual("TargetAge");
            value.RawValue.ShouldEqual("38");
            value.Source.ShouldEqual("Anonymous");
        }
        public void log_for_nested_class_in_array()
        {
            var report = BindingScenario <DeepClass1> .For(x =>
            {
                x.Data(@"
NestedTargets[0]TargetName=Jeremy
NestedTargets[0]TargetAge=38
NestedTargets[0]TargetEyeColor=Blue
NestedTargets[1]TargetName=Lindsey
NestedTargets[1]TargetAge=29
NestedTargets[1]TargetEyeColor=Hazel


");
            }).Report;


            report.WriteToConsole(true);

            var elements = report.For <DeepClass1>(x => x.NestedTargets).Elements;

            elements.Count.ShouldEqual(2);

            var age0 = elements.First().For <ClassThatNestsTarget>(x => x.Target).Nested.For <Target>(x => x.Age);

            age0.Binder.ShouldBeOfType <ConversionPropertyBinder>();
            age0.Converter.ShouldBeOfType <NumericTypeFamily>();
            age0.Values.Single().RawValue.ShouldEqual("38");
            age0.Values.Single().RawKey.ShouldEqual("NestedTargets[0]TargetAge");
        }
 public void SetUp()
 {
     theScenario = BindingScenario <HolderClass> .For(x =>
     {
         x.Data("HeldClassName", "Jeremy");
         x.Data("HeldClassAge", "NOT A NUMBER");
     });
 }
 public void the_conversion_problems_should_be_recorded()
 {
     BindingScenario <BinderTarget> .For(x =>
     {
         x.Data("Age", "abc");
         x.Data("Name", "Jeremy");
     }).Problems.Count.ShouldEqual(1);
 }
        private bool WithValue(string value)
        {
            var scenario = BindingScenario <BooleanTarget> .For(x => { x.Data(o => o.IsTrue, value); });

            scenario.Problems.Any().ShouldBeFalse();

            return(scenario.Model.IsTrue);
        }
Пример #17
0
 public void should_build()
 {
     using (new ScopedCulture(CultureInfo.CreateSpecificCulture("en-us")))
     {
         BindingScenario <PropertyHolder> .Build(x => x.Data("Property", "1,000.001"))
         .Property.ShouldEqual(1000.001m);
     }
 }
Пример #18
0
        public void expand_environment_variables_for_settings_marked_for_expansion()
        {
            string expandedVariable = Environment.GetEnvironmentVariable("SystemRoot");

            var scenario = BindingScenario <TestSettings> .For(x =>
            {
                x.Data(o => o.DefaultPath, "%SystemRoot%\\foo");
            });

            scenario.Model.DefaultPath.ShouldEqual(expandedVariable + @"\foo");
        }
Пример #19
0
        public void apply_collection_binding_when_it_is_one_value_should_delegate_to_the_conversion()
        {
            var guys = BindingScenario <HybridHolder> .Build(x =>
            {
                x.Data(@"
Guys=Jeremy:38,Max:8
");
            }).Guys;

            guys.ShouldHaveTheSameElementsAs(new HybridGuy("Jeremy", 38), new HybridGuy("Max", 8));
        }
Пример #20
0
        public void use_binding_attribute()
        {
            var target = BindingScenario <FakeTarget> .For(x =>
            {
                x.BindPropertyWith <AttributePropertyBinder>(o => o.Color1);
                x.BindPropertyWith <AttributePropertyBinder>(o => o.Color2);
            }).Model;

            target.Color1.ShouldEqual("red");
            target.Color2.ShouldEqual("green");
        }
        public void SetUp()
        {
            theScenario = BindingScenario <HolderClass> .For(x =>
            {
                x.Data(@"
HeldClassName=Jeremy
HeldClassAge=36
");
            });

            holder = theScenario.Model;
        }
        public void Multiple_levels_of_bound_objects()
        {
            var scenario = BindingScenario <Duck> .For(x =>
            {
                x.Data("WingSpan", "7");
                x.Data("TurduckenName", "Bob");
            });

            scenario.Problems.Any().ShouldBeFalse();
            scenario.Model.WingSpan.ShouldEqual(7);
            scenario.Model.Turducken.Name.ShouldEqual("Bob");
        }
Пример #23
0
        public void nullable_property_has_no_data_and_should_be_null()
        {
            var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");

            BindingScenario <DateTimeTarget> .For(x =>
            {
                x.Registry.Add(new DateTimeToUtcConverterFamily());
                x.Service <ITimeZoneContext>(new SimpleTimeZoneContext(timeZone));

                // no data for NullableDate
            }).Model.NullableDate.ShouldBeNull();
        }
Пример #24
0
        public void should_populate_fullurl_from_current_http_request()
        {
            var stubCurrentHttpRequest = OwinHttpRequest.ForTesting();
            var model =
                BindingScenario <FullUrlModel> .For(x => {
                x.BindPropertyWith <CurrentRequestFullUrlPropertyBinder>(f => f.FullUrl);
                x.Service <IHttpRequest>(stubCurrentHttpRequest);
            })
                .Model;

            model.FullUrl.ShouldEqual(stubCurrentHttpRequest.FullUrl());
        }
Пример #25
0
        public void nullable_property_has_empty_string_in_the_request()
        {
            var timeZone = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");

            BindingScenario <DateTimeTarget> .For(x =>
            {
                x.Registry.Add(new DateTimeToUtcConverterFamily());
                x.Service <ITimeZoneContext>(new SimpleTimeZoneContext(timeZone));

                x.Data(o => o.NullableDate, "");
            }).Model.NullableDate.ShouldBeNull();
        }
Пример #26
0
        public void happy_path_for_nullable_datetime()
        {
            var localTime = new DateTime(2012, 6, 27, 8, 0, 0);
            var timeZone  = TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");

            BindingScenario <DateTimeTarget> .For(x =>
            {
                x.Registry.Add(new DateTimeToUtcConverterFamily());
                x.Service <ITimeZoneContext>(new SimpleTimeZoneContext(timeZone));

                x.Data(o => o.NullableDate, localTime.ToString());
            }).Model.NullableDate.ShouldEqual(localTime.ToUniversalTime(timeZone));
        }
Пример #27
0
        public void builds_the_log()
        {
            var theLog  = new RequestLog();
            var builder = MockRepository.GenerateStub <IRequestLogBuilder>();

            builder.Stub(x => x.BuildForCurrentRequest()).Return(theLog);

            BindingScenario <FakeRequestModel> .For(x =>
            {
                x.Service(builder);
                x.BindPropertyWith(theBinder, model => model.CurrentRequest);
            }).Model.CurrentRequest.ShouldBeTheSameAs(theLog);
        }
        public void bind_by_header()
        {
            var headers = OwinHttpRequest.ForTesting();

            headers.AppendHeader("Last-Event-ID", "something");
            headers.AppendHeader(HttpResponseHeaders.Warning, "oh no!");


            var target = BindingScenario <HeaderValueTarget> .For(x => { x.Service <IHttpRequest>(headers); }).Model;

            target.LastEventId.ShouldBe("something");
            target.Warning.ShouldBe("oh no!");
        }
Пример #29
0
        public void SetUp()
        {
            var theHttpRequest = new CurrentChain(new BehaviorChain(), new Dictionary <string, object>());

            theExpectedHash = ResourceHash.For(theHttpRequest);

            FubuApplication.SetupNamingStrategyForHttpHeaders();

            theEtagRequest = BindingScenario <ETaggedRequest> .Build(x =>
            {
                x.Service <ICurrentChain>(theHttpRequest);
                x.Data("If-None-Match", "12345");
            });
        }
Пример #30
0
        public void apply_collection_that_can_be_converted_as_individual_values()
        {
            var guys = BindingScenario <HybridHolder> .Build(x =>
            {
                x.Data(@"
Guys[0]Name=Jeremy
Guys[0]Age=38
Guys[1]Name=Max
Guys[1]Age=8
");
            }).Guys;

            guys.ShouldHaveTheSameElementsAs(new HybridGuy("Jeremy", 38), new HybridGuy("Max", 8));
        }