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 {
|
|
9 protected readonly Mock<HttpContextBase> HttpCtxStub = new Mock<HttpContextBase>();
|
|
10 protected readonly ControllerContext ControllerCtx = new ControllerContext();
|
|
11
|
|
12 protected void SetupTests()
|
|
13 {
|
|
14 ControllerCtx.HttpContext = HttpCtxStub.Object;
|
|
15 }
|
|
16
|
|
17 protected static TModel BindModel<TModel>(Controller controller, IValueProvider valueProvider) where TModel : class
|
|
18 {
|
|
19 var binder = ModelBinders.Binders.GetBinder(typeof(TModel));
|
|
20 var bindingContext = new ModelBindingContext()
|
|
21 {
|
|
22 FallbackToEmptyPrefix = true,
|
|
23 ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(TModel)),
|
|
24 ModelName = "NotUsedButNotNull",
|
|
25 ModelState = controller.ModelState,
|
|
26 PropertyFilter = (name => true),
|
|
27 ValueProvider = valueProvider
|
|
28 };
|
|
29
|
|
30 return (TModel)binder.BindModel(controller.ControllerContext, bindingContext);
|
|
31 }
|
|
32 }
|
|
33 }
|