comparison Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs @ 209:a36a76bd6ec3

Se soluciona ticket 173. Se agrega eliminación de personas siempre y cuando no esté asociada a ninguna van.
author alabra
date Wed, 24 Aug 2011 19:27:30 -0300
parents bfd472758bc3
children b9850b647a4e
comparison
equal deleted inserted replaced
208:607384590bf8 209:a36a76bd6ec3
16 { 16 {
17 var personaRepository = new Mock<IPersonaRepository>(); 17 var personaRepository = new Mock<IPersonaRepository>();
18 Persona persona=null; 18 Persona persona=null;
19 personaRepository.Setup(r => r.Save(It.IsAny<Persona>())).Callback<Persona>(p => persona = p); 19 personaRepository.Setup(r => r.Save(It.IsAny<Persona>())).Callback<Persona>(p => persona = p);
20 20
21 var personaService = new PersonaService(personaRepository.Object); 21 var personaService = new PersonaService(personaRepository.Object, DefaultEventoRepository);
22 22
23 Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "nelopauselli", "Nelo Pauselli")); 23 Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "nelopauselli", "Nelo Pauselli"));
24 personaRepository.Verify(r=>r.Save(It.IsAny<Persona>()), Times.Once()); 24 personaRepository.Verify(r=>r.Save(It.IsAny<Persona>()), Times.Once());
25 Assert.IsNotNull(persona); 25 Assert.IsNotNull(persona);
26 Assert.AreEqual(1, persona.Cuentas.Count()); 26 Assert.AreEqual(1, persona.Cuentas.Count());
41 public void Asociar_persona_existente_por_twitter() 41 public void Asociar_persona_existente_por_twitter()
42 { 42 {
43 var personaRepository = DefaultPersonaRepository; 43 var personaRepository = DefaultPersonaRepository;
44 44
45 personaRepository.Save(new Persona("Mariano Pauselli", "marianopauselli@gmail.com", "marianopauselli", "http://marianopauselli.blogspot.com")); 45 personaRepository.Save(new Persona("Mariano Pauselli", "marianopauselli@gmail.com", "marianopauselli", "http://marianopauselli.blogspot.com"));
46 var personaService = new PersonaService(personaRepository); 46 var personaService = new PersonaService(personaRepository, DefaultEventoRepository);
47 47
48 Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "marianopauselli", "Mariano Pauselli")); 48 Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "marianopauselli", "Mariano Pauselli"));
49 49
50 var persona = personaRepository.GetByNombre("Mariano Pauselli"); 50 var persona = personaRepository.GetByNombre("Mariano Pauselli");
51 Assert.IsNotNull(persona); 51 Assert.IsNotNull(persona);
64 [Test] 64 [Test]
65 public void Agregar_y_modificar_persona() 65 public void Agregar_y_modificar_persona()
66 { 66 {
67 var personaRepository = DefaultPersonaRepository; 67 var personaRepository = DefaultPersonaRepository;
68 68
69 var personaService = new PersonaService(personaRepository); 69 var personaService = new PersonaService(personaRepository, DefaultEventoRepository);
70 var r = personaService.Add("Mariano Pauselli", "marianopauselli", string.Empty, string.Empty, null); 70 var r = personaService.Add("Mariano Pauselli", "marianopauselli", string.Empty, string.Empty, null);
71 Assert.IsTrue(r.Succeful); 71 Assert.IsTrue(r.Succeful);
72 72
73 var todas = personaService.GetAll(); 73 var todas = personaService.GetAll();
74 Assert.AreEqual(2, todas.Count()); 74 Assert.AreEqual(2, todas.Count());
95 var personaRepository = DefaultPersonaRepository; 95 var personaRepository = DefaultPersonaRepository;
96 96
97 var p1 = personaRepository.GetByTwitter("nelopauselli"); 97 var p1 = personaRepository.GetByTwitter("nelopauselli");
98 Assert.IsNotNull(p1); 98 Assert.IsNotNull(p1);
99 Assert.AreEqual(1, p1.Cuentas.Count()); 99 Assert.AreEqual(1, p1.Cuentas.Count());
100 100
101 var personaService = new PersonaService(personaRepository); 101 var personaService = new PersonaService(personaRepository, DefaultEventoRepository);
102 102
103 personaService.AddCuenta(IdentityProviderEnum.Google, "nelopauselli"); 103 personaService.AddCuenta(IdentityProviderEnum.Google, "nelopauselli");
104 104
105 var p2 = personaRepository.GetByTwitter("nelopauselli"); 105 var p2 = personaRepository.GetByTwitter("nelopauselli");
106 Assert.IsNotNull(p2); 106 Assert.IsNotNull(p2);
134 134
135 [Test] 135 [Test]
136 public void Modificar_persona_inexistente() 136 public void Modificar_persona_inexistente()
137 { 137 {
138 var personaRepository = DefaultPersonaRepository; 138 var personaRepository = DefaultPersonaRepository;
139 var personaService = new PersonaService(personaRepository); 139 var personaService = new PersonaService(personaRepository, DefaultEventoRepository);
140 var r = personaService.Update(new Guid(), "Mariano Pauselli", "marianopauselli", "marianopauselli@gmail.com", string.Empty, null); 140 var r = personaService.Update(new Guid(), "Mariano Pauselli", "marianopauselli", "marianopauselli@gmail.com", string.Empty, null);
141 141
142 Assert.IsFalse(r.Succeful); 142 Assert.IsFalse(r.Succeful);
143 } 143 }
144
145 [Test]
146 public void Eliminar_persona_no_asociado_van()
147 {
148 var personaRepository = DefaultPersonaRepository;
149
150 var personaService = new PersonaService(personaRepository, DefaultEventoRepository);
151 var r = personaService.Add("Alejandro Labra", "alabras", "alejandro.labra@gmail.com", string.Empty, null);
152 Assert.IsTrue(r.Succeful);
153
154 var persona = personaRepository.GetByNombre("Alejandro Labra");
155 Assert.IsNotNull(persona);
156
157 var delete = personaService.Delete(persona.Id);
158 Assert.IsTrue(delete.Succeful);
159 }
160
161 [Test]
162 public void Eliminar_persona_asociado_vans()
163 {
164 var publicador = new Mock<IPublicador>();
165 var personaService = new PersonaService(DefaultPersonaRepository, DefaultEventoRepository);
166
167 var agenda = new Agenda(publicador.Object, DefaultEventoRepository, DefaultPersonaRepository);
168
169 var fechaInicio = DateTime.Now.ToUniversalTime();
170 var fechaTermino = fechaInicio.AddHours(2);
171 agenda.Agendar("Van para publicar", TestsHelper.GetOrCreatePonente("alabra"), fechaInicio, fechaTermino,
172 "http://groups.google.com/group/altnet-hispano/browse_thread/thread/65d6d26eb381386e", TipoEvento.Van);
173
174 Assert.AreEqual(0, agenda.GetEventosActivos(EventoPropuestoState.GetInstance()).Count);
175
176 var eventos = agenda.GetEventosActivos();
177 Assert.AreEqual(1, eventos.Count);
178
179 var evento = eventos[0];
180 Assert.IsNotNull(evento.Ponente);
181
182 var delete = personaService.Delete(evento.Ponente.Id);
183 Assert.IsFalse(delete.Succeful);
184 }
144 } 185 }
145 } 186 }