# HG changeset patch # User nelopauselli # Date 1312844911 10800 # Node ID 6ee05ceea8c39ae3919d3c500e30e728941f4812 # Parent 222362c294167add0d7c3405f47f6c27a29614c0 Implementando test de workflow también con nh diff -r 222362c29416 -r 6ee05ceea8c3 Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj --- a/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj Mon Aug 08 16:42:52 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj Mon Aug 08 20:08:31 2011 -0300 @@ -98,7 +98,8 @@ - + + diff -r 222362c29416 -r 6ee05ceea8c3 Agendas/trunk/src/Agendas.Tests/Workflows/Workflow.cs --- a/Agendas/trunk/src/Agendas.Tests/Workflows/Workflow.cs Mon Aug 08 16:42:52 2011 -0300 +++ b/Agendas/trunk/src/Agendas.Tests/Workflows/Workflow.cs Mon Aug 08 20:08:31 2011 -0300 @@ -1,4 +1,5 @@ using System; +using System.Linq; using AltNetHispano.Agendas.Domain; using AltNetHispano.Agendas.Domain.Repositories; using NUnit.Framework; @@ -7,61 +8,105 @@ { internal class Workflow { + private readonly Func _requestEmulator; private readonly Agenda _agenda; + private readonly IEventoRepository _eventoRepository; + private Guid _eventoId; - public Workflow(IPublicador publicador, IEventoRepository eventoRepository, IPersonaRepository personaRepository, IPatrocinadorRepository patrocinadorRepository) + public Workflow(IPublicador publicador, IEventoRepository eventoRepository, IPersonaRepository personaRepository, + IPatrocinadorRepository patrocinadorRepository, Func requestEmulator) { + _requestEmulator = requestEmulator; + _eventoRepository = eventoRepository; _agenda = new Agenda(publicador, eventoRepository, personaRepository, patrocinadorRepository); } public void Proponer() { - - var resultado = _agenda.Proponer("SOLID", TestsHelper.GetOrCreatePonente("Jorge"), null, TipoEvento.Van); - Assert.IsTrue(resultado.Succeful); + using (_requestEmulator.Invoke()) + { + var resultado = _agenda.Proponer("SOLID", TestsHelper.GetOrCreatePonente("Jorge"), null, TipoEvento.Van); + Assert.IsTrue(resultado.Succeful); + } + + GetId(); } public void Agendar() { - var resultado = _agenda.Agendar("SOLID", TestsHelper.GetOrCreatePonente("Jorge"), DateTime.Today.AddDays(5), null, TipoEvento.Van); - Assert.IsTrue(resultado.Succeful); + using (_requestEmulator.Invoke()) + { + var resultado = _agenda.Agendar("SOLID", TestsHelper.GetOrCreatePonente("Jorge"), DateTime.Today.AddDays(5), null, + TipoEvento.Van); + Assert.IsTrue(resultado.Succeful); + } + + GetId(); } - public void Confirmar(Guid eventoId) + private void GetId() { - var resultado = _agenda.Confirmar(eventoId); - Assert.IsTrue(resultado.Succeful); + using (_requestEmulator.Invoke()) + { + var evento = _eventoRepository.GetActivos().SingleOrDefault(); + Assert.IsNotNull(evento); + _eventoId = evento.Id; + } } - public void Publicar(Guid eventoId) + public void Confirmar() { - var resultado = _agenda.Publicar(eventoId, 1, "http://www.altnethispano.org/", new TimeSpan(2, 11, 0)); - Assert.IsTrue(resultado.Succeful); + using (_requestEmulator.Invoke()) + { + var resultado = _agenda.Confirmar(_eventoId); + Assert.IsTrue(resultado.Succeful); + } + } + + public void Publicar() + { + using (_requestEmulator.Invoke()) + { + var resultado = _agenda.Publicar(_eventoId, 1, "http://www.altnethispano.org/", new TimeSpan(2, 11, 0)); + Assert.IsTrue(resultado.Succeful); + } } - public void Cancelar(Guid eventoId) - { - var resultado = _agenda.Cancelar(eventoId); - Assert.IsTrue(resultado.Succeful); - } + public void Cancelar() + { + using (_requestEmulator.Invoke()) + { + var resultado = _agenda.Cancelar(_eventoId); + Assert.IsTrue(resultado.Succeful); + } + } - public void Descartar(Guid eventoId) - { - var resultado = _agenda.Descartar(eventoId); - Assert.IsTrue(resultado.Succeful); - } + public void Descartar() + { + using (_requestEmulator.Invoke()) + { + var resultado = _agenda.Descartar(_eventoId); + Assert.IsTrue(resultado.Succeful); + } + } - public void ReProponer(Guid eventoId) - { - var resultado = _agenda.ReProponer(eventoId); - Assert.IsTrue(resultado.Succeful); - } + public void ReProponer() + { + using (_requestEmulator.Invoke()) + { + var resultado = _agenda.ReProponer(_eventoId); + Assert.IsTrue(resultado.Succeful); + } + } - public void ReAgendar(Guid eventoId) - { - var resultado = _agenda.ReAgendar(eventoId); - Assert.IsTrue(resultado.Succeful); - } + public void ReAgendar() + { + using (_requestEmulator.Invoke()) + { + var resultado = _agenda.ReAgendar(_eventoId); + Assert.IsTrue(resultado.Succeful); + } + } } } \ No newline at end of file diff -r 222362c29416 -r 6ee05ceea8c3 Agendas/trunk/src/Agendas.Tests/Workflows/WorkflowMemoryTests.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Tests/Workflows/WorkflowMemoryTests.cs Mon Aug 08 20:08:31 2011 -0300 @@ -0,0 +1,165 @@ +using System; +using System.Collections.Generic; +using AltNetHispano.Agendas.Domain; +using Moq; +using NUnit.Framework; + +namespace AltNetHispano.Agendas.Tests.Workflows +{ + [TestFixture] + public class WorkflowMemoryTests : TestBase + { + private Mock _publicador; + private Workflow _workflow; + + [SetUp] + public void InitPublicador() + { + _publicador = new Mock(); + _workflow = new Workflow(_publicador.Object, DefaultEventoRepository, DefaultPersonaRepository, + DefaultPatrocinadorRepository, () => new Mock().Object); + } + + [Test] + public void Proponer() + { + _workflow.Proponer(); + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Once()); + } + + [Test] + public void Proponer_y_agendar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(2)); + } + + [Test] + public void Proponer_agendar_y_cancelar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _publicador.Verify(p=>p.Publicar(It.IsAny>()), Times.Exactly(3)); + } + + [Test] + public void Proponer_agendar_cancelar_y_reagendar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.ReAgendar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); + } + + [Test] + public void Proponer_agendar_cancelar_reproponer_agendar_y_confirmar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.ReProponer(); + + _workflow.Agendar(); + + _workflow.Confirmar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(6)); + } + + [Test] + public void Proponer_agendar_cancelar_reagendar_y_confirmar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.ReAgendar(); + + _workflow.Confirmar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(5)); + } + + [Test] + public void Proponer_agendar_cancelar_y_reproponer() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.ReProponer(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); + } + + [Test] + public void Proponer_y_descartar() + { + _workflow.Proponer(); + + _workflow.Descartar(); + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(2)); + } + + [Test] + public void Proponer_agendar_cancelar_y_descartar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.Descartar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); + } + + [Test] + public void Proponer_agendar_y_confirmar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Confirmar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(3)); + } + + [Test] + public void Proponer_agendar_confirmar_publicar() + { + const string urlWiki = "http://www.altnethispano.org/wiki/van-2010-10-21-mono-cecil.ashx"; + + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Confirmar(); + + _workflow.Publicar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); + } + } +} \ No newline at end of file diff -r 222362c29416 -r 6ee05ceea8c3 Agendas/trunk/src/Agendas.Tests/Workflows/WorkflowNhTests.cs --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Tests/Workflows/WorkflowNhTests.cs Mon Aug 08 20:08:31 2011 -0300 @@ -0,0 +1,164 @@ +using System.Collections.Generic; +using Agendas.NHibernate; +using AltNetHispano.Agendas.Domain; +using AltNetHispano.Agendas.Tests.Cruds; +using Moq; +using NUnit.Framework; + +namespace AltNetHispano.Agendas.Tests.Workflows +{ + [TestFixture] + public class WorkflowNhTests : TestBase + { + private Mock _publicador; + private Workflow _workflow; + + [SetUp] + public void InitPublicador() + { + _publicador = new Mock(); + _workflow = new Workflow(_publicador.Object, DefaultEventoRepository, DefaultPersonaRepository, DefaultPatrocinadorRepository, () => new RequestEmulator(NhHelper.GetSessionFactory())); + } + + [Test] + public void Proponer() + { + _workflow.Proponer(); + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Once()); + } + + [Test] + public void Proponer_y_agendar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(2)); + } + [Test] + public void Proponer_agendar_y_cancelar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(3)); + } + + [Test] + public void Proponer_agendar_cancelar_y_reagendar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.ReAgendar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); + } + + [Test] + public void Proponer_agendar_cancelar_reproponer_agendar_y_confirmar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.ReProponer(); + + _workflow.Agendar(); + + _workflow.Confirmar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(6)); + } + + [Test] + public void Proponer_agendar_cancelar_reagendar_y_confirmar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.ReAgendar(); + + _workflow.Confirmar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(5)); + } + + [Test] + public void Proponer_agendar_cancelar_y_reproponer() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.ReProponer(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); + } + + [Test] + public void Proponer_y_descartar() + { + _workflow.Proponer(); + + _workflow.Descartar(); + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(2)); + } + + [Test] + public void Proponer_agendar_cancelar_y_descartar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Cancelar(); + + _workflow.Descartar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); + } + + [Test] + public void Proponer_agendar_y_confirmar() + { + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Confirmar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(3)); + } + + [Test] + public void Proponer_agendar_confirmar_publicar() + { + const string urlWiki = "http://www.altnethispano.org/wiki/van-2010-10-21-mono-cecil.ashx"; + + _workflow.Proponer(); + + _workflow.Agendar(); + + _workflow.Confirmar(); + + _workflow.Publicar(); + + _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); + } + } +} \ No newline at end of file diff -r 222362c29416 -r 6ee05ceea8c3 Agendas/trunk/src/Agendas.Tests/Workflows/WorkflowTests.cs --- a/Agendas/trunk/src/Agendas.Tests/Workflows/WorkflowTests.cs Mon Aug 08 16:42:52 2011 -0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,189 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using AltNetHispano.Agendas.Domain; -using Moq; -using NUnit.Framework; - -namespace AltNetHispano.Agendas.Tests.Workflows -{ - [TestFixture] - public class WorkflowTests : TestBase - { - private Mock _publicador; - private Workflow _workflow; - - [SetUp] - public void InitPublicador() - { - _publicador = new Mock(); - _workflow = new Workflow(_publicador.Object, DefaultEventoRepository, DefaultPersonaRepository, DefaultPatrocinadorRepository); - } - - [Test] - public void Proponer() - { - _workflow.Proponer(); - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Once()); - } - - [Test] - public void Proponer_y_agendar() - { - _workflow.Proponer(); - - _workflow.Agendar(); - - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(2)); - } - [Test] - public void Proponer_agendar_y_cancelar() - { - _workflow.Proponer(); - - _workflow.Agendar(); - - var evento = DefaultEventoRepository.GetActivos().SingleOrDefault(); - Assert.IsNotNull(evento); - - _workflow.Cancelar(evento.Id); - - _publicador.Verify(p=>p.Publicar(It.IsAny>()), Times.Exactly(3)); - } - - [Test] - public void Proponer_agendar_cancelar_y_reagendar() - { - _workflow.Proponer(); - - _workflow.Agendar(); - - var evento = DefaultEventoRepository.GetActivos().SingleOrDefault(); - Assert.IsNotNull(evento); - - _workflow.Cancelar(evento.Id); - - _workflow.ReAgendar(evento.Id); - - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); - } - - [Test] - public void Proponer_agendar_cancelar_reproponer_agendar_y_confirmar() - { - _workflow.Proponer(); - - _workflow.Agendar(); - - var evento = DefaultEventoRepository.GetActivos().SingleOrDefault(); - Assert.IsNotNull(evento); - - _workflow.Cancelar(evento.Id); - - _workflow.ReProponer(evento.Id); - - _workflow.Agendar(); - - _workflow.Confirmar(evento.Id); - - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(6)); - } - - [Test] - public void Proponer_agendar_cancelar_reagendar_y_confirmar() - { - _workflow.Proponer(); - - _workflow.Agendar(); - - var evento = DefaultEventoRepository.GetActivos().SingleOrDefault(); - Assert.IsNotNull(evento); - - _workflow.Cancelar(evento.Id); - - _workflow.ReAgendar(evento.Id); - - _workflow.Confirmar(evento.Id); - - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(5)); - } - - [Test] - public void Proponer_agendar_cancelar_y_reproponer() - { - _workflow.Proponer(); - - _workflow.Agendar(); - - var evento = DefaultEventoRepository.GetActivos().SingleOrDefault(); - Assert.IsNotNull(evento); - - _workflow.Cancelar(evento.Id); - - _workflow.ReProponer(evento.Id); - - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); - } - - [Test] - public void Proponer_y_descartar() - { - _workflow.Proponer(); - var evento = DefaultEventoRepository.GetActivos().SingleOrDefault(); - Assert.IsNotNull(evento); - - _workflow.Descartar(evento.Id); - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(2)); - } - - [Test] - public void Proponer_agendar_cancelar_y_descartar() - { - _workflow.Proponer(); - - _workflow.Agendar(); - - var evento = DefaultEventoRepository.GetActivos().SingleOrDefault(); - Assert.IsNotNull(evento); - - _workflow.Cancelar(evento.Id); - - _workflow.Descartar(evento.Id); - - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); - } - - [Test] - public void Proponer_agendar_y_confirmar() - { - _workflow.Proponer(); - - _workflow.Agendar(); - - var evento = DefaultEventoRepository.GetActivos().SingleOrDefault(); - Assert.IsNotNull(evento); - - _workflow.Confirmar(evento.Id); - - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(3)); - } - - [Test] - public void Proponer_agendar_confirmar_publicar() - { - const string urlWiki = "http://www.altnethispano.org/wiki/van-2010-10-21-mono-cecil.ashx"; - - _workflow.Proponer(); - - _workflow.Agendar(); - - var evento = DefaultEventoRepository.GetActivos().SingleOrDefault(); - Assert.IsNotNull(evento); - - _workflow.Confirmar(evento.Id); - - _workflow.Publicar(evento.Id); - - _publicador.Verify(p => p.Publicar(It.IsAny>()), Times.Exactly(4)); - } - } -} \ No newline at end of file