Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Web.Tests/Controllers/MvcControllerTestsBase.cs @ 262:b87a4875b2b6
ControllerTests: Refactoring.
author | juanjose.montesdeocaarbos |
---|---|
date | Sat, 22 Oct 2011 14:08:30 -0300 |
parents | |
children | 3339d1da6a63 |
comparison
equal
deleted
inserted
replaced
261:d669e9b9e24e | 262:b87a4875b2b6 |
---|---|
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 } |