view Agendas/trunk/src/Agendas.Tests/PersonaServiceTests.cs @ 142:62dc9fb3a03e

Quitando cuentas BuiltIn
author Nelo@Guinea.neluz.int
date Mon, 01 Aug 2011 00:28:04 -0300
parents 7a2eeb9e9bf9
children 2dbb15f4510f
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 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);
		}
	}
}