changeset 1:6bb4ab4c0611

Tests de Crud para repositorio de Vans
author nelopauselli
date Sat, 22 Jan 2011 19:50:32 -0300
parents 3f7dbb633b71
children c03560ae4762
files Agendas/trunk/src/Agendas.Domain/Agenda.cs Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj Agendas/trunk/src/Agendas.Domain/Evento.cs Agendas/trunk/src/Agendas.Domain/IRecordador.cs Agendas/trunk/src/Agendas.Domain/Repositories/IEventoRepository.cs Agendas/trunk/src/Agendas.Domain/Van.cs Agendas/trunk/src/Agendas.Repositories.Memory/Agendas.Repositories.Memory.csproj Agendas/trunk/src/Agendas.Repositories.Memory/Class1.cs Agendas/trunk/src/Agendas.Repositories.Memory/Properties/AssemblyInfo.cs Agendas/trunk/src/Agendas.Repositories.Memory/VanRepositoryMemory.cs Agendas/trunk/src/Agendas.Tests/AgendaTests.cs Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj Agendas/trunk/src/Agendas.Tests/EventoTests.cs Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs Agendas/trunk/src/Agendas.sln
diffstat 15 files changed, 323 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Domain/Agenda.cs	Sat Jan 22 17:13:46 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Agenda.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -1,22 +1,33 @@
-using AltNetHispano.Agendas.Domain.Repositories;
+using System;
+using AltNetHispano.Agendas.Domain.Repositories;
 
 namespace AltNetHispano.Agendas.Domain
 {
 	public class Agenda
 	{
 		private readonly IPublicador _publicador;
+		private readonly IRecordador _recordador;
 		private readonly IEventoRepository _eventoRepository;
 
-		public Agenda(IPublicador publicador, IEventoRepository eventoRepository)
+		public Agenda(IPublicador publicador, IRecordador recordador, IEventoRepository eventoRepository)
 		{
 			_publicador = publicador;
+			_recordador = recordador;
 			_eventoRepository = eventoRepository;
 		}
 
 		public void Publicar(Evento evento)
 		{
 			_eventoRepository.Save(evento);
-			_publicador.Publicar(evento);
+
+			if (_publicador != null)
+				_publicador.Publicar(evento);
+		}
+
+		public void Recordar(Evento evento)
+		{
+			if (_recordador != null)
+				_recordador.Recordar(evento);
 		}
 	}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj	Sat Jan 22 17:13:46 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj	Sat Jan 22 19:50:32 2011 -0300
@@ -44,6 +44,7 @@
     <Compile Include="Cafe.cs" />
     <Compile Include="CompositePublicador.cs" />
     <Compile Include="Evento.cs" />
+    <Compile Include="IRecordador.cs" />
     <Compile Include="Repositories\IEventoRepository.cs" />
     <Compile Include="IPublicador.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
--- a/Agendas/trunk/src/Agendas.Domain/Evento.cs	Sat Jan 22 17:13:46 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Evento.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -1,6 +1,9 @@
-namespace AltNetHispano.Agendas.Domain
+using System;
+
+namespace AltNetHispano.Agendas.Domain
 {
 	public class Evento
 	{
+		public Guid Id { get; set; }
 	}
 }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Domain/IRecordador.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -0,0 +1,7 @@
+namespace AltNetHispano.Agendas.Domain
+{
+	public interface IRecordador
+	{
+		void Recordar(Evento evento);
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Repositories/IEventoRepository.cs	Sat Jan 22 17:13:46 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Repositories/IEventoRepository.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -1,7 +1,21 @@
-namespace AltNetHispano.Agendas.Domain.Repositories
+using System;
+
+namespace AltNetHispano.Agendas.Domain.Repositories
 {
 	public interface IEventoRepository
 	{
 		void Save(Evento evento);
+		void Delete(Evento evento);
+		void Update(Evento evento);
+	}
+
+	public interface IVanRepository : IEventoRepository
+	{
+		Van Get(Guid vanId);
+	}
+
+	public interface ICafeRepository : IEventoRepository
+	{
+		Cafe Get(Guid vanId);
 	}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Domain/Van.cs	Sat Jan 22 17:13:46 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Van.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -1,6 +1,18 @@
-namespace AltNetHispano.Agendas.Domain
+using System;
+using System.Collections.Generic;
+
+namespace AltNetHispano.Agendas.Domain
 {
 	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/Agendas.Repositories.Memory.csproj	Sat Jan 22 19:50:32 2011 -0300
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProductVersion>8.0.30703</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
+    <ProjectGuid>{28C5EBFB-EE69-4765-A880-D4DE0BC89F48}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>Agendas.Repositories.Memory</RootNamespace>
+    <AssemblyName>Agendas.Repositories.Memory</AssemblyName>
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="Class1.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="VanRepositoryMemory.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\Agendas.Domain\Agendas.Domain.csproj">
+      <Project>{A14907DF-02E4-4FA7-BE27-4292AF50AA22}</Project>
+      <Name>Agendas.Domain</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/Class1.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -0,0 +1,11 @@
+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/Properties/AssemblyInfo.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following 
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Agendas.Repositories.Memory")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Microsoft")]
+[assembly: AssemblyProduct("Agendas.Repositories.Memory")]
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible 
+// to COM components.  If you need to access a type in this assembly from 
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("b5eed6a9-cfdc-4f27-8629-bcfa976ac30a")]
+
+// Version information for an assembly consists of the following four values:
+//
+//      Major Version
+//      Minor Version 
+//      Build Number
+//      Revision
+//
+// You can specify all the values or you can default the Build and Revision Numbers 
+// by using the '*' as shown below:
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/VanRepositoryMemory.cs	Sat Jan 22 19:50:32 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 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 17:13:46 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/AgendaTests.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -9,50 +9,44 @@
 	public class AgendaTests
 	{
 		[Test]
-		public void PublicarVan()
+		public void Publicar_van()
 		{
 			var publicador = new Mock<IPublicador>();
-			publicador.Setup(p => p.Publicar(It.IsAny<Evento>())).Verifiable();
-
 			var eventoRepository = new Mock<IEventoRepository>();
 
-			var agenda = new Agenda(publicador.Object, eventoRepository.Object);
+			var agenda = new Agenda(publicador.Object, null, eventoRepository.Object);
 
 			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 PublicarCafe()
+		public void Publicar_cafe()
 		{
 			var publicador = new Mock<IPublicador>();
-			publicador.Setup(p => p.Publicar(It.IsAny<Evento>())).Verifiable();
-
 			var eventoRepository = new Mock<IEventoRepository>();
 
-			var agenda = new Agenda(publicador.Object, eventoRepository.Object);
+			var agenda = new Agenda(publicador.Object, null, eventoRepository.Object);
 
 			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]
-		public void PublicarComposite()
+		public void Publicar_van_multiples_publicadores()
 		{
 			var publicador1 = new Mock<IPublicador>();
-			publicador1.Setup(p => p.Publicar(It.IsAny<Evento>())).Verifiable();
-
 			var publicador2 = new Mock<IPublicador>();
-			publicador2.Setup(p => p.Publicar(It.IsAny<Evento>())).Verifiable();
 
 			var eventoRepository = new Mock<IEventoRepository>();
 
-			var agenda = new Agenda(new CompositePublicador (new[] { publicador1.Object, publicador2.Object } ), eventoRepository.Object);
+			var agenda = new Agenda(new CompositePublicador (new[] { publicador1.Object, publicador2.Object } ), null, eventoRepository.Object);
 
 			var cafe = new Cafe();
 			agenda.Publicar(cafe);
@@ -60,5 +54,27 @@
 			publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
 			publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
 		}
+
+		[Test]
+		public void Publicar_y_recordar_van()
+		{
+			var publicador1 = new Mock<IPublicador>();
+			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 van = new Van();
+			agenda.Publicar(van);
+
+			agenda.Recordar(van);
+
+			publicador1.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
+			publicador2.Verify(p => p.Publicar(It.IsAny<Evento>()), Times.Exactly(1));
+			recordador1.Verify(r => r.Recordar(It.IsAny<Evento>()), Times.Exactly(1));
+
+		}
 	}
 }
--- a/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj	Sat Jan 22 17:13:46 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj	Sat Jan 22 19:50:32 2011 -0300
@@ -47,6 +47,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="AgendaTests.cs" />
+    <Compile Include="EventoTests.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
   </ItemGroup>
   <ItemGroup>
@@ -58,6 +59,10 @@
       <Project>{45804F1F-EB72-4F82-A227-088CAD9B785D}</Project>
       <Name>Agendas.Google</Name>
     </ProjectReference>
+    <ProjectReference Include="..\Agendas.Repositories.Memory\Agendas.Repositories.Memory.csproj">
+      <Project>{28C5EBFB-EE69-4765-A880-D4DE0BC89F48}</Project>
+      <Name>Agendas.Repositories.Memory</Name>
+    </ProjectReference>
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Tests/EventoTests.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -0,0 +1,76 @@
+using System;
+using Agendas.Repositories.Memory;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Domain.Repositories;
+using NUnit.Framework;
+
+namespace AltNetHispano.Agendas.Tests
+{
+	[TestFixture]
+	public class EventoTests
+	{
+		[Test]
+		public void Crud()
+		{
+			Guid vanId;
+			{
+				var van = new Van
+							{
+								Titulo = "TDD - Diseño Basado en Ejemplos",
+								Ponente = "Carlos Blé",
+								Fecha = new DateTime(2010, 04, 16)
+							};
+				IVanRepository eventoRepository = new VanRepositoryMemory();
+
+				eventoRepository.Save(van);
+				vanId = van.Id;
+			}
+
+			const string sintesis =
+				"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();
+
+				var van = eventoRepository.Get(vanId);
+
+				Assert.IsNotNull(van);
+				Assert.AreEqual("Carlos Blé", van.Ponente);
+				Assert.AreEqual("TDD - Diseño Basado en Ejemplos", van.Titulo);
+				Assert.AreEqual(new DateTime(2010, 04, 16), van.Fecha);
+
+				van.Sintesis = sintesis;
+				van.Enlaces = new[] { "www.carlosble.com", "www.dirigidoPorTests.com" };
+				van.Fecha = new DateTime(2010, 04, 17);
+
+				eventoRepository.Update(van);
+			}
+
+			{
+				IVanRepository eventoRepository = new VanRepositoryMemory();
+
+				var van = eventoRepository.Get(vanId);
+
+				Assert.IsNotNull(van);
+				Assert.AreEqual("Carlos Blé", van.Ponente);
+				Assert.AreEqual("TDD - Diseño Basado en Ejemplos", van.Titulo);
+				Assert.AreEqual(new DateTime(2010, 04, 17), van.Fecha);
+				Assert.AreEqual(sintesis, van.Sintesis);
+				Assert.IsNotNull(van.Enlaces);
+				Assert.AreEqual(2, van.Enlaces.Count);
+				Assert.AreEqual("www.carlosble.com", van.Enlaces[0]);
+				Assert.AreEqual("www.dirigidoPorTests.com", van.Enlaces[1]);
+
+				eventoRepository.Delete(van);
+			}
+
+			{
+				IVanRepository eventoRepository = new VanRepositoryMemory();
+
+				var van = eventoRepository.Get(vanId);
+
+				Assert.IsNull(van);
+			}
+		}
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs	Sat Jan 22 17:13:46 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Twitter/TwitterPublicador.cs	Sat Jan 22 19:50:32 2011 -0300
@@ -3,11 +3,16 @@
 
 namespace Agendas.Twitter
 {
-	public class TwitterPublicador : IPublicador
+	public class TwitterPublicador : IPublicador, IRecordador
 	{
 		public void Publicar(Evento evento)
 		{
 			throw new NotImplementedException();
 		}
+
+		public void Recordar(Evento evento)
+		{
+			throw new NotImplementedException();
+		}
 	}
 }
--- a/Agendas/trunk/src/Agendas.sln	Sat Jan 22 17:13:46 2011 -0300
+++ b/Agendas/trunk/src/Agendas.sln	Sat Jan 22 19:50:32 2011 -0300
@@ -9,6 +9,8 @@
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agendas.Twitter", "Agendas.Twitter\Agendas.Twitter.csproj", "{D8DA7ED2-A274-4DF6-9DD2-A9DC65F4C2F5}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agendas.Repositories.Memory", "Agendas.Repositories.Memory\Agendas.Repositories.Memory.csproj", "{28C5EBFB-EE69-4765-A880-D4DE0BC89F48}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -31,6 +33,10 @@
 		{D8DA7ED2-A274-4DF6-9DD2-A9DC65F4C2F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{D8DA7ED2-A274-4DF6-9DD2-A9DC65F4C2F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{D8DA7ED2-A274-4DF6-9DD2-A9DC65F4C2F5}.Release|Any CPU.Build.0 = Release|Any CPU
+		{28C5EBFB-EE69-4765-A880-D4DE0BC89F48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{28C5EBFB-EE69-4765-A880-D4DE0BC89F48}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{28C5EBFB-EE69-4765-A880-D4DE0BC89F48}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{28C5EBFB-EE69-4765-A880-D4DE0BC89F48}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE