annotate Agendas/trunk/src/Agendas.Tests/PulicarTests.cs @ 59:4a4e12e32256

Poder quitar un ponente de un evento propuesto
author nelopauselli
date Mon, 16 May 2011 20:32:37 -0300
parents 3059a5f8930f
children cb3f7b47c1f0
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 AltNetHispano.Agendas.Domain;
50
3ebe89c88caa Agregando propiedad al Evento sobre el Usuario que lo crea o que realizó la
nelopauselli
parents: 45
diff changeset
4 using AltNetHispano.Agendas.Domain.Exceptions;
20
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 {
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
11 [TestFixture]
20
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]
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
15 public void CompositePublicador_constructor_parametro_null_debe_generar_ArgumentNullException()
50
3ebe89c88caa Agregando propiedad al Evento sobre el Usuario que lo crea o que realizó la
nelopauselli
parents: 45
diff changeset
16 {
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
17 Assert.Throws<ArgumentNullException>(() => new CompositePublicador(null));
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
18 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
19
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
20 [Test]
51
4a63a73e38e4 Cambio de nombres de test intentando describir mejor lo que verifican
nelopauselli
parents: 50
diff changeset
21 public void Intentar_publicar_evento_donde_ocurre_una_excepcion_no_manejada()
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
22 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
23 var publicador = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
24 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
25
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
26 publicador.Setup(p => p.Publicar(It.IsAny<Evento>())).Throws(new Exception("Error intencional"));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
27
50
3ebe89c88caa Agregando propiedad al Evento sobre el Usuario que lo crea o que realizó la
nelopauselli
parents: 45
diff changeset
28 var agenda = new Agenda(publicador.Object, null, repository.Object, DefaultPonenteRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
29
24
41b283d27e3e Ponentes como entidad
nelo@MTEySS.neluz.int
parents: 23
diff changeset
30 Assert.Throws<Exception>(() => agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now));
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
31 Assert.AreEqual(0, agenda.GetEventosPublicados().Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
32
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
33 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
34 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
35 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
36
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
37 [Test]
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
38 public void Intentar_publicar_evento_sin_servicio_de_seguridad()
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
39 {
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
40 IdentityContext.Current = null;
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
41
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
42 var publicador = new Mock<IPublicador>();
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
43 var repository = new Mock<IEventoRepository>();
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
44
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
45 var agenda = new Agenda(publicador.Object, null, repository.Object, DefaultPonenteRepository);
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
46
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
47 Assert.Throws<IdentityContextNotConfiguredException>(
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
48 () => agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
49 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
50 }
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
51
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
52 [Test]
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
53 public void Intentar_publicar_evento_sin_usuario_autenticado()
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
54 {
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
55 SetCurrentUser(null);
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
56
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
57 var publicador = new Mock<IPublicador>();
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
58 var repository = new Mock<IEventoRepository>();
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
59
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
60 var agenda = new Agenda(publicador.Object, null, repository.Object, DefaultPonenteRepository);
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
61
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
62 Assert.Throws<UsuarioNoAutenticadoException>(() => agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
63
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
64 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(0));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
65 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
66 }
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
67
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
68 [Test]
59
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
69 public void Intentar_publicar_evento_sin_ponente()
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
70 {
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
71 var agenda = new Agenda(null, null, DefaultEventoRepository, DefaultPonenteRepository);
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
72
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
73 var r = agenda.Publicar("Van para publicar", string.Empty, DateTime.Now);
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
74
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
75 Assert.IsFalse(r.Succeful);
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
76 }
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
77
4a4e12e32256 Poder quitar un ponente de un evento propuesto
nelopauselli
parents: 54
diff changeset
78 [Test]
51
4a63a73e38e4 Cambio de nombres de test intentando describir mejor lo que verifican
nelopauselli
parents: 50
diff changeset
79 public void Publicar_evento_con_multiples_publicadores()
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
80 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
81 var publicador1 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
82 var publicador2 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
83
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
84 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
85
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
86 var agenda = new Agenda(new CompositePublicador(new[] {publicador1.Object, publicador2.Object}), null,
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
87 repository.Object, DefaultPonenteRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
88
24
41b283d27e3e Ponentes como entidad
nelo@MTEySS.neluz.int
parents: 23
diff changeset
89 agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
90
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
91 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
92 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
93 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
94 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
95
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
96 [Test]
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
97 public void Publicar_evento_correctamente()
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
98 {
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
99 var publicador = new Mock<IPublicador>();
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
100
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
101 var agenda = new Agenda(publicador.Object, null, DefaultEventoRepository, DefaultPonenteRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
102
24
41b283d27e3e Ponentes como entidad
nelo@MTEySS.neluz.int
parents: 23
diff changeset
103 agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now);
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
104 Assert.AreEqual(1, agenda.GetEventosPublicados().Count);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
105
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
106 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
107 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
108
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
109 [Test]
51
4a63a73e38e4 Cambio de nombres de test intentando describir mejor lo que verifican
nelopauselli
parents: 50
diff changeset
110 public void Publicar_y_modificar_evento()
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
111 {
22
d6e124e5c9c4 DefaultEventoRepository en tests
nelo@MTEySS.neluz.int
parents: 21
diff changeset
112 var repository = DefaultEventoRepository;
36
65bbf1ab2b24 cuando se modifica un evento, también debe ser publicada dicha modificación
nelo@MTEySS.neluz.int
parents: 24
diff changeset
113 var publicador = new Mock<IPublicador>();
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
114
50
3ebe89c88caa Agregando propiedad al Evento sobre el Usuario que lo crea o que realizó la
nelopauselli
parents: 45
diff changeset
115 var agenda = new Agenda(publicador.Object, null, repository, DefaultPonenteRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
116
24
41b283d27e3e Ponentes como entidad
nelo@MTEySS.neluz.int
parents: 23
diff changeset
117 agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
118
36
65bbf1ab2b24 cuando se modifica un evento, también debe ser publicada dicha modificación
nelo@MTEySS.neluz.int
parents: 24
diff changeset
119 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
65bbf1ab2b24 cuando se modifica un evento, también debe ser publicada dicha modificación
nelo@MTEySS.neluz.int
parents: 24
diff changeset
120
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
121 var evento = repository.GetEventosConFecha().First();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
122 Assert.AreNotEqual(Guid.Empty, evento.Id);
23
a85674a7aa7a ajustes menores en tests
nelo@MTEySS.neluz.int
parents: 22
diff changeset
123 Assert.IsNotNull(evento.Fecha);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
124
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
125 DateTime fecha = evento.Fecha.Value.AddDays(7);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
126 agenda.ModificarEvento(evento.Id, "otro titulo", "otro ponente", fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
127
36
65bbf1ab2b24 cuando se modifica un evento, también debe ser publicada dicha modificación
nelo@MTEySS.neluz.int
parents: 24
diff changeset
128 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(2));
65bbf1ab2b24 cuando se modifica un evento, también debe ser publicada dicha modificación
nelo@MTEySS.neluz.int
parents: 24
diff changeset
129
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
130 evento = repository.GetEventosConFecha().First();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
131 Assert.AreEqual("otro titulo", evento.Titulo);
24
41b283d27e3e Ponentes como entidad
nelo@MTEySS.neluz.int
parents: 23
diff changeset
132 Assert.AreEqual("otro ponente", evento.Ponente.Nombre);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
133 Assert.AreEqual(fecha, evento.Fecha);
45
2edc705aae0a Coverage 100% sobre Agendas.Tests
juanjose.montesdeocaarbos
parents: 39
diff changeset
134
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
135 var idEventoNoExistente = new Guid("99999999999999999999999999999999");
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
136 Assert.Throws<EventoNotFoundException>(
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
137 () => agenda.ModificarEvento(idEventoNoExistente, "algún título", "un ponente", DateTime.Now));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
138 }
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
139
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
140 [Test]
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
141 public void Publicar_y_recordar_evento()
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
142 {
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
143 var publicador1 = new Mock<IPublicador>();
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
144 var publicador2 = new Mock<IPublicador>();
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
145 var recordador1 = new Mock<IRecordador>();
45
2edc705aae0a Coverage 100% sobre Agendas.Tests
juanjose.montesdeocaarbos
parents: 39
diff changeset
146
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
147 var agenda = new Agenda(new CompositePublicador(new[] {publicador1.Object, publicador2.Object}), recordador1.Object,
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
148 DefaultEventoRepository, DefaultPonenteRepository);
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
149
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
150 agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now);
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
151
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
152 var van = agenda.GetEventosPublicados().Single(v => v.Titulo == "Van para publicar");
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
153 agenda.Recordar(van.Id);
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
154
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
155 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
156 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
157 recordador1.Verify(r => r.Recordar(It.IsAny<Evento>()), Times.Exactly(1));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
158 }
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
159 }
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
160 }