public PostController(PostService PostSvc, UserService UserSvc, PostCommentService CommentSvc, PostTypeService TypeSvc) { this.PostSvc = PostSvc; this.UserSvc = UserSvc; this.CommentSvc = CommentSvc; this.TypeSvc = TypeSvc; }
public void TestCreatePostCommentUserNotFound() { var comment = PostCommentMockings.PostComments.FirstOrDefault(); comment.User.Id = Guid.Empty; var result = PostCommentService.CommentPost(comment).GetAwaiter().GetResult(); }
public async Task ReturnsRedirectResultIfRedirectIsSpecified() { var commentFactoryMock = new Mock <ICommentFactory>(); commentFactoryMock.Setup(x => x.CreateFromFormAsync(It.IsAny <IFormCollection>())) .ReturnsAsync(new CommentResult(new Comment(string.Empty, string.Empty, string.Empty))); var pullRequestServiceMock = new Mock <IPullRequestService>(); pullRequestServiceMock.Setup(x => x.TryCreatePullRequestAsync(It.IsAny <Comment>())) .ReturnsAsync(new PullRequestResult()); var formMock = new Mock <IFormCollection>(); formMock.Setup(x => x["CommentSite"]).Returns(_website); formMock.Setup(x => x["Redirect"]).Returns(_website); var postCommentService = new PostCommentService( _config, commentFactoryMock.Object, pullRequestServiceMock.Object); var redirectResult = await postCommentService.PostCommentAsync(formMock.Object).ConfigureAwait(false); Assert.Empty(redirectResult.Error); Assert.Equal(HttpStatusCode.Redirect, redirectResult.HttpStatusCode); Assert.Equal(_website, redirectResult.RedirectUrl !.AbsoluteUri); }
public UserController(UserService UserSvc, PostCommentService CommentSvc, PostService PostSvc, SendEmailService SendEmailSvc) { this.UserSvc = UserSvc; this.CommentSvc = CommentSvc; this.PostSvc = PostSvc; this.SendEmailSvc = SendEmailSvc; }
public async Task Create_Async_Test() { var options = new DbContextOptionsBuilder <FriendyContext>() .UseInMemoryDatabase(databaseName: "Create_Async_Test") .Options; int postId = 1; string content = new Guid().ToString(); using (var context = new FriendyContext(options)) { var repo = new RepositoryWrapper(context); var service = new PostCommentService(repo, null); var controller = new PostCommentController(service); var res = await controller.CreateAsync(_userId, new NewCommentDto() { PostId = postId, Content = content }, null); var value = res.Value; Assert.NotNull(value); Assert.IsType <object>(value); Assert.Equal(value.Content, content); } }
public void TestGetPostComment() { var comment = PostCommentService.GetPostComment(PostCommentMockings.GetGuid(0)).GetAwaiter() .GetResult(); Assert.AreEqual(PostCommentMockings.GetGuid(0), comment.Id); }
public void TestDeletePostComment() { foreach (var commentForPost in PostCommentMockings.PostComments) { Assert.IsTrue(PostCommentService.DeletePostComment(commentForPost.Id).GetAwaiter().GetResult()); } }
public void TestGetPostComments() { var comments = PostCommentService.GetPostComments(PostCommentMockings.GetGuid(1)) .GetAwaiter().GetResult(); Assert.AreEqual(30, comments.Count); }
public async Task ReturnsErrorResultIfPullRequestFails() { var commentFactoryMock = new Mock <ICommentFactory>(); commentFactoryMock.Setup(x => x.CreateFromFormAsync(It.IsAny <IFormCollection>())) .ReturnsAsync(new CommentResult(new Comment(string.Empty, string.Empty, string.Empty))); var errorMessage = "ErrorBecauseOfReasons"; var pullRequestServiceMock = new Mock <IPullRequestService>(); pullRequestServiceMock.Setup(x => x.TryCreatePullRequestAsync(It.IsAny <Comment>())) .ReturnsAsync(new PullRequestResult(new Exception(errorMessage))); var formMock = new Mock <IFormCollection>(); formMock.Setup(x => x["CommentSite"]).Returns(_website); var postCommentService = new PostCommentService( _config, commentFactoryMock.Object, pullRequestServiceMock.Object); var errorResult = await postCommentService.PostCommentAsync(formMock.Object).ConfigureAwait(false); Assert.NotEmpty(errorResult.Error); Assert.Equal(HttpStatusCode.BadRequest, errorResult.HttpStatusCode); Assert.Contains(errorMessage, errorResult.Error, StringComparison.OrdinalIgnoreCase); }
public async Task ReturnsErrorResultIfFormHasErrors() { var errorMessage = "ErrorBecauseOfReasons"; var commentFactoryMock = new Mock <ICommentFactory>(); commentFactoryMock.Setup(x => x.CreateFromFormAsync(It.IsAny <IFormCollection>())) .ReturnsAsync(new CommentResult(new Comment(string.Empty, string.Empty, string.Empty), new string[] { errorMessage }, new InvalidOperationException())); var formMock = new Mock <IFormCollection>(); formMock.Setup(x => x["CommentSite"]).Returns(_website); var postCommentService = new PostCommentService( _config, commentFactoryMock.Object, Mock.Of <IPullRequestService>()); var errorResult = await postCommentService.PostCommentAsync(formMock.Object).ConfigureAwait(false); Assert.NotEmpty(errorResult.Error); Assert.Equal(HttpStatusCode.BadRequest, errorResult.HttpStatusCode); Assert.Contains(errorMessage, errorResult.Error, StringComparison.InvariantCulture); }
public void TestCreatePostComment() { foreach (var commentForPost in PostCommentMockings.PostComments) { var comment = PostCommentService.CommentPost(commentForPost).GetAwaiter() .GetResult(); Assert.IsNotNull(comment); } }
public async Task ThrowsIfFormIsNull() { var postCommentService = new PostCommentService( Options.Create(new WebConfiguration()), Mock.Of <ICommentFactory>(), Mock.Of <IPullRequestService>()); await Assert.ThrowsAsync <ArgumentNullException>( () => postCommentService.PostCommentAsync(null !)).ConfigureAwait(false); }
public void TestGetPostCommentsPart() { var comments = new List <PostComment>(); for (int i = 1; i < 7; i++) { comments.AddRange(PostCommentService .GetPostComments(PostCommentMockings.GetGuid(1), comments.Count == 0 ? DateTimeOffset.Now : comments.Last().CommentedAt, 5) .GetAwaiter().GetResult()); Assert.AreEqual(comments.Min(comment => comment.CommentedAt), comments.Last().CommentedAt); Assert.AreEqual(i * 5, comments.Count); } }
public async Task ReturnsErrorResultIfCommentDoesNotComeFromSpecifiedWebsite(string postedSite) { var formMock = new Mock <IFormCollection>(); formMock.Setup(x => x["CommentSite"]).Returns(postedSite); var postCommentService = new PostCommentService( _config, Mock.Of <ICommentFactory>(), Mock.Of <IPullRequestService>()); var errorResult = await postCommentService.PostCommentAsync(formMock.Object).ConfigureAwait(false); Assert.NotEmpty(errorResult.Error); Assert.Equal(HttpStatusCode.BadRequest, errorResult.HttpStatusCode); }
public DashboardModel GetResponses() { var model = new DashboardModel() { Labels = new List <string>(), Datas = new List <int>() }; var list = PostCommentService.GetAll(); var date = DateTime.Now.AddDays(-6); int i = 1; for (var d = date; i <= 7; d = d.AddDays(1), i++) { model.Labels.Add(d.ToString("ddd,dd")); model.Datas.Add(list.Count(l => l.COMMENTDATE.Day == d.Day)); } return(model); }
//[InlineData(2,7)] public async Task Get_All_By_Post_Id_Tests(int postId, int userId) { var options = new DbContextOptionsBuilder <FriendyContext>() .UseInMemoryDatabase(databaseName: "Get_All_By_Post_Id_Tests") .Options; using (var context = new FriendyContext(options)) { var data = GetData(20).ToList(); context.MainComment.AddRange(data); context.SaveChanges(); } using (var context = new FriendyContext(options)) { var repo = new RepositoryWrapper(context); var service = new PostCommentService(repo, null); var controller = new PostCommentController(service); var res = await controller.GetAllByPostIdAsync(postId, userId); Assert.NotNull(res); } }
public void PostCommentTestInitialize() { DbContext = new RoomMateExpressDbContext(ConnectionString); PostCommentService = new PostCommentService(DbContext); }
public Result <PostComment> SaveComment(PostComment com) { com.USERID = HttpUtil.UserProfile.ID; return(PostCommentService.Insert(com)); }
public CommentController() { this.commentService = new PostCommentService(); }
public List <PostComment> GetByPostID(int pid) { return(PostCommentService.GetByPostID(pid)); }
public List <PostComment> GetByUserID(int uid) { return(PostCommentService.GetByUserID(uid)); }
public PostCommentsController() { _postCommentService = new PostCommentService(); _logService = new LogService(); _userService = new UserService(); }
public List <PostComment> GetAll() { return(PostCommentService.GetAll()); }