annotate Agendas/trunk/src/Agendas.Tests/PulicarTests.cs @ 23:a85674a7aa7a

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