diff Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs @ 243:59f8fa2f835e

Ticket 177: Valor de Duración de VAN en 0.
author juanjose.montesdeocaarbos
date Thu, 06 Oct 2011 08:13:05 -0300
parents 5cc1681d3789
children bdc946dd5c94
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs	Wed Oct 05 07:57:21 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs	Thu Oct 06 08:13:05 2011 -0300
@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
+using System.Web.Mvc;
 using Agendas.NHibernate;
 using Agendas.Repositories.Tests.Infraestructure;
 using AltNetHispano.Agendas.Domain;
@@ -16,47 +17,98 @@
 	[TestFixture]
 	public class EventoControllerTests
 	{
-		[SetUp]
-		public void SetearUsuario()
+        private void PopulatePersona()
+        {
+            using (new RequestEmulator(NhHelper.GetSessionFactory()))
+            {
+                var personaController = new PersonaController();
+                personaController.Nueva(new PersonaNewModel
+                                            {
+                                                Nombre = "Persona 1",
+                                                Blog = "http://blog.persona1.com",
+                                                EMail = "info@persona1.com",
+                                                Roles = new string[] {"Administrador", "Usuario"},
+                                                Twitter = "persona1"
+                                            });
+            }
+        }
+
+	    private Guid GetGuidPersona()
+        {
+            using (new RequestEmulator(NhHelper.GetSessionFactory()))
+            {
+                var personaController = new PersonaController();
+                var viewResult = (ViewResult) personaController.Index();
+                return ((PersonaIndexModel) viewResult.Model).Items.FirstOrDefault().Id;
+            }
+        }
+
+		private void SetearUsuario()
 		{
 			var seguridad = new Mock<ISeguridad>();
 			seguridad.Setup(s => s.GetUserName()).Returns("neluz");
 			IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory()));
-
 		}
 
-		[Test]
-		[Ignore]
+        [SetUp]
+        public void Setup()
+        {
+            NhHelperTest.CleanDb();
+            PopulatePersona();
+            SetearUsuario();
+        }
+
+	    [Test]
 		public void Publicar_Evento()
 		{
+		    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(5),
+			                		Fecha = DateTime.Today.AddDays(15),
 			                		Hora = new TimeSpan(18, 0, 0),
-			                		Ponentes = new[] {Guid.NewGuid()},
+                                    Ponentes = new[] { GetGuidPersona()},
 			                		TipoEvento = (int) TipoEvento.Van,
-			                		Titulo = "Título 1"
+			                		Titulo = "Título 2"
 			                	};
-
+		    
 			using (new RequestEmulator(NhHelper.GetSessionFactory()))
 			{
-				var resultNuevo = eventoController.Nuevo(eventoNew);
+			    eventoController.Nuevo(eventoNew);
 			}
-
-            var eventoPublicar = new EventoPublicarModel
-                                     {
-                                         NroOrden = 1,
-                                         Titulo = "Título 1",
-                                         UrlWiki = "http://www.altnethistpano.org/vans/titulo-1.ashx",
-                                         DuracionReal = new TimeSpan(0, 0, 0)
-                                     };
-
+            using (new RequestEmulator(NhHelper.GetSessionFactory()))
+            {
+                viewResult = (ViewResult)eventoController.Index();
+			}
+            using (new RequestEmulator(NhHelper.GetSessionFactory()))
+            {
+                eventosDto = ((EventoIndexModel) viewResult.Model).ProximosEventos;
+            }
             using (new RequestEmulator(NhHelper.GetSessionFactory()))
             {
-                var resultPublicar = eventoController.Publicar(eventoPublicar);
+                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)
+                };
+            }
+            using (new RequestEmulator(NhHelper.GetSessionFactory()))
+            {
+                var resultPublicar = (ViewResult)eventoController.Publicar(eventoPublicar);
+                var modelState = resultPublicar.ViewData.ModelState.FirstOrDefault().Value;
+
+                Assert.AreEqual(1, modelState.Errors.Count);
+                Assert.AreEqual("Duración fuera de rango", modelState.Errors.FirstOrDefault().ErrorMessage);
+                
             }
         }
     }