diff Agendas/trunk/src/Agendas.Web.Tests/Controllers/PersonaControllerTests.cs @ 262:b87a4875b2b6

ControllerTests: Refactoring.
author juanjose.montesdeocaarbos
date Sat, 22 Oct 2011 14:08:30 -0300
parents d669e9b9e24e
children 3339d1da6a63
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Web.Tests/Controllers/PersonaControllerTests.cs	Sat Oct 22 13:59:18 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web.Tests/Controllers/PersonaControllerTests.cs	Sat Oct 22 14:08:30 2011 -0300
@@ -15,11 +15,8 @@
 namespace Agendas.Web.Tests.Controllers
 {
     [TestFixture]
-    public class PersonaControllerTests
+    public class PersonaControllerTests : MvcControllerTestsBase
     {
-        readonly Mock<HttpContextBase> _httpCtxStub = new Mock<HttpContextBase>();
-        readonly ControllerContext _controllerCtx = new ControllerContext();
-
         private void SetearUsuario()
         {
             var seguridad = new Mock<ISeguridad>();
@@ -33,13 +30,13 @@
             NhHelperTest.CleanDb();
             //PopulatePersona();
             SetearUsuario();
-            _controllerCtx.HttpContext = _httpCtxStub.Object;
+            SetupTests();
         }
 
         [Test]
         public void PersonaNueva_ErrorAlGuardarTwitterConArroba()
         {
-            var personaController = new PersonaController { ControllerContext = _controllerCtx };
+            var personaController = new PersonaController { ControllerContext = ControllerCtx };
 
             var form = new FormCollection
                            {
@@ -64,7 +61,7 @@
         [Test]
         public void PersonaModificar_ErrorAlGuardarTwitterConArroba()
         {
-            var personaController = new PersonaController {ControllerContext = _controllerCtx};
+            var personaController = new PersonaController {ControllerContext = ControllerCtx};
 
             #region PersonaNew
             var personaNew = new PersonaNewModel
@@ -108,21 +105,5 @@
                 Assert.IsFalse(personaController.TempData.ContainsKey("error"));
             }
         }
-
-        protected static TModel BindModel<TModel>(Controller controller, IValueProvider valueProvider) where TModel : class
-        {
-            IModelBinder binder = ModelBinders.Binders.GetBinder(typeof(TModel));
-            ModelBindingContext bindingContext = new ModelBindingContext()
-            {
-                FallbackToEmptyPrefix = true,
-                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(null, typeof(TModel)),
-                ModelName = "NotUsedButNotNull",
-                ModelState = controller.ModelState,
-                PropertyFilter = (name => { return true; }),
-                ValueProvider = valueProvider
-            };
-
-            return (TModel)binder.BindModel(controller.ControllerContext, bindingContext);
-        }
     }
 }