view Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs @ 143:2dbb15f4510f

Asociar Twitter a Persona existente
author Nelo@Guinea.neluz.int
date Mon, 01 Aug 2011 09:41:29 -0300
parents 62dc9fb3a03e
children 5a1f7233aa5a
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 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);
		}
	}
}