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

DefaultEventoRepository en tests
author nelo@MTEySS.neluz.int
date Tue, 15 Mar 2011 06:56:02 -0300
parents 43360bf09b1a
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.Collections.Generic;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
3 using System.Linq;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
4 using Agendas.Repositories.Memory;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
5 using AltNetHispano.Agendas.Domain;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
6 using AltNetHispano.Agendas.Domain.Exceptions;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
7 using AltNetHispano.Agendas.Domain.Repositories;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
8 using Moq;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
9 using NUnit.Framework;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
10
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
11 namespace AltNetHispano.Agendas.Tests
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
12 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
13 [TestFixture]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
14 public class PropuestasTests : TestBase
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
15 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
16 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
17 public void Propuesta_de_van_con_usuario_autenticado()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
18 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
19 var seguridad = new Mock<ISeguridad>();
22
d6e124e5c9c4 DefaultEventoRepository en tests
nelo@MTEySS.neluz.int
parents: 21
diff changeset
20 var agenda = new Agenda(null, null, seguridad.Object, DefaultEventoRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
21
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
22 seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());
21
43360bf09b1a unificando criterio de parámetros en Agenda
nelo@MTEySS.neluz.int
parents: 20
diff changeset
23 agenda.Proponer("Van propuesta");
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
24
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
25 IList<Evento> eventosPropuestos = agenda.GetEventosPropuestos();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
26 Assert.IsNotNull(eventosPropuestos);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
27 Assert.AreEqual(1, eventosPropuestos.Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
28 Assert.AreEqual("Van propuesta", eventosPropuestos[0].Titulo);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
29 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
30
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
31 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
32 public void Verificar_propuesta_separada_de_publicacion()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
33 {
21
43360bf09b1a unificando criterio de parámetros en Agenda
nelo@MTEySS.neluz.int
parents: 20
diff changeset
34 var agenda = new Agenda(null, null, SeguridadServiceDefault, new EventoRepository());
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
35
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
36 var vanPublicada = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
37
21
43360bf09b1a unificando criterio de parámetros en Agenda
nelo@MTEySS.neluz.int
parents: 20
diff changeset
38 agenda.Proponer("Van propuesta");
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
39 agenda.Publicar(vanPublicada.Titulo, vanPublicada.Ponente, vanPublicada.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
40
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
41 IList<Evento> eventosPropuestos = agenda.GetEventosPropuestos();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
42 IList<Evento> eventosPublicados = agenda.GetEventosPublicados();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
43
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
44 Assert.AreEqual(1, eventosPropuestos.Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
45 Assert.AreEqual(1, eventosPublicados.Count);
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 Propuesta_de_van_sin_titulo()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
50 {
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 seguridad = new Mock<ISeguridad>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
54 var agenda = new Agenda(null, null, seguridad.Object, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
55
21
43360bf09b1a unificando criterio de parámetros en Agenda
nelo@MTEySS.neluz.int
parents: 20
diff changeset
56 Assert.Throws<ValidationException>(() => agenda.Proponer(string.Empty));
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
57
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 Agendar_van_propuesta_sin_fecha()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
63 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
64 var seguridad = new Mock<ISeguridad>();
22
d6e124e5c9c4 DefaultEventoRepository en tests
nelo@MTEySS.neluz.int
parents: 21
diff changeset
65 var agenda = new Agenda(null, null, seguridad.Object, DefaultEventoRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
66
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
67 seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
68
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
69 {
21
43360bf09b1a unificando criterio de parámetros en Agenda
nelo@MTEySS.neluz.int
parents: 20
diff changeset
70 agenda.Proponer("Van propuesta");
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
71 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
72
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
73 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
74 var van = agenda.GetEventosPropuestos().FirstOrDefault();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
75 Assert.IsNotNull(van);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
76 Assert.Throws<ValidationException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
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
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 Agendar_van_propuesta_sin_ponente()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
82 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
83 var seguridad = new Mock<ISeguridad>();
22
d6e124e5c9c4 DefaultEventoRepository en tests
nelo@MTEySS.neluz.int
parents: 21
diff changeset
84 var agenda = new Agenda(null, null, seguridad.Object, DefaultEventoRepository);
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
85
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
86 seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
87
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
88 {
21
43360bf09b1a unificando criterio de parámetros en Agenda
nelo@MTEySS.neluz.int
parents: 20
diff changeset
89 agenda.Proponer("Van propuesta");
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
90 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
91
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
92 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
93 var van = agenda.GetEventosPropuestos().FirstOrDefault();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
94 Assert.IsNotNull(van);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
95
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
96 van.Fecha = DateTime.Today.AddDays(5);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
97 Assert.Throws<ValidationException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
98 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
99 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
100
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
101 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
102 public void Van_crud()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
103 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
104 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
105
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
106 Guid vanId;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
107 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
108 var agenda = new Agenda(null, null, SeguridadServiceDefault, new EventoRepository());
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
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
111 IAgendaRepository agendaRepository = new AgendaRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
112
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
113 agendaRepository.Save(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
114 vanId = agenda.Id;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
115 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
116
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
117 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
118 IAgendaRepository agendaRepository = new AgendaRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
119
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
120 Agenda agenda = agendaRepository.Get(vanId);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
121
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
122 Assert.IsNotNull(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
123 Assert.AreEqual(1, agenda.GetEventosPublicados().Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
124 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
125
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
126 agendaRepository.Update(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
127 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
128
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
129 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
130 IAgendaRepository agendaRepository = new AgendaRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
131
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
132 Agenda agenda = agendaRepository.Get(vanId);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
133
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
134 Assert.IsNotNull(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
135 Assert.AreEqual(2, agenda.GetEventosPublicados().Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
136
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
137 agendaRepository.Delete(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
138 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
139
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
140 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
141 IAgendaRepository agendaRepository = new AgendaRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
142
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
143 Agenda agenda = agendaRepository.Get(vanId);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
144
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
145 Assert.IsNull(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
146 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
147 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
148 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
149 }