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"); }
private bool WithValue(string value) { return(BindingScenario <BooleanTarget> .For(x => { x.Data(o => o.IsTrue, value); }).Model.IsTrue); }
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 will_convert_comma_delimited_list_into_int_array() { BindingScenario <HerpDerp> .For(setup => { setup.Data("Numbers=1, 2, 3"); }).Model.Numbers.ShouldHaveTheSameElementsAs(1, 2, 3); }
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 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 set_a_property_correctly_against_a_binding_context() { BindingScenario <Address> .For(x => { x.Data(o => o.Address1, "2035 Ozark"); }).Model.Address1.ShouldEqual("2035 Ozark"); }
public void will_convert_comma_delimited_list_into_string_array() { BindingScenario <HerpDerp> .For(setup => { setup.Data("Strings=herp, derp"); }).Model.Strings.ShouldHaveTheSameElementsAs("herp", "derp"); }
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); }
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 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"); }
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()); }
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(); }
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(); }
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"); }
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!"); }
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)); }
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 captures_all_properties() { var report = BindingScenario <Target> .For(x => { x.Data(@" Name=Jeremy Age=38 EyeColor=Blue "); }).Report; report.Properties.Select(x => x.Property.Name).OrderBy(x => x) .ShouldHaveTheSameElementsAs("Age", "EyeColor", "Name"); }
public void should_populate_relativeurl_from_current_http_request() { var stubCurrentHttpRequest = new StubCurrentHttpRequest { TheRelativeUrl = "~/foo" }; var model = BindingScenario <RelativeUrlModel> .For(x => { x.BindPropertyWith <CurrentRequestRelativeUrlPropertyBinder>(f => f.RelativeUrl); x.Service <ICurrentHttpRequest>(stubCurrentHttpRequest); }) .Model; model.RelativeUrl.ShouldEqual(stubCurrentHttpRequest.RelativeUrl()); }
public void bind_by_header() { var headers = new StubRequestHeaders(); headers.Data["Last-Event-ID"] = "something"; headers.Data[HttpResponseHeaders.Warning] = "oh no!"; var target = BindingScenario <HeaderValueTarget> .For(x => { x.Service <IRequestHeaders>(headers); }).Model; target.LastEventId.ShouldEqual("something"); target.Warning.ShouldEqual("oh no!"); }
public void setting_a_property_should_log_a_value_converter() { var scenario = BindingScenario <Address> .For(x => { x.Data("Address1", "2035 Ozark"); }); var property = typeof(Address).GetProperty("Address1"); var converter = propertyBinder.As <ConversionPropertyBinder>().FindConverter(property); var propertyReport = scenario.Report.For(property); propertyReport.Binder.ShouldBeOfType <ConversionPropertyBinder>(); propertyReport.Converter.ShouldEqual(converter); }
public void captures_the_property_binder_and_converter_if_exists() { var report = BindingScenario <Target> .For(x => { x.Data(@" Name=Jeremy Age=38 EyeColor=Blue "); }).Report; var propReport = report.For(ReflectionHelper.GetProperty <Target>(x => x.Age)); propReport.Binder.ShouldBeOfType <ConversionPropertyBinder>(); propReport.Converter.ShouldBeOfType <NumericTypeFamily>(); }
public void should_populate_relativeurl_from_current_http_request() { var stubCurrentHttpRequest = OwinHttpRequest.ForTesting().FullUrl("http://server/foo"); var model = BindingScenario <RelativeUrlModel> .For(x => { x.BindPropertyWith <CurrentRequestRelativeUrlPropertyBinder>(f => f.RelativeUrl); x.Service <IHttpRequest>(stubCurrentHttpRequest); }) .Model; model.RelativeUrl.ShouldBe(stubCurrentHttpRequest.RelativeUrl()); }
public void captures_the_values_used_on_a_property() { var report = BindingScenario <Target> .For(x => { x.Data(@" Name=Jeremy Age=38 EyeColor=Blue "); }).Report; var propReport = report.For(ReflectionHelper.GetProperty <Target>(x => x.Age)); var value = propReport.Values.Single(); value.RawKey.ShouldEqual("Age"); value.RawValue.ShouldEqual("38"); value.Source.ShouldEqual("Anonymous"); }
public void can_bind_array() { var scenario = BindingScenario <LocalityArray> .For(x => { x.Data(@" Localities[0]ZipCode=72712 Localities[0]CountyName=Benton Localities[1]ZipCode=64755 Localities[1]CountyName=Jasper Localities[2]ZipCode=78750 Localities[2]CountyName=Travis "); }); scenario.Model.Localities.ShouldHaveTheSameElementsAs( new LocalityViewModel("72712", "Benton"), new LocalityViewModel("64755", "Jasper"), new LocalityViewModel("78750", "Travis")); }
public void can_bind_collection_on_a_leaf_property() { var scenario = BindingScenario <HasAddress> .For(x => { x.Data(@" Name=Jeremy AddressDescription=the house down the road AddressLocalities[0]ZipCode=72712 AddressLocalities[0]CountyName=Benton AddressLocalities[1]ZipCode=64755 AddressLocalities[1]CountyName=Jasper AddressLocalities[2]ZipCode=78750 AddressLocalities[2]CountyName=Travis "); }); scenario.Model.Address.Localities.ShouldHaveTheSameElementsAs( new LocalityViewModel("72712", "Benton"), new LocalityViewModel("64755", "Jasper"), new LocalityViewModel("78750", "Travis")); scenario.Model.Address.Description.ShouldEqual("the house down the road"); scenario.Model.Name.ShouldEqual("Jeremy"); }