annotate Agendas/trunk/src/Agendas.Tests/PropuestasTests.cs @ 20:c5a99dde072f

reorganizando tests
author nelo@MTEySS.neluz.int
date Mon, 14 Mar 2011 20:59:28 -0300
parents
children 43360bf09b1a
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 repository = new EventoRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
20
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
21 var van = new Evento { Titulo = "Van propuesta" };
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
22
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
23 var seguridad = new Mock<ISeguridad>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
24 var agenda = new Agenda(null, null, seguridad.Object, repository);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
25
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
26 seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
27 agenda.Proponer(van);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
28
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
29 IList<Evento> eventosPropuestos = agenda.GetEventosPropuestos();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
30 Assert.IsNotNull(eventosPropuestos);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
31 Assert.AreEqual(1, eventosPropuestos.Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
32 Assert.AreEqual("Van propuesta", eventosPropuestos[0].Titulo);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
33 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
34
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
35 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
36 public void Verificar_propuesta_separada_de_publicacion()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
37 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
38 var seguridad = new Mock<ISeguridad>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
39 var agenda = new Agenda(null, null, seguridad.Object, new EventoRepository());
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
40
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
41 var vanPropuesta = new Evento { Titulo = "Van propuesta" };
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
42 var vanPublicada = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
43 seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
44
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
45 agenda.Proponer(vanPropuesta);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
46 agenda.Publicar(vanPublicada.Titulo, vanPublicada.Ponente, vanPublicada.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
47
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
48 IList<Evento> eventosPropuestos = agenda.GetEventosPropuestos();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
49 IList<Evento> eventosPublicados = agenda.GetEventosPublicados();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
50
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
51 Assert.AreEqual(1, eventosPropuestos.Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
52 Assert.AreEqual(1, eventosPublicados.Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
53 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
54
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
55 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
56 public void Propuesta_de_van_sin_titulo()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
57 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
58 var repository = new Mock<IEventoRepository>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
59 var van = new Evento();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
60
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
61 var seguridad = new Mock<ISeguridad>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
62 var agenda = new Agenda(null, null, seguridad.Object, repository.Object);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
63
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
64 Assert.Throws<ValidationException>(() => agenda.Proponer(van));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
65 Assert.AreEqual(Guid.Empty, van.Id);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
66
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
67 repository.Verify(p => p.Save(It.IsAny<Evento>()), Times.Exactly(0));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
68 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
69
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
70 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
71 public void Agendar_van_propuesta_sin_fecha()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
72 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
73 var repository = new EventoRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
74
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
75 var seguridad = new Mock<ISeguridad>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
76 var agenda = new Agenda(null, null, seguridad.Object, repository);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
77
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
78 seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
79
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
80 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
81 var van = new Evento {Titulo = "Van propuesta"};
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
82 agenda.Proponer(van);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
83 }
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 var van = agenda.GetEventosPropuestos().FirstOrDefault();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
87 Assert.IsNotNull(van);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
88 Assert.Throws<ValidationException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
89 }
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 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
93 public void Agendar_van_propuesta_sin_ponente()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
94 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
95 var repository = new EventoRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
96
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
97 var seguridad = new Mock<ISeguridad>();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
98 var agenda = new Agenda(null, null, seguridad.Object, repository);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
99
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
100 seguridad.Setup(s => s.GetPrincipal()).Returns(SeguridadObjectMother.GetGenericPrincipalAutenticadoSinRoles());
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
101
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
102 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
103 var van = new Evento { Titulo = "Van propuesta" };
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
104 agenda.Proponer(van);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
105 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
106
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
107 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
108 var van = agenda.GetEventosPropuestos().FirstOrDefault();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
109 Assert.IsNotNull(van);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
110
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
111 van.Fecha = DateTime.Today.AddDays(5);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
112 Assert.Throws<ValidationException>(() => agenda.Publicar(van.Titulo, van.Ponente, van.Fecha));
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
113 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
114 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
115
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
116 [Test]
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
117 public void Van_crud()
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
118 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
119 var van = EventoObjectMother.GetVanValidaParaPublicar();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
120
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
121 Guid vanId;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
122 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
123 var agenda = new Agenda(null, null, SeguridadServiceDefault, new EventoRepository());
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 IAgendaRepository agendaRepository = new AgendaRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
127
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
128 agendaRepository.Save(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
129 vanId = agenda.Id;
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
130 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
131
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
132 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
133 IAgendaRepository agendaRepository = new AgendaRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
134
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
135 Agenda agenda = agendaRepository.Get(vanId);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
136
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
137 Assert.IsNotNull(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
138 Assert.AreEqual(1, agenda.GetEventosPublicados().Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
139 agenda.Publicar(van.Titulo, van.Ponente, van.Fecha);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
140
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
141 agendaRepository.Update(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
142 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
143
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
144 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
145 IAgendaRepository agendaRepository = new AgendaRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
146
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
147 Agenda agenda = agendaRepository.Get(vanId);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
148
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
149 Assert.IsNotNull(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
150 Assert.AreEqual(2, agenda.GetEventosPublicados().Count);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
151
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
152 agendaRepository.Delete(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
153 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
154
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
155 {
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
156 IAgendaRepository agendaRepository = new AgendaRepository();
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
157
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
158 Agenda agenda = agendaRepository.Get(vanId);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
159
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
160 Assert.IsNull(agenda);
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
161 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
162 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
163 }
c5a99dde072f reorganizando tests
nelo@MTEySS.neluz.int
parents:
diff changeset
164 }