Exemple #1
0
        public void TestConvert_FromModelToEntity_AuthorIsCorrect()
        {
            // Prepare
            var model    = GenerateArticleModel();
            var expected = "Test Author";

            // Act
            var actual = ArticleConverter.Convert(model).Author;

            // Assert
            Assert.AreEqual(expected, actual);
        } // TEST METHOD ENDS
Exemple #2
0
        public void TestConvert_FromModelToEntity_IdIsCorrect()
        {
            // Prepare
            var model    = GenerateArticleModel();
            var expected = Guid.Parse("b4a87b22-097a-46fa-845f-e88a250b834e");

            // Act
            var actual = ArticleConverter.Convert(model).Id;

            // Assert
            Assert.AreEqual(expected, actual);
        } // TEST METHOD ENDS
Exemple #3
0
        public void TestConvert_FromModelToEntity_CreatedIsCorrect()
        {
            // Prepare
            var model    = GenerateArticleModel();
            var expected = new DateTime(2018, 1, 1);

            // Act
            var actual = ArticleConverter.Convert(model).Created;

            // Assert
            Assert.AreEqual(expected, actual);
        } // TEST METHOD ENDS
Exemple #4
0
        public void TestConvert_FromEntityToModel_AuthorIsCorrect()
        {
            // Prepare
            var entity   = GenerateArticleEntity();
            var expected = "Test Author";

            // Act
            var actual = ArticleConverter.Convert(entity).Author;

            // Assert
            Assert.AreEqual(expected, actual);
        } // TEST METHOD ENDS
Exemple #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 Business.Models.Article IModelService <Business.Models.Article, Guid> .Create(Business.Models.Article model)
 {
     try
     {
         // [email protected]
         // Le generamos un id único al nuevo articulo
         model.Id = Guid.NewGuid();
         // Insertamos datos en la base de datos
         this.database.Article.InsertOnSubmit(ArticleConverter.Convert(model));
         // Guardamos los cambios
         this.database.SubmitChanges();
         return(model);
     } // TRY ENDS
     catch (Exception e)
     {
         Console.Out.WriteLine(e.Message);
         Console.Out.WriteLine(e.StackTrace);
     } // CATCH ENDS
     return(null);
 }     // CREATE ENDS ------------------------------------------------------ //
Exemple #6
0
        }     // DELETE ENDS ------------------------------------------------------ //

        /// <summary>
        ///
        /// </summary>
        /// <param name="modelId"></param>
        /// <returns></returns>
        Business.Models.Article IModelService <Business.Models.Article, Guid> .Get(Guid modelId)
        {
            try
            {
                // Usamos una consulta LINQ para buscar el artículo en la base de datos
                var query = from article in this.database.Article
                            where article.Id == modelId
                            select article;

                // Si hay resultados, entonces buscamos el primero y lo devolvemos
                foreach (var result in query)
                {
                    return(ArticleConverter.Convert(result));
                } // FOREACH ENDS
            }     // TRY ENDS
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            } // CATCH ENDS
            return(null);
        }     // GET ENDS --------------------------------------------------------- //
Exemple #7
0
        public IEnumerable <Business.Models.Article> GetArticlesByAuthor(string userName)
        {
            // La lista de articulos
            List <Business.Models.Article> results = new List <Business.Models.Article>();

            try
            {
                var query = from article in this.database.Article
                            where article.Author == userName
                            select article;

                foreach (var result in query)
                {
                    results.Add(ArticleConverter.Convert(result));
                } // FOREACH ENDS
            }     // TRY ENDS
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            } // CATCH ENDS
            return(results);
        }
Exemple #8
0
        public IEnumerable <Business.Models.Article> GetArticlesByTag(string tag)
        {
            List <Business.Models.Article> results = new List <Business.Models.Article>();

            try
            {
                var query = from articleTag in this.database.Article_Tag
                            where articleTag.Tag == tag
                            select articleTag;

                foreach (var result in query)
                {
                    results.Add(ArticleConverter.Convert(result.Article));
                }
            } // TRY ENDS
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message);
                Console.Out.WriteLine(e.StackTrace);
            } // CATCH ENDS
            return(results);
        }
Exemple #9
0
        }     // GET ENDS --------------------------------------------------------- //

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        IEnumerable <Business.Models.Article> IModelService <Business.Models.Article, Guid> .Get()
        {
            // La lista de articulos
            List <Business.Models.Article> results = new List <Business.Models.Article>();

            try
            {
                // Usamos una consulta LINQ para buscar el artículo en la base de datos
                var query = from article in this.database.Article
                            select article;

                // Si hay resultados, entonces buscamos el primero y lo devolvemos
                foreach (var result in query)
                {
                    results.Add(ArticleConverter.Convert(result));
                } // FOREACH ENDS
            }     // TRY ENDS
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            } // CATCH ENDS
            return(results);
        }     // GET ENDS --------------------------------------------------------- //