view Agendas/trunk/src/Agendas.Tests/TestBase.cs @ 274:72a96459f910

Ticket #123: Patrocinadores de las vans.
author juanjose.montesdeocaarbos
date Wed, 30 Nov 2011 08:56:01 -0300
parents 5346c0500594
children
line wrap: on
line source

using System;
using AltNetHispano.Agendas.Domain;
using AltNetHispano.Agendas.Domain.Repositories;
using AltNetHispano.Agendas.Repositories.Memory;
using Moq;
using NUnit.Framework;

namespace AltNetHispano.Agendas.Tests
{
	public class TestBase
	{
		protected static IEventoRepository DefaultEventoRepository
		{
			get { return new EventoRepository(); }
		}

		protected static IPersonaRepository DefaultPersonaRepository
		{
			get { return new PersonaRepository(); }
		}

		protected static IPatrocinadorRepository DefaultPatrocinadorRepository
		{
			get { return new PatrocinadorRepository(); }
		}
		
		[SetUp]
		public void LimpiarEventos()
		{
			EventoRepository.Clear();
		}

		[SetUp]
		public void PatrocinadoresEventos()
		{
			PatrocinadorRepository.Clear();
		}

		[SetUp]
		public void LimpiarPonentes()
		{
			PersonaRepository.Clear();
			SetCurrentUser("nelopauselli", "Nelo Pauselli");
		}

		protected static void SetCurrentUser(string username, string nombre)
		{
			const IdentityProviderEnum identityProvider = IdentityProviderEnum.Twitter;
			string logonName = null;
			if (username != null)
				logonName = Identification.Map[(int) IdentityProviderEnum.Twitter] + username;

			var seguridad = new Mock<ISeguridad>();
			seguridad.Setup(s => s.GetUserName()).Returns(logonName);
			
			IPersonaRepository personaRepository = new PersonaRepository();
			var persona = new Persona(nombre);
			persona.AddCuenta(new Cuenta(identityProvider, username));
			persona.Twitter = username;

			personaRepository.Save(persona);

			IdentityContext.Init(seguridad.Object, personaRepository);
		}
	}
}