comparison Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs @ 245:bdc946dd5c94

Agregando Tests a Agenda.Web
author juanjose.montesdeocaarbos
date Fri, 07 Oct 2011 09:41:55 -0300
parents 59f8fa2f835e
children cef4fc893333
comparison
equal deleted inserted replaced
244:31fb96912d37 245:bdc946dd5c94
1 using System; 1 using System;
2 using System.Collections.Generic; 2 using System.Collections.Generic;
3 using System.Linq; 3 using System.Linq;
4 using System.Text;
5 using System.Web.Mvc; 4 using System.Web.Mvc;
6 using Agendas.NHibernate; 5 using Agendas.NHibernate;
7 using Agendas.Repositories.Tests.Infraestructure; 6 using Agendas.Repositories.Tests.Infraestructure;
8 using AltNetHispano.Agendas.Domain; 7 using AltNetHispano.Agendas.Domain;
9 using AltNetHispano.Agendas.Repositories.NHibernate; 8 using AltNetHispano.Agendas.Repositories.NHibernate;
56 NhHelperTest.CleanDb(); 55 NhHelperTest.CleanDb();
57 PopulatePersona(); 56 PopulatePersona();
58 SetearUsuario(); 57 SetearUsuario();
59 } 58 }
60 59
60 [Test]
61 public void Nuevo_Evento()
62 {
63 ViewResult viewResult = null;
64 IEnumerable<EventoDto> eventosDto = null;
65 EventoPublicarModel eventoPublicar = null;
66 var eventoController = new EventoController();
67
68 var eventoNew = new EventoNewModel
69 {
70 Duracion = new TimeSpan(0, 0, 0),
71 Fecha = DateTime.Today.AddDays(15),
72 Hora = new TimeSpan(18, 0, 0),
73 Ponentes = new[] { GetGuidPersona() },
74 TipoEvento = (int)TipoEvento.Van,
75 Titulo = "Título"
76 };
77
78 using (new RequestEmulator(NhHelper.GetSessionFactory()))
79 {
80 var resultNuevo = eventoController.Nuevo(eventoNew);
81 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultNuevo);
82 Assert.AreEqual("Index", ((RedirectToRouteResult) resultNuevo).RouteValues["action"]);
83 }
84 }
85
86 [Test]
87 public void Nuevo_Evento_Erroneo_Sin_Ponente()
88 {
89 ViewResult viewResult = null;
90 IEnumerable<EventoDto> eventosDto = null;
91 EventoPublicarModel eventoPublicar = null;
92 var eventoController = new EventoController();
93
94 var eventoNew = new EventoNewModel
95 {
96 Duracion = new TimeSpan(0, 0, 0),
97 Fecha = DateTime.Today.AddDays(15),
98 Hora = new TimeSpan(18, 0, 0),
99 TipoEvento = (int)TipoEvento.Van,
100 Titulo = "Título"
101 };
102
103 using (new RequestEmulator(NhHelper.GetSessionFactory()))
104 {
105 var resultNuevo = (ViewResult)eventoController.Nuevo(eventoNew);
106 var modelState = resultNuevo.ViewData.ModelState.FirstOrDefault().Value;
107 Assert.AreEqual(1, modelState.Errors.Count);
108 Assert.AreEqual("Debe indicar el ponente para este tipo de evento", modelState.Errors.FirstOrDefault().ErrorMessage);
109 }
110 }
111
61 [Test] 112 [Test]
62 public void Publicar_Evento() 113 public void Publicar_Evento_Erroneo_Duracion_Fuera_Rango()
63 { 114 {
64 ViewResult viewResult = null; 115 ViewResult viewResult = null;
65 IEnumerable<EventoDto> eventosDto = null; 116 IEnumerable<EventoDto> eventosDto = null;
66 EventoPublicarModel eventoPublicar = null; 117 EventoPublicarModel eventoPublicar = null;
67 var eventoController = new EventoController(); 118 var eventoController = new EventoController();
109 Assert.AreEqual(1, modelState.Errors.Count); 160 Assert.AreEqual(1, modelState.Errors.Count);
110 Assert.AreEqual("Duración fuera de rango", modelState.Errors.FirstOrDefault().ErrorMessage); 161 Assert.AreEqual("Duración fuera de rango", modelState.Errors.FirstOrDefault().ErrorMessage);
111 162
112 } 163 }
113 } 164 }
114 } 165 }
115 166
116 } 167 }