view Agendas/trunk/src/Agendas.Tests/PropuestasTests.cs @ 21:43360bf09b1a

unificando criterio de parámetros en Agenda
author nelo@MTEySS.neluz.int
date Mon, 14 Mar 2011 21:05:19 -0300
parents c5a99dde072f
children d6e124e5c9c4
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.Linq;
using Agendas.Repositories.Memory;
using AltNetHispano.Agendas.Domain;
using AltNetHispano.Agendas.Domain.Exceptions;
using AltNetHispano.Agendas.Domain.Repositories;
using Moq;
using NUnit.Framework;

namespace AltNetHispano.Agendas.Tests
{
	[TestFixture]
	public class PropuestasTests : TestBase
	{
		[Test]
		public void Propuesta_de_van_con_usuario_autenticado()
		{
			var repository = new EventoRepository();

            var seguridad = new Mock<ISeguridad>();
            var agenda = new Agenda(null, null, seguridad.Object, repository);
            
            seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());
			agenda.Proponer("Van propuesta");

			IList<Evento> eventosPropuestos = agenda.GetEventosPropuestos();
			Assert.IsNotNull(eventosPropuestos);
			Assert.AreEqual(1, eventosPropuestos.Count);
			Assert.AreEqual("Van propuesta", eventosPropuestos[0].Titulo);
		}

        [Test]
        public void Verificar_propuesta_separada_de_publicacion()
        {
            var agenda = new Agenda(null, null, SeguridadServiceDefault, new EventoRepository());

            var vanPublicada = EventoObjectMother.GetVanValidaParaPublicar();

			agenda.Proponer("Van propuesta");
            agenda.Publicar(vanPublicada.Titulo, vanPublicada.Ponente, vanPublicada.Fecha);

            IList<Evento> eventosPropuestos = agenda.GetEventosPropuestos();
            IList<Evento> eventosPublicados = agenda.GetEventosPublicados();

            Assert.AreEqual(1, eventosPropuestos.Count);
            Assert.AreEqual(1, eventosPublicados.Count);
		}

		[Test]
		public void Propuesta_de_van_sin_titulo()
		{
			var repository = new Mock<IEventoRepository>();

            var seguridad = new Mock<ISeguridad>();
            var agenda = new Agenda(null, null, seguridad.Object, repository.Object);
            
            Assert.Throws<ValidationException>(() => agenda.Proponer(string.Empty));

			repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
		}

		[Test]
		public void Agendar_van_propuesta_sin_fecha()
		{
			var repository = new EventoRepository();
			
			var seguridad = new Mock<ISeguridad>();
            var agenda = new Agenda(null, null, seguridad.Object, repository);
            
            seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());

			{
                agenda.Proponer("Van propuesta");
			}

			{
				var van = agenda.GetEventosPropuestos().FirstOrDefault();
				Assert.IsNotNull(van);
                Assert.Throws<ValidationException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
			}
		}

		[Test]
		public void Agendar_van_propuesta_sin_ponente()
		{
			var repository = new EventoRepository();
						
			var seguridad = new Mock<ISeguridad>();
            var agenda = new Agenda(null, null, seguridad.Object, repository);
            
            seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());

			{
				agenda.Proponer("Van propuesta");
			}

			{
				var van = agenda.GetEventosPropuestos().FirstOrDefault();
				Assert.IsNotNull(van);

				van.Fecha = DateTime.Today.AddDays(5);
                Assert.Throws<ValidationException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
			}
		}

		[Test]
		public void Van_crud()
		{
			var van = EventoObjectMother.GetVanValidaParaPublicar();
            
            Guid vanId;
			{
                var agenda = new Agenda(null, null, SeguridadServiceDefault, new EventoRepository());
                agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);

				IAgendaRepository agendaRepository = new AgendaRepository();

				agendaRepository.Save(agenda);
				vanId = agenda.Id;
			}

			{
				IAgendaRepository agendaRepository = new AgendaRepository();

				Agenda agenda = agendaRepository.Get(vanId);

				Assert.IsNotNull(agenda);
				Assert.AreEqual(1, agenda.GetEventosPublicados().Count);
                agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);

				agendaRepository.Update(agenda);
			}

			{
				IAgendaRepository agendaRepository = new AgendaRepository();

				Agenda agenda = agendaRepository.Get(vanId);

				Assert.IsNotNull(agenda);
				Assert.AreEqual(2, agenda.GetEventosPublicados().Count);

				agendaRepository.Delete(agenda);
			}

			{
				IAgendaRepository agendaRepository = new AgendaRepository();

				Agenda agenda = agendaRepository.Get(vanId);

				Assert.IsNull(agenda);
			}
		}
	}
}