Mercurial > altnet-hispano
comparison 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 |
comparison
equal
deleted
inserted
replaced
242:5cc1681d3789 | 243:59f8fa2f835e |
---|---|
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; | 4 using System.Text; |
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; |
7 using AltNetHispano.Agendas.Domain; | 8 using AltNetHispano.Agendas.Domain; |
8 using AltNetHispano.Agendas.Repositories.NHibernate; | 9 using AltNetHispano.Agendas.Repositories.NHibernate; |
9 using AltNetHispano.Agendas.Web.Controllers; | 10 using AltNetHispano.Agendas.Web.Controllers; |
14 namespace Agendas.Web.Tests.Controllers | 15 namespace Agendas.Web.Tests.Controllers |
15 { | 16 { |
16 [TestFixture] | 17 [TestFixture] |
17 public class EventoControllerTests | 18 public class EventoControllerTests |
18 { | 19 { |
19 [SetUp] | 20 private void PopulatePersona() |
20 public void SetearUsuario() | 21 { |
22 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
23 { | |
24 var personaController = new PersonaController(); | |
25 personaController.Nueva(new PersonaNewModel | |
26 { | |
27 Nombre = "Persona 1", | |
28 Blog = "http://blog.persona1.com", | |
29 EMail = "info@persona1.com", | |
30 Roles = new string[] {"Administrador", "Usuario"}, | |
31 Twitter = "persona1" | |
32 }); | |
33 } | |
34 } | |
35 | |
36 private Guid GetGuidPersona() | |
37 { | |
38 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
39 { | |
40 var personaController = new PersonaController(); | |
41 var viewResult = (ViewResult) personaController.Index(); | |
42 return ((PersonaIndexModel) viewResult.Model).Items.FirstOrDefault().Id; | |
43 } | |
44 } | |
45 | |
46 private void SetearUsuario() | |
21 { | 47 { |
22 var seguridad = new Mock<ISeguridad>(); | 48 var seguridad = new Mock<ISeguridad>(); |
23 seguridad.Setup(s => s.GetUserName()).Returns("neluz"); | 49 seguridad.Setup(s => s.GetUserName()).Returns("neluz"); |
24 IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory())); | 50 IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory())); |
25 | |
26 } | 51 } |
27 | 52 |
28 [Test] | 53 [SetUp] |
29 [Ignore] | 54 public void Setup() |
55 { | |
56 NhHelperTest.CleanDb(); | |
57 PopulatePersona(); | |
58 SetearUsuario(); | |
59 } | |
60 | |
61 [Test] | |
30 public void Publicar_Evento() | 62 public void Publicar_Evento() |
31 { | 63 { |
64 ViewResult viewResult = null; | |
65 IEnumerable<EventoDto> eventosDto = null; | |
66 EventoPublicarModel eventoPublicar = null; | |
32 var eventoController = new EventoController(); | 67 var eventoController = new EventoController(); |
33 | 68 |
34 var eventoNew = new EventoNewModel | 69 var eventoNew = new EventoNewModel |
35 { | 70 { |
36 Duracion = new TimeSpan(0, 0, 0), | 71 Duracion = new TimeSpan(0, 0, 0), |
37 Fecha = DateTime.Today.AddDays(5), | 72 Fecha = DateTime.Today.AddDays(15), |
38 Hora = new TimeSpan(18, 0, 0), | 73 Hora = new TimeSpan(18, 0, 0), |
39 Ponentes = new[] {Guid.NewGuid()}, | 74 Ponentes = new[] { GetGuidPersona()}, |
40 TipoEvento = (int) TipoEvento.Van, | 75 TipoEvento = (int) TipoEvento.Van, |
41 Titulo = "Título 1" | 76 Titulo = "Título 2" |
42 }; | 77 }; |
43 | 78 |
44 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 79 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
45 { | 80 { |
46 var resultNuevo = eventoController.Nuevo(eventoNew); | 81 eventoController.Nuevo(eventoNew); |
47 } | 82 } |
48 | |
49 var eventoPublicar = new EventoPublicarModel | |
50 { | |
51 NroOrden = 1, | |
52 Titulo = "Título 1", | |
53 UrlWiki = "http://www.altnethistpano.org/vans/titulo-1.ashx", | |
54 DuracionReal = new TimeSpan(0, 0, 0) | |
55 }; | |
56 | |
57 using (new RequestEmulator(NhHelper.GetSessionFactory())) | 83 using (new RequestEmulator(NhHelper.GetSessionFactory())) |
58 { | 84 { |
59 var resultPublicar = eventoController.Publicar(eventoPublicar); | 85 viewResult = (ViewResult)eventoController.Index(); |
86 } | |
87 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
88 { | |
89 eventosDto = ((EventoIndexModel) viewResult.Model).ProximosEventos; | |
90 } | |
91 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
92 { | |
93 var firstEvent = eventosDto.LastOrDefault(); | |
94 | |
95 eventoPublicar = new EventoPublicarModel | |
96 { | |
97 Id = firstEvent.Id, | |
98 NroOrden = 1, | |
99 //Titulo = "Título 2", | |
100 UrlWiki = "http://www.altnethistpano.org/vans/titulo-1.ashx", | |
101 DuracionReal = new TimeSpan(0, 0, 0) | |
102 }; | |
103 } | |
104 using (new RequestEmulator(NhHelper.GetSessionFactory())) | |
105 { | |
106 var resultPublicar = (ViewResult)eventoController.Publicar(eventoPublicar); | |
107 var modelState = resultPublicar.ViewData.ModelState.FirstOrDefault().Value; | |
108 | |
109 Assert.AreEqual(1, modelState.Errors.Count); | |
110 Assert.AreEqual("Duración fuera de rango", modelState.Errors.FirstOrDefault().ErrorMessage); | |
111 | |
60 } | 112 } |
61 } | 113 } |
62 } | 114 } |
63 | 115 |
64 } | 116 } |