changeset 137:2d1adbaf0373

CRUD de Patrocinador
author nelopauselli
date Thu, 28 Jul 2011 09:26:24 -0300
parents 462a78196d11
children 62791999ad01
files Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj Agendas/trunk/src/Agendas.Domain/Patrocinador.cs Agendas/trunk/src/Agendas.Domain/Repositories/IPatrocinadorRepository.cs Agendas/trunk/src/Agendas.NHibernate/NhHelper.cs Agendas/trunk/src/Agendas.Repositories.Memory/Agendas.Repositories.Memory.csproj Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs Agendas/trunk/src/Agendas.Repositories.Memory/PatrocinadorRepository.cs Agendas/trunk/src/Agendas.Repositories.Memory/RepositoryBase.cs Agendas/trunk/src/Agendas.Repositories.NHibernate/Agendas.Repositories.NHibernate.csproj Agendas/trunk/src/Agendas.Repositories.NHibernate/PatrocinadorRepository.cs Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrudMemoryTests.cs Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrudNhTests.cs Agendas/trunk/src/Agendas.Tests/Cruds/EventoTests.cs Agendas/trunk/src/Agendas.Tests/Cruds/PatrocinadorCrud.cs Agendas/trunk/src/Agendas.Tests/Cruds/PatrocinadorCrudMemoryTests.cs Agendas/trunk/src/Agendas.Tests/Cruds/PatrocinadorCrudNhTests.cs Agendas/trunk/src/Agendas.Tests/Cruds/RequestEmulator.cs Agendas/trunk/src/Agendas.Tests/images/apress.gif
diffstat 19 files changed, 410 insertions(+), 96 deletions(-) [+]
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj	Tue Jul 26 14:33:49 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Agendas.Domain.csproj	Thu Jul 28 09:26:24 2011 -0300
@@ -61,10 +61,12 @@
     <Compile Include="IdentityContext.cs" />
     <Compile Include="Exceptions\InvalidStateException.cs" />
     <Compile Include="ISeguridad.cs" />
+    <Compile Include="Patrocinador.cs" />
     <Compile Include="Persona.cs" />
     <Compile Include="Repositories\IEventoRepository.cs" />
     <Compile Include="IPublicador.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
+    <Compile Include="Repositories\IPatrocinadorRepository.cs" />
     <Compile Include="Repositories\IPersonaRepository.cs" />
     <Compile Include="Resultado.cs" />
     <Compile Include="Services\PersonaService.cs" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Domain/Patrocinador.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -0,0 +1,19 @@
+using System;
+
+namespace AltNetHispano.Agendas.Domain
+{
+	public class Patrocinador : Identificable
+	{
+		public virtual string Nombre { get; set; }
+		public virtual byte[] Logo { get; set; }
+
+		public Patrocinador(string nombre)
+		{
+			Nombre = nombre;
+		}
+
+		protected Patrocinador()
+		{
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Domain/Repositories/IPatrocinadorRepository.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -0,0 +1,11 @@
+using System;
+
+namespace AltNetHispano.Agendas.Domain.Repositories
+{
+	public interface IPatrocinadorRepository
+	{
+		void Save(Patrocinador patrocinador);
+		Patrocinador Get(Guid patrocinadorId);
+		void Delete(Patrocinador patrocinador);
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.NHibernate/NhHelper.cs	Tue Jul 26 14:33:49 2011 -0300
+++ b/Agendas/trunk/src/Agendas.NHibernate/NhHelper.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -22,6 +22,7 @@
 				orm.TablePerClass<Track>();
 				orm.TablePerClass<TrackLog>();
 				orm.TablePerClass<Cuenta>();
+				orm.TablePerClass<Patrocinador>();
 
 				orm.Cascade<Evento, Persona>(Cascade.None);
 				orm.Cascade<Persona, Evento>(Cascade.None);
--- a/Agendas/trunk/src/Agendas.Repositories.Memory/Agendas.Repositories.Memory.csproj	Tue Jul 26 14:33:49 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/Agendas.Repositories.Memory.csproj	Thu Jul 28 09:26:24 2011 -0300
@@ -41,6 +41,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="EventoRepository.cs" />
+    <Compile Include="PatrocinadorRepository.cs" />
     <Compile Include="PonenteRepository.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="RepositoryBase.cs" />
--- a/Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs	Tue Jul 26 14:33:49 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/EventoRepository.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -18,17 +18,6 @@
 			return Objects.Values.Where(e => e.Estado == state.GetDescripcion()).ToList();
 		}
 
-		public void Delete(Evento evento)
-		{
-			Objects.Remove(evento.Id);
-		}
-
-		public Evento Get(Guid vanId)
-        {
-            Evento evento;
-            return Objects.TryGetValue(vanId, out evento) ? evento : null;
-        }
-
 		public IList<Evento> GetActivos()
 		{
 			return
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/PatrocinadorRepository.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -0,0 +1,13 @@
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Domain.Repositories;
+
+namespace AltNetHispano.Agendas.Repositories.Memory
+{
+	public class PatrocinadorRepository : RepositoryBase<Patrocinador>, IPatrocinadorRepository
+	{
+		public static void Clear()
+		{
+			Objects.Clear();
+		}
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Repositories.Memory/RepositoryBase.cs	Tue Jul 26 14:33:49 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Repositories.Memory/RepositoryBase.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -8,6 +8,12 @@
 	{
 		protected static readonly IDictionary<Guid, T> Objects = new Dictionary<Guid, T>();
 
+		public T Get(Guid id)
+		{
+			T value;
+			return Objects.TryGetValue(id, out value) ? value : null;
+		}
+
 		public void Save(T obj)
 		{
 			if (obj.Id==Guid.Empty)
@@ -20,5 +26,11 @@
 				Objects.Add(obj.Id, obj);
 		}
 
+		public void Delete(T obj)
+		{
+			Objects.Remove(obj.Id);
+		}
+
+
 	}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Repositories.NHibernate/Agendas.Repositories.NHibernate.csproj	Tue Jul 26 14:33:49 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/Agendas.Repositories.NHibernate.csproj	Thu Jul 28 09:26:24 2011 -0300
@@ -53,6 +53,7 @@
   </ItemGroup>
   <ItemGroup>
     <Compile Include="EventoRepository.cs" />
+    <Compile Include="PatrocinadorRepository.cs" />
     <Compile Include="PonenteRepository.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="RepositoryBase.cs" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Repositories.NHibernate/PatrocinadorRepository.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -0,0 +1,25 @@
+using System;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Domain.Repositories;
+using NHibernate;
+
+namespace AltNetHispano.Agendas.Repositories.NHibernate
+{
+	public class PatrocinadorRepository : RepositoryBase<Patrocinador>, IPatrocinadorRepository
+	{
+		public PatrocinadorRepository(ISessionFactory sessionFactory)
+			: base(sessionFactory)
+		{
+		}
+
+		public Patrocinador Get(Guid patrocinadorId)
+		{
+			return Session.Get<Patrocinador>(patrocinadorId);
+		}
+
+		public void Delete(Patrocinador patrocinador)
+		{
+			Session.Delete(patrocinador);
+		}
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj	Tue Jul 26 14:33:49 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/Agendas.Tests.csproj	Thu Jul 28 09:26:24 2011 -0300
@@ -64,6 +64,7 @@
     <Reference Include="System" />
     <Reference Include="System.Configuration" />
     <Reference Include="System.Core" />
+    <Reference Include="System.Drawing" />
     <Reference Include="System.ServiceModel" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Data.DataSetExtensions" />
@@ -76,11 +77,15 @@
     <Compile Include="Blog\PublicadorTests.cs" />
     <Compile Include="Cruds\EventoCrud.cs" />
     <Compile Include="Cruds\EventoCrudNhTests.cs" />
+    <Compile Include="Cruds\PatrocinadorCrud.cs" />
+    <Compile Include="Cruds\PatrocinadorCrudMemoryTests.cs" />
+    <Compile Include="Cruds\PatrocinadorCrudNhTests.cs" />
+    <Compile Include="Cruds\RequestEmulator.cs" />
     <Compile Include="DateTimeFormattingTests.cs" />
     <Compile Include="PersonaServiceTests.cs" />
     <Compile Include="PonentesTests.cs" />
     <Compile Include="PropuestasTests.cs" />
-    <Compile Include="Cruds\EventoTests.cs" />
+    <Compile Include="Cruds\EventoCrudMemoryTests.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="AgendarTests.cs" />
     <Compile Include="TestBase.cs" />
@@ -124,6 +129,9 @@
     <Content Include="hibernate.cfg.xml">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
+    <Content Include="images\apress.gif">
+      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+    </Content>
   </ItemGroup>
   <ItemGroup />
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrudMemoryTests.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -0,0 +1,64 @@
+using System;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Repositories.Memory;
+using Moq;
+using NUnit.Framework;
+
+namespace AltNetHispano.Agendas.Tests.Cruds
+{
+	[TestFixture]
+	public class EventoCrudMemoryTests
+	{
+		private EventoCrud _eventoCrud;
+
+		#region SetUp
+
+		[SetUp]
+		public void BorrarRepositorios()
+		{
+			EventoRepository.Clear();
+			PersonaRepository.Clear();
+		}
+
+		[SetUp]
+		public void SetearUsuario()
+		{
+			var seguridad = new Mock<ISeguridad>();
+			seguridad.Setup(s => s.GetUserName()).Returns("neluz");
+			IdentityContext.Init(seguridad.Object, new PersonaRepository());
+		}
+
+		[SetUp]
+		public void CreateCrud()
+		{
+			_eventoCrud = new EventoCrud(() => new EventoRepository(), ()=>new PersonaRepository(), () => new Mock<IDisposable>().Object);
+		}
+
+		#endregion
+
+		[Test]
+		public void Create()
+		{
+			_eventoCrud.Create();
+		}
+
+		[Test]
+		public void Read()
+		{
+			_eventoCrud.Read();
+		}
+
+		[Test]
+		public void Update()
+		{
+			_eventoCrud.Update();
+		}
+
+		[Test]
+		public void Delete()
+		{
+			_eventoCrud.Delete();
+		}
+
+	}
+}
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrudNhTests.cs	Tue Jul 26 14:33:49 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/Cruds/EventoCrudNhTests.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -1,11 +1,9 @@
-using System;
-using Agendas.NHibernate;
+using Agendas.NHibernate;
 using AltNetHispano.Agendas.Domain;
 using AltNetHispano.Agendas.Repositories.NHibernate;
 using Moq;
 using NHibernate;
 using NHibernate.Cfg;
-using NHibernate.Context;
 using NHibernate.Tool.hbm2ddl;
 using NUnit.Framework;
 
@@ -69,21 +67,4 @@
 		}
 
 	}
-
-	public class RequestEmulator : IDisposable
-	{
-		private readonly ISession _session;
-
-		public RequestEmulator(ISessionFactory sessionFactory)
-		{
-			_session = sessionFactory.OpenSession();
-			CurrentSessionContext.Bind(_session);
-		}
-
-		public void Dispose()
-		{
-			_session.Flush();
-			_session.Close();
-		}
-	}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Tests/Cruds/EventoTests.cs	Tue Jul 26 14:33:49 2011 -0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,64 +0,0 @@
-using System;
-using AltNetHispano.Agendas.Domain;
-using AltNetHispano.Agendas.Repositories.Memory;
-using Moq;
-using NUnit.Framework;
-
-namespace AltNetHispano.Agendas.Tests.Cruds
-{
-	[TestFixture]
-	public class EventoCrudMemoryTests
-	{
-		private EventoCrud _eventoCrud;
-
-		#region SetUp
-
-		[SetUp]
-		public void BorrarRepositorios()
-		{
-			EventoRepository.Clear();
-			PersonaRepository.Clear();
-		}
-
-		[SetUp]
-		public void SetearUsuario()
-		{
-			var seguridad = new Mock<ISeguridad>();
-			seguridad.Setup(s => s.GetUserName()).Returns("neluz");
-			IdentityContext.Init(seguridad.Object, new PersonaRepository());
-		}
-
-		[SetUp]
-		public void CreateCrud()
-		{
-			_eventoCrud = new EventoCrud(() => new EventoRepository(), ()=>new PersonaRepository(), () => new Mock<IDisposable>().Object);
-		}
-
-		#endregion
-
-		[Test]
-		public void Create()
-		{
-			_eventoCrud.Create();
-		}
-
-		[Test]
-		public void Read()
-		{
-			_eventoCrud.Read();
-		}
-
-		[Test]
-		public void Update()
-		{
-			_eventoCrud.Update();
-		}
-
-		[Test]
-		public void Delete()
-		{
-			_eventoCrud.Delete();
-		}
-
-	}
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Tests/Cruds/PatrocinadorCrud.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -0,0 +1,96 @@
+using System;
+using System.Drawing;
+using System.IO;
+using System.Linq;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Domain.Repositories;
+using NUnit.Framework;
+
+namespace AltNetHispano.Agendas.Tests.Cruds
+{
+	public class PatrocinadorCrud
+	{
+		private readonly IPatrocinadorRepository _patrocinadorRepository;
+		private readonly Func<IDisposable> _requestEmulator;
+		private byte[] _logo;
+
+		public PatrocinadorCrud(Func<IPatrocinadorRepository> createPatrocinadorRepository, Func<IDisposable> requestEmulator)
+		{
+			_patrocinadorRepository = createPatrocinadorRepository.Invoke();
+			_requestEmulator = requestEmulator;
+		}
+
+		public Guid Create()
+		{
+			using (_requestEmulator.Invoke())
+			{
+				var patrocinador = new Patrocinador("APRESS");
+
+				var image = Image.FromFile("images/apress.gif");
+				var ms = new MemoryStream();
+				image.Save(ms, image.RawFormat);
+				_logo = ms.ToArray();
+
+				patrocinador.Logo = _logo;
+
+				_patrocinadorRepository.Save(patrocinador);
+				return patrocinador.Id;
+			}
+		}
+
+		public void Read()
+		{
+			Guid patrocinadorId = Create();
+
+			using (_requestEmulator.Invoke())
+			{
+				var patrocinador = _patrocinadorRepository.Get(patrocinadorId);
+
+				Assert.IsNotNull(patrocinador);
+				Assert.AreEqual("APRESS", patrocinador.Nombre);
+				Assert.IsNotNull(patrocinador.Logo);
+				Assert.AreEqual(_logo, patrocinador.Logo);
+			}
+		}
+
+		public void Update()
+		{
+			Guid patrocinadorId = Create();
+
+			using (_requestEmulator.Invoke())
+			{
+				var patrocinador = _patrocinadorRepository.Get(patrocinadorId);
+				Assert.IsNotNull(patrocinador);
+
+				patrocinador.Nombre = "Apress";
+			}
+
+			using (_requestEmulator.Invoke())
+			{
+				var patrocinador = _patrocinadorRepository.Get(patrocinadorId);
+
+				Assert.IsNotNull(patrocinador);
+				Assert.AreEqual("Apress", patrocinador.Nombre);
+			}
+		}
+
+		public void Delete()
+		{
+			Guid patrocinadorId = Create();
+
+			using (_requestEmulator.Invoke())
+			{
+				var patrocinador = _patrocinadorRepository.Get(patrocinadorId);
+				Assert.IsNotNull(patrocinador);
+
+				_patrocinadorRepository.Delete(patrocinador);
+			}
+
+			using (_requestEmulator.Invoke())
+			{
+				var patrocinador = _patrocinadorRepository.Get(patrocinadorId);
+				Assert.IsNull(patrocinador);
+			}
+		}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Tests/Cruds/PatrocinadorCrudMemoryTests.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -0,0 +1,63 @@
+using System;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Repositories.Memory;
+using Moq;
+using NUnit.Framework;
+
+namespace AltNetHispano.Agendas.Tests.Cruds
+{
+	[TestFixture]
+	public class PatrocinadorCrudMemoryTests
+	{
+		private PatrocinadorCrud _eventoCrud;
+
+		#region SetUp
+
+		[SetUp]
+		public void BorrarRepositorios()
+		{
+			PatrocinadorRepository.Clear();
+		}
+
+		[SetUp]
+		public void SetearUsuario()
+		{
+			var seguridad = new Mock<ISeguridad>();
+			seguridad.Setup(s => s.GetUserName()).Returns("neluz");
+			IdentityContext.Init(seguridad.Object, new PersonaRepository());
+		}
+
+		[SetUp]
+		public void CreateCrud()
+		{
+			_eventoCrud = new PatrocinadorCrud(() => new PatrocinadorRepository(), () => new Mock<IDisposable>().Object);
+		}
+
+		#endregion
+
+		[Test]
+		public void Create()
+		{
+			_eventoCrud.Create();
+		}
+
+		[Test]
+		public void Read()
+		{
+			_eventoCrud.Read();
+		}
+
+		[Test]
+		public void Update()
+		{
+			_eventoCrud.Update();
+		}
+
+		[Test]
+		public void Delete()
+		{
+			_eventoCrud.Delete();
+		}
+
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Tests/Cruds/PatrocinadorCrudNhTests.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -0,0 +1,69 @@
+using Agendas.NHibernate;
+using AltNetHispano.Agendas.Domain;
+using AltNetHispano.Agendas.Repositories.NHibernate;
+using Moq;
+using NHibernate;
+using NHibernate.Cfg;
+using NHibernate.Tool.hbm2ddl;
+using NUnit.Framework;
+
+namespace AltNetHispano.Agendas.Tests.Cruds
+{
+	[TestFixture]
+	public class PatrocinadorCrudNhTests
+	{
+		private PatrocinadorCrud _patrocinadorCrud;
+
+		#region SetUp
+
+		[SetUp]
+		public void BorrarRepositorios()
+		{
+			Configuration cfg = NhHelper.GetConfiguration();
+			var schemaExport = new SchemaExport(cfg);
+			schemaExport.Create(false, true);
+		}
+
+		[SetUp]
+		public void SetearUsuario()
+		{
+			var seguridad = new Mock<ISeguridad>();
+			seguridad.Setup(s => s.GetUserName()).Returns("neluz");
+			IdentityContext.Init(seguridad.Object, new PersonaRepository(NhHelper.GetSessionFactory()));
+		}
+
+		[SetUp]
+		public void CreateCrud()
+		{
+			ISessionFactory sessionFactory = NhHelper.GetSessionFactory();
+			_patrocinadorCrud = new PatrocinadorCrud(() => new PatrocinadorRepository(sessionFactory), () => new RequestEmulator(sessionFactory));
+		}
+
+		#endregion
+
+		[Test]
+		public void Create()
+		{
+			_patrocinadorCrud.Create();
+		}
+
+		[Test]
+		public void Read()
+		{
+			_patrocinadorCrud.Read();
+		}
+
+		[Test]
+		public void Update()
+		{
+			_patrocinadorCrud.Update();
+		}
+
+		[Test]
+		public void Delete()
+		{
+			_patrocinadorCrud.Delete();
+		}
+
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Tests/Cruds/RequestEmulator.cs	Thu Jul 28 09:26:24 2011 -0300
@@ -0,0 +1,23 @@
+using System;
+using NHibernate;
+using NHibernate.Context;
+
+namespace AltNetHispano.Agendas.Tests.Cruds
+{
+	public class RequestEmulator : IDisposable
+	{
+		private readonly ISession _session;
+
+		public RequestEmulator(ISessionFactory sessionFactory)
+		{
+			_session = sessionFactory.OpenSession();
+			CurrentSessionContext.Bind(_session);
+		}
+
+		public void Dispose()
+		{
+			_session.Flush();
+			_session.Close();
+		}
+	}
+}
\ No newline at end of file
Binary file Agendas/trunk/src/Agendas.Tests/images/apress.gif has changed