Mercurial > altnet-hispano
comparison Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs @ 284:79942e030118
#123: Patrocinadores de las vans: Se verifica que para publicar una Van, debe tener al menos un Patrocinador.
author | juanjose.montesdeocaarbos |
---|---|
date | Wed, 28 Dec 2011 09:35:27 -0300 |
parents | 2e17dfd1ba35 |
children |
comparison
equal
deleted
inserted
replaced
283:2e17dfd1ba35 | 284:79942e030118 |
---|---|
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.Web; | |
4 using System.Web.Mvc; | 5 using System.Web.Mvc; |
5 using Agendas.NHibernate; | 6 using Agendas.NHibernate; |
6 using Agendas.Repositories.Tests.Infraestructure; | 7 using Agendas.Repositories.Tests.Infraestructure; |
8 using Agendas.Web.Tests.Helpers; | |
7 using AltNetHispano.Agendas.Domain; | 9 using AltNetHispano.Agendas.Domain; |
8 using AltNetHispano.Agendas.Repositories.NHibernate; | 10 using AltNetHispano.Agendas.Repositories.NHibernate; |
9 using AltNetHispano.Agendas.Web.Controllers; | 11 using AltNetHispano.Agendas.Web.Controllers; |
10 using AltNetHispano.Agendas.Web.Models; | 12 using AltNetHispano.Agendas.Web.Models; |
11 using Moq; | 13 using Moq; |
30 Twitter = "persona1" | 32 Twitter = "persona1" |
31 }); | 33 }); |
32 } | 34 } |
33 } | 35 } |
34 | 36 |
37 private void PopulatePatrocinador() | |
38 { | |
39 //using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
40 //{ | |
41 // var patrocinadorController = new PatrocinadorController(new HttpServerStub()) | |
42 // { ControllerContext = ControllerCtx }; | |
43 // var form = new FormCollection | |
44 // { | |
45 // {"Nombre", "APRESS"}, | |
46 // {"Logo", @"images\apress.gif"} | |
47 // }; | |
48 // var patrocinadorNew = BindModel<PatrocinadorNewModel>(patrocinadorController, form); | |
49 // patrocinadorController.Nuevo(patrocinadorNew); | |
50 | |
51 //} | |
52 //using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
53 //{ | |
54 // var patrocinadorController = new PatrocinadorController(new HttpServerStub()); | |
55 // patrocinadorController.Nuevo(new PatrocinadorNewModel | |
56 // { | |
57 // Nombre = "jetbrains" | |
58 // }); | |
59 //} | |
60 //using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
61 //{ | |
62 // var patrocinadorController = new PatrocinadorController(new HttpServerStub()); | |
63 // patrocinadorController.Nuevo(new PatrocinadorNewModel | |
64 // { | |
65 // Nombre = "oreilly" | |
66 // }); | |
67 //} | |
68 } | |
69 | |
35 private Guid GetGuidPersona() | 70 private Guid GetGuidPersona() |
36 { | 71 { |
37 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 72 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
38 { | 73 { |
39 var personaController = new PersonaController(); | 74 var personaController = new PersonaController(); |
40 var viewResult = (ViewResult)personaController.Index(); | 75 var viewResult = (ViewResult)personaController.Index(); |
41 return ((PersonaIndexModel)viewResult.Model).Items.FirstOrDefault().Id; | 76 return ((PersonaIndexModel)viewResult.Model).Items.FirstOrDefault().Id; |
42 } | 77 } |
43 } | 78 } |
44 | 79 |
80 private static IEnumerable<PatrocinadorDto> GetPatrocinadores() | |
81 { | |
82 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
83 { | |
84 var patrocinadorController = new PatrocinadorController(); | |
85 var viewResult = (ViewResult)patrocinadorController.Index(); | |
86 return ((PatrocinadorIndexModel)viewResult.Model).Items; | |
87 } | |
88 } | |
89 | |
45 private void SetearUsuario() | 90 private void SetearUsuario() |
46 { | 91 { |
47 var seguridad = new Mock<ISeguridad>(); | 92 var seguridad = new Mock<ISeguridad>(); |
48 seguridad.Setup(s => s.GetUserName()).Returns("neluz"); | 93 seguridad.Setup(s => s.GetUserName()).Returns("neluz"); |
49 IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory())); | 94 IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory())); |
50 } | 95 } |
51 | 96 |
97 private IEnumerable<EventoDto> PrepararEventoParaConfirmar(EventoController eventoController) | |
98 { | |
99 ViewResult viewResult = null; | |
100 IEnumerable<EventoDto> eventosDto = null; | |
101 var formEvento = new FormCollection | |
102 { | |
103 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, | |
104 {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, | |
105 {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, | |
106 {"Ponentes", GetGuidPersona().ToString()}, | |
107 {"TipoEvento", ((int)TipoEvento.Van).ToString()}, | |
108 {"Titulo", "Título 2"} | |
109 }; | |
110 var eventoNew = BindModel<EventoNewModel>(eventoController, formEvento); | |
111 | |
112 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
113 { | |
114 eventoController.Nuevo(eventoNew); | |
115 } | |
116 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
117 { | |
118 viewResult = (ViewResult)eventoController.Index(); | |
119 } | |
120 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
121 { | |
122 eventosDto = ((EventoIndexModel)viewResult.Model).ProximosEventos; | |
123 } | |
124 | |
125 return eventosDto; | |
126 } | |
127 | |
128 private IEnumerable<EventoDto> PrepararEventoParaPublicar(EventoController eventoController) | |
129 { | |
130 var eventosDto = PrepararEventoParaConfirmar(eventoController); | |
131 | |
132 foreach (var model in eventosDto.Select(eventoDto => new EventoConfirmModel() | |
133 { | |
134 Id = eventoDto.Id, | |
135 //Recordatorios = null,// Lo comentamos para no agregar la referencia a Agendas.Twitter | |
136 Titulo = eventoDto.Titulo | |
137 })) | |
138 { | |
139 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
140 { | |
141 eventoController.Confirmar(model); | |
142 } | |
143 } | |
144 | |
145 return eventosDto; | |
146 } | |
147 | |
148 internal void RegisterBinders() | |
149 { | |
150 ModelBinders.Binders[typeof(HttpPostedFileBase)] = new HttpPostedFileBaseModelBinder(); | |
151 } | |
152 | |
52 [SetUp] | 153 [SetUp] |
53 public void Setup() | 154 public void Setup() |
54 { | 155 { |
55 NhHelperTest.CleanDb(); | 156 NhHelperTest.CleanDb(); |
56 PopulatePersona(); | 157 PopulatePersona(); |
158 PopulatePatrocinador(); | |
159 RegisterBinders(); | |
57 SetearUsuario(); | 160 SetearUsuario(); |
58 } | 161 } |
59 | 162 |
60 [Test] | 163 [Test] |
61 public void Nuevo_Evento() | 164 public void Nuevo_Evento() |
110 } | 213 } |
111 | 214 |
112 [Test] | 215 [Test] |
113 public void Publicar_Evento_Erroneo_Duracion_Fuera_Rango() | 216 public void Publicar_Evento_Erroneo_Duracion_Fuera_Rango() |
114 { | 217 { |
115 ViewResult viewResult = null; | 218 var eventoController = new EventoController { ControllerContext = ControllerCtx }; |
116 IEnumerable<EventoDto> eventosDto = null; | 219 var eventosDto = PrepararEventoParaPublicar(eventoController); |
117 EventoPublicarModel eventoPublicar = null; | 220 EventoPublicarModel eventoPublicar = null; |
118 var eventoController = new EventoController { ControllerContext = ControllerCtx }; | 221 |
119 var formEvento = new FormCollection | |
120 { | |
121 {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, | |
122 {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, | |
123 {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, | |
124 {"Ponentes", GetGuidPersona().ToString()}, | |
125 {"TipoEvento", ((int)TipoEvento.Van).ToString()}, | |
126 {"Titulo", "Título 2"} | |
127 }; | |
128 var eventoNew = BindModel<EventoNewModel>(eventoController, formEvento); | |
129 | |
130 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
131 { | |
132 eventoController.Nuevo(eventoNew); | |
133 } | |
134 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
135 { | |
136 viewResult = (ViewResult)eventoController.Index(); | |
137 } | |
138 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
139 { | |
140 eventosDto = ((EventoIndexModel)viewResult.Model).ProximosEventos; | |
141 } | |
142 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 222 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
143 { | 223 { |
144 var firstEvent = eventosDto.LastOrDefault(); | 224 var firstEvent = eventosDto.LastOrDefault(); |
145 var formPublicar = new FormCollection | 225 var formPublicar = new FormCollection |
146 { | 226 { |
147 {"Id", (firstEvent.Id).ToString()}, | 227 {"Id", (firstEvent.Id).ToString()}, |
148 {"Titulo", "Título 2"}, | 228 {"Titulo", "Título 2"}, |
149 {"NroOrden", "1"}, | 229 {"NroOrden", "1"}, |
150 {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"}, | 230 {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"}, |
151 {"DuracionReal", (new TimeSpan(0, 0, 0)).ToString()} | 231 {"DuracionReal", (new TimeSpan(0, 0, 0)).ToString()}, |
232 {"Patrocinadores", (Guid.NewGuid()).ToString()} | |
152 }; | 233 }; |
153 eventoPublicar = BindModel<EventoPublicarModel>(eventoController, formPublicar); | 234 eventoPublicar = BindModel<EventoPublicarModel>(eventoController, formPublicar); |
154 } | 235 } |
155 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 236 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
156 { | 237 { |
160 Assert.AreEqual(1, modelState[string.Empty].Errors.Count); | 241 Assert.AreEqual(1, modelState[string.Empty].Errors.Count); |
161 Assert.AreEqual("Duración fuera de rango", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage); | 242 Assert.AreEqual("Duración fuera de rango", modelState[string.Empty].Errors.FirstOrDefault().ErrorMessage); |
162 | 243 |
163 } | 244 } |
164 } | 245 } |
246 | |
247 [Test] | |
248 public void Publicar_Evento_Sin_Patrocinador() | |
249 { | |
250 var eventoController = new EventoController { ControllerContext = ControllerCtx }; | |
251 var eventosDto = PrepararEventoParaPublicar(eventoController); | |
252 EventoPublicarModel eventoPublicar = null; | |
253 | |
254 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
255 { | |
256 var firstEvent = eventosDto.LastOrDefault(); | |
257 var formPublicar = new FormCollection | |
258 { | |
259 {"Id", (firstEvent.Id).ToString()}, | |
260 {"Titulo", "Título 2"}, | |
261 {"NroOrden", "1"}, | |
262 {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"}, | |
263 {"DuracionReal", (new TimeSpan(2, 0, 0)).ToString()} | |
264 }; | |
265 eventoPublicar = BindModel<EventoPublicarModel>(eventoController, formPublicar); | |
266 } | |
267 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
268 { | |
269 var resultPublicar = (ViewResult)eventoController.Publicar(eventoPublicar); | |
270 var modelState = resultPublicar.ViewData.ModelState; | |
271 | |
272 Assert.AreEqual(1, modelState["Patrocinadores"].Errors.Count); | |
273 Assert.AreEqual("El campo Patrocinadores es obligatorio.", modelState["Patrocinadores"].Errors.FirstOrDefault().ErrorMessage); | |
274 | |
275 } | |
276 } | |
277 | |
278 [Test] | |
279 public void Publicar_Evento_Satisfactoriamente() | |
280 { | |
281 var eventoController = new EventoController {ControllerContext = ControllerCtx}; | |
282 var eventosDto = PrepararEventoParaPublicar(eventoController); | |
283 EventoPublicarModel eventoPublicar = null; | |
284 //var patrocinadores = GetPatrocinadores(); | |
285 EventoDto lastEvent = null; | |
286 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
287 { | |
288 lastEvent = eventosDto.LastOrDefault(); | |
289 } | |
290 | |
291 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
292 { | |
293 var formPublicar = new FormCollection | |
294 { | |
295 {"Id", (lastEvent.Id).ToString()}, | |
296 {"Titulo", "Título 2"}, | |
297 {"NroOrden", "1"}, | |
298 {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"}, | |
299 {"DuracionReal", (new TimeSpan(2, 0, 0)).ToString()}, | |
300 {"Patrocinadores", (Guid.NewGuid()).ToString()} | |
301 }; | |
302 eventoPublicar = BindModel<EventoPublicarModel>(eventoController, formPublicar); | |
303 } | |
304 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
305 { | |
306 var resultPublicar = eventoController.Publicar(eventoPublicar); | |
307 Assert.IsInstanceOf(typeof (RedirectToRouteResult), resultPublicar); | |
308 Assert.AreEqual("Index", ((RedirectToRouteResult) resultPublicar).RouteValues["action"]); | |
309 } | |
310 } | |
165 } | 311 } |
166 | 312 |
167 } | 313 } |