Exemple #1
0
        public void ShouldEditComment()
        {
            Result  result  = Context.Results.FirstOrDefault();
            Student student = Context.Students.FirstOrDefault();
            User    user    = Context.Users.FirstOrDefault();

            int commentId = Repository.Add(new Comment
            {
                AssessmentId     = result.AssessmentId,
                StudentId        = result.StudentId,
                UserId           = user.Id,
                Message          = "ShouldEditComment",
                DateTimeCreation = DateTime.Today
            });
            Comment comment = Repository.GetById(commentId);

            comment.Message = "NewMessage";
            bool resultB = Repository.Edit(comment);

            comment = Repository.GetById(commentId);
            Assert.Multiple(() =>
            {
                Assert.IsTrue(resultB);
                Assert.That(comment.Message, Is.EqualTo("NewMessage"));
            });
        }
        public async Task UpdateComment(CommentUpdateDto commentUpdate)
        {
            var comment = await _repository.GetById(commentUpdate.Id);

            comment.Content      = commentUpdate.NewContent;
            comment.LastEditDate = commentUpdate.LastEditDate;
            await _repository.Update(comment);
        }
        public void UpdateTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());
            var userRepository    = new UserRepository(new InMemoryDbContextFactory());
            var author            = new UserDetailModel();
            var dbAuthor          = userRepository.Insert(author);

            var commentOld = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = dbAuthor,
                Content   = "Mamka mi zjedla rezen.",
            };

            var commentNew = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Content   = "Ocko mi zjedol rezen nakoniec.",
                Author    = dbAuthor
            };

            var commentDetail = commentRepository.Insert(commentNew);

            commentRepository.Update(commentNew);

            var commentDatabase = commentRepository.GetById(commentDetail.Id);

            Assert.NotNull(commentDatabase);
            Assert.Equal(commentNew.Timestamp, commentDatabase.Timestamp);
            Assert.Equal(commentNew.Content, commentDatabase.Content);

            commentRepository.Remove(commentDatabase.Id);
        }
        public IHttpActionResult GetCommentWithId(int cid, int id)
        {
            CommentRepository cr = new CommentRepository();
            Comment           c  = cr.GetById(cid);

            if (c == null || c.PostId != id)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }
            c.HyperLinks.Add(new HyperLink()
            {
                HRef = "https://localhost::44313/api/posts/" + c.PostId + "/comments/" + c.CommentId, HttpMethod = "GET", Relation = "Self"
            });
            c.HyperLinks.Add(new HyperLink()
            {
                HRef = "https://localhost::44313/api/posts/" + c.PostId + "/comments", HttpMethod = "Post", Relation = "Create a new Post"
            });
            c.HyperLinks.Add(new HyperLink()
            {
                HRef = "https://localhost::44313/api/posts/" + c.PostId + "/comments/" + c.CommentId, HttpMethod = "PUT", Relation = "Edit self"
            });
            c.HyperLinks.Add(new HyperLink()
            {
                HRef = "https://localhost::44313/api/posts/" + c.PostId + "/comments/" + c.CommentId, HttpMethod = "DELETE", Relation = "DELETE self"
            });
            return(Ok(c));
        }
Exemple #5
0
        public ActionResult EditComment(int?ParentTaskId, int?id)
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            CommentRepository RepoComment = RepositoryFactory.GetCommentRepository();

            Comment comment = null;

            if (id == null)
            {
                comment = new Comment();
                comment.ParentTaskId = ParentTaskId.Value;
                comment.ParentUserId = AuthenticationManager.LoggedUser.Id;
            }
            else
            {
                comment = RepoComment.GetById(id.Value);
            }

            ViewData["comment"] = comment;

            return(View());
        }
        public void GetByIdTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());
            var userRepository    = new UserRepository(new InMemoryDbContextFactory());

            var author = new UserDetailModel();

            var dbAuthor = userRepository.Insert(author);

            var comment = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = dbAuthor,
                Content   = "Dneska som mala na obed kuraci steak",
            };

            var commentDetail = commentRepository.Insert(comment);

            var commentDatabase = commentRepository.GetById(commentDetail.Id);

            Assert.NotNull(commentDatabase);
            Assert.Equal(comment.Timestamp, commentDatabase.Timestamp);
            Assert.NotNull(commentDatabase.Author);
            Assert.Equal(comment.Content, commentDatabase.Content);
            commentRepository.Remove(commentDatabase.Id);
        }
Exemple #7
0
        public void InsertComment()
        {
            InMemoryDbContextFactory Db = new InMemoryDbContextFactory();
            var dbContext = Db.CreateDbContext();

            ContributionRepository contributionRepository = new ContributionRepository(dbContext);
            CommentRepository      commentRepository      = new CommentRepository(dbContext);

            ContributionModel contributionModel = new ContributionModel
            {
                Id      = Guid.NewGuid(),
                Message = "Doufáme, že z projektu dostaneme dostatečný počet bodů",
                Title   = "We belive"
            };

            dbContext.DetachAllEntities();

            CommentModel commentModel = new CommentModel()
            {
                Id           = Guid.NewGuid(),
                Message      = "Prvni",
                Contribution = contributionModel
            };

            contributionRepository.Insert(contributionModel);
            var contributionRepositoryResponse = contributionRepository.GetById(contributionModel.Id);

            Assert.NotNull(contributionRepositoryResponse);

            commentRepository.Insert(commentModel);
            var commentRepositoryResponse = commentRepository.GetById(commentModel.Id);

            Assert.NotNull(commentRepositoryResponse);
        }
Exemple #8
0
        public ActionResult DeleteReply(int id)
        {
            Comment           comment           = new Comment();
            CommentRepository commentRepository = new CommentRepository();

            comment = commentRepository.GetById(id);
            commentRepository.Delete(comment);
            return(RedirectToAction("Articles"));
        }
        public void ShouldEditComment()
        {
            int commentId = Repository.Add(new Comment
            {
                Message          = "ShouldEditComment",
                DateTimeCreation = DateTime.Today
            });
            Comment comment = Repository.GetById(commentId);

            comment.Message = "NewMessage";
            bool result = Repository.Edit(comment);

            comment = Repository.GetById(commentId);
            Assert.Multiple(() =>
            {
                Assert.IsTrue(result);
                Assert.That(comment.Message, Is.EqualTo("NewMessage"));
            });
        }
        public IActionResult Get(int id)
        {
            var comment = _commentRepo.GetById(id);

            if (comment == null)
            {
                return(NotFound());
            }
            return(Ok(comment));
        }
Exemple #11
0
        public void TestEntityGetById()
        {
            var mockTeste = new Mock <IGetDB <Comment> >();

            var commentRepository = new CommentRepository(mockTeste.Object);

            commentRepository.GetById(Guid.NewGuid());

            mockTeste.Verify(x => x.GetRegisterById(It.IsAny <Guid>()));
        }
Exemple #12
0
 public ActionResult <CommentModel> GetCommentById(int id)
 {
     try
     {
         return(_repository.GetById(id));
     }
     catch (Exception e)
     {
         return(null);
     }
 }
Exemple #13
0
        public JsonResult Reply(int commentId, int replyId, string content)
        {
            CommentRepository commentRepository = new CommentRepository();
            Comment           comment           = new Comment();
            Comment           replyComment      = new Comment();

            if (replyId == 0)
            {
                comment = commentRepository.GetById(commentId);
                replyComment.Article       = comment.Article;
                replyComment.ArticleID     = comment.ArticleID;
                replyComment.DateCreated   = DateTime.Now;
                replyComment.UserID        = AuthenticationManager.LoggedUser.Id;
                replyComment.Content       = content;
                replyComment.ParentComment = comment;
                string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
                int    start     = type.LastIndexOf(".") + 1;
                int    positions = type.Length - start;
                type = type.Substring(start, positions);
                replyComment.UserType = type;
                commentRepository.Save(replyComment);
            }
            if (commentId == 0)
            {
                comment             = commentRepository.GetById(replyId);
                comment.Content     = content;
                comment.DateCreated = DateTime.Now;
                string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
                int    start     = type.LastIndexOf(".") + 1;
                int    positions = type.Length - start;
                type             = type.Substring(start, positions);
                comment.UserType = type;
                commentRepository.Save(comment);
            }
            SelectListItem item = new SelectListItem()
            {
                Text = commentId.ToString(), Value = comment.Article.Id.ToString()
            };

            return(Json(item, JsonRequestBehavior.AllowGet));
        }
        public IHttpActionResult DeleteCommentWithId(int cid, int id)
        {
            CommentRepository cr = new CommentRepository();
            Comment           c  = cr.GetById(cid);

            if (c.PostId == id)
            {
                cr.Delete(cid);
                return(StatusCode(HttpStatusCode.NoContent));
            }
            return(StatusCode(HttpStatusCode.NotFound));
        }
Exemple #15
0
        public IHttpActionResult Get(int id, int id2)
        {
            List <Comment> cmt     = postRepository.GetCommentsByPost(id);
            Comment        comment = commentRepository.GetById(id2);

            bool check = false;

            foreach (var item in cmt)
            {
                if (item.CommentId == comment.CommentId)
                {
                    check = true;
                }
            }

            if (comment == null || check == false)
            {
                return(StatusCode(HttpStatusCode.NoContent));
            }

            return(Ok(comment));
        }
        public bool RemoveComment(int commentId)
        {
            var comment = commentRepository.GetById(commentId);

            if (comment != null)
            {
                commentRepository.Remove(comment);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #17
0
        public ActionResult Delete(int id)
        {
            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("Login", "Home"));
            }

            CommentRepository RepoComment = RepositoryFactory.GetCommentRepository();
            Comment           comment     = RepoComment.GetById(id);

            RepoComment.Delete(comment);

            return(RedirectToAction("Index", "CommentManagement", new { ParentTaskId = comment.ParentTaskId }));
        }
        public void CommentRepozitoryTest()
        {
            var Repository = new CommentRepository(new InMemoryDbContextFactory());

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(0));

            var Comment1 = new CommentModel()
            {
                Author     = 1,
                AuthorName = "Milos Hlava",
                Date       = new DateTime(2019, 1, 4),
                Id         = 1,
                Text       = "Testovaci koment"
            };

            var Comment2 = new CommentModel()
            {
                Author     = 2,
                AuthorName = "Jozef Hlava",
                Date       = new DateTime(2019, 1, 5),
                Id         = 2,
                Text       = "Testovaci koment cislo 2"
            };

            Repository.Create(Comment1);
            Repository.Create(Comment2);
            var ReceivedComment1 = Repository.GetById(1);
            var ReceivedComment2 = Repository.GetById(2);

            Assert.Equal(Comment1, ReceivedComment1);
            Assert.Equal(Comment2, ReceivedComment2);

            Comment1.Text = "Updatovany text";
            Repository.Update(Comment1);
            ReceivedComment1 = Repository.GetById(1);

            Assert.Equal(Comment1, ReceivedComment1);

            List <CommentModel> ReceivedAllComments = Repository.GetAll();

            var AllComments = new List <CommentModel>();

            AllComments.Add(Comment1);
            AllComments.Add(Comment2);

            var Comparer = new CollectionComparer <CommentModel>();

            Assert.True(Comparer.Equals(AllComments, ReceivedAllComments));

            Repository.Delete(1);

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(1));

            Repository.Delete(2);

            Assert.Throws <System.InvalidOperationException>(() => Repository.GetById(2));
        }
Exemple #19
0
        public void GetByIdCommentModelTest()
        {
            //Arrange
            var postDetailModel = new PostDetailModel()
            {
                Title    = "NewTitle",
                Comments = new List <CommentDetailModel>(5)
            };
            var date = new DateTime();

            var commentModel = new CommentDetailModel()
            {
                CreationTime = date,
                BelongsTo    = new PostListModel(),
            };
            var userDetailModel = new UserDetailModel()
            {
                Name     = "NewUser",
                Email    = "*****@*****.**",
                Password = "******"
            };

            //Act
            var returnedUserModel          = _userRepository.Create(userDetailModel);
            var returnedPostDetailModel    = _postRepository.Create(postDetailModel, returnedUserModel);
            var returnedCommentDetailModel = _commentRepository.Create(commentModel, returnedUserModel, returnedPostDetailModel);
            var returnedGetById            = _commentRepository.GetById(returnedCommentDetailModel.Id);

            //Assert
            Assert.NotNull(returnedGetById);

            //Teardown
            _commentRepository.Delete(returnedGetById);
            _postRepository.Delete(returnedPostDetailModel);
            _userRepository.Delete(returnedUserModel);
        }
        public void InsertTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());

            var comment = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = new UserDetailModel(),
                Content   = "Pockaj, kym mi doperie pracka",
            };

            var commentDetail = commentRepository.Insert(comment);
            var commentId     = commentRepository.GetById(commentDetail.Id);

            Assert.NotNull(commentId);
            commentRepository.Remove(commentId.Id);
        }
        public void RemoveTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());

            var comment = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = new UserDetailModel(),
                Content   = "Pracka mi konecne doprala.",
            };

            var commentDetail = commentRepository.Insert(comment);

            commentRepository.Remove(commentDetail.Id);

            var commentDatabase = commentRepository.GetById(commentDetail.Id);

            Assert.Null(commentDatabase);
        }
Exemple #22
0
        public JsonResult Comment(int articleId, int commentId, string content)
        {
            ArticleRepository articleRepository = new ArticleRepository();
            CommentRepository commentRepository = new CommentRepository();
            Article           article           = new Article();
            Comment           comment           = new Comment();

            article = articleRepository.GetById(articleId);
            if (commentId == 0)
            {
                comment.ArticleID   = articleId;
                comment.Content     = content;
                comment.DateCreated = DateTime.Now;
                comment.UserID      = AuthenticationManager.LoggedUser.Id;
                string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
                int    start     = type.LastIndexOf(".") + 1;
                int    positions = type.Length - start;
                type             = type.Substring(start, positions);
                comment.UserType = type;
            }
            else
            {
                comment             = commentRepository.GetById(commentId);
                comment.Content     = content;
                comment.DateCreated = DateTime.Now;
                string type      = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
                int    start     = type.LastIndexOf(".") + 1;
                int    positions = type.Length - start;
                type             = type.Substring(start, positions);
                comment.UserType = type;
            }
            commentRepository.Save(comment);
            string         comentator     = AuthenticationManager.LoggedUser.FirstName + " " + AuthenticationManager.LoggedUser.LastName;
            SelectListItem commentContent = new SelectListItem()
            {
                Text = comment.Content, Value = comentator
            };

            return(Json(commentContent, JsonRequestBehavior.AllowGet));
        }
Exemple #23
0
        public void GetGetAllCommentsOfContributionById()
        {
            InMemoryDbContextFactory Db = new InMemoryDbContextFactory();
            var dbContext = Db.CreateDbContext();

            ContributionRepository contributionRepository = new ContributionRepository(dbContext);
            CommentRepository      commentRepository      = new CommentRepository(dbContext);

            ContributionModel contributionModel1 = new ContributionModel()
            {
                Id = Guid.NewGuid(),
            };

            ContributionModel contributionModel2 = new ContributionModel()
            {
                Id = Guid.NewGuid(),
            };

            ContributionModel contributionModel3 = new ContributionModel()
            {
                Id = Guid.NewGuid(),
            };

            contributionRepository.Insert(contributionModel1);
            contributionRepository.Insert(contributionModel2);
            contributionRepository.Insert(contributionModel3);

            var contributionRepositoryResponse1 = contributionRepository.GetById(contributionModel1.Id);
            var contributionRepositoryResponse2 = contributionRepository.GetById(contributionModel2.Id);
            var contributionRepositoryResponse3 = contributionRepository.GetById(contributionModel3.Id);

            Assert.NotNull(contributionRepositoryResponse1);
            Assert.NotNull(contributionRepositoryResponse2);
            Assert.NotNull(contributionRepositoryResponse3);

            dbContext.DetachAllEntities();

            CommentModel commentModel1 = new CommentModel
            {
                Id           = Guid.NewGuid(),
                Message      = "Ahoj",
                Contribution = contributionModel1
            };

            CommentModel commentModel2 = new CommentModel
            {
                Id           = Guid.NewGuid(),
                Message      = "světe",
                Contribution = contributionModel1
            };

            CommentModel commentModel3 = new CommentModel
            {
                Id           = Guid.NewGuid(),
                Message      = "Lorem",
                Contribution = contributionModel2
            };

            commentRepository.Insert(commentModel1);
            commentRepository.Insert(commentModel2);
            commentRepository.Insert(commentModel3);

            var commentRepositoryResponse1 = commentRepository.GetById(commentModel1.Id);
            var commentRepositoryResponse2 = commentRepository.GetById(commentModel2.Id);
            var commentRepositoryResponse3 = commentRepository.GetById(commentModel3.Id);

            Assert.NotNull(commentRepositoryResponse1);
            Assert.NotNull(commentRepositoryResponse2);
            Assert.NotNull(commentRepositoryResponse3);

            var contr1Id = contributionModel1.Id;
            var contr2Id = contributionModel2.Id;

            List <CommentModel> commentList1 = new List <CommentModel>();

            commentList1.Add(commentModel1);
            commentList1.Add(commentModel2);

            contributionModel1.Comments = commentList1;

            List <CommentModel> commentList2 = new List <CommentModel>();

            commentList2.Add(commentModel3);

            contributionModel2.Comments = commentList2;

            var commentRepositoryResponseCon1 = commentRepository.GetAllCommentsOfContributionById(contr1Id);

            Assert.NotNull(commentRepositoryResponseCon1);
            Assert.Equal(commentRepositoryResponseCon1.ElementAt(0).Id, commentModel1.Id);
            Assert.Equal(commentRepositoryResponseCon1.ElementAt(1).Id, commentModel2.Id);

            var commentRepositoryResponseCon2 = commentRepository.GetAllCommentsOfContributionById(contr2Id);

            Assert.NotNull(commentRepositoryResponseCon2);
            Assert.Equal(commentRepositoryResponseCon2.ElementAt(0).Id, commentModel3.Id);
        }
 public JsonResult Reply(int commentId, int replyId, string content)
 {
     CommentRepository commentRepository = new CommentRepository();
     Comment comment = new Comment();
     Comment replyComment = new Comment();
     if (replyId == 0)
     {
         comment = commentRepository.GetById(commentId);
         replyComment.Article = comment.Article;
         replyComment.ArticleID = comment.ArticleID;
         replyComment.DateCreated = DateTime.Now;
         replyComment.UserID = AuthenticationManager.LoggedUser.Id;
         replyComment.Content = content;
         replyComment.ParentComment = comment;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         replyComment.UserType = type;
         commentRepository.Save(replyComment);
     }
     if (commentId == 0)
     {
         comment = commentRepository.GetById(replyId);
         comment.Content = content;
         comment.DateCreated = DateTime.Now;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         comment.UserType = type;
         commentRepository.Save(comment);
     }
     SelectListItem item = new SelectListItem() { Text = commentId.ToString(), Value = comment.Article.Id.ToString() };
     return Json(item, JsonRequestBehavior.AllowGet);
 }
        public void GetByIdReturnsNull()
        {
            dbFactory.Run(db => db.Insert(new Comment { Id = 1, Message = "Test Item" }));

            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            var response = repository.GetById(2);

            Assert.IsNull(response);
        }
 public Comment GetById(string CommentId)
 {
     return(_commentRepository.GetById(CommentId));
 }
 public Comment GetById(int id)
 {
     return(_repo.GetById(id));
 }
Exemple #28
0
 public IActionResult GetCommentsById(int id)
 {
     return(Ok(_commentRepository.GetById(id)));
 }
 public ActionResult DeleteReply(int id)
 {
     Comment comment = new Comment();
     CommentRepository commentRepository = new CommentRepository();
     comment = commentRepository.GetById(id);
     commentRepository.Delete(comment);
     return RedirectToAction("Articles");
 }
Exemple #30
0
 public IActionResult CommentDetails(int id)
 {
     return(View(_commentRepository.GetById(id)));
 }
Exemple #31
0
 public CommentDetailModel GetComment(Guid id)
 {
     return(repository.GetById(id));
 }
Exemple #32
0
        public void RemoveCommentById_AddNewCommentThenRemoveIt_ReturnsTrue()
        {
            // Arrange
            var options = new DbContextOptionsBuilder <FacilityContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new FacilityContext(options);
            ICommentRepository       commentRepository       = new CommentRepository(context);
            IIncidentRepository      incidentRepository      = new IncidentRepository(context);
            IRoomRepository          roomRepository          = new RoomRepository(context);
            IFloorRepository         floorRepository         = new FloorRepository(context);
            IComponentTypeRepository componentTypeRepository = new ComponentTypeRepository(context);
            IIssueRepository         issueRepository         = new IssueRepository(context);

            var floor = new FloorTO {
                Number = 2
            };
            var addedFloor = floorRepository.Add(floor);

            context.SaveChanges();

            RoomTO room = new RoomTO {
                Name = new MultiLanguageString("Room1", "Room1", "Room1"), Floor = addedFloor
            };
            var addedRoom = roomRepository.Add(room);

            context.SaveChanges();

            var componentType = new ComponentTypeTO {
                Archived = false, Name = new MultiLanguageString("Name1EN", "Name1FR", "Name1NL")
            };
            var addedComponentType = componentTypeRepository.Add(componentType);

            context.SaveChanges();

            var issue = new IssueTO {
                Description = "Broken thing", Name = new MultiLanguageString("Issue1EN", "Issue1FR", "Issue1NL"), ComponentType = addedComponentType
            };
            var addedIssue = issueRepository.Add(issue);

            context.SaveChanges();

            var incident = new IncidentTO
            {
                Description = "This thing is broken !",
                Room        = addedRoom,
                Issue       = addedIssue,
                Status      = IncidentStatus.Waiting,
                SubmitDate  = DateTime.Now,
                UserId      = 1,
            };
            var addedIncident = incidentRepository.Add(incident);

            context.SaveChanges();

            var comment = new CommentTO
            {
                Incident   = addedIncident,
                Message    = "I got in touch with the right people, it'll get fixed soon!",
                SubmitDate = DateTime.Now,
                UserId     = 1
            };
            var addedComment = commentRepository.Add(comment);

            context.SaveChanges();

            // Act
            var result = commentRepository.Remove(addedComment.Id);

            context.SaveChanges();

            // Assert
            Assert.IsTrue(result);
            Assert.ThrowsException <KeyNotFoundException>(() => commentRepository.GetById(addedComment.Id));
        }
Exemple #33
0
        public void AddFormReturnsCorrectNumberOfForm()
        {
            var options = new DbContextOptionsBuilder <EvaluationContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var memoryContext = new EvaluationContext(options))
            {
                //Arrange
                ICommentRepository             commentRepository             = new CommentRepository(memoryContext);
                IFormRepository                formRepository                = new FormRepository(memoryContext);
                IResponseRepository            responseRepository            = new ResponseRepository(memoryContext);
                IQuestionRepository            questionRepository            = new QuestionRepository(memoryContext);
                ISubmissionRepository          submissionRepository          = new SubmissionRepository(memoryContext);
                IQuestionPropositionRepository questionPropositionRepository = new QuestionPropositionRepository(memoryContext);

                #region Form

                var Form1 = new FormTO
                {
                    Name = new MultiLanguageString
                           (
                        "Daily evaluation form",
                        "Formulaire d'évaluation journalier",
                        "Dagelijks evaluatieformulier"
                           ),
                };
                var formAdded1 = formRepository.Add(Form1);
                memoryContext.SaveChanges();

                #endregion

                #region Questions

                var Question1 = new QuestionTO
                {
                    Form     = formAdded1,
                    Position = 1,
                    Libelle  = new MultiLanguageString
                               (
                        "What is your general impression after this first day of training ?",
                        "Quelle est votre impression générale après cette première journée de formation ?",
                        "Wat is je algemene indruk na deze eerste dag van training ?"
                               ),
                    Type = QuestionType.SingleChoice,
                };

                var Question2 = new QuestionTO
                {
                    Form     = formAdded1,
                    Position = 2,
                    Libelle  = new MultiLanguageString
                               (
                        "Is the pace right for you ?",
                        "Est-ce que le rythme vous convient ?",
                        "Is het tempo geschikt voor u ?"
                               ),
                    Type = QuestionType.SingleChoice,
                };

                var Question3 = new QuestionTO
                {
                    Form     = formAdded1,
                    Position = 3,
                    Libelle  = new MultiLanguageString
                               (
                        "Do you have questions related to the subject studied today ?",
                        "Avez-vous des questions relatives à la matière étudiée aujourd’hui ?",
                        "Heb je vragen over het onderwerp dat vandaag is bestudeerd ?"
                               ),
                    Type = QuestionType.Open
                };

                var Question4 = new QuestionTO
                {
                    Form     = formAdded1,
                    Position = 4,
                    Libelle  = new MultiLanguageString
                               (
                        "Do you have specific questions / particular topics that you would like deepen during this training ?",
                        "Avez-vous des questions spécifiques/sujets particuliers que vous aimeriez approfondir durant cette formation ?",
                        "Heeft u specifieke vragen / specifieke onderwerpen die u graag zou willen verdiepen tijdens deze training ?"
                               ),
                    Type = QuestionType.Open
                };

                var Question5 = new QuestionTO
                {
                    Form     = formAdded1,
                    Position = 5,
                    Libelle  = new MultiLanguageString
                               (
                        "What objectives do you pursue by following this training ?",
                        "Quels objectifs poursuivez-vous en suivant cette formation ?",
                        "Welke doelstellingen streeft u na door deze training te volgen?"
                               ),
                    Type = QuestionType.Open
                };

                var questionAdded1 = questionRepository.Add(Question1);
                var questionAdded2 = questionRepository.Add(Question2);
                var questionAdded3 = questionRepository.Add(Question3);
                var questionAdded4 = questionRepository.Add(Question4);
                var questionAdded5 = questionRepository.Add(Question5);
                memoryContext.SaveChanges();

                #endregion

                #region QuestionProposition
                var QuestionProposition1 = new QuestionPropositionTO
                {
                    Question = questionAdded1,
                    Libelle  = new MultiLanguageString("good", "bonne", "goed"),
                    Position = 1
                };

                var QuestionProposition2 = new QuestionPropositionTO
                {
                    Question = questionAdded1,
                    Libelle  = new MultiLanguageString("medium", "moyenne", "gemiddelde"),
                    Position = 2
                };

                var QuestionProposition3 = new QuestionPropositionTO
                {
                    Question = questionAdded1,
                    Libelle  = new MultiLanguageString("bad", "mauvaise", "slecht"),
                    Position = 3
                };

                var QuestionProposition4 = new QuestionPropositionTO
                {
                    Question = questionAdded2,
                    Libelle  = new MultiLanguageString("yes", "oui", "ja"),
                    Position = 1
                };

                var QuestionProposition5 = new QuestionPropositionTO
                {
                    Question = questionAdded2,
                    Libelle  = new MultiLanguageString("too fast", "trop rapide", "te snel"),
                    Position = 2
                };

                var QuestionProposition6 = new QuestionPropositionTO
                {
                    Question = questionAdded2,
                    Libelle  = new MultiLanguageString("too slow", "trop lent", "te langzaam"),
                    Position = 3
                };

                var questionPropositionAdded1 = questionPropositionRepository.Add(QuestionProposition1);
                var questionPropositionAdded2 = questionPropositionRepository.Add(QuestionProposition2);
                var questionPropositionAdded3 = questionPropositionRepository.Add(QuestionProposition3);
                var questionPropositionAdded4 = questionPropositionRepository.Add(QuestionProposition4);
                var questionPropositionAdded5 = questionPropositionRepository.Add(QuestionProposition5);
                var questionPropositionAdded6 = questionPropositionRepository.Add(QuestionProposition6);

                memoryContext.SaveChanges();

                #endregion

                #region Submission
                var submission1 = new SubmissionTO
                {
                    SessionId  = 30,
                    AttendeeId = 1012,
                    Date       = DateTime.Today,
                };
                var submission2 = new SubmissionTO
                {
                    SessionId  = 31,
                    AttendeeId = 2607,
                    Date       = DateTime.Today,
                };
                var submission3 = new SubmissionTO
                {
                    SessionId  = 2,
                    AttendeeId = 1612,
                    Date       = DateTime.Today,
                };

                var submissionAdded1 = submissionRepository.Add(submission1);
                var submissionAdded2 = submissionRepository.Add(submission2);
                var submissionAdded3 = submissionRepository.Add(submission3);
                memoryContext.SaveChanges();

                #endregion

                #region Responses
                var response1 = new ResponseTO
                {
                    Question            = questionAdded1,
                    Submission          = submissionAdded1,
                    QuestionProposition = questionPropositionAdded1,
                };

                var response2 = new ResponseTO
                {
                    Question            = questionAdded2,
                    Submission          = submissionAdded2,
                    QuestionProposition = questionPropositionAdded2,
                };

                var response3 = new ResponseTO
                {
                    Question   = questionAdded3,
                    Submission = submissionAdded3,
                    Text       = "Ceci est une réponse à une question ouverte",
                    //QuestionProposition = QuestionProposition3,
                };

                var response4 = new ResponseTO
                {
                    Question   = questionAdded4,
                    Submission = submissionAdded1,
                    Text       = "Ceci est une réponse à une question ouverte",
                };

                //Assert
                var responseAdded1 = responseRepository.Add(response1);
                var responseAdded2 = responseRepository.Add(response2);
                var responseAdded3 = responseRepository.Add(response3);
                var responseAdded4 = responseRepository.Add(response4);
                memoryContext.SaveChanges();

                #endregion

                #region Comment
                var comment1 = new CommentTO
                {
                    Response = responseAdded1,
                    Content  = "ceci est un commentaire"
                };

                var comment2 = new CommentTO
                {
                    Response = responseAdded2,
                    Content  = "ceci est un commentaire"
                };

                var commentAdded1 = commentRepository.Add(comment1);
                var commentAdded2 = commentRepository.Add(comment2);
                memoryContext.SaveChanges();
                #endregion

                //Act
                var result = commentRepository.GetById(commentAdded1.Id);

                //Assert
                Assert.AreEqual("ceci est un commentaire", result.Content);
            }
        }
 public JsonResult Comment(int articleId, int commentId, string content)
 {
     ArticleRepository articleRepository = new ArticleRepository();
     CommentRepository commentRepository = new CommentRepository();
     Article article = new Article();
     Comment comment = new Comment();
     article = articleRepository.GetById(articleId);
     if (commentId == 0)
     {
         comment.ArticleID = articleId;
         comment.Content = content;
         comment.DateCreated = DateTime.Now;
         comment.UserID = AuthenticationManager.LoggedUser.Id;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         comment.UserType = type;
     }
     else
     {
         comment = commentRepository.GetById(commentId);
         comment.Content = content;
         comment.DateCreated = DateTime.Now;
         string type = AuthenticationManager.LoggedUser.GetType().BaseType.ToString();
         int start = type.LastIndexOf(".") + 1;
         int positions = type.Length - start;
         type = type.Substring(start, positions);
         comment.UserType = type;
     }
     commentRepository.Save(comment);
     string comentator = AuthenticationManager.LoggedUser.FirstName + " " + AuthenticationManager.LoggedUser.LastName;
     SelectListItem commentContent = new SelectListItem() { Text = comment.Content, Value = comentator };
     return Json(commentContent, JsonRequestBehavior.AllowGet);
 }