Mercurial > altnet-hispano
view Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs @ 156:6e554de521aa
Estética de altnet hispano
author | Nelo@Guinea.neluz.int |
---|---|
date | Thu, 04 Aug 2011 18:44:57 -0300 |
parents | 5a1f7233aa5a |
children | f17252543cbf |
line wrap: on
line source
using System.Linq; using AltNetHispano.Agendas.Domain; using AltNetHispano.Agendas.Domain.Repositories; using AltNetHispano.Agendas.Domain.Services; using Moq; using NUnit.Framework; namespace AltNetHispano.Agendas.Tests { [TestFixture] public class PersonaServiceTests : TestBase { [Test] public void Crear_nueva_persona() { var personaRepository = new Mock<IPersonaRepository>(); Persona persona=null; personaRepository.Setup(r => r.Save(It.IsAny<Persona>())).Callback<Persona>(p => persona = p); var personaService = new PersonaService(personaRepository.Object); Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "nelopauselli", "Nelo Pauselli")); personaRepository.Verify(r=>r.Save(It.IsAny<Persona>()), Times.Once()); Assert.IsNotNull(persona); Assert.AreEqual(1, persona.Cuentas.Count()); Assert.AreEqual("nelopauselli", persona.Twitter); Cuenta cuenta = persona.Cuentas.First(); Assert.AreEqual(IdentityProviderEnum.Twitter, cuenta.IdentityProvider); Assert.AreEqual("nelopauselli", cuenta.LogonName); personaRepository.Setup(r => r.GetCuenta(IdentityProviderEnum.Twitter, "nelopauselli")).Returns(cuenta); Assert.AreEqual(1, persona.Cuentas.Count()); Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "nelopauselli", "Nelo Pauselli")); Assert.AreEqual(1, persona.Cuentas.Count()); } [Test] public void Asociar_persona_existente_por_twitter() { var personaRepository = DefaultPersonaRepository; personaRepository.Save(new Persona("Mariano Pauselli", "marianopauselli@gmail.com", "marianopauselli", "http://marianopauselli.blogspot.com")); var personaService = new PersonaService(personaRepository); Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "marianopauselli", "Mariano Pauselli")); var persona = personaRepository.GetByNombre("Mariano Pauselli"); Assert.IsNotNull(persona); Assert.AreEqual(1, persona.Cuentas.Count()); Assert.AreEqual("marianopauselli", persona.Twitter); Cuenta cuenta = persona.Cuentas.First(); Assert.AreEqual(IdentityProviderEnum.Twitter, cuenta.IdentityProvider); Assert.AreEqual("marianopauselli", cuenta.LogonName); Assert.AreEqual(1, persona.Cuentas.Count()); Assert.IsTrue(personaService.CreateIfNotExist(IdentityProviderEnum.Twitter, "marianopauselli", "Mariano Pauselli")); Assert.AreEqual(1, persona.Cuentas.Count()); } [Test] public void Agregar_y_modificar_persona() { var personaRepository = DefaultPersonaRepository; var personaService = new PersonaService(personaRepository); var r = personaService.Add("Mariano Pauselli", "marianopauselli", string.Empty); Assert.IsTrue(r.Succeful); var todas = personaService.GetAll(); Assert.AreEqual(2, todas.Count()); var p1 = todas.SingleOrDefault(p => p.Nombre == "Mariano Pauselli"); Assert.IsNotNull(p1); var personaId = p1.Id; var p2 = personaService.GetById(personaId); Assert.AreEqual(p1, p2); Assert.AreSame(p1, p2); personaService.Update(personaId, p1.Nombre, p1.Twitter, "marianopauselli@gmail.com"); var p3 = personaService.GetById(personaId); Assert.IsNotNull(p3); Assert.AreEqual("marianopauselli@gmail.com",p3.Mail); } [Test] public void Agregar_y_modificar_cuenta() { var personaRepository = DefaultPersonaRepository; var p1 = personaRepository.GetByTwitter("nelopauselli"); Assert.IsNotNull(p1); Assert.AreEqual(1, p1.Cuentas.Count()); var personaService = new PersonaService(personaRepository); personaService.AddCuenta(IdentityProviderEnum.Google, "nelopauselli"); var p2 = personaRepository.GetByTwitter("nelopauselli"); Assert.IsNotNull(p2); Assert.AreEqual(2, p2.Cuentas.Count()); var personaId = p2.Id; personaService.RemoveCuenta(IdentityProviderEnum.Google, "nelopauselli"); Assert.AreEqual(1, personaRepository.Get(personaId).Cuentas.Count()); personaService.RemoveCuenta(IdentityProviderEnum.Twitter, "nelopauselli"); Assert.AreEqual(0, personaRepository.Get(personaId).Cuentas.Count()); } [Test] public void IdentificacionGoogle() { var builtIn = new Identification(Identification.Map[(int)IdentityProviderEnum.Google] + "nelo"); Assert.AreEqual(IdentityProviderEnum.Google, builtIn.IdentityProvider); Assert.AreEqual("nelo", builtIn.LogonName); } [Test] public void IdentificacionTwitter() { var builtIn = new Identification(Identification.Map[(int)IdentityProviderEnum.Twitter] + "nelo"); Assert.AreEqual(IdentityProviderEnum.Twitter, builtIn.IdentityProvider); Assert.AreEqual("nelo", builtIn.LogonName); } } }