annotate Agendas/trunk/src/Agendas.Web.Tests/Controllers/MvcControllerTestsBase.cs @ 264:cef4fc893333

EventoControllerTests: No se estaba pasando el HttpContext al test.
author juanjose.montesdeocaarbos
date Sat, 22 Oct 2011 17:27:45 -0300
parents 3339d1da6a63
children 3bb779434ae8
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 {
b87a4875b2b6 ControllerTests: Refactoring.
juanjose.montesdeocaarbos
parents:
diff changeset
9 protected readonly ControllerContext ControllerCtx = new ControllerContext();
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 }