annotate Agendas/trunk/src/Agendas.Tests/PulicarTests.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
rev   line source
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
1 using System;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
2 using System.Linq;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
3 using Agendas.Repositories.Memory;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
4 using AltNetHispano.Agendas.Domain;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
5 using AltNetHispano.Agendas.Domain.Repositories;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
6 using Moq;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
7 using NUnit.Framework;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
8
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
9 namespace AltNetHispano.Agendas.Tests
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
10 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
11 [TestFixture]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
12 public class PulicarTests : TestBase
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
13 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
14 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
15 public void Publicar_van_con_usuario_autenticado()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
16 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
17 var publicador = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
18 var repository = new EventoRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
19
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
20 var agenda = new Agenda(publicador.Object, null, SeguridadServiceDefault, repository);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
21
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
22 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
23
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
24 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
25 Assert.AreEqual(1, agenda.GetEventosPublicados().Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
26
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
27 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
28 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
29
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
30 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
31 public void Publicar_van_sin_usuario_autenticado() {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
32 var seguridad = new Mock<ISeguridad>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
33 seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalSinAutenticar());
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
34
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
35 var publicador = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
36 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
37
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
38 var agenda = new Agenda(publicador.Object, null, seguridad.Object, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
39
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
40 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
41
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
42 Assert.Throws<UsuarioNoAutenticadoException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
43
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
44 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
45 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
46 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
47
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
48 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
49 public void Publicar_van_sin_servicio_de_seguridad()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
50 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
51 var publicador = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
52 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
53
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
54 var agenda = new Agenda(publicador.Object, null, null, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
55
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
56 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
57
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
58 Assert.Throws<UsuarioNoAutenticadoException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
59 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
60 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
61
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
62 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
63 public void Error_al_publicar_van()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
64 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
65 var publicador = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
66 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
67
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
68 publicador.Setup(p => p.Publicar(It.IsAny<Evento>())).Throws(new Exception("Error intencional"));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
69
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
70 var agenda = new Agenda(publicador.Object, null, SeguridadServiceDefault, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
71
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
72 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
73 Assert.Throws<Exception>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
74 Assert.AreEqual(0, agenda.GetEventosPublicados().Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
75
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
76 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
77 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
78 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
79
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
80 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
81 public void Publicar_van_multiples_publicadores()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
82 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
83 var publicador1 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
84 var publicador2 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
85
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
86 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
87
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
88 var agenda = new Agenda(new CompositePublicador(new[] { publicador1.Object, publicador2.Object }), null, SeguridadServiceDefault, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
89
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
90 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
91 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
92
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
93 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
94 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
95 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
96 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
97
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
98 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
99 public void Publicar_y_recordar_van()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
100 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
101 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
102
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
103 var publicador1 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
104 var publicador2 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
105 var recordador1 = new Mock<IRecordador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
106
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
107 var agenda = new Agenda(new CompositePublicador(new[] { publicador1.Object, publicador2.Object }), recordador1.Object, SeguridadServiceDefault, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
108
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
109 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
110 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
111
21
43360bf09b1a unificando criterio de parámetros en Agenda
nelo@MTEySS.neluz.int
parents: 20
diff changeset
112 agenda.Recordar(van.Id);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
113
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
114 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
115 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
116 recordador1.Verify(r => r.Recordar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
117
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
118 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
119 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
120
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
121 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
122 public void Publicar_y_modificar_van()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
123 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
124 var repository = new EventoRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
125
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
126 var agenda = new Agenda(null, null, SeguridadServiceDefault, repository);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
127
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
128 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
129 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
130
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
131 var evento = repository.GetEventosConFecha().First();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
132 Assert.AreNotEqual(Guid.Empty, evento.Id);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
133
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
134 DateTime fecha = evento.Fecha.Value.AddDays(7);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
135 agenda.ModificarEvento(evento.Id, "otro titulo", "otro ponente", fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
136
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
137 evento = repository.GetEventosConFecha().First();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
138 Assert.AreEqual("otro titulo", evento.Titulo);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
139 Assert.AreEqual("otro ponente", evento.Ponente);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
140 Assert.AreEqual(fecha, evento.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
141 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
142 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
143 }