# HG changeset patch # User juanjose.montesdeocaarbos # Date 1325075727 10800 # Node ID 79942e03011838506b2a184439d1f0143b811172 # Parent 2e17dfd1ba35bd223111db09d6c95f61abfcbb64 #123: Patrocinadores de las vans: Se verifica que para publicar una Van, debe tener al menos un Patrocinador. diff -r 2e17dfd1ba35 -r 79942e030118 Agendas/trunk/src/Agendas.Domain/Agenda.cs --- a/Agendas/trunk/src/Agendas.Domain/Agenda.cs Mon Dec 26 14:34:46 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Domain/Agenda.cs Wed Dec 28 09:35:27 2011 -0300 @@ -189,7 +189,7 @@ var evento = GetEvento(eventoId); - if (/*evento.Tipo == TipoEvento.Van &&*/ evento.Patrocinadores.Count() == 0) + if (evento.Patrocinadores.Count() == 0) return new EventoResultado(false, "La VAN debe tener al menos un Patrocinador para ser publicada.", null); evento.Publicar(numeroOrden, urlWiki, duracion); @@ -270,19 +270,22 @@ var agregar = new List(); var quitar = new List(); - foreach (var patrocinadorId in patrocinadores) + if (patrocinadores != null) { - if (!evento.Patrocinadores.Any(p => p.Id == patrocinadorId)) + foreach (var patrocinadorId in patrocinadores) { - var patrocinador = _patrocinadorRepository.Get(patrocinadorId); - agregar.Add(patrocinador); + if (!evento.Patrocinadores.Any(p => p.Id == patrocinadorId)) + { + var patrocinador = _patrocinadorRepository.Get(patrocinadorId); + agregar.Add(patrocinador); + } } - } - foreach (var patrocinador in evento.Patrocinadores) - { - if (!patrocinadores.Any(p => p == patrocinador.Id)) - quitar.Add(patrocinador); + foreach (var patrocinador in evento.Patrocinadores) + { + if (!patrocinadores.Any(p => p == patrocinador.Id)) + quitar.Add(patrocinador); + } } foreach (var patrocinador in agregar) diff -r 2e17dfd1ba35 -r 79942e030118 Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs --- a/Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs Mon Dec 26 14:34:46 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web.Tests/Controllers/EventoControllerTests.cs Wed Dec 28 09:35:27 2011 -0300 @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Web; using System.Web.Mvc; using Agendas.NHibernate; using Agendas.Repositories.Tests.Infraestructure; +using Agendas.Web.Tests.Helpers; using AltNetHispano.Agendas.Domain; using AltNetHispano.Agendas.Repositories.NHibernate; using AltNetHispano.Agendas.Web.Controllers; @@ -32,6 +34,39 @@ } } + private void PopulatePatrocinador() + { + //using (new RequestEmulator(NhHelper.GetSessionFactory())) + //{ + // var patrocinadorController = new PatrocinadorController(new HttpServerStub()) + // { ControllerContext = ControllerCtx }; + // var form = new FormCollection + // { + // {"Nombre", "APRESS"}, + // {"Logo", @"images\apress.gif"} + // }; + // var patrocinadorNew = BindModel(patrocinadorController, form); + // patrocinadorController.Nuevo(patrocinadorNew); + + //} + //using (new RequestEmulator(NhHelper.GetSessionFactory())) + //{ + // var patrocinadorController = new PatrocinadorController(new HttpServerStub()); + // patrocinadorController.Nuevo(new PatrocinadorNewModel + // { + // Nombre = "jetbrains" + // }); + //} + //using (new RequestEmulator(NhHelper.GetSessionFactory())) + //{ + // var patrocinadorController = new PatrocinadorController(new HttpServerStub()); + // patrocinadorController.Nuevo(new PatrocinadorNewModel + // { + // Nombre = "oreilly" + // }); + //} + } + private Guid GetGuidPersona() { using (new RequestEmulator(NhHelper.GetSessionFactory())) @@ -42,6 +77,16 @@ } } + private static IEnumerable GetPatrocinadores() + { + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + var patrocinadorController = new PatrocinadorController(); + var viewResult = (ViewResult)patrocinadorController.Index(); + return ((PatrocinadorIndexModel)viewResult.Model).Items; + } + } + private void SetearUsuario() { var seguridad = new Mock(); @@ -49,11 +94,69 @@ IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory())); } + private IEnumerable PrepararEventoParaConfirmar(EventoController eventoController) + { + ViewResult viewResult = null; + IEnumerable eventosDto = null; + var formEvento = new FormCollection + { + {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, + {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, + {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, + {"Ponentes", GetGuidPersona().ToString()}, + {"TipoEvento", ((int)TipoEvento.Van).ToString()}, + {"Titulo", "Título 2"} + }; + var eventoNew = BindModel(eventoController, formEvento); + + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + eventoController.Nuevo(eventoNew); + } + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + viewResult = (ViewResult)eventoController.Index(); + } + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + eventosDto = ((EventoIndexModel)viewResult.Model).ProximosEventos; + } + + return eventosDto; + } + + private IEnumerable PrepararEventoParaPublicar(EventoController eventoController) + { + var eventosDto = PrepararEventoParaConfirmar(eventoController); + + foreach (var model in eventosDto.Select(eventoDto => new EventoConfirmModel() + { + Id = eventoDto.Id, + //Recordatorios = null,// Lo comentamos para no agregar la referencia a Agendas.Twitter + Titulo = eventoDto.Titulo + })) + { + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + eventoController.Confirmar(model); + } + } + + return eventosDto; + } + + internal void RegisterBinders() + { + ModelBinders.Binders[typeof(HttpPostedFileBase)] = new HttpPostedFileBaseModelBinder(); + } + [SetUp] public void Setup() { NhHelperTest.CleanDb(); PopulatePersona(); + PopulatePatrocinador(); + RegisterBinders(); SetearUsuario(); } @@ -112,35 +215,12 @@ [Test] public void Publicar_Evento_Erroneo_Duracion_Fuera_Rango() { - ViewResult viewResult = null; - IEnumerable eventosDto = null; + var eventoController = new EventoController { ControllerContext = ControllerCtx }; + var eventosDto = PrepararEventoParaPublicar(eventoController); EventoPublicarModel eventoPublicar = null; - var eventoController = new EventoController { ControllerContext = ControllerCtx }; - var formEvento = new FormCollection - { - {"Duracion", (new TimeSpan(0, 0, 0)).ToString()}, - {"Fecha", (DateTime.Today.AddDays(15)).ToString()}, - {"Hora", (new TimeSpan(18, 0, 0)).ToString()}, - {"Ponentes", GetGuidPersona().ToString()}, - {"TipoEvento", ((int)TipoEvento.Van).ToString()}, - {"Titulo", "Título 2"} - }; - var eventoNew = BindModel(eventoController, formEvento); using (new RequestEmulator(NhHelper.GetSessionFactory())) { - eventoController.Nuevo(eventoNew); - } - 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 firstEvent = eventosDto.LastOrDefault(); var formPublicar = new FormCollection { @@ -148,7 +228,8 @@ {"Titulo", "Título 2"}, {"NroOrden", "1"}, {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"}, - {"DuracionReal", (new TimeSpan(0, 0, 0)).ToString()} + {"DuracionReal", (new TimeSpan(0, 0, 0)).ToString()}, + {"Patrocinadores", (Guid.NewGuid()).ToString()} }; eventoPublicar = BindModel(eventoController, formPublicar); } @@ -162,6 +243,71 @@ } } + + [Test] + public void Publicar_Evento_Sin_Patrocinador() + { + var eventoController = new EventoController { ControllerContext = ControllerCtx }; + var eventosDto = PrepararEventoParaPublicar(eventoController); + EventoPublicarModel eventoPublicar = null; + + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + var firstEvent = eventosDto.LastOrDefault(); + var formPublicar = new FormCollection + { + {"Id", (firstEvent.Id).ToString()}, + {"Titulo", "Título 2"}, + {"NroOrden", "1"}, + {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"}, + {"DuracionReal", (new TimeSpan(2, 0, 0)).ToString()} + }; + eventoPublicar = BindModel(eventoController, formPublicar); + } + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + var resultPublicar = (ViewResult)eventoController.Publicar(eventoPublicar); + var modelState = resultPublicar.ViewData.ModelState; + + Assert.AreEqual(1, modelState["Patrocinadores"].Errors.Count); + Assert.AreEqual("El campo Patrocinadores es obligatorio.", modelState["Patrocinadores"].Errors.FirstOrDefault().ErrorMessage); + + } + } + + [Test] + public void Publicar_Evento_Satisfactoriamente() + { + var eventoController = new EventoController {ControllerContext = ControllerCtx}; + var eventosDto = PrepararEventoParaPublicar(eventoController); + EventoPublicarModel eventoPublicar = null; + //var patrocinadores = GetPatrocinadores(); + EventoDto lastEvent = null; + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + lastEvent = eventosDto.LastOrDefault(); + } + + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + var formPublicar = new FormCollection + { + {"Id", (lastEvent.Id).ToString()}, + {"Titulo", "Título 2"}, + {"NroOrden", "1"}, + {"UrlWiki", "http://www.altnethistpano.org/vans/titulo-1.ashx"}, + {"DuracionReal", (new TimeSpan(2, 0, 0)).ToString()}, + {"Patrocinadores", (Guid.NewGuid()).ToString()} + }; + eventoPublicar = BindModel(eventoController, formPublicar); + } + using (new RequestEmulator(NhHelper.GetSessionFactory())) + { + var resultPublicar = eventoController.Publicar(eventoPublicar); + Assert.IsInstanceOf(typeof (RedirectToRouteResult), resultPublicar); + Assert.AreEqual("Index", ((RedirectToRouteResult) resultPublicar).RouteValues["action"]); + } + } } } \ No newline at end of file diff -r 2e17dfd1ba35 -r 79942e030118 Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs --- a/Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs Mon Dec 26 14:34:46 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Controllers/EventoController.cs Wed Dec 28 09:35:27 2011 -0300 @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Web.Mvc; using AltNetHispano.Agendas.Domain; @@ -113,6 +114,9 @@ [CustomAuthorize(Roles = Roles.Administrador)] public ActionResult Publicar(EventoPublicarModel model) { + var a = AgendaFactory.GetAgenda(); + a.IndicarPatrocinadores(new Guid(model.Id), model.Patrocinadores); + return GenericAction( (agenda, m) => agenda.Publicar(new Guid(m.Id), m.NroOrden, m.UrlWiki, m.DuracionReal), diff -r 2e17dfd1ba35 -r 79942e030118 Agendas/trunk/src/Agendas.Web/Models/EventoModel.cs --- a/Agendas/trunk/src/Agendas.Web/Models/EventoModel.cs Mon Dec 26 14:34:46 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Web/Models/EventoModel.cs Wed Dec 28 09:35:27 2011 -0300 @@ -100,6 +100,9 @@ [Required] public TimeSpan DuracionReal { get; set; } + + [Required] + public IEnumerable Patrocinadores { get; set; } } public class EventoConfirmModel