view Agendas/trunk/src/Agendas.Tests/PropuestasTests.cs @ 29:016b9b9b8d3a

Cuando se publica una van con el mismo titulo que una propuesta, se utiliza esta última promoviendola a evento publicado.
author nelo@MTEySS.neluz.int
date Wed, 16 Mar 2011 08:25:02 -0300
parents 71b02443450a
children 3c5657d99727
line wrap: on
line source

using System;
using System.Collections.Generic;
using System.Linq;
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 seguridad = new Mock<ISeguridad>();
            var agenda = new Agenda(null, null, seguridad.Object, DefaultEventoRepository, DefaultPonenteRepository);
            
            seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());
			agenda.Proponer("Van propuesta", null);

			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, DefaultEventoRepository, DefaultPonenteRepository);

			agenda.Proponer("Van propuesta", null);
            agenda.Publicar("Van publicada", "jjmontes", DateTime.Now);

            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, DefaultPonenteRepository);

			Assert.Throws<ValidationException>(() => agenda.Proponer(string.Empty, null));

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

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

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

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

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

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

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

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

		[Test]
		public void Publicar_van_propuesta()
		{
			var agenda = new Agenda(null, null, SeguridadServiceDefault, DefaultEventoRepository, DefaultPonenteRepository);

			agenda.Proponer("Van", null);
			{
				IList<Evento> eventosPropuestos = agenda.GetEventosPropuestos();
				IList<Evento> eventosPublicados = agenda.GetEventosPublicados();

				Assert.AreEqual(1, eventosPropuestos.Count);
				Assert.AreEqual(0, eventosPublicados.Count);
			}
			
			agenda.Publicar("Van", "jjmontes", DateTime.Now);
			{
				IList<Evento> eventosPropuestos = agenda.GetEventosPropuestos();
				IList<Evento> eventosPublicados = agenda.GetEventosPublicados();

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

	}
}