262
|
1 using System.Web;
|
|
2 using System.Web.Mvc;
|
|
3 using Moq;
|
|
4
|
|
5 namespace Agendas.Web.Tests.Controllers
|
|
6 {
|
|
7 public class MvcControllerTestsBase
|
|
8 {
|
270
|
9 protected ControllerContext ControllerCtx = new ControllerContext();
|
262
|
10
|
|
11 protected static TModel BindModel<TModel>(Controller controller, IValueProvider valueProvider) where TModel : class
|
|
12 {
|
|
13 var binder = ModelBinders.Binders.GetBinder(typeof(TModel));
|
|
14 var bindingContext = new ModelBindingContext()
|
|
15 {
|
|
16 FallbackToEmptyPrefix = true,
|
|
17 ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(TModel)),
|
|
18 ModelName = "NotUsedButNotNull",
|
|
19 ModelState = controller.ModelState,
|
|
20 PropertyFilter = (name => true),
|
|
21 ValueProvider = valueProvider
|
|
22 };
|
|
23
|
|
24 return (TModel)binder.BindModel(controller.ControllerContext, bindingContext);
|
|
25 }
|
|
26 }
|
|
27 }
|