Permalink
Browse files

Introduced ObjectTypeFamily

  • Loading branch information...
1 parent d3c3533 commit 69f07d5185f16072ef9268f817cd7426996a5837 @emiaj emiaj committed Feb 7, 2012
@@ -0,0 +1,48 @@
+using System.Reflection;
+using FubuCore.Binding;
+using FubuCore.Reflection;
+using FubuTestingSupport;
+using NUnit.Framework;
+
+namespace FubuCore.Testing.Binding
+{
+ [TestFixture]
+ public class ObjectTypeFamilyTester : InteractionContext<ObjectTypeFamily>
+ {
+ private PropertyInfo _objectProperty;
+ private PropertyInfo _stringProperty;
+ private object _value;
+ protected override void beforeEach()
+ {
+ _objectProperty = ReflectionHelper.GetProperty<MyModel>(p => p.ObjectProperty);
+ _stringProperty = ReflectionHelper.GetProperty<MyModel>(p => p.StringProperty);
+ _value = "value";
+ }
+
+ [Test]
+ public void matches_for_property_of_object_type_positive()
+ {
+ ClassUnderTest.Matches(_objectProperty).ShouldBeTrue();
+ }
+
+ [Test]
+ public void matches_for_property_of_object_type_negative()
+ {
+ ClassUnderTest.Matches(_stringProperty).ShouldBeFalse();
+ }
+
+ [Test]
+ public void convert_returns_the_context_property_value()
+ {
+ ClassUnderTest.Convert(new InMemoryBindingContext().WithPropertyValue(_value)).ShouldEqual(_value);
+ }
+
+
+ public class MyModel
+ {
+ public object ObjectProperty { get; set; }
+ public string StringProperty { get; set; }
+ }
+
+ }
+}
@@ -33,6 +33,13 @@ public void matches_by_property_type_negative()
}
[Test]
+ public void matches_by_object_property_type_negative()
+ {
+ var binder = new PassthroughConverter<HttpPostedFileBase>();
+ binder.Matches(property(x => x.File3)).ShouldBeFalse();
+ }
+
+ [Test]
public void build_passes_through()
{
var binder = new PassthroughConverter<HttpPostedFileBase>();
@@ -53,5 +60,6 @@ public class ModelWithHttpPostedFileBase
{
public HttpPostedFileBase File { get; set; }
public string File2 { get; set; }
+ public object File3 { get; set; }
}
}
@@ -83,6 +83,7 @@
<Compile Include="Binding\ModelBinderCacheTester.cs" />
<Compile Include="Binding\NestedObjectConversionIntegrationTester.cs" />
<Compile Include="Binding\ObjectResolverTester.cs" />
+ <Compile Include="Binding\ObjectTypeFamilyTester.cs" />
<Compile Include="Binding\PassthroughBinderTester.cs" />
<Compile Include="Binding\PropertyBinderCacheTester.cs" />
<Compile Include="Binding\PropertyBinderTester.cs" />
@@ -0,0 +1,17 @@
+using System.Reflection;
+
+namespace FubuCore.Binding
+{
+ public class ObjectTypeFamily : StatelessConverter
+ {
+ public override bool Matches(PropertyInfo property)
+ {
+ return property.PropertyType == typeof(object);
+ }
+
+ public override object Convert(IPropertyContext context)
+ {
+ return context.PropertyValue;
+ }
+ }
+}
@@ -7,7 +7,7 @@ public class PassthroughConverter<T> : StatelessConverter
{
public override bool Matches(PropertyInfo property)
{
- return property.PropertyType.IsAssignableFrom(typeof (T));
+ return property.PropertyType.IsAssignableFrom(typeof(T)) && property.PropertyType != typeof(object);
}
public override object Convert(IPropertyContext context)
@@ -40,6 +40,7 @@ private void addPolicies()
Add<BooleanFamily>();
Add<NumericTypeFamily>();
+ Add<ObjectTypeFamily>();
}
public void Add<T>() where T : IConverterFamily, new()
@@ -87,6 +87,7 @@
<Compile Include="Binding\NestedObjectPropertyBinder.cs" />
<Compile Include="Binding\NumericTypeFamily.cs" />
<Compile Include="Binding\ObjectResolver.cs" />
+ <Compile Include="Binding\ObjectTypeFamily.cs" />
<Compile Include="Binding\PassthroughConverter.cs" />
<Compile Include="Binding\PrefixedRequestData.cs" />
<Compile Include="Binding\PropertyBinderCache.cs" />

0 comments on commit 69f07d5

Please sign in to comment.