Skip to content

Instantly share code, notes, and snippets.

Created December 31, 2012 21:35
Show Gist options
  • Save anonymous/4422887 to your computer and use it in GitHub Desktop.
Save anonymous/4422887 to your computer and use it in GitHub Desktop.
[Fact]
public void Should_bind_to_IEnumerable_T_from_form()
{
//Given
var typeConverters = new ITypeConverter[] { new CollectionConverter(), new FallbackConverter(), };
var binder = this.GetBinder(typeConverters);
var context = CreateContextWithHeader("Content-Type", new[] { "application/x-www-form-urlencoded" });
context.Request.Form["StringProperty_1"] = "Test";
context.Request.Form["IntProperty_1"] = "1";
context.Request.Form["StringProperty_2"] = "Test2";
context.Request.Form["IntProperty_2"] = "2";
// When
var result = (IEnumerable<TestModel>)binder.Bind(context, typeof(IEnumerable<TestModel>), null, new BindingConfig());
// Then
result.First().StringProperty.ShouldEqual("Test");
result.First().IntProperty.ShouldEqual(1);
result.Last().StringProperty.ShouldEqual("Test2");
result.Last().IntProperty.ShouldEqual(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment