Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.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 | bdc946dd5c94 |
children | d255b0621503 |
comparison
equal
deleted
inserted
replaced
263:3339d1da6a63 | 264:cef4fc893333 |
---|---|
12 using NUnit.Framework; | 12 using NUnit.Framework; |
13 | 13 |
14 namespace Agendas.Web.Tests.Controllers | 14 namespace Agendas.Web.Tests.Controllers |
15 { | 15 { |
16 [TestFixture] | 16 [TestFixture] |
17 public class EventoControllerTests | 17 public class EventoControllerTests: MvcControllerTestsBase |
18 { | 18 { |
19 private void PopulatePersona() | 19 private void PopulatePersona() |
20 { | 20 { |
21 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 21 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
22 { | 22 { |
61 public void Nuevo_Evento() | 61 public void Nuevo_Evento() |
62 { | 62 { |
63 ViewResult viewResult = null; | 63 ViewResult viewResult = null; |
64 IEnumerable<EventoDto> eventosDto = null; | 64 IEnumerable<EventoDto> eventosDto = null; |
65 EventoPublicarModel eventoPublicar = null; | 65 EventoPublicarModel eventoPublicar = null; |
66 var eventoController = new EventoController(); | 66 var eventoController = new EventoController { ControllerContext = ControllerCtx }; |
67 | 67 var form = new FormCollection |
68 var eventoNew = new EventoNewModel | 68 { |
69 { | 69 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, |
70 Duracion = new TimeSpan(0, 0, 0), | 70 {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, |
71 Fecha = DateTime.Today.AddDays(15), | 71 {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, |
72 Hora = new TimeSpan(18, 0, 0), | 72 {"Ponentes", GetGuidPersona().ToString()}, |
73 Ponentes = new[] { GetGuidPersona() }, | 73 {"TipoEvento", ((int)TipoEvento.Van).ToString()}, |
74 TipoEvento = (int)TipoEvento.Van, | 74 {"Titulo", "Título"} |
75 Titulo = "Título" | 75 }; |
76 }; | 76 var eventoNew = BindModel<EventoNewModel>(eventoController, form); |
77 | 77 |
78 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 78 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
79 { | 79 { |
80 var resultNuevo = eventoController.Nuevo(eventoNew); | 80 var resultNuevo = eventoController.Nuevo(eventoNew); |
81 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultNuevo); | 81 Assert.IsInstanceOf(typeof(RedirectToRouteResult), resultNuevo); |
87 public void Nuevo_Evento_Erroneo_Sin_Ponente() | 87 public void Nuevo_Evento_Erroneo_Sin_Ponente() |
88 { | 88 { |
89 ViewResult viewResult = null; | 89 ViewResult viewResult = null; |
90 IEnumerable<EventoDto> eventosDto = null; | 90 IEnumerable<EventoDto> eventosDto = null; |
91 EventoPublicarModel eventoPublicar = null; | 91 EventoPublicarModel eventoPublicar = null; |
92 var eventoController = new EventoController(); | 92 var eventoController = new EventoController { ControllerContext = ControllerCtx }; |
93 | 93 var form = new FormCollection |
94 var eventoNew = new EventoNewModel | 94 { |
95 { | 95 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, |
96 Duracion = new TimeSpan(0, 0, 0), | 96 {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, |
97 Fecha = DateTime.Today.AddDays(15), | 97 {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, |
98 Hora = new TimeSpan(18, 0, 0), | 98 {"TipoEvento", ((int)TipoEvento.Van).ToString()}, |
99 TipoEvento = (int)TipoEvento.Van, | 99 {"Titulo", "Título"} |
100 Titulo = "Título" | 100 }; |
101 }; | 101 var eventoNew = BindModel<EventoNewModel>(eventoController, form); |
102 | 102 |
103 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 103 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
104 { | 104 { |
105 var resultNuevo = (ViewResult)eventoController.Nuevo(eventoNew); | 105 var resultNuevo = (ViewResult)eventoController.Nuevo(eventoNew); |
106 var modelState = resultNuevo.ViewData.ModelState.FirstOrDefault().Value; | 106 var modelState = resultNuevo.ViewData.ModelState; |
107 Assert.AreEqual(1, modelState.Errors.Count); | 107 Assert.AreEqual(1, modelState[string.Empty].Errors.Count); |
108 Assert.AreEqual("Debe indicar el ponente para este tipo de evento", modelState.Errors.FirstOrDefault().ErrorMessage); | 108 Assert.AreEqual("Debe indicar el ponente para este tipo de evento", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage); |
109 } | 109 } |
110 } | 110 } |
111 | 111 |
112 [Test] | 112 [Test] |
113 public void Publicar_Evento_Erroneo_Duracion_Fuera_Rango() | 113 public void Publicar_Evento_Erroneo_Duracion_Fuera_Rango() |
114 { | 114 { |
115 ViewResult viewResult = null; | 115 ViewResult viewResult = null; |
116 IEnumerable<EventoDto> eventosDto = null; | 116 IEnumerable<EventoDto> eventosDto = null; |
117 EventoPublicarModel eventoPublicar = null; | 117 EventoPublicarModel eventoPublicar = null; |
118 var eventoController = new EventoController(); | 118 var eventoController = new EventoController { ControllerContext = ControllerCtx }; |
119 | 119 var formEvento = new FormCollection |
120 var eventoNew = new EventoNewModel | 120 { |
121 { | 121 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, |
122 Duracion = new TimeSpan(0, 0, 0), | 122 {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, |
123 Fecha = DateTime.Today.AddDays(15), | 123 {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, |
124 Hora = new TimeSpan(18, 0, 0), | 124 {"Ponentes", GetGuidPersona().ToString()}, |
125 Ponentes = new[] { GetGuidPersona()}, | 125 {"TipoEvento", ((int)TipoEvento.Van).ToString()}, |
126 TipoEvento = (int) TipoEvento.Van, | 126 {"Titulo", "Título 2"} |
127 Titulo = "Título 2" | 127 }; |
128 }; | 128 var eventoNew = BindModel<EventoNewModel>(eventoController, formEvento); |
129 | 129 |
130 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 130 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
131 { | 131 { |
132 eventoController.Nuevo(eventoNew); | 132 eventoController.Nuevo(eventoNew); |
133 } | 133 } |
140 eventosDto = ((EventoIndexModel) viewResult.Model).ProximosEventos; | 140 eventosDto = ((EventoIndexModel) viewResult.Model).ProximosEventos; |
141 } | 141 } |
142 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 142 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
143 { | 143 { |
144 var firstEvent = eventosDto.LastOrDefault(); | 144 var firstEvent = eventosDto.LastOrDefault(); |
145 | 145 var formPublicar = new FormCollection |
146 eventoPublicar = new EventoPublicarModel | 146 { |
147 { | 147 {"Id", (firstEvent.Id).ToString()}, |
148 Id = firstEvent.Id, | 148 {"Titulo", "Título 2"}, |
149 NroOrden = 1, | 149 {"NroOrden", "1"}, |
150 //Titulo = "Título 2", | 150 {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"}, |
151 UrlWiki = "http://www.altnethistpano.org/vans/titulo-1.ashx", | 151 {"DuracionReal", (new TimeSpan(0, 0, 0)).ToString()} |
152 DuracionReal = new TimeSpan(0, 0, 0) | 152 }; |
153 }; | 153 eventoPublicar = BindModel<EventoPublicarModel>(eventoController, formPublicar); |
154 } | 154 } |
155 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 155 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
156 { | 156 { |
157 var resultPublicar = (ViewResult)eventoController.Publicar(eventoPublicar); | 157 var resultPublicar = (ViewResult)eventoController.Publicar(eventoPublicar); |
158 var modelState = resultPublicar.ViewData.ModelState.FirstOrDefault().Value; | 158 var modelState = resultPublicar.ViewData.ModelState; |
159 | 159 |
160 Assert.AreEqual(1, modelState.Errors.Count); | 160 Assert.AreEqual(1, modelState[string.Empty].Errors.Count); |
161 Assert.AreEqual("Duración fuera de rango", modelState.Errors.FirstOrDefault().ErrorMessage); | 161 Assert.AreEqual("Duración fuera de rango", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage); |
162 | 162 |
163 } | 163 } |
164 } | 164 } |
165 } | 165 } |
166 | 166 |