Skip to content

Instantly share code, notes, and snippets.

@theorigin
Created September 5, 2012 17:32
Show Gist options
  • Save theorigin/3640710 to your computer and use it in GitHub Desktop.
Save theorigin/3640710 to your computer and use it in GitHub Desktop.
[Test]
public void ShouldReturnModelWithValuesSetCorrectly()
{
var formCollection = new NameValueCollection
{
{ "page", "5" },
{ "rp", "8" },
{ "query", "smith" },
{ "sortname", "sname" },
{ "sortorder", "sorder" }
};
var valueProvider = new NameValueCollectionValueProvider(formCollection, null);
var metadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(SomeViewModel));
var bindingContext = new ModelBindingContext
{
ModelName = string.Empty,
ValueProvider = valueProvider,
ModelMetadata = metadata
};
var controllerContext = new ControllerContext();
var sut = new SomeViewModelBinder();
var actual = (SomeViewModel)sut.BindModel(controllerContext, bindingContext);
actual.CurrentPage.Should().Be(int.Parse(formCollection["page"]));
actual.ItemsPerPage.Should().Be(int.Parse(formCollection["rp"]));
actual.OrderBy.Should().Be(formCollection["sortname"]);
actual.OrderDirection.Should().Be(formCollection["sortorder"]);
actual.Query.Should().Be(formCollection["query"]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment