public MonitorSvc(IArticleRepo articleRepo, ICategoryRepo categoryRepo, ITagRepo tagRepo, ICommentRepo commentRepo) { _articleRepo = articleRepo; _categoryRepo = categoryRepo; _tagRepo = tagRepo; _commentRepo = commentRepo; }
protected async override Task <CommentView> HandleInput(CommentDeleteParams input) { using (var connection = database.GetConnection()) { ICommentRepo commentRepo = database.GetRepo <ICommentRepo>(connection); IPostRepo postRepo = database.GetRepo <IPostRepo>(connection); Comment?comment = await commentRepo.FindById(input.CommentId); if (comment == null) { throw new InvalidOperationException(); } // Check to see if they have permission first. if (!(await this.permissionHandler.HasPermission(input.User, PermissionAction.DeleteComment, comment))) { throw new AuthorizationException(); } // (Hopefully) it would be impossible for post to be null if a comment exists... Post post = (await postRepo.FindById(comment.PostId)) !; post.CommentCount -= (comment.ChildCount() + 1); using (var transaction = connection.BeginTransaction()) { await commentRepo.Delete(comment); await postRepo.Update(post); transaction.Commit(); } return(commentMapper.Map(comment)); } }
public PostController(IPostRepo postRepo, IUserRepo userRepo, ICommentRepo commentRepo, IBlobService blobService) { _postRepo = postRepo; _userRepo = userRepo; _commentRepo = commentRepo; _blobService = blobService; }
public HomePageController(ICommentLikeRepo CommentLike, ICommentRepo PostComments, IPostRepo Post, IFriendRepo Friends, IPostLikeRepo PostLikes) { _Post = Post; _Friends = Friends; _PostLikes = PostLikes; _PostComments = PostComments; _CommentLike = CommentLike; }
public void CommentRepository_DeleteById_ThrowsExceptionWhenIdNotFound() { //arrange ICommentRepo cr = GetInMemoryCommentRepository(); //assert Assert.ThrowsAny <ArgumentNullException>(() => cr.DeleteById(0)); }
public UserController(IUserRepo userrepo, IGender gender, ICommentRepo comments, IPostRepo post, ICodeRepo code) { this._user = userrepo; this._gender = gender; this._comm = comments; this._postrepo = post; this._coderepo = code; }
public ProfileController(ICommentLikeRepo CommentLike, IUserRepo User, ICommentRepo PostComments, IPostRepo Post, IFriendRepo Friends, IPostLikeRepo PostLikes) { _Post = Post; _Friends = Friends; _PostLikes = PostLikes; _PostComments = PostComments; _CommentLike = CommentLike; _User = User; }
public Server_ForumHandler() { _postRepo = new PostRepo(); _commentRepo = new CommentRepo(); _postList = new List <PostModel>(); _commentList = new List <CommentModel>(); _ratingRepo = new RatingRepo(); _reportRepo = new ReportRepo(); _reportModels = new List <ReportModel>(); }
public ProfileController(ApplicationDbContext db, ICommentLikeRepo CommentLike, IUserRepo User, ICommentRepo PostComments, IPostRepo Post, IFriendRepo Friends, IPostLikeRepo PostLikes) { _Post = Post; _Friends = Friends; _PostLikes = PostLikes; _PostComments = PostComments; _CommentLike = CommentLike; _User = User; this.db = db; }
public void CommentRepository_Update_ThrowsExceptionWhenIdNotFound() { //arrange ICommentRepo cr = GetInMemoryCommentRepository(); //nothing in the database so trying to update should throw exception //assert Assert.ThrowsAny <ArgumentNullException>(() => cr.Update(comment)); }
public ProjectController(UserManager <ApplicationUsers> userManager, IProjectUsersRepo projectUsersRepo, IProjectmanagerRepo projectmanagerRepo, ITaskRepo taskRepo, ICommentRepo commentRepo) { _userManager = userManager; _projectUsersRepo = projectUsersRepo; _projectmanagerRepo = projectmanagerRepo; _taskRepo = taskRepo; _commentRepo = commentRepo; }
protected async override Task <CommentView> HandleInput(CommentCreateParams input) { using (var connection = database.GetConnection()) { IPostRepo postRepo = database.GetRepo <IPostRepo>(connection); ICommentRepo commentRepo = database.GetRepo <ICommentRepo>(connection); IVoteRepo voteRepo = database.GetRepo <IVoteRepo>(connection); // Locate the post to ensure it actually exists. Post?post = await postRepo.FindById(input.PostId); if (post == null) { throw new InvalidOperationException(); } using (var transaction = connection.BeginTransaction()) { Comment comment = new Comment() { User = input.User, PostId = post.Id, Body = input.Body, CreationDate = DateTime.UtcNow }; // Set the parent comment if needed. if (input.ParentId != 0) { comment.Parent = await commentRepo.FindById(input.ParentId); } // Update the comment count cache on the post. post.CommentCount++; comment.Upvotes++; await commentRepo.Add(comment); Vote upvote = new Vote() { User = input.User, ResourceId = comment.Id, ResourceType = VoteResourceType.Comment, Direction = VoteDirection.Up }; await postRepo.Update(post); await voteRepo.Add(upvote); comment.Vote = upvote; transaction.Commit(); return(commentMapper.Map(comment)); } } }
public void CommentRepository_GetById_ThrowsExceptionWhenIdNotFound() { //arrange ICommentRepo cr = GetInMemoryCommentRepository(); //act cr.Add(comment); //Id should be 1 //assert Assert.ThrowsAny <ArgumentNullException>(() => cr.GetById(0)); }
public void CommentRepository_GetByReviewId_ReturnsIEnumerable() { //arrange ICommentRepo cr = GetInMemoryCommentRepository(); //act cr.Add(comment); //Id should be 1 //assert Assert.IsAssignableFrom <IEnumerable <Comment> >(cr.GetByReviewId(1)); }
public void CommentRepository_CreateLike_CreatesOneAndOnlyOneCommentLikePerUser() { //arrange ICommentRepo cr = GetInMemoryCommentRepository(); //act cr.Add(comment); cr.CreateLike(1, 1); //user 1 likes comment 1 cr.CreateLike(1, 1); //if user 1 likes the same comment again, won't cause exception //assert Assert.True(true); }
public void Setup() { List <Comment> comment = new List <Comment>() { new Comment { commentid = 1, body = "body added for comment 1", userid = 1, contentid = 1, shorttext = "slug-1" }, new Comment { commentid = 2, body = "body added for comment 2", userid = 2, contentid = 2, shorttext = "slug-2" }, new Comment { commentid = 3, body = "body added for comment 3", userid = 3, contentid = 3, shorttext = "slug-3" }, new Comment { commentid = 4, body = "body added for comment 4", userid = 4, contentid = 4, shorttext = "slug-4" }, new Comment { commentid = 4, body = "body added for comment 5", userid = 4, contentid = 5, shorttext = "slug-5" } }; var mockrepo = new Mock <ICommentRepo>(); // add method mockrepo.Setup(m => m.Add(It.IsAny <Comment>())) .Callback <Comment>(a => comment.Add(a)); // find all method mockrepo.Setup(m => m.FindAll()).Returns(comment); // find by id method mockrepo.Setup(m => m.FindByID(It.IsAny <int>())) .Returns((int i) => comment .Where(w => w.commentid == i).Single()); // update method mockrepo.Setup(m => m.Update(It.IsAny <Comment>())) .Callback <Comment>(p => comment.Where(w => w.commentid == p.commentid).First(a => { a.shorttext = p.shorttext; a.userid = p.userid; a.contentid = p.contentid; a.body = p.body; return(true); })); // remove method mockrepo.Setup(m => m.Remove(It.IsAny <int>())) .Callback <int>(i => comment.Remove(comment.Where(w => w.commentid == i).First())); _mockrepo = mockrepo.Object; }
public void CommentRepository_Add_AddsComment() { //arrange ICommentRepo cr = GetInMemoryCommentRepository(); //act cr.Add(comment); var savedComment = cr.GetById(1); //should have Id of 1 //assert Assert.Equal(1, savedComment.CommentId); Assert.Equal(1, savedComment.ReviewId); Assert.Equal(1, savedComment.UserId); Assert.IsType <DateTime>(savedComment.Date); }
public void CommentRepository_Update_UpdatesComment() { //arrange ICommentRepo cr = GetInMemoryCommentRepository(); //act cr.Add(comment); var savedComment = cr.GetById(1); //should have Id of 1 savedComment.Content = "Updated content"; cr.Update(savedComment); var updatedComment = cr.GetById(1); //assert Assert.Equal("Updated content", updatedComment.Content); }
public static Post ToPost(IUserRepo userRepo, ICommentRepo commentRepo, PostApiModel apiModel) { apiModel.Content.EnforceNoSpecialCharacters(nameof(apiModel.Content)); // if status is not null, filter out any non-file allowed characters if (!apiModel.PictureUrl.IsNullOrEmpty()) { apiModel.PictureUrl.EnforceNoSpecialCharacters(nameof(apiModel.PictureUrl)); } var user = userRepo.GetUserByIdAsync(apiModel.User.Id).Result; List <Comment> comments = null; List <User> likedByUsers = null; if (apiModel.Comments is not null && apiModel.Comments.Any()) { var commentIds = apiModel .Comments .Select(c => c.Id) .ToList(); comments = commentRepo.GetCommentsByIdsAsync(commentIds) .Result .ToList(); } if (apiModel.LikedByUserIds is not null && apiModel.LikedByUserIds.Any()) { likedByUsers = userRepo.GetUsersByIdsAsync(apiModel.LikedByUserIds) .Result .ToList(); } comments ??= new List <Comment>(); likedByUsers ??= new List <User>(); return(new Post { Id = apiModel.Id, Content = apiModel.Content, CreatedAt = apiModel.CreatedAt, Picture = apiModel.PictureUrl, User = user, LikedByUsers = likedByUsers, Comments = comments }); }
protected override async Task <VoteView> HandleInput(VoteOnCommentParams input) { using (var connection = database.GetConnection()) { IVoteRepo voteRepo = database.GetRepo <IVoteRepo>(connection); ICommentRepo commentRepo = database.GetRepo <ICommentRepo>(connection); IUserRepo userRepo = database.GetRepo <IUserRepo>(connection); using (var transaction = connection.BeginTransaction()) { Comment comment = (await commentRepo.FindById(input.CommentId)) !; Vote? oldVote = await voteRepo.FindByUserAndComment(input.User.Username, input.CommentId); // Wipe out the old one... if (oldVote != null) { comment.RemoveVote(oldVote.Direction); await voteRepo.Delete(oldVote); comment.User.CommentKarma -= (int)oldVote.Direction; } // Create the new vote, and update the comment's karma cache. Vote newVote = new Vote() { User = input.User, ResourceType = VoteResourceType.Comment, ResourceId = input.CommentId, Direction = input.Vote }; comment.AddVote(newVote.Direction); comment.User.CommentKarma += (int)newVote.Direction; await voteRepo.Add(newVote); await commentRepo.Update(comment); await userRepo.Update(comment.User); transaction.Commit(); return(voteViewMapper.Map(newVote)); } } }
protected async override Task <IEnumerable <CommentView> > HandleInput(FindByValueParams <int> input) { using (var connection = database.GetConnection()) { ICommentRepo commentRepo = database.GetRepo <ICommentRepo>(connection); IEnumerable <Comment> comments = await commentRepo.FindByPost(input.Value); if (input.User != null) { IVoteRepo voteRepo = database.GetRepo <IVoteRepo>(connection); foreach (Comment c in comments) { await GetVotes(voteRepo, c, input.User); } } return(comments.Select(c => commentMapper.Map(c))); } }
protected async override Task <CommentView?> HandleInput(FindByValueParams <int> input) { using (var connection = database.GetConnection()) { ICommentRepo commentRepo = database.GetRepo <ICommentRepo>(connection); Comment?c = await commentRepo.FindById(input.Value); if (c == null) { return(null); } if (input.User != null) { IVoteRepo voteRepo = database.GetRepo <IVoteRepo>(connection); await GetVotes(voteRepo, c, input.User); } return(commentMapper.Map(c)); } }
protected async override Task <PagedResultSet <CommentView> > HandleInput(FindByValueParams <string> input) { using (var connection = database.GetConnection()) { ICommentRepo commentRepo = database.GetRepo <ICommentRepo>(connection); PagedResultSet <Comment> comments = await commentRepo.FindByUser(input.Value, input.Pagination?.PageNumber ?? 0, input.Pagination?.PageSize ?? Comment.PageSize); if (input.User != null) { foreach (Comment c in comments) { IVoteRepo voteRepo = database.GetRepo <IVoteRepo>(connection); await GetVotes(voteRepo, c, input.User); } } return(new PagedResultSet <CommentView>( comments.Select(c => commentMapper.Map(c)), comments.Pagination )); } }
public static Comment ToComment(ICommentRepo commentRepo, IUserRepo userRepo, IPostRepo postRepo, CommentApiModel apiModel) { // no special characters are allowed apiModel.Content.EnforceNoSpecialCharacters(nameof(apiModel.Content)); var user = userRepo.GetUserByIdAsync(apiModel.User.Id) .Result; user.NullCheck(nameof(user)); var post = postRepo.GetPostByIdAsync(apiModel.PostId) .Result; post.NullCheck(nameof(user)); List <Comment> childComments = null; if (apiModel.ChildCommentIds is not null && apiModel.ChildCommentIds.Any()) { childComments = commentRepo.GetCommentsByIdsAsync(apiModel.ChildCommentIds) .Result .ToList(); } childComments ??= new List <Comment>(); return(new Comment { Id = apiModel.Id, Content = apiModel.Content, CreatedAt = apiModel.CreatedAt, User = user, Post = post, ChildrenComments = childComments }); }
protected override async Task <CommentView> HandleInput(CommentUpdateParams input) { using (var connection = database.GetConnection()) { ICommentRepo commentRepo = database.GetRepo <ICommentRepo>(connection); Comment? comment = await commentRepo.FindById(input.CommentId); if (comment == null) { throw new NotFoundException(); } if (!(await this.commentPermissionHandler.HasPermission(input.User, PermissionAction.UpdateComment, comment))) { throw new AuthorizationException(); } comment.Body = input.Body; comment.WasUpdated = true; await commentRepo.Update(comment); return(commentMapper.Map(comment)); } }
public ImageCommentController(IImageCommentRepo imageCommentRepo, ICommentRepo commentRepo) { _imageCommentRepo = imageCommentRepo; _commentRepo = commentRepo; }
public void ICommentRepo(ICommentRepo c) { comments = c; }
public CommentOps(ICommentRepo iComment) { _repo = iComment; }
public CommentController(ICommentRepo repo, IMapper mapper) { _repo = repo; _mapper = mapper; }
public CommentsController(ICommentRepo repository, IMapper mapper) { _repository = repository; _mapper = mapper; }
public CommentController(ICommentRepo commentRepo, IUserRepo userRepo, IPostRepo postRepo) { _commentRepo = commentRepo; _userRepo = userRepo; _postRepo = postRepo; }
public ClassForDemonstratingDelegateFactories(ICommentRepo commentRepo, string prefix) { _commentRepo = commentRepo; _prefix = prefix; }