Ejemplo n.º 1
0
        public void TestConvert_FromEntityToModel_UserNameIsCorrect()
        {
            // Prepare
            var entity   = GenerateCommentEntity();
            var expected = "Test UserName";

            // Act
            var actual = CommentConverter.Convert(entity).UserName;

            // Assert
            Assert.AreEqual(expected, actual);
        } // TEST METHOD ENDS
Ejemplo n.º 2
0
        public void TestConvert_FromModelToEntity_UserNameIsCorrect()
        {
            // Prepare
            var model    = GenerateCommentModel();
            var expected = "Test UserName";

            // Act
            var actual = CommentConverter.Convert(model).UserName;

            // Assert
            Assert.AreEqual(expected, actual);
        } // TEST METHOD ENDS
Ejemplo n.º 3
0
        public void TestConvert_FromModelToEntity_IdIsCorrect()
        {
            // Prepare
            var model    = GenerateCommentModel();
            var expected = Guid.Parse("c23f5a47-5256-4a2d-9748-3b50eeb1a5d8");

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

            // Assert
            Assert.AreEqual(expected, actual);
        } // TEST METHOD ENDS
Ejemplo n.º 4
0
        public void TestConvert_FromModelToEntity_CreatedIsCorrect()
        {
            // Prepare
            var model    = GenerateCommentModel();
            var expected = new DateTime(2018, 1, 1);

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

            // Assert
            Assert.AreEqual(expected, actual);
        } // TEST METHOD ENDS
Ejemplo n.º 5
0
        public void TestConvert_FromModelToEntity_ArticleIdIsCorrect()
        {
            // Prepare
            var model    = GenerateCommentModel();
            var expected = Guid.Parse("e605822e-d4c0-4b4c-929e-09628573485f");

            // Act
            var actual = CommentConverter.Convert(model).ArticleId;

            // Assert
            Assert.AreEqual(expected, actual);
        } // TEST METHOD ENDS
Ejemplo n.º 6
0
        } // ------------------------------------------------------------------ //

        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Business.Models.Comment IModelService <Business.Models.Comment, Guid> .Create(Business.Models.Comment model)
        {
            try
            {
                // Le generamos un id único al nuevo comentario
                model.Id = Guid.NewGuid();
                // Insertamos datos en la base de datos
                this.database.Comment.InsertOnSubmit(CommentConverter.Convert(model));
                // Guardamos los cambios
                this.database.SubmitChanges();
                return(model);
            } // TRY ENDS
            catch (Exception e)
            {
                Console.Out.WriteLine(e.Message);
            } // CATCH ENDS
            return(null);
        }     // CREATE ENDS ------------------------------------------------------ //
Ejemplo n.º 7
0
        } // CONSTRUCTOR ENDS ------------------------------------------------- //

        /// <summary>
        ///
        /// </summary>
        /// <param name="articleId"></param>
        /// <returns></returns>
        public List <Business.Models.Comment> GetCommentsForArticle(Guid articleId)
        {
            List <Business.Models.Comment> comments = new List <Business.Models.Comment>();

            try
            {
                var query = from x in this.database.Comment
                            where x.ArticleId == articleId
                            select x;
                foreach (var comment in query)
                {
                    comments.Add(CommentConverter.Convert(comment));
                } // FOR ENDS
            }     // TRY ENDS
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            } // CATCH ENDS
            return(comments);
        }     // METHOD GET COMMENTS FOR ARTICLE ENDS ----------------------------- //
Ejemplo n.º 8
0
        }     // DELETE ENDS ------------------------------------------------------ //

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

                // Si hay resultados, entonces buscamos el primero y lo devolvemos
                foreach (var result in query)
                {
                    return(CommentConverter.Convert(result));
                } // FOREACH ENDS
            }     // TRY ENDS
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            } // CATCH ENDS
            return(null);
        }     // GET ENDS --------------------------------------------------------- //
Ejemplo n.º 9
0
        }     // GET ENDS --------------------------------------------------------- //

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

            try
            {
                // Usamos una consulta LINQ para buscar el comentario en la base de datos
                var query = from comment in this.database.Comment
                            select comment;

                // Si hay resultados, entonces buscamos el primero y lo devolvemos
                foreach (var result in query)
                {
                    results.Add(CommentConverter.Convert(result));
                } // FOREACH ENDS
            }     // TRY ENDS
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            } // CATCH ENDS
            return(results);
        }     // GET ENDS --------------------------------------------------------- //
Ejemplo n.º 10
0
 public CommentBusinessImpl(ICommentRepository repository)
 {
     _repository = repository;
     _converter  = new CommentConverter();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// コメントを文字列に変換する
        /// </summary>
        private string ConvertToString(List <JsonComment> comments)
        {
            var converter = new CommentConverter();

            return(converter.GetXML(comments));
        }
 public void ConvertTest()
 {
     AbstractConverter<Comment, CommentDto> converter = new CommentConverter();
 }
        public async Task <List <CommentViewModel> > GetAllCommentsByPostIDAsync(int ID, CancellationToken ct = default(CancellationToken))
        {
            List <CommentViewModel> comments = CommentConverter.ConvertList(await _commentRepository.GetAllByPostIDAsync(ID, ct));

            return(comments);
        }
        public async Task <CommentViewModel> GetCommentByIDAsync(int ID, CancellationToken ct = default(CancellationToken))
        {
            CommentViewModel comment = CommentConverter.Convert(await _commentRepository.GetByIDAsync(ID));

            return(comment);
        }
Ejemplo n.º 15
0
 public CommentsController(BloggingPlatformDB _db, CommentConverter _commentConverter)
 {
     db = _db;
     commentConverter = _commentConverter;
 }