annotate Agendas/trunk/src/Agendas.Tests/PulicarTests.cs @ 54:3059a5f8930f

Code cleanup
author nelopauselli
date Sat, 14 May 2011 13:01:24 -0300
parents 4a63a73e38e4
children 4a4e12e32256
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]
51
4a63a73e38e4 Cambio de nombres de test intentando describir mejor lo que verifican
nelopauselli
parents: 50
diff changeset
69 public void Publicar_evento_con_multiples_publicadores()
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
70 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
71 var publicador1 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
72 var publicador2 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
73
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
74 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
75
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
76 var agenda = new Agenda(new CompositePublicador(new[] {publicador1.Object, publicador2.Object}), null,
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
77 repository.Object, DefaultPonenteRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
78
24
41b283d27e3e Ponentes como entidad
nelo@MTEySS.neluz.int
parents: 23
diff changeset
79 agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
80
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
81 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
82 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
83 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
84 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
85
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
86 [Test]
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
87 public void Publicar_evento_correctamente()
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
88 {
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
89 var publicador = new Mock<IPublicador>();
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
90
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
91 var agenda = new Agenda(publicador.Object, null, DefaultEventoRepository, DefaultPonenteRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
92
24
41b283d27e3e Ponentes como entidad
nelo@MTEySS.neluz.int
parents: 23
diff changeset
93 agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now);
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
94 Assert.AreEqual(1, agenda.GetEventosPublicados().Count);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
95
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
96 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
97 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
98
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
99 [Test]
51
4a63a73e38e4 Cambio de nombres de test intentando describir mejor lo que verifican
nelopauselli
parents: 50
diff changeset
100 public void Publicar_y_modificar_evento()
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
101 {
22
d6e124e5c9c4 DefaultEventoRepository en tests
nelo@MTEySS.neluz.int
parents: 21
diff changeset
102 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
103 var publicador = new Mock<IPublicador>();
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
104
50
3ebe89c88caa Agregando propiedad al Evento sobre el Usuario que lo crea o que realizó la
nelopauselli
parents: 45
diff changeset
105 var agenda = new Agenda(publicador.Object, null, repository, DefaultPonenteRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
106
24
41b283d27e3e Ponentes como entidad
nelo@MTEySS.neluz.int
parents: 23
diff changeset
107 agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
108
36
65bbf1ab2b24 cuando se modifica un evento, también debe ser publicada dicha modificación
nelo@MTEySS.neluz.int
parents: 24
diff changeset
109 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
110
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
111 var evento = repository.GetEventosConFecha().First();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
112 Assert.AreNotEqual(Guid.Empty, evento.Id);
23
a85674a7aa7a ajustes menores en tests
nelo@MTEySS.neluz.int
parents: 22
diff changeset
113 Assert.IsNotNull(evento.Fecha);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
114
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
115 DateTime fecha = evento.Fecha.Value.AddDays(7);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
116 agenda.ModificarEvento(evento.Id, "otro titulo", "otro ponente", fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
117
36
65bbf1ab2b24 cuando se modifica un evento, también debe ser publicada dicha modificación
nelo@MTEySS.neluz.int
parents: 24
diff changeset
118 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
119
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
120 evento = repository.GetEventosConFecha().First();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
121 Assert.AreEqual("otro titulo", evento.Titulo);
24
41b283d27e3e Ponentes como entidad
nelo@MTEySS.neluz.int
parents: 23
diff changeset
122 Assert.AreEqual("otro ponente", evento.Ponente.Nombre);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
123 Assert.AreEqual(fecha, evento.Fecha);
45
2edc705aae0a Coverage 100% sobre Agendas.Tests
juanjose.montesdeocaarbos
parents: 39
diff changeset
124
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
125 var idEventoNoExistente = new Guid("99999999999999999999999999999999");
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
126 Assert.Throws<EventoNotFoundException>(
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
127 () => agenda.ModificarEvento(idEventoNoExistente, "algún título", "un ponente", DateTime.Now));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
128 }
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
129
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
130 [Test]
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
131 public void Publicar_y_recordar_evento()
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
132 {
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
133 var publicador1 = new Mock<IPublicador>();
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
134 var publicador2 = new Mock<IPublicador>();
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
135 var recordador1 = new Mock<IRecordador>();
45
2edc705aae0a Coverage 100% sobre Agendas.Tests
juanjose.montesdeocaarbos
parents: 39
diff changeset
136
54
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
137 var agenda = new Agenda(new CompositePublicador(new[] {publicador1.Object, publicador2.Object}), recordador1.Object,
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
138 DefaultEventoRepository, DefaultPonenteRepository);
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
139
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
140 agenda.Publicar("Van para publicar", "jjmontes", DateTime.Now);
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
141
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
142 var van = agenda.GetEventosPublicados().Single(v => v.Titulo == "Van para publicar");
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
143 agenda.Recordar(van.Id);
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
144
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
145 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
146 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
147 recordador1.Verify(r => r.Recordar(It.IsAny<Evento>()), Times.Exactly(1));
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
148 }
3059a5f8930f Code cleanup
nelopauselli
parents: 51
diff changeset
149 }
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
150 }