changeset 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 5ddc574deeea
files Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs
diffstat 1 files changed, 48 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs	Sat Oct 22 14:56:14 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs	Sat Oct 22 17:27:45 2011 -0300
@@ -14,7 +14,7 @@
 namespace Agendas.Web.Tests.Controllers
 {
 	[TestFixture]
-	public class EventoControllerTests
+	public class EventoControllerTests: MvcControllerTestsBase
 	{
         private void PopulatePersona()
         {
@@ -63,17 +63,17 @@
             ViewResult viewResult = null;
             IEnumerable<EventoDto> eventosDto = null;
             EventoPublicarModel eventoPublicar = null;
-            var eventoController = new EventoController();
-
-            var eventoNew = new EventoNewModel
-            {
-                Duracion = new TimeSpan(0, 0, 0),
-                Fecha = DateTime.Today.AddDays(15),
-                Hora = new TimeSpan(18, 0, 0),
-                Ponentes = new[] { GetGuidPersona() },
-                TipoEvento = (int)TipoEvento.Van,
-                Titulo = "Título"
-            };
+            var eventoController = new EventoController { ControllerContext = ControllerCtx };
+            var form = new FormCollection
+                           {
+                               {"Duracion", (new TimeSpan(0, 0, 0)).ToString()},
+                               {"Fecha", (DateTime.Today.AddDays(15)).ToString()},
+                               {"Hora", (new TimeSpan(18, 0, 0)).ToString()},
+                               {"Ponentes", GetGuidPersona().ToString()},
+                               {"TipoEvento", ((int)TipoEvento.Van).ToString()},
+                               {"Titulo", "Título"}
+                           };
+            var eventoNew = BindModel<EventoNewModel>(eventoController, form); 
 
             using (new RequestEmulator(NhHelper.GetSessionFactory()))
             {
@@ -89,23 +89,23 @@
             ViewResult viewResult = null;
             IEnumerable<EventoDto> eventosDto = null;
             EventoPublicarModel eventoPublicar = null;
-            var eventoController = new EventoController();
-
-            var eventoNew = new EventoNewModel
-            {
-                Duracion = new TimeSpan(0, 0, 0),
-                Fecha = DateTime.Today.AddDays(15),
-                Hora = new TimeSpan(18, 0, 0),
-                TipoEvento = (int)TipoEvento.Van,
-                Titulo = "Título"
-            };
+            var eventoController = new EventoController { ControllerContext = ControllerCtx };
+            var form = new FormCollection
+                           {
+                               {"Duracion", (new TimeSpan(0, 0, 0)).ToString()},
+                               {"Fecha", (DateTime.Today.AddDays(15)).ToString()},
+                               {"Hora", (new TimeSpan(18, 0, 0)).ToString()},
+                               {"TipoEvento", ((int)TipoEvento.Van).ToString()},
+                               {"Titulo", "Título"}
+                           };
+            var eventoNew = BindModel<EventoNewModel>(eventoController, form);
 
             using (new RequestEmulator(NhHelper.GetSessionFactory()))
             {
                 var resultNuevo = (ViewResult)eventoController.Nuevo(eventoNew);
-                var modelState = resultNuevo.ViewData.ModelState.FirstOrDefault().Value;
-                Assert.AreEqual(1, modelState.Errors.Count);
-                Assert.AreEqual("Debe indicar el ponente para este tipo de evento", modelState.Errors.FirstOrDefault().ErrorMessage);
+                var modelState = resultNuevo.ViewData.ModelState;
+                Assert.AreEqual(1, modelState[string.Empty].Errors.Count);
+                Assert.AreEqual("Debe indicar el ponente para este tipo de evento", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage);
             }
         }
 
@@ -115,17 +115,17 @@
 		    ViewResult viewResult = null;
 		    IEnumerable<EventoDto> eventosDto = null;
 		    EventoPublicarModel eventoPublicar = null;
-			var eventoController = new EventoController();
-
-			var eventoNew = new EventoNewModel
-			                	{
-			                		Duracion = new TimeSpan(0, 0, 0),
-			                		Fecha = DateTime.Today.AddDays(15),
-			                		Hora = new TimeSpan(18, 0, 0),
-                                    Ponentes = new[] { GetGuidPersona()},
-			                		TipoEvento = (int) TipoEvento.Van,
-			                		Titulo = "Título 2"
-			                	};
+            var eventoController = new EventoController { ControllerContext = ControllerCtx };
+            var formEvento = new FormCollection
+                           {
+                               {"Duracion", (new TimeSpan(0, 0, 0)).ToString()},
+                               {"Fecha", (DateTime.Today.AddDays(15)).ToString()},
+                               {"Hora", (new TimeSpan(18, 0, 0)).ToString()},
+                               {"Ponentes", GetGuidPersona().ToString()},
+                               {"TipoEvento", ((int)TipoEvento.Van).ToString()},
+                               {"Titulo", "Título 2"}
+                           };
+            var eventoNew = BindModel<EventoNewModel>(eventoController, formEvento); 
 		    
 			using (new RequestEmulator(NhHelper.GetSessionFactory()))
 			{
@@ -142,23 +142,23 @@
             using (new RequestEmulator(NhHelper.GetSessionFactory()))
             {
                 var firstEvent = eventosDto.LastOrDefault();
-
-                eventoPublicar = new EventoPublicarModel
-                {
-                    Id = firstEvent.Id,
-                    NroOrden = 1,
-                    //Titulo = "Título 2",
-                    UrlWiki = "http://www.altnethistpano.org/vans/titulo-1.ashx",
-                    DuracionReal = new TimeSpan(0, 0, 0)
-                };
+                var formPublicar = new FormCollection
+                           {
+                               {"Id", (firstEvent.Id).ToString()},
+                               {"Titulo", "Título 2"},
+                               {"NroOrden", "1"},
+                               {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"},
+                               {"DuracionReal", (new TimeSpan(0, 0, 0)).ToString()}
+                           };
+                eventoPublicar = BindModel<EventoPublicarModel>(eventoController, formPublicar); 
             }
             using (new RequestEmulator(NhHelper.GetSessionFactory()))
             {
                 var resultPublicar = (ViewResult)eventoController.Publicar(eventoPublicar);
-                var modelState = resultPublicar.ViewData.ModelState.FirstOrDefault().Value;
+                var modelState = resultPublicar.ViewData.ModelState;
 
-                Assert.AreEqual(1, modelState.Errors.Count);
-                Assert.AreEqual("Duración fuera de rango", modelState.Errors.FirstOrDefault().ErrorMessage);
+                Assert.AreEqual(1, modelState[string.Empty].Errors.Count);
+                Assert.AreEqual("Duración fuera de rango", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage);
                 
             }
         }