annotate Agendas/trunk/src/Agendas.Web.Tests/Controllers/MvcControllerTestsBase.cs @ 270:3bb779434ae8

PersonaController: Coverage 100%
author juanjose.montesdeocaarbos
date Wed, 26 Oct 2011 09:31:17 -0300
parents 3339d1da6a63
children bf993f99cee3
rev   line source
262
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
1 using System.Web;
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
2 using System.Web.Mvc;
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
3 using Moq;
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
4
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
5 namespace Agendas.Web.Tests.Controllers
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
6 {
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
7 public class MvcControllerTestsBase
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
8 {
270
3bb779434ae8 PersonaController: Coverage 100%
juanjose.montesdeocaarbos
parents: 263
diff changeset
9 protected ControllerContext ControllerCtx = new ControllerContext();
262
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
10
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
11 protected static TModel BindModel<TModel>(Controller controller, IValueProvider valueProvider) where TModel : class
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
12 {
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
13 var binder = ModelBinders.Binders.GetBinder(typeof(TModel));
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
14 var bindingContext = new ModelBindingContext()
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
15 {
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
16 FallbackToEmptyPrefix = true,
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
17 ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(TModel)),
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
18 ModelName = "NotUsedButNotNull",
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
19 ModelState = controller.ModelState,
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
20 PropertyFilter = (name => true),
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
21 ValueProvider = valueProvider
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
22 };
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
23
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
24 return (TModel)binder.BindModel(controller.ControllerContext, bindingContext);
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
25 }
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
26 }
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
27 }