changeset 2:c03560ae4762

Test de Crud para la agenda
author nelopauselli
date Sat, 22 Jan 2011 20:21:31 -0300
parents 6bb4ab4c0611
children 5f007e266509
files Agendas/trunk/src/Agendas.Domain/Agenda.cs Agendas/trunk/src/Agendas.Domain/Cafe.cs Agendas/trunk/src/Agendas.Domain/Evento.cs Agendas/trunk/src/Agendas.Domain/Repositories/IEventoRepository.cs Agendas/trunk/src/Agendas.Domain/Van.cs Agendas/trunk/src/Agendas.Repositories.Memory/AgendaRepository.cs Agendas/trunk/src/Agendas.Repositories.Memory/Agendas.Repositories.Memory.csproj Agendas/trunk/src/Agendas.Repositories.Memory/CafeRepository.cs Agendas/trunk/src/Agendas.Repositories.Memory/Class1.cs Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs Agendas/trunk/src/Agendas.Repositories.Memory/VanRepository.cs Agendas/trunk/src/Agendas.Repositories.Memory/VanRepositoryMemory.cs Agendas/trunk/src/Agendas.Tests/AgendaTests.cs Agendas/trunk/src/Agendas.Tests/EventoTests.cs
diffstat 14 files changed, 246 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Domain/Agenda.cs	Sat Jan 22 19:50:32 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Agenda.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -1,5 +1,5 @@
 using System;
-using AltNetHispano.Agendas.Domain.Repositories;
+using System.Collections.Generic;
 
 namespace AltNetHispano.Agendas.Domain
 {
@@ -7,18 +7,26 @@
 	{
 		private readonly IPublicador _publicador;
 		private readonly IRecordador _recordador;
-		private readonly IEventoRepository _eventoRepository;
+
+		public Guid Id { get; set; }
 
-		public Agenda(IPublicador publicador, IRecordador recordador, IEventoRepository eventoRepository)
+		private readonly IList<Evento> _eventos;
+		public IEnumerable<Evento> Eventos
+		{
+			get { return _eventos; }
+		}
+
+
+		public Agenda(IPublicador publicador, IRecordador recordador)
 		{
 			_publicador = publicador;
 			_recordador = recordador;
-			_eventoRepository = eventoRepository;
+			_eventos = new List<Evento>();
 		}
 
 		public void Publicar(Evento evento)
 		{
-			_eventoRepository.Save(evento);
+			_eventos.Add(evento);
 
 			if (_publicador != null)
 				_publicador.Publicar(evento);
--- a/Agendas/trunk/src/Agendas.Domain/Cafe.cs	Sat Jan 22 19:50:32 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Cafe.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -1,4 +1,6 @@
-namespace AltNetHispano.Agendas.Domain
+using System;
+
+namespace AltNetHispano.Agendas.Domain
 {
 	public class Cafe : Evento
 	{
--- a/Agendas/trunk/src/Agendas.Domain/Evento.cs	Sat Jan 22 19:50:32 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Evento.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -2,8 +2,12 @@
 
 namespace AltNetHispano.Agendas.Domain
 {
-	public class Evento
+	public abstract class Evento
 	{
 		public Guid Id { get; set; }
+		public string Titulo { get; set; }
+		public DateTime Fecha { get; set; }
+		public string Sintesis { get; set; }
+
 	}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Repositories/IEventoRepository.cs	Sat Jan 22 19:50:32 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Repositories/IEventoRepository.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -18,4 +18,12 @@
 	{
 		Cafe Get(Guid vanId);
 	}
+
+	public interface IAgendaRepository
+	{
+		void Save(Agenda agenda);
+		void Delete(Agenda agenda);
+		void Update(Agenda agenda);
+		Agenda Get(Guid agendaId);
+	}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Van.cs	Sat Jan 22 19:50:32 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Van.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -5,14 +5,8 @@
 {
 	public class Van : Evento
 	{
-		public string Titulo { get; set; }
-
 		public string Ponente { get; set; }
 
-		public DateTime Fecha { get; set; }
-
-		public string Sintesis { get; set; }
-
 		public IList<string> Enlaces { get; set; }
 	}
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/AgendaRepository.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -0,0 +1,38 @@
+using System;
+using System.Collections.Generic;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Domain.Repositories;
+
+namespace Agendas.Repositories.Memory
+{
+	public class AgendaRepository : IAgendaRepository
+	{
+		protected static readonly IDictionary<Guid, Agenda> Agendas = new Dictionary<Guid, Agenda>();
+
+		public void Save(Agenda agenda)
+		{
+			if (Guid.Empty.Equals(agenda.Id))
+			{
+				agenda.Id = Guid.NewGuid();
+				Agendas.Add(agenda.Id, agenda);
+			}
+		}
+
+		public void Update(Agenda agenda)
+		{
+			//nada que hacer en este método para este repositorio
+		}
+
+		public void Delete(Agenda agenda)
+		{
+			Agendas.Remove(agenda.Id);
+		}
+
+		public Agenda Get(Guid agendaId)
+		{
+			Agenda agenda;
+			return Agendas.TryGetValue(agendaId, out agenda) ? agenda : null;
+
+		}
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Repositories.Memory/Agendas.Repositories.Memory.csproj	Sat Jan 22 19:50:32 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/Agendas.Repositories.Memory.csproj	Sat Jan 22 20:21:31 2011 -0300
@@ -40,9 +40,11 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
-    <Compile Include="Class1.cs" />
+    <Compile Include="AgendaRepository.cs" />
+    <Compile Include="CafeRepository.cs" />
+    <Compile Include="EventoRepository.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
-    <Compile Include="VanRepositoryMemory.cs" />
+    <Compile Include="VanRepository.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\Agendas.Domain\Agendas.Domain.csproj">
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/CafeRepository.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -0,0 +1,15 @@
+using System;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Domain.Repositories;
+
+namespace Agendas.Repositories.Memory
+{
+	public  class CafeRepository : EventoRepository, ICafeRepository
+	{
+		public Cafe Get(Guid vanId)
+		{
+			Evento evento;
+			return Eventos.TryGetValue(vanId, out evento) ? evento as Cafe : null;
+		}
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Repositories.Memory/Class1.cs	Sat Jan 22 19:50:32 2011 -0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace Agendas.Repositories.Memory
-{
-	public class Class1
-	{
-	}
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -0,0 +1,30 @@
+using System;
+using System.Collections.Generic;
+using AltNetHispano.Agendas.Domain;
+
+namespace Agendas.Repositories.Memory
+{
+	public abstract class EventoRepository
+	{
+		protected static readonly IDictionary<Guid, Evento> Eventos = new Dictionary<Guid, Evento>();
+
+		public void Save(Evento evento)
+		{
+			if (Guid.Empty.Equals(evento.Id))
+			{
+				evento.Id = Guid.NewGuid();
+				Eventos.Add(evento.Id, evento);
+			}
+		}
+
+		public void Update(Evento evento)
+		{
+			//nada que hacer en este método para este repositorio
+		}
+
+		public void Delete(Evento evento)
+		{
+			Eventos.Remove(evento.Id);
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/VanRepository.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -0,0 +1,15 @@
+using System;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Domain.Repositories;
+
+namespace Agendas.Repositories.Memory
+{
+	public class VanRepository : EventoRepository, IVanRepository
+	{
+		public Van Get(Guid vanId)
+		{
+			Evento evento;
+			return Eventos.TryGetValue(vanId, out evento) ? evento as Van : null;
+		}
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Repositories.Memory/VanRepositoryMemory.cs	Sat Jan 22 19:50:32 2011 -0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,38 +0,0 @@
-using System;
-using System.Collections.Generic;
-using AltNetHispano.Agendas.Domain;
-using AltNetHispano.Agendas.Domain.Repositories;
-
-namespace Agendas.Repositories.Memory
-{
-	public class VanRepositoryMemory : IVanRepository
-	{
-		private static readonly IDictionary<Guid, Evento> Vans = new Dictionary<Guid, Evento>();
-
-		public void Save(Evento evento)
-		{
-			if (Guid.Empty.Equals(evento.Id))
-			{
-				evento.Id = Guid.NewGuid();
-				Vans.Add(evento.Id, evento);
-			}
-		}
-
-		public void Update(Evento evento)
-		{
-			//nada que hacer en este método para este repositorio
-		}
-
-		public Van Get(Guid vanId)
-		{
-			Evento evento;
-			return Vans.TryGetValue(vanId, out evento) ? evento as Van : null;
-		}
-
-		public void Delete(Evento evento)
-		{
-			Vans.Remove(evento.Id);
-		}
-
-	}
-}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Tests/AgendaTests.cs	Sat Jan 22 19:50:32 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/AgendaTests.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -1,4 +1,7 @@
-using AltNetHispano.Agendas.Domain;
+using System;
+using System.Linq;
+using Agendas.Repositories.Memory;
+using AltNetHispano.Agendas.Domain;
 using AltNetHispano.Agendas.Domain.Repositories;
 using Moq;
 using NUnit.Framework;
@@ -12,30 +15,26 @@
 		public void Publicar_van()
 		{
 			var publicador = new Mock<IPublicador>();
-			var eventoRepository = new Mock<IEventoRepository>();
 
-			var agenda = new Agenda(publicador.Object, null, eventoRepository.Object);
+			var agenda = new Agenda(publicador.Object, null);
 
 			var van = new Van();
 			agenda.Publicar(van);
 
 			publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
-			eventoRepository.Verify(r => r.Save(It.IsAny<Evento>()), Times.Exactly(1));
 		}
 
 		[Test]
 		public void Publicar_cafe()
 		{
 			var publicador = new Mock<IPublicador>();
-			var eventoRepository = new Mock<IEventoRepository>();
 
-			var agenda = new Agenda(publicador.Object, null, eventoRepository.Object);
+			var agenda = new Agenda(publicador.Object, null);
 
 			var cafe = new Cafe();
 			agenda.Publicar(cafe);
 
 			publicador.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
-			eventoRepository.Verify(r => r.Save(It.IsAny<Evento>()), Times.Exactly(1));
 		}
 
 		[Test]
@@ -44,9 +43,7 @@
 			var publicador1 = new Mock<IPublicador>();
 			var publicador2 = new Mock<IPublicador>();
 
-			var eventoRepository = new Mock<IEventoRepository>();
-
-			var agenda = new Agenda(new CompositePublicador (new[] { publicador1.Object, publicador2.Object } ), null, eventoRepository.Object);
+			var agenda = new Agenda(new CompositePublicador (new[] { publicador1.Object, publicador2.Object } ), null);
 
 			var cafe = new Cafe();
 			agenda.Publicar(cafe);
@@ -62,9 +59,7 @@
 			var publicador2 = new Mock<IPublicador>();
 			var recordador1 = new Mock<IRecordador>();
 
-			var eventoRepository = new Mock<IEventoRepository>();
-
-			var agenda = new Agenda(new CompositePublicador(new[] { publicador1.Object, publicador2.Object }), recordador1.Object, eventoRepository.Object);
+			var agenda = new Agenda(new CompositePublicador(new[] { publicador1.Object, publicador2.Object }), recordador1.Object);
 
 			var van = new Van();
 			agenda.Publicar(van);
@@ -75,6 +70,53 @@
 			publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
 			recordador1.Verify(r => r.Recordar(It.IsAny<Evento>()), Times.Exactly(1));
 
+			Assert.AreEqual(1, agenda.Eventos.Count());
+		}
+
+		[Test]
+		public void Van_crud()
+		{
+			Guid vanId;
+			{
+				var agenda = new Agenda(null, null);
+				agenda.Publicar(new Van());
+
+				IAgendaRepository agendaRepository = new AgendaRepository();
+
+				agendaRepository.Save(agenda);
+				vanId = agenda.Id;
+			}
+
+			{
+				IAgendaRepository agendaRepository = new AgendaRepository();
+
+				var agenda = agendaRepository.Get(vanId);
+
+				Assert.IsNotNull(agenda);
+				Assert.AreEqual(1, agenda.Eventos.Count());
+				agenda.Publicar(new Cafe());
+
+				agendaRepository.Update(agenda);
+			}
+
+			{
+				IAgendaRepository agendaRepository = new AgendaRepository();
+
+				var agenda = agendaRepository.Get(vanId);
+
+				Assert.IsNotNull(agenda);
+				Assert.AreEqual(2, agenda.Eventos.Count());
+
+				agendaRepository.Delete(agenda);
+			}
+
+			{
+				IAgendaRepository agendaRepository = new AgendaRepository();
+
+				var agenda = agendaRepository.Get(vanId);
+
+				Assert.IsNull(agenda);
+			}
 		}
 	}
 }
--- a/Agendas/trunk/src/Agendas.Tests/EventoTests.cs	Sat Jan 22 19:50:32 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/EventoTests.cs	Sat Jan 22 20:21:31 2011 -0300
@@ -10,7 +10,7 @@
 	public class EventoTests
 	{
 		[Test]
-		public void Crud()
+		public void Van_crud()
 		{
 			Guid vanId;
 			{
@@ -20,7 +20,7 @@
 								Ponente = "Carlos Blé",
 								Fecha = new DateTime(2010, 04, 16)
 							};
-				IVanRepository eventoRepository = new VanRepositoryMemory();
+				IVanRepository eventoRepository = new VanRepository();
 
 				eventoRepository.Save(van);
 				vanId = van.Id;
@@ -30,7 +30,7 @@
 				"Durante la primera hora se habló de los principios SOLID, de BDD, TDD y ATDD. Discusión entre las diferencias entre TDD y BDD, así como también sobre algunas cuestiones relativas a la nomenclatura.\n Durante la segunda hora se realizó un ejercicio práctico demostrando como se comienza a practicar TDD.\n La última parte de la VAN es la mas interesante respecto a lo que es TDD y como se practica.";
 
 			{
-				IVanRepository eventoRepository = new VanRepositoryMemory();
+				IVanRepository eventoRepository = new VanRepository();
 
 				var van = eventoRepository.Get(vanId);
 
@@ -47,7 +47,7 @@
 			}
 
 			{
-				IVanRepository eventoRepository = new VanRepositoryMemory();
+				IVanRepository eventoRepository = new VanRepository();
 
 				var van = eventoRepository.Get(vanId);
 
@@ -65,12 +65,67 @@
 			}
 
 			{
-				IVanRepository eventoRepository = new VanRepositoryMemory();
+				IVanRepository eventoRepository = new VanRepository();
 
 				var van = eventoRepository.Get(vanId);
 
 				Assert.IsNull(van);
 			}
 		}
+
+		[Test]
+		public void Cafe_crud()
+		{
+			Guid cafeId;
+			{
+				var cafe = new Cafe
+				{
+					Titulo = "La Inmortalidad de la Medusa - Arquitectura",
+					Fecha = new DateTime(2010, 08, 27),
+				};
+				ICafeRepository eventoRepository = new CafeRepository();
+
+				eventoRepository.Save(cafe);
+				cafeId = cafe.Id;
+			}
+
+			const string sintesis =
+				"Se habló sobre la sensación de perdida de control con el uso de frameworks, la Organización en capas de una aplicación, servicios en la web que se combinan.\nSe discutió un poco sobre Testing Unitario vs Test de Integración. Testing con Stubs vs Mocks, la diferencia entre decir que debe hacer un componente y como debe hacerlo.\nSe habló sobre MVVM.";
+
+			{
+				ICafeRepository eventoRepository = new CafeRepository();
+
+				var cafe = eventoRepository.Get(cafeId);
+
+				Assert.IsNotNull(cafe);
+				Assert.AreEqual("La Inmortalidad de la Medusa - Arquitectura", cafe.Titulo);
+				Assert.AreEqual(new DateTime(2010, 08, 27), cafe.Fecha);
+
+				cafe.Sintesis = sintesis;
+
+				eventoRepository.Update(cafe);
+			}
+
+			{
+				ICafeRepository eventoRepository = new CafeRepository();
+
+				var cafe = eventoRepository.Get(cafeId);
+
+				Assert.IsNotNull(cafe);
+				Assert.AreEqual("La Inmortalidad de la Medusa - Arquitectura", cafe.Titulo);
+				Assert.AreEqual(new DateTime(2010, 08, 27), cafe.Fecha);
+				Assert.AreEqual(sintesis, cafe.Sintesis);
+
+				eventoRepository.Delete(cafe);
+			}
+
+			{
+				ICafeRepository eventoRepository = new CafeRepository();
+
+				var cafe = eventoRepository.Get(cafeId);
+
+				Assert.IsNull(cafe);
+			}
+		}
 	}
 }
\ No newline at end of file