annotate Agendas/trunk/src/Agendas.Tests/PulicarTests.cs @ 22:d6e124e5c9c4

DefaultEventoRepository en tests
author nelo@MTEySS.neluz.int
date Tue, 15 Mar 2011 06:56:02 -0300
parents 43360bf09b1a
children a85674a7aa7a
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
22
d6e124e5c9c4 DefaultEventoRepository en tests
nelo@MTEySS.neluz.int
parents: 21
diff changeset
19 var agenda = new Agenda(publicador.Object, null, SeguridadServiceDefault, DefaultEventoRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
21 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
22
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
23 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
24 Assert.AreEqual(1, agenda.GetEventosPublicados().Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
25
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
26 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
27 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
28
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
29 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
30 public void Publicar_van_sin_usuario_autenticado() {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
31 var seguridad = new Mock<ISeguridad>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
32 seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalSinAutenticar());
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
33
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
34 var publicador = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
35 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
36
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
37 var agenda = new Agenda(publicador.Object, null, seguridad.Object, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
38
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
39 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
40
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
41 Assert.Throws<UsuarioNoAutenticadoException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
42
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
43 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
44 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
45 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
46
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
47 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
48 public void Publicar_van_sin_servicio_de_seguridad()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
49 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
50 var publicador = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
51 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
52
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
53 var agenda = new Agenda(publicador.Object, null, null, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
54
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
55 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
56
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
57 Assert.Throws<UsuarioNoAutenticadoException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
58 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
59 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
60
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
61 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
62 public void Error_al_publicar_van()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
63 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
64 var publicador = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
65 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
66
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
67 publicador.Setup(p => p.Publicar(It.IsAny<Evento>())).Throws(new Exception("Error intencional"));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
68
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
69 var agenda = new Agenda(publicador.Object, null, SeguridadServiceDefault, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
70
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
71 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
72 Assert.Throws<Exception>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
73 Assert.AreEqual(0, agenda.GetEventosPublicados().Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
74
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
75 publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
76 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
77 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
78
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
79 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
80 public void Publicar_van_multiples_publicadores()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
81 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
82 var publicador1 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
83 var publicador2 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
84
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
85 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
86
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
87 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
88
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
89 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
90 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
91
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
92 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
93 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
94 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
95 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
96
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
97 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
98 public void Publicar_y_recordar_van()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
99 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
100 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
101
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
102 var publicador1 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
103 var publicador2 = new Mock<IPublicador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
104 var recordador1 = new Mock<IRecordador>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
105
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
106 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
107
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
108 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
109 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
110
21
43360bf09b1a unificando criterio de parámetros en Agenda
nelo@MTEySS.neluz.int
parents: 20
diff changeset
111 agenda.Recordar(van.Id);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
112
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
113 publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
114 publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
115 recordador1.Verify(r => r.Recordar(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
116
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
117 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(1));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
118 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
119
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
120 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
121 public void Publicar_y_modificar_van()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
122 {
22
d6e124e5c9c4 DefaultEventoRepository en tests
nelo@MTEySS.neluz.int
parents: 21
diff changeset
123 var repository = DefaultEventoRepository;
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
124
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
125 var agenda = new Agenda(null, null, SeguridadServiceDefault, repository);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
126
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
127 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
128 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
129
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
130 var evento = repository.GetEventosConFecha().First();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
131 Assert.AreNotEqual(Guid.Empty, evento.Id);
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 }