Created
September 5, 2012 17:32
-
-
Save theorigin/3640710 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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