Mercurial > altnet-hispano
diff Agendas/trunk/src/Agendas.Repositories.Tests/PersonaCrud.cs @ 222:68b09c30b0d2
Separando los test de persistencia en un proyecto aparte
author | nelopauselli |
---|---|
date | Mon, 19 Sep 2011 18:18:17 -0300 |
parents | Agendas/trunk/src/Agendas.Tests/Cruds/PersonaCrud.cs@b9850b647a4e |
children | 50442a103281 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Agendas/trunk/src/Agendas.Repositories.Tests/PersonaCrud.cs Mon Sep 19 18:18:17 2011 -0300 @@ -0,0 +1,187 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Agendas.Repositories.Tests.Infraestructure; +using AltNetHispano.Agendas.Domain; +using AltNetHispano.Agendas.Domain.Repositories; +using AltNetHispano.Agendas.Domain.Services; +using NUnit.Framework; + +namespace Agendas.Repositories.Tests +{ + public abstract class PersonaCrud<T> where T : IInfraestrutureFactory, new() + { + private readonly IPersonaRepository _personaRepository; + private readonly Func<IDisposable> _requestEmulator; + private readonly PersonaService _personaService; + private readonly IEventoRepository _eventoRepository; + + protected PersonaCrud() + { + var infraestrutureFactory = new T(); + + _eventoRepository = infraestrutureFactory.GetEventoRepository(); + _personaRepository = infraestrutureFactory.GetPonenteRepository(); + _requestEmulator = infraestrutureFactory.GetRequestEmulator(); + + _personaService = new PersonaService(_personaRepository, _eventoRepository); + } + + [Test] + public void CreateAdministrador() + { + Guid id; + using (_requestEmulator.Invoke()) + { + var r = CreatePersona("Nelo Pauselli", "nelopauselli", "nelopauselli@gmail.com", "http://nelopauselli.blogspot.com", + null); + Assert.AreEqual("Nelo Pauselli", r.Nombre); + Assert.AreNotEqual(Guid.Empty, r.Id); + + id = r.Id; + } + + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.GetByNombre("Nelo Pauselli"); + Assert.IsNotNull(persona); + Assert.AreEqual(id, persona.Id); + } + } + + private ResultadoAdd CreatePersona(string nombre, string twitter, string mail, string blog, IEnumerable<string> roles) + { + return _personaService.Add(nombre, twitter, mail, blog, roles); + } + + [Test] + public void ReadAdministrador() + { + Guid personaId; + using (_requestEmulator.Invoke()) + { + var r = CreatePersona("Nelo Pauselli", "nelopauselli", "nelopauselli@gmail.com", "http://nelopauselli.blogspot.com", + null); + personaId = r.Id; + } + + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.Get(personaId); + + Assert.IsNotNull(persona); + Assert.AreEqual("Nelo Pauselli", persona.Nombre); + Assert.AreEqual("nelopauselli", persona.Twitter); + Assert.AreEqual("nelopauselli@gmail.com", persona.Mail); + Assert.AreEqual("http://nelopauselli.blogspot.com", persona.Blog); + + Assert.IsTrue(persona.Cuentas.Any()); + Assert.AreEqual("nelopauselli", persona.Cuentas.First().LogonName); + Assert.AreEqual(IdentityProviderEnum.Twitter, persona.Cuentas.First().IdentityProvider); + + Assert.IsTrue(persona.Roles.Any()); + Assert.IsTrue(persona.Roles.Contains(Roles.Usuario)); + Assert.IsTrue(persona.Roles.Contains(Roles.Administrador)); + } + } + + [Test] + public void CreateUsuario() + { + using (_requestEmulator.Invoke()) + { + CreatePersona("Pablo Morales", "pablomorales", "pablomorales@gmail.com", "http://pablomorales.blogspot.com", + new[] {Roles.Usuario}); + } + + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.GetByNombre("Pablo Morales"); + Assert.IsNotNull(persona); + } + } + + [Test] + public void ReadUsuario() + { + Guid personaId; + using (_requestEmulator.Invoke()) + { + var r = CreatePersona("Pablo Morales", "pablomorales", "pablomorales@gmail.com", "http://pablomorales.blogspot.com", + new[] {Roles.Usuario}); + personaId = r.Id; + } + + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.Get(personaId); + + Assert.IsNotNull(persona); + Assert.AreEqual("Pablo Morales", persona.Nombre); + Assert.AreEqual("pablomorales", persona.Twitter); + Assert.AreEqual("pablomorales@gmail.com", persona.Mail); + Assert.AreEqual("http://pablomorales.blogspot.com", persona.Blog); + + Assert.IsTrue(persona.Cuentas.Any()); + Assert.AreEqual("pablomorales", persona.Cuentas.First().LogonName); + Assert.AreEqual(IdentityProviderEnum.Twitter, persona.Cuentas.First().IdentityProvider); + + Assert.IsTrue(persona.Roles.Any()); + Assert.IsTrue(persona.Roles.Contains(Roles.Usuario)); + Assert.IsFalse(persona.Roles.Contains(Roles.Administrador)); + } + } + + [Test] + public void Update() + { + Guid personaId; + using (_requestEmulator.Invoke()) + { + var r = CreatePersona("Nelo Pauselli", "nelopauselli", "nelopauselli@gmail.com", "http://nelopauselli.blogspot.com", + null); + personaId = r.Id; + } + + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.Get(personaId); + Assert.IsNotNull(persona); + + persona.Nombre = "Nelo Mariano Pauselli"; + } + + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.Get(personaId); + + Assert.IsNotNull(persona); + Assert.AreEqual("Nelo Mariano Pauselli", persona.Nombre); + } + } + + [Test] + public void Delete() + { + Guid personaId; + using (_requestEmulator.Invoke()) + { + var r = CreatePersona("Nelo Pauselli", "nelopauselli", "nelopauselli@gmail.com", + "http://nelopauselli.blogspot.com", null); + personaId = r.Id; + } + + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.Get(personaId); + Assert.IsNotNull(persona); + _personaService.Delete(personaId); + } + using (_requestEmulator.Invoke()) + { + var persona = _personaRepository.Get(personaId); + Assert.IsNull(persona); + } + } + } +} \ No newline at end of file