public static IRepositoryService<Comment> Create()
 {
     IDatabaseFactory databaseFactory = new DatabaseFactory();
     IUnitOfWork unitOfWork = new UnitOfWork(databaseFactory);
     IRepository<Comment> commentRepository = new CommentRepository(databaseFactory);
     return new CommentEntityService((ICommentRepository) commentRepository, unitOfWork);
 }
        public void PagesGetCorrectItems()
        {
            var comments = new Comment[12];

            for(int i = 0; i < 12; i++)
            {
                comments[i] = new Comment() {Text = "This is comment " + i.ToString("D2"), Author = "Chuck Finley"};
            }

            var postId = CreatePost("Comments Test", "Comments Test", DateTime.Now, comments);

            var repo = new CommentRepository(new BlogContext());

            int virtualItemCount;
            int pageSize = 5;
            var criteria = new CommentCriteria() { PostId = postId };
            var order = Order<Comment>.By(c => c.Text);

            var page0 = repo.Retrieve(pageSize, 0, out virtualItemCount, criteria, order).ToList();
            page0.Count().Should().Be(5);
            page0.First().Text.Should().EndWith("00");
            page0.Last().Text.Should().EndWith("04");

            var page1 = repo.Retrieve(pageSize, 1, out virtualItemCount, criteria, order).ToList();
            page1.Count().Should().Be(5);
            page1.First().Text.Should().EndWith("05");
            page1.Last().Text.Should().EndWith("09");

            var page2 = repo.Retrieve(pageSize, 2, out virtualItemCount, criteria, order).ToList();
            page2.Count().Should().Be(2);
            page2.First().Text.Should().EndWith("10");
            page2.Last().Text.Should().EndWith("11");
        }
        public void ShouldGetTheRightNumberOfComments()
        {
            const int personId   = 1;
            const int roleId     = 4;
            var commentsToDelete = _context.Comments.Where(c => c.AboutPersonId == personId).ToList();
            foreach(var commentToDelete in commentsToDelete)
                _context.DeleteObject(commentToDelete);

            _context.SaveChanges();

            ICommentRepository commentsRepo = new CommentRepository();
            var currentPerson = new Person {PersonId = personId, RoleId = roleId};

            const string testComment = "Test Comment";

            var newComment = new CommentDto
            {
                Comment       = testComment,
                AboutPersonId = personId,
                CommentDate   = DateTime.Now
            };

            var commentId = commentsRepo.SaveItem(currentPerson, newComment);

            var sut = commentsRepo.GetListOfComments(currentPerson, personId);

            Assert.That(sut.Count(), Is.EqualTo(1));
        }
Exemple #4
0
        public void ShouldGetTheRightPersonWhoMadeTheComment()
        {
            const int personId = 1;
            const int roleId = 1;
            var commentsToDelete = Context.Comments.Where(c => c.AboutPersonId == personId).ToList();
            foreach (var commentToDelete in commentsToDelete)
                Context.DeleteObject(commentToDelete);

            ICommentRepository commentsRepo = new CommentRepository(Context);
            var currentPerson = new Person { PersonId = personId, RoleId = roleId };

            const string testComment = "Test Comment";

            var newComment = new CommentDto
            {
                Comment       = testComment,
                AboutPersonId = personId,
                CommentDate   = DateTime.Now
            };

            var commentId = commentsRepo.SaveItem(currentPerson, newComment);
            var sut       = commentsRepo.GetListOfComments(currentPerson, personId).ToList();

            Assert.That(sut[0].CreatedByPerson, Is.EqualTo("Peter Munnings"));
        }
Exemple #5
0
 public static ISearch<Comment> GetCommentSearch()
 {
     if (CommentSearch == null)
     {
         CommentSearch = new CommentRepository();
     }
     return CommentSearch;
 }
Exemple #6
0
 public static ICRUDRepository<Comment> GetCommentRepository()
 {
     if (commentRepo == null)
     {
         commentRepo = new CommentRepository();
     }
     return commentRepo;
 }
        public void AddReturnsId()
        {
            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            var response = repository.Add(new Comment());

            Assert.IsNotNull(response);
            Assert.AreEqual(response.Id, 1);
        }
Exemple #8
0
 public SqlDAL()
 {
     DBContext = new AlbumsDBModel();
     _albumRepository = new AlbumRepository(DBContext);
     _roleRepository = new RoleRepository(DBContext);
     _userRepository = new UserRepository(DBContext);
     _commentRepository = new CommentRepository(DBContext);
     _likeRepository = new LikeRepository(DBContext);
     _albumsPhotoRepository = new AlbumsPhotoRepository(DBContext);
     _photoRepository = new PhotoRepository(DBContext);
 }
        public void GetCommentOrganizerId_Call_GetResult_Test()
        {
            var context = new MyEventsContext();
            var comment = context.Comments.Include("Session.EventDefinition").FirstOrDefault();

            ICommentRepository target = new CommentRepository();

            int organizerId = target.GetOrganizerId(comment.CommentId);

            Assert.AreEqual(organizerId, comment.Session.EventDefinition.OrganizerId);
        }
        public void ExpectDataValidationException()
        {
            CommentRepository repo = new CommentRepository(new BlogContext());

            var comment = new Comment();
            comment.PostID = -1;
            comment.Text = "This shouldn't be saveable";

            Action save = () => repo.Save(comment);

            save.ShouldThrow<DataValidationException>();
        }
        public void DeleteComment_NoExists_NotFail_Test()
        {
            var context = new MyEventsContext();
            var comment = context.Comments.FirstOrDefault();
            int expected = context.Comments.Count();

            ICommentRepository target = new CommentRepository();
            target.Delete(0);

            int actual = context.Comments.Count();

            Assert.AreEqual(expected, actual);
        }
 public static void Initialize()
 {
     UserRepository = new UserRepository();
     PostRepository = new PostRepository();
     HeaderImageRepository = new HeaderImageRepository();
     MessageRepository = new MessageRepository();
     CommentRepository = new CommentRepository();
     PostVotingRepository = new PostVotingRepository();
     CommentVotingRepository = new CommentVotingRepository();
     MessageSettingsRepository = new MessageSettingsRepository();
     TagRepository = new TagRepository();
     TagPostRepository = new TagPostRepository();
 }
        public void AddPersists()
        {
            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            repository.Add(new Comment { Message = "Test Item" });

            dbFactory.Run(db =>
                              {
                                  var response = db.Select<Comment>();

                                  Assert.AreEqual(response.Count, 1);
                                  Assert.AreEqual(response[0].Message, "Test Item");
                              });
        }
        public void DeleteFails()
        {
            dbFactory.Run(db => db.Insert(new Comment { Id = 1, Message = "Test Item" }));

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

            repository.Delete(2);
            dbFactory.Run(db =>
                              {
                                  var response = db.Select<Comment>();

                                  Assert.AreEqual(response.Count, 1);
                                  Assert.AreEqual(response[0].Message, "Test Item");
                              });
        }
Exemple #15
0
 public ActionResult AddComment(string content, string userId, string ariticleId, string comment_temp)
 {
    
     CommentRepository cr = new CommentRepository();
     UserRepository ur = new UserRepository();
     string result = "";
     if (comment_temp != "null")
     {
         string[] array = comment_temp.Split('#');
         int id = Int32.Parse(array[0]);
         string firstUserId = array[1];
         Comment c = cr.FindByID(id);
         User u = ur.FindByID(userId);
         User firstUser = ur.FindByID(firstUserId);
         c.Isleaf = 1;
         cr.Update(c);
         Comment comment = new Comment();
         comment.UserId = userId;
         comment.AriticleId = ariticleId;
         comment.Content = content;
         comment.NickName = u.NickName;
         comment.FirstNickName = firstUser.NickName;
         comment.Pid = id;
         comment.Isleaf = 0;
         comment.CommentTime = DateTime.Now;
         cr.Add(comment);
         result = "";
         result = JsonConvert.SerializeObject(comment);
     }
     else {
         User u = ur.FindByID(userId);
         Comment comment = new Comment();
         comment.UserId = userId;
         comment.Content = content;
         comment.CommentTime = DateTime.Now;
         comment.AriticleId = ariticleId;
         comment.Pid = 0;
         comment.Isleaf = 0;
         comment.Level = 1;
         comment.NickName = u.NickName;
         comment.FirstNickName = null;
         cr.Add(comment);
         result = "";
         result = JsonConvert.SerializeObject(comment);
         ;
     }
     return Content(result);
 }
        public void AddComment_Added_NotFail_Test()
        {
            var context = new MyEventsContext();
            int sessionId = context.Sessions.FirstOrDefault().SessionId;
            int registeredUserId = context.RegisteredUsers.FirstOrDefault().RegisteredUserId;
            int expected = context.Comments.Count() + 1;

            ICommentRepository target = new CommentRepository();
            Comment comment = new Comment();
            comment.SessionId = sessionId;
            comment.AddedDateTime = DateTime.UtcNow;
            comment.RegisteredUserId = registeredUserId;
            comment.Text = "sample comment";
            target.Add(comment);

            int actual = context.Comments.Count();

            Assert.AreEqual(expected, actual);
        }
Exemple #17
0
        private static void CreatePost(string title)
        {
            var postRepository = new PostRepository();
            var categoryRepository = new CategoryRepository();
            var commentRepository = new CommentRepository();

            var post = new Post
                           {
                               Title = title,
                               PostedDate = DateTime.Now,
                               Contents = "This is just a simple test post..."
                           };

            for (int i = 0; i < 10; i++)
            {
                var category = new Category
                                   {
                                       Name = "Category " + i,
                                       CreatedDate = DateTime.Now,
                                       Description = "Just a test..."
                                   };

                post.AddCategory(category);
                categoryRepository.Create(category);
            }

            for (int i = 0; i < 20; i++)
            {
                var comment = new Comment
                                  {
                                      PostedDate = DateTime.Now,
                                      Author = "Author " + i,
                                      Text = "testing..."
                                  };

                post.AddComment(comment);
                commentRepository.Create(comment);
            }

            postRepository.Create(post);
        }
        public void CommentsCanBeFilteredByPost()
        {
            var comment1 = new Comment() { Text = "This is a comment for the first post", Author = "Chuck Finley" };
            var comment2 = new Comment() { Text = "This is a comment for the first post", Author = "Chuck Finley" };
            var comment3 = new Comment() { Text = "This is a comment for the second post", Author = "Santos L. Helper" };
            var comment4 = new Comment() { Text = "This is a comment for the second post", Author = "Santos L. Helper" };

            var post1Id = CreatePost("Comments Test 1", "Comments Test 1", DateTime.Now, comment1, comment2);
            var post2Id = CreatePost("Comments Test 2", "Comments Test 2", DateTime.Now, comment3, comment4);

            var repo = new CommentRepository(new BlogContext());

            int virtualItemCount;
            var comments = repo.Retrieve(10, 0, out virtualItemCount, new CommentCriteria() { PostId = post2Id }).ToList();

            comment3.PostID = post2Id;
            comment4.PostID = post2Id;
            var comparisonComments = new Collection<Comment>() { comment3, comment4 };

            comments.Count().Should().Be(2);
            comments.ShouldAllBeEquivalentTo(comparisonComments,
                options => options.Excluding(o => o.ID));
        }
        public void CommentsShouldSavedWithPost()
        {
            var title = "Comments Test";
            var text = "Comments Test";
            var publishDate = DateTime.Now;

            var comment1 = new Comment() {Text = "This is a comment", Author = "Chuck Finley"};
            var comment2 = new Comment() { Text = "This is a comment", Author = "Chuck Finley" };

            var postId = CreatePost(title, text, publishDate, comment1, comment2);

            var repo = new CommentRepository(new BlogContext());

            int virtualItemCount;
            var comments = repo.Retrieve(10, 0, out virtualItemCount, new CommentCriteria() {PostId = postId}).ToList();

            comment1.PostID = postId;
            comment2.PostID = postId;
            var comparisonComments = new Collection<Comment>() {comment1, comment2};

            comments.Count().Should().Be(2);
            comments.ShouldAllBeEquivalentTo(comparisonComments,
                options => options.Excluding(o => o.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 CommentsController(CommentRepository commentRepository)
 {
     this.commentRepository = commentRepository;
 }
 private void initializeTest()
 {
     _connectionString = "server=wt-220.ruc.dk;database=raw4;uid=raw4;pwd=raw4";
     _commentMapper = new CommentMapper(_connectionString);
     _commentRepository = new CommentRepository(_commentMapper);
 }
Exemple #23
0
 protected void Page_Load(object sender, EventArgs e)
 {
     LogUtil.Logger.Writeln(String.Format(".  -<font color = 'cyan'><u> Comment OnInit:  RecID {0}</u></font>",idst));
     _presenter = new CommentsPresenter();
        // _presenter.Init(this, IsPostBack);
        // _presenter.LoadComments();
     _com = new CommentRepository();
     _ac = new AccountRepository();
     tb_comment.Text = "";
     Image1.ImageUrl ="~/Image/ProfileAvatar.aspx?AccountID=" + _usersession.CurrentUser.AccountID;
     Label1.Text ="Bình luận cho "+ _ac.GetAccountByID(idac).UserName.ToUpper()+" ";
 }
Exemple #24
0
 public List<Comment> GetCommentChidren(int id) {
     CommentRepository cr = new CommentRepository();
     return cr.GetCommentChidren(id).ToList();
 }
        public void GetComment_Call_GetResults_Test()
        {
            var context = new MyEventsContext();
            int sessionId = context.Comments.FirstOrDefault().SessionId;
            int expectedCount = context.Comments.Count(q => q.SessionId == sessionId);

            ICommentRepository target = new CommentRepository();

            IEnumerable<Comment> results = target.GetAll(sessionId);

            Assert.IsNotNull(results);
            Assert.AreEqual(expectedCount, results.Count());
        }
        public void UpdateIsSingular()
        {
            dbFactory.Run(db =>
                              {
                                  db.Insert(new Comment { Id = 1, Message = "Test Item" });
                                  db.Insert(new Comment { Id = 2, Message = "Test Item 2" });
                              });

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

            repository.Update(new Comment { Id = 1, Message = "Test Edit" });

            dbFactory.Run(db =>
                              {
                                  var response = db.Select<Comment>();

                                  Assert.AreEqual(response.Count, 2);
                                  Assert.AreEqual(response.Single(x => x.Id == 1).Message, "Test Edit");
                                  Assert.AreEqual(response.Single(x => x.Id == 2).Message, "Test Item 2");
                              });
        }
        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 void GetAllReturnsItems()
        {
            dbFactory.Run(db =>
                              {
                                  db.Insert(new Comment { Id = 1, Message = "Test Item" });
                                  db.Insert(new Comment { Id = 2, Message = "Test Item 2" });
                              });

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

            var response = repository.GetAll();

            Assert.IsNotNull(response);
            Assert.AreEqual(response.Count, 2);
            Assert.AreEqual(response.Single(x => x.Id == 1).Message, "Test Item");
            Assert.AreEqual(response.Single(x => x.Id == 2).Message, "Test Item 2");
        }
        public void GetAllReturnsEmpty()
        {
            var repository = new CommentRepository(dbFactory, personRepository, issueRepository);

            var response = repository.GetAll();

            Assert.IsNotNull(response);
            Assert.AreEqual(response.Count, 0);
        }
        public void VirtualCountEqualsTotalItems()
        {
            var comments = new Comment[12];

            for (int i = 0; i < 12; i++)
            {
                comments[i] = new Comment() { Text = "This is comment " + i.ToString("D2"), Author = "Chuck Finley" };
            }

            var postId = CreatePost("Comments Test", "Comments Test", DateTime.Now, comments);

            var repo = new CommentRepository(new BlogContext());

            int virtualItemCount;
            int pageSize = 5;

            var criteria = new CommentCriteria() {PostId = postId};
            var order =  Order<Comment>.By(c => c.Text);

            var page0 = repo.Retrieve(pageSize, 0, out virtualItemCount, criteria, order).ToList();
            virtualItemCount.Should().Be(12);

            var page1 = repo.Retrieve(pageSize, 1, out virtualItemCount, criteria, order).ToList();
            virtualItemCount.Should().Be(12);

            var page2 = repo.Retrieve(pageSize, 2, out virtualItemCount, criteria, order).ToList();
            virtualItemCount.Should().Be(12);
        }