changeset 105:1d820f17fc75

ajustes y correcciones en el publicador de blogs agregado de numeroOrden y urlWiki en metodo Publicar de Agenda y Evento (con test)
author jorge.rowies
date Mon, 06 Jun 2011 09:12:52 -0300
parents c5034884c7d7
children 80c22175c9b5
files Agendas/trunk/src/Agendas.Blog/Agendas.Blog.csproj Agendas/trunk/src/Agendas.Blog/IPostWriter.cs Agendas/trunk/src/Agendas.Blog/Impl/AgendarReunionPostWriter.cs Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicador.cs Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicadorConfig.cs Agendas/trunk/src/Agendas.Blog/Impl/NullObjectPostWriter.cs Agendas/trunk/src/Agendas.Blog/Impl/PostWriter.cs Agendas/trunk/src/Agendas.Blog/Impl/PostWriterWebServiceAdapter.cs Agendas/trunk/src/Agendas.Blog/Impl/PublicarReunionPostWriter.cs Agendas/trunk/src/Agendas.Blog/Properties/Resources.Designer.cs Agendas/trunk/src/Agendas.Blog/Properties/Resources.resx Agendas/trunk/src/Agendas.Domain/Agenda.cs Agendas/trunk/src/Agendas.Domain/Evento.cs Agendas/trunk/src/Agendas.Tests/AgendarTests.cs Agendas/trunk/src/Agendas.Tests/Blog/PostWriterWebServiceAdapterTests.cs Agendas/trunk/src/Agendas.Tests/Blog/PublicadorTests.cs Agendas/trunk/src/Agendas.Tests/Workflows/Workflow.cs
diffstat 17 files changed, 116 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- a/Agendas/trunk/src/Agendas.Blog/Agendas.Blog.csproj	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Agendas.Blog.csproj	Mon Jun 06 09:12:52 2011 -0300
@@ -47,6 +47,7 @@
     <Compile Include="Exceptions\PostWriterServiceUrlNotFoundException.cs" />
     <Compile Include="Impl\BlogPublicador.cs" />
     <Compile Include="Exceptions\BlogWriterMasterKeyNotFoundException.cs" />
+    <Compile Include="Impl\BlogPublicadorConfig.cs" />
     <Compile Include="IPostWriter.cs" />
     <Compile Include="IPostWriterFactory.cs" />
     <Compile Include="Impl\NullObjectPostWriter.cs" />
--- a/Agendas/trunk/src/Agendas.Blog/IPostWriter.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/IPostWriter.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -4,6 +4,6 @@
 {
   public interface IPostWriter
   {
-    void WritePost(Evento evento);
+    void WritePost(Track track);
   }
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Blog/Impl/AgendarReunionPostWriter.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Impl/AgendarReunionPostWriter.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -12,23 +12,23 @@
 	  {
 	  }
 
-	  protected override string GetTitle(Evento evento)
+    protected override string GetTitle(Track track)
 		{
 			return string.Format(CultureInfo.InvariantCulture, Resources.VAN_Realizacion_Title,
-													 evento.Ponente.Nombre, //Nombre y apellido del ponente
-													 evento.Titulo //Tema a tratar en la reunion
+													 track.Evento.Ponente.Nombre, //Nombre y apellido del ponente
+													 track.Evento.Titulo //Tema a tratar en la reunion
 				);
 		}
 
-		protected override string GetBody(Evento evento)
+    protected override string GetBody(Track track)
 		{
-			var fecha = getFechaFormateada(evento.Fecha);
+			var fecha = getFechaFormateada(track.Evento.Fecha);
 			return string.Format(CultureInfo.InvariantCulture, Resources.VAN_Realizacion_Body,
 													 fecha, //Fecha y hora en GMT+0
-													 evento.Ponente.Nombre, //Nombre y apellido del ponente
-													 evento.Titulo, //Tema a tratar en la reunion
-													 getUrlInvitacion(evento), //Url a la invitacion realizada por el ponente (por lo general es el thread en la lista de correo)
-													 GetNombreUsuario(evento) //Usuario que postea en el blog
+													 track.Evento.Ponente.Nombre, //Nombre y apellido del ponente
+													 track.Evento.Titulo, //Tema a tratar en la reunion
+													 getUrlInvitacion(track.Evento), //Url a la invitacion realizada por el ponente (por lo general es el thread en la lista de correo)
+													 GetNombreUsuario(track) //Usuario que postea en el blog
 				);
 		}
 
--- a/Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicador.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicador.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -15,7 +15,7 @@
     public void Publicar(IEnumerable<Track> tracks)
     {
       foreach (var track in tracks)
-        _postWriterFactory.GetPostWriter(track.Accion).WritePost(track.Evento);
+        _postWriterFactory.GetPostWriter(track.Accion).WritePost(track);
     }
   }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Agendas/trunk/src/Agendas.Blog/Impl/BlogPublicadorConfig.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -0,0 +1,37 @@
+using System;
+
+namespace Agendas.Blog.Impl
+{
+  public class BlogPublicadorConfig
+  {
+    public BlogPublicadorConfig(string postWriterServiceUrl, string blogName, string blogWriterMasterKey)
+    {
+      if (string.IsNullOrEmpty(postWriterServiceUrl)) throw new ArgumentNullException("postWriterServiceUrl");
+      if (string.IsNullOrEmpty(blogName)) throw new ArgumentNullException("blogName");
+      if (string.IsNullOrEmpty(blogWriterMasterKey)) throw new ArgumentNullException("blogWriterMasterKey");
+
+      _postWriterServiceUrl = postWriterServiceUrl;
+      _blogName = blogName;
+      _blogWriterMasterKey = blogWriterMasterKey;
+    }
+
+    private readonly string _postWriterServiceUrl;
+    private readonly string _blogName;
+    private readonly string _blogWriterMasterKey;
+
+    public string BlogWriterMasterKey
+    {
+      get { return _blogWriterMasterKey; }
+    }
+
+    public string BlogName
+    {
+      get { return _blogName; }
+    }
+
+    public string PostWriterServiceUrl
+    {
+      get { return _postWriterServiceUrl; }
+    }
+  }
+}
--- a/Agendas/trunk/src/Agendas.Blog/Impl/NullObjectPostWriter.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Impl/NullObjectPostWriter.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -8,17 +8,17 @@
     {
     }
 
-    public override void WritePost(Evento evento)
+    public override void WritePost(Track track)
     {
       //no-op
     }
 
-    protected override string GetBody(Evento evento)
+    protected override string GetBody(Track track)
     {
       throw new System.NotImplementedException();
     }
 
-    protected override string GetTitle(Evento evento)
+    protected override string GetTitle(Track track)
     {
       throw new System.NotImplementedException();
     }
--- a/Agendas/trunk/src/Agendas.Blog/Impl/PostWriter.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Impl/PostWriter.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -12,20 +12,20 @@
       _postWriterWebService = postWriterWebService;
     }
 
-    public virtual void WritePost(Evento evento)
+    public virtual void WritePost(Track track)
     {
-      var title = GetTitle(evento);
-      var body = GetBody(evento);
-      this.ExecuteService(title, body, this.GetNombreUsuario(evento));
+      var title = GetTitle(track);
+      var body = GetBody(track);
+      this.ExecuteService(title, body, this.GetNombreUsuario(track));
     }
 
-    protected abstract string GetBody(Evento evento);
+    protected abstract string GetBody(Track track);
 
-    protected abstract string GetTitle(Evento evento);
+    protected abstract string GetTitle(Track track);
 
-    protected string GetNombreUsuario(Evento evento)
+    protected string GetNombreUsuario(Track track)
     {
-      return evento.Tracks.Single(t => t.Accion == Accion.Publicar).Usuario.Nombre;
+      return track.Usuario.Nombre;
     }
 
     protected void ExecuteService(string title, string body, string author)
--- a/Agendas/trunk/src/Agendas.Blog/Impl/PostWriterWebServiceAdapter.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Impl/PostWriterWebServiceAdapter.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -9,15 +9,14 @@
 {
   public class PostWriterWebServiceAdapter : IPostWriterWebService
   {
+    private readonly BlogPublicadorConfig _config;
     private readonly PostWriterWebServiceSoapClient _service;
 
-    public PostWriterWebServiceAdapter()
+    public PostWriterWebServiceAdapter(BlogPublicadorConfig config)
     {
-      var postWriterUrl = System.Configuration.ConfigurationManager.AppSettings["PublicadorBlog.PostWriterServiceUrl"];
-      if (string.IsNullOrEmpty(postWriterUrl))
-        throw new PostWriterServiceUrlNotFoundException();
-
-      _service = new PortalSitefinity.PostWriterWebServiceSoapClient(new BasicHttpBinding(), new EndpointAddress(postWriterUrl));
+      _config = config;
+      _service = new PortalSitefinity.PostWriterWebServiceSoapClient(new BasicHttpBinding(),
+                                                                     new EndpointAddress(config.PostWriterServiceUrl));
     }
 
     private static string buildToken(string key, DateTime time)
@@ -38,23 +37,15 @@
     public void WriteBlogPost(string postTitle, string postHtmlContent, string postAuthor, bool setPublicationDate)
     {
       var securityToken = getSecurityToken();
-      var blogName = System.Configuration.ConfigurationManager.AppSettings["PublicadorBlog.BlogName"];
-      if (string.IsNullOrEmpty(blogName))
-        throw new BlogNameNotFoundException();
-
-      _service.WriteBlogPost(securityToken, blogName, postTitle, postHtmlContent, postAuthor, setPublicationDate);
+      _service.WriteBlogPost(securityToken, _config.BlogName, postTitle, postHtmlContent, postAuthor, setPublicationDate);
     }
 
-    private static string getSecurityToken()
+    private string getSecurityToken()
     {
-      var masterKey = System.Configuration.ConfigurationManager.AppSettings["PublicadorBlog.BlogWriterMasterKey"];
-      if (string.IsNullOrEmpty(masterKey))
-        throw new BlogWriterMasterKeyNotFoundException();
-
       var now = DateTime.UtcNow;
       now = new DateTime(now.Year, now.Month, now.Day, now.Hour, now.Minute, 0, 0);
 
-      return buildToken(masterKey, now);
+      return buildToken(_config.BlogWriterMasterKey, now);
     }
   }
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Blog/Impl/PublicarReunionPostWriter.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Impl/PublicarReunionPostWriter.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -11,20 +11,20 @@
     {
     }
 
-    protected override string GetTitle(Evento evento)
+    protected override string GetTitle(Track track)
     {
       return string.Format(CultureInfo.InvariantCulture, Resources.VAN_Publicacion_Title,
-                           evento.NumeroOrden, //# de VAN en el historial
-                           evento.Ponente.Nombre //Nombre y apellido del ponente
+                           track.Evento.NumeroOrden, //# de VAN en el historial
+                           track.Evento.Ponente.Nombre //Nombre y apellido del ponente
 
         );
     }
 
-    protected override string GetBody(Evento evento)
+    protected override string GetBody(Track track)
     {
-      return string.Format(CultureInfo.InvariantCulture, Resources.VAN_Realizacion_Body,
-													 evento.UrlWiki, //Url al video publicado en la wiki
-                           GetNombreUsuario(evento) //Usuario que postea en el blog
+      return string.Format(CultureInfo.InvariantCulture, Resources.VAN_Publicacion_Body,
+													 track.Evento.UrlWiki, //Url al video publicado en la wiki
+                           GetNombreUsuario(track) //Usuario que postea en el blog
         );
     }
   }
--- a/Agendas/trunk/src/Agendas.Blog/Properties/Resources.Designer.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Properties/Resources.Designer.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -101,7 +101,7 @@
         }
         
         /// <summary>
-        ///   Looks up a localized string similar to &lt;p&gt;En el siguiente enlace a la lista de correos, podrán encontrar el detalle de los temas a tratar:&lt;/p&gt;
+        ///   Looks up a localized string similar to &lt;p&gt;En el siguiente enlace, podrán encontrar el detalle de los temas a tratar:&lt;/p&gt;
         ///&lt;p&gt;&lt;a href=&quot;{0}&quot;&gt;{0}&lt;/a&gt;&lt;/p&gt;
         ///&lt;p&gt;&lt;/p&gt;.
         /// </summary>
--- a/Agendas/trunk/src/Agendas.Blog/Properties/Resources.resx	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Blog/Properties/Resources.resx	Mon Jun 06 09:12:52 2011 -0300
@@ -145,7 +145,7 @@
 &lt;p&gt;{4}&lt;/p&gt;</value>
   </data>
   <data name="VAN_Realizacion_Body_UrlListaCorreo" xml:space="preserve">
-    <value>&lt;p&gt;En el siguiente enlace a la lista de correos, podrán encontrar el detalle de los temas a tratar:&lt;/p&gt;
+    <value>&lt;p&gt;En el siguiente enlace, podrán encontrar el detalle de los temas a tratar:&lt;/p&gt;
 &lt;p&gt;&lt;a href="{0}"&gt;{0}&lt;/a&gt;&lt;/p&gt;
 &lt;p&gt;&lt;/p&gt;</value>
   </data>
--- a/Agendas/trunk/src/Agendas.Domain/Agenda.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Agenda.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -115,11 +115,11 @@
 			return new Resultado(true);
 		}
 
-		public Resultado Publicar(Guid eventoId)
+		public Resultado Publicar(Guid eventoId, short numeroOrden, string urlWiki)
 		{
 			Evento evento = GetEvento(eventoId);
 
-			evento.Publicar();
+			evento.Publicar(numeroOrden, urlWiki);
 
 			Notify(evento);
 
--- a/Agendas/trunk/src/Agendas.Domain/Evento.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Domain/Evento.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -175,8 +175,10 @@
       this.GetEstado().Promover(this, Accion.Confirmar);
 		}
 
-		public virtual void Publicar()
-		{
+    public virtual void Publicar(short numeroOrden, string urlWiki)
+    {
+      this.NumeroOrden = numeroOrden;
+      this.UrlWiki = urlWiki;
       this.GetEstado().Promover(this, Accion.Publicar);
 		}
 
--- a/Agendas/trunk/src/Agendas.Tests/AgendarTests.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/AgendarTests.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -258,13 +258,31 @@
       var evento = DefaultEventoRepository.GetEventosConFecha().Single(e => e.Titulo == "Html 5");
 
       agenda.Confirmar(evento.Id);
-      agenda.Publicar(evento.Id);
+      agenda.Publicar(evento.Id, 0, string.Empty);
 
       Assert.IsInstanceOf(typeof(EventoPublicadoState), evento.GetEstado());
       Assert.That(evento.GetTrackNews().Count(t => t.Accion == Accion.Publicar) == 1);
     }
 
     [Test]
+    public void Al_publicar_un_evento_debe_asignarse_el_nro_de_reunion_y_la_url_de_la_wiki()
+    {
+      var publicador1 = new Mock<IPublicador>();
+
+      var agenda = new Agenda(publicador1.Object, DefaultEventoRepository, DefaultPersonaRepository);
+      agenda.Agendar("Html 5", "jjmontes", DateTime.MinValue, urlInvitacion);
+
+      var evento = DefaultEventoRepository.GetEventosConFecha().Single(e => e.Titulo == "Html 5");
+      agenda.Confirmar(evento.Id);
+
+      const string urlWiki = "http://www.altnethispano.org/wiki/van-2010-10-21-mono-cecil.ashx";
+      agenda.Publicar(evento.Id, 71, urlWiki);
+
+      Assert.AreEqual(71, evento.NumeroOrden);
+      Assert.AreEqual(urlWiki, evento.UrlWiki);
+    }
+
+    [Test]
     [ExpectedException(typeof(AccionNoSoportadaException))]
     public void Al_confirmar_sin_agendar_debe_lanzarse_excepcion()
     {
@@ -293,7 +311,7 @@
 
       Assert.IsFalse(evento.Estado.GetType() == typeof(EventoConfirmadoState));
 
-      agenda.Publicar(evento.Id);
+      agenda.Publicar(evento.Id, 0, string.Empty);
     }
 	}
 }
\ No newline at end of file
--- a/Agendas/trunk/src/Agendas.Tests/Blog/PostWriterWebServiceAdapterTests.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/Blog/PostWriterWebServiceAdapterTests.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -16,52 +16,11 @@
   [TestFixture]
   public class PostWriterWebServiceAdapterTests
   {
-    [SetUp]
-    public void ClearAppSettings()
-    {
-      ConfigurationManager.AppSettings["PublicadorBlog.PostWriterServiceUrl"] = "";
-      ConfigurationManager.AppSettings["PublicadorBlog.BlogName"] = "";
-      ConfigurationManager.AppSettings["PublicadorBlog.BlogWriterMasterKey"] = "";
-    }
-
     [Test]
     [ExpectedException(typeof(EndpointNotFoundException))]
     public void Si_la_url_es_invalida_debe_lanzar_excepcion()
     {
-      ConfigurationManager.AppSettings["PublicadorBlog.PostWriterServiceUrl"] = "http://dummy/dummy.aspx";
-      ConfigurationManager.AppSettings["PublicadorBlog.BlogName"] = "dummy";
-      ConfigurationManager.AppSettings["PublicadorBlog.BlogWriterMasterKey"] = "dummy";
-
-      var srv = new PostWriterWebServiceAdapter();
-      srv.WriteBlogPost(null, null, null, false);
-    }
-
-    [Test]
-    [ExpectedException(typeof(PostWriterServiceUrlNotFoundException))]
-    public void Si_la_url_no_esta_configurada_debe_lanzar_excepcion()
-    {
-      var srv = new PostWriterWebServiceAdapter();
-      srv.WriteBlogPost(null, null, null, false);
-    }
-
-    [Test]
-    [ExpectedException(typeof(BlogNameNotFoundException))]
-    public void Si_el_nombre_del_blog_no_esta_configurado_debe_lanzar_excepcion()
-    {
-      ConfigurationManager.AppSettings["PublicadorBlog.PostWriterServiceUrl"] = "http://dummy/dummy.aspx";
-      ConfigurationManager.AppSettings["PublicadorBlog.BlogWriterMasterKey"] = "dummy";
-
-      var srv = new PostWriterWebServiceAdapter();
-      srv.WriteBlogPost(null, null, null, false);
-    }
-
-    [Test]
-    [ExpectedException(typeof(BlogWriterMasterKeyNotFoundException))]
-    public void Si_la_master_key_no_esta_configurada_debe_lanzar_excepcion()
-    {
-      ConfigurationManager.AppSettings["PublicadorBlog.PostWriterServiceUrl"] = "http://dummy/dummy.aspx";
-
-      var srv = new PostWriterWebServiceAdapter();
+      var srv = new PostWriterWebServiceAdapter(new BlogPublicadorConfig("http://dummy/dummy.aspx", "dummy", "dummy"));
       srv.WriteBlogPost(null, null, null, false);
     }
   }
--- a/Agendas/trunk/src/Agendas.Tests/Blog/PublicadorTests.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/Blog/PublicadorTests.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -25,14 +25,17 @@
     [Test]
     public void El_publicador_debe_disparar_los_writers_segun_la_accion_de_cada_track()
     {
-      var eventoAgendar = Evento.Agendar(null, null, DateTime.MinValue, null);
-      var eventoPublicar = Evento.Agendar(null, null, DateTime.MinValue, null);
+      //var eventoAgendar = Evento.Agendar(null, null, DateTime.MinValue, null);
+      //var eventoPublicar = Evento.Agendar(null, null, DateTime.MinValue, null);
+
+      var trackAgendar = new Track(null, Accion.Agendar);
+      var trackPublicar = new Track(null, Accion.Publicar);
 
       var agendarPostWriter = new Mock<IPostWriter>();
-      agendarPostWriter.Setup(writer => writer.WritePost(eventoAgendar));
+      agendarPostWriter.Setup(writer => writer.WritePost(trackAgendar));
 
       var publicarPostWriter = new Mock<IPostWriter>();
-      publicarPostWriter.Setup(writer => writer.WritePost(eventoPublicar));
+      publicarPostWriter.Setup(writer => writer.WritePost(trackPublicar));
 
       var factory = new Mock<IPostWriterFactory>();
       factory.Setup(f => f.GetPostWriter(Accion.Agendar)).Returns(agendarPostWriter.Object);
@@ -41,15 +44,15 @@
       var publicador = new BlogPublicador(factory.Object);
       publicador.Publicar(new List<Track>
                             {
-                              new Track(eventoAgendar, Accion.Agendar),
-                              new Track(eventoPublicar, Accion.Publicar)
+                              trackAgendar,
+                              trackPublicar
                             });
 
       factory.Verify(f => f.GetPostWriter(Accion.Agendar), Times.Once());
       factory.Verify(f => f.GetPostWriter(Accion.Publicar), Times.Once());
 
-      agendarPostWriter.Verify(pw => pw.WritePost(eventoAgendar), Times.Once());
-      publicarPostWriter.Verify(pw => pw.WritePost(eventoPublicar), Times.Once());
+      agendarPostWriter.Verify(pw => pw.WritePost(trackAgendar), Times.Once());
+      publicarPostWriter.Verify(pw => pw.WritePost(trackPublicar), Times.Once());
     }
   }
 }
--- a/Agendas/trunk/src/Agendas.Tests/Workflows/Workflow.cs	Sun Jun 05 13:22:36 2011 -0300
+++ b/Agendas/trunk/src/Agendas.Tests/Workflows/Workflow.cs	Mon Jun 06 09:12:52 2011 -0300
@@ -36,7 +36,7 @@
 
 		public void Publicar(Guid eventoId)
 		{
-			var resultado = _agenda.Publicar(eventoId);
+			var resultado = _agenda.Publicar(eventoId, 0, string.Empty);
 			Assert.IsTrue(resultado.Succeful);
 		}
 	}