public void CommentMovie_ValidData_ShouldCommentPartialView() { var fakeUser = this.mocks.UserRepositoryMock.Object.All().FirstOrDefault(u => u.Id == "12345"); var fakeComments = new List <Comment>() { new Comment() { Id = 1, CreatedAt = new DateTime(2017, 04, 23), Content = "Comment 1" }, new Comment() { Id = 2, CreatedAt = new DateTime(2017, 04, 24), Content = "Comment 2" }, new Comment() { Id = 3, CreatedAt = new DateTime(2017, 04, 23), Content = "Comment 3" } }; this.mocks.CommentRepositoryMock = new Mock <IRepository <Comment> >(); this.mocks.CommentRepositoryMock.Setup(r => r.All()).Returns(fakeComments.AsQueryable()); fakeComments.Add(new Comment() { Id = 0, CreatedAt = new DateTime(2017, 05, 07), Content = "Test Content 4", MovieId = 1, AuthorId = "12345" }); this.CheckUserCredentials(fakeUser); var commentInput = new CreateCommentInputModel() { MovieId = 1, Content = "Test Content 4" }; this.controller.WithCallTo(c => c.Create(commentInput)).ShouldRenderPartialView("_CommentPartial"); }
public async Task <IActionResult> Create(CreateCommentInputModel input) { if (!this.ModelState.IsValid) { return(this.RedirectToAction("ById", "Inquiries", new { id = input.InquiryId })); } var parentId = input.ParentId == 0 ? (int?)null : input.ParentId; if (parentId.HasValue) { if (!await this.commentsService.IsInPostId(parentId.Value, input.InquiryId)) { return(this.BadRequest()); } } var claimsIdentity = (ClaimsIdentity)this.User.Identity; var claim = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier); var userId = claim.Value; await this.commentsService.Create(input.InquiryId, userId, input.Content, parentId); return(this.RedirectToAction("ById", "Inquiries", new { id = input.InquiryId })); }
public async Task <IActionResult> CreateComment(CreateCommentInputModel input) { if (!this.ModelState.IsValid) { return(Redirect("/School/Forum")); } var post = this.postsService.GetPost(input.PostId); if (post == null) { return(Redirect("/School/Forum")); } var user = await this.userManager.GetUserAsync(this.User); if (post.SchoolId != user.SchoolId) { return(Redirect("/School/Forum")); } await this.commentsService.AddCommentAsync(post.Id, input.Content, user.Id); return(Redirect("/School/Forum")); }
public async Task <IActionResult> AddCommentToRestaurant(CreateCommentInputModel input) { if (!this.ModelState.IsValid) { foreach (var modelState in this.ModelState.Values) { foreach (var error in modelState.Errors) { this.TempData[ErrorNotification] = error.ErrorMessage; } } return(this.RedirectToRoute("restaurant", new { id = input.Id, name = input.RestaurantName.ToSlug() })); } string userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); var id = await this.commentService.AddCommentToRestaurantAsync(input.Id, input.CommentContent, userId); var result = this.CheckIfIdIsZero(id); if (result != null) { this.TempData[ErrorNotification] = CommentNotFound; return(result); } this.TempData[SuccessNotification] = string.Format(SuccessfullyCommentRestaurant, input.RestaurantName); return(this.RedirectToRoute("restaurant", new { id = input.Id, name = input.RestaurantName.ToSlug() })); }
public async Task DeleteByIdAsync_WithCorrectData_ShouldSuccessfullyDelete() { var testContent = "TestContent"; // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var commentRepository = new EfDeletableEntityRepository <Comment>(context); var commentsService = new CommentsService(commentRepository); var inputModel = new CreateCommentInputModel() { CommentContent = testContent, }; await commentsService.CreateAsync(inputModel); var comment = commentRepository.All().FirstOrDefault(c => c.Content == testContent); // Act var expectedCommentsCount = 0; await commentsService.DeleteByIdAsync(comment.Id); var actualCommentsCount = commentRepository.All().Count(); // Assert Assert.Equal(expectedCommentsCount, actualCommentsCount); }
public async Task Create(CreateCommentInputModel model) { var product = this.productService.GetIdByNameAndGroup(model.ProductName, GroupType.Fireplace.ToString()); var fireplace = this.fireplaceService.GetById <DetailsFireplaceViewModel>(model.ProductId); if (product == null) { throw new ArgumentNullException(string.Format("Product with Id: {0} does not exist.", model.ProductId)); } var comment = new Comment { Id = Guid.NewGuid().ToString(), Content = model.Content, FullName = model.FullName, Email = model.Email, ProductId = product, IsDeleted = false, CreatedOn = DateTime.UtcNow, }; var contentEmail = new StringBuilder(); var content = GeneratEmailContent(model, fireplace, contentEmail, comment); await this.emailSender.SendEmailAsync( model.Email, model.FullName, AdminEmail, "Запитване", content); await this.commentRepository.AddAsync(comment); await this.commentRepository.SaveChangesAsync(); }
public IActionResult Add(CreateCommentInputModel createCommentInputModel, string id) { if (!ModelState.IsValid) { this.RedirectToAction(nameof(Add)); } var username = this.User.Identity.Name; var channel = this.channelService.GetChannelByTubeUserName(username); var channelPicUrl = string.Empty; if (channel == null) { channelPicUrl = GlobalConstants.dafaultChannelPicUrl; } else { channelPicUrl = channel.ChannelPicUrl; } var user = this.userService.GetTubeUserByUsername(username); this.historyService.DeleteLastHistory(user.Id); username = user.FirstName + " " + user.LastName; this.commentService.CreateComment(createCommentInputModel.Text, username, id, channelPicUrl);; return(this.RedirectToAction("Watch", "Videos", new { id })); }
public async Task <IActionResult> Create(CreateCommentInputModel input) { var parentId = input.ParentId == 0 ? (int?)null : input.ParentId; if (parentId.HasValue) { if (!this.commentsService.IsInMovieId(parentId.Value, input.MovieId)) { return(this.BadRequest()); } } if (input.Content == null || input.Content.Length < 3 || input.Content.Length > 500) { return(this.NoContent()); } var userId = this.userManager.GetUserId(this.User); await this.commentsService.Create(input.MovieId, userId, input.Content, parentId); return(this.RedirectToAction("Details", "Movies", new { id = input.MovieId })); }
public async Task <IActionResult> CreateComment(CreateCommentInputModel model) { var userId = this.userManager.GetUserId(this.User); var parentId = model.ParentId == 0 ? (int?)null : model.ParentId; if (parentId.HasValue) { if (!this.commentsService.IsInPostId(parentId.Value, model.PostId)) { return(this.BadRequest()); } } var sanitizer = new HtmlSanitizer(); var content = sanitizer.Sanitize(model.Content); await this.commentsService.CreateAsync(model.PostId, userId, content, parentId); return(this.RedirectToAction("ById", "Articles", new { id = model.PostId })); }
public async Task <IActionResult> Create(CreateCommentInputModel input) { if (!this.ModelState.IsValid) { return(this.NotFound()); } int?parentId = input.ParentId == 0 ? null : input.ParentId; if (parentId.HasValue) { if (this.commentService.IsInPostId(parentId.Value, input.PostId)) { this.BadRequest(); } } var userId = this.userManager.GetUserId(this.User); await this.commentService.CreateComment(input.PostId, userId, input.Content, parentId); return(this.RedirectToAction("ById", "Posts", new { id = input.PostId })); }
public async Task Create(CreateCommentInputModel input, int?parentId = null) { var user = this.db.Users.Find(input.UserId); var comment = new Comment { Content = input.Content, ParentId = parentId, UserId = input.UserId, UserUsername = input.UserUserName, }; await this.db.Comments.AddAsync(comment); if (input.ArticleId == 0) { this.db.Posts.FirstOrDefault(x => x.Id == input.PostId).Comments.Add(comment); } else if (input.PostId == 0) { this.db.Articles.FirstOrDefault(x => x.Id == input.ArticleId).Comments.Add(comment); } await this.db.SaveChangesAsync(); }
public async Task <IActionResult> Create(CreateCommentInputModel input) { var parentId = input.ParentId == 0 ? (int?)null : input.ParentId; if (parentId.HasValue) { if (!await this.commentsService.IsInMovieId(parentId.Value, input.MovieId)) { return(this.BadRequest()); } } var userId = this.userManager.GetUserId(this.User); try { await this.commentsService.Create(input.MovieId, userId, input.Content, parentId); } catch (ArgumentException aex) { return(this.BadRequest(aex.Message)); } return(this.RedirectToAction("Details", "Movies", new { id = input.MovieId })); }
public void CreateComment(CreateCommentInputModel createCommentInputModel) { var comment = new ProjectComment(createCommentInputModel.Content, createCommentInputModel.IdProject, createCommentInputModel.IdUser); _dbContext.ProjectComments.Add(comment); _dbContext.SaveChanges(); }
public async Task <IActionResult> Create(CreateCommentInputModel input) { var userId = this.userManager.GetUserId(this.User); await this.commentsService.Create(input.PostId, userId, input.Content, input.ParentId); return(this.RedirectToAction("ById", "Posts", new { id = input.PostId })); }
public async Task <IActionResult> Create(CreateCommentInputModel input) { if (this.ModelState.IsValid) { var parentId = input.ParentId == "0" ? null : input.ParentId; if (parentId != null) { if (!this.commentsService.IsInPostId(parentId, input.PostId)) { this.TempData["Error"] = ErrorMessages.DontMakeBullshits; return(this.RedirectToAction("Index", "Post", new { id = input.PostId })); } bool isParentApproved = await this.commentsService.IsParentCommentApproved(parentId); if (!isParentApproved) { this.TempData["Error"] = ErrorMessages.CannotCommentNotApprovedComment; return(this.RedirectToAction("Index", "Post", new { id = input.PostId })); } } var currentUser = await this.userManager.GetUserAsync(this.User); var isBlocked = this.commentsService.IsBlocked(currentUser); if (isBlocked) { this.TempData["Error"] = ErrorMessages.YouAreBlock; return(this.RedirectToAction("Index", "Post", new { id = input.PostId })); } var isInRole = await this.commentsService.IsInBlogRole(currentUser); if (!isInRole) { this.TempData["Error"] = string.Format(ErrorMessages.NotInBlogRoles, Roles.Contributor); return(this.RedirectToAction("Index", "Post", new { id = input.PostId })); } Post currentPost = await this.commentsService.ExtractCurrentPost(input.PostId); if (currentPost.PostStatus == PostStatus.Banned || currentPost.PostStatus == PostStatus.Pending) { this.TempData["Error"] = ErrorMessages.CannotCommentNotApprovedBlogPost; return(this.RedirectToAction("Index", "Post", new { id = input.PostId })); } var tuple = await this.commentsService .Create(input.PostId, currentUser, input.SanitizedContent, parentId); this.TempData[tuple.Item1] = tuple.Item2; return(this.RedirectToAction("Index", "Post", new { id = input.PostId })); } this.TempData["Error"] = ErrorMessages.InvalidInputModel; return(this.RedirectToAction("Index", "Blog")); }
public async Task AddComment_WithNoneExistingProduct_ShouldThrowException() { // Arrange var context = ApplicationDbContextInMemoryFactory.InitializeContext(); var groupRepository = new EfDeletableEntityRepository <Product_Group>(context); var productRepository = new EfDeletableEntityRepository <Product>(context); var fireplaceRepository = new EfDeletableEntityRepository <Fireplace_chamber>(context); var suggestItemsReposotory = new EfDeletableEntityRepository <SuggestProduct>(context); var commentsRepository = new EfDeletableEntityRepository <Comment>(context); var groupService = new GroupService(groupRepository); var prodcutService = new ProductService(productRepository, groupService); var cloudinaryService = new FakeCloudinary(); var sugestItemsRepositoryService = new SuggestProdcut(suggestItemsReposotory); var emailSender = new FakeEmailSender(); var fireplaceService = new FireplaceService(fireplaceRepository, groupService, prodcutService, cloudinaryService, sugestItemsRepositoryService); var commentServices = new CommentService(commentsRepository, prodcutService, fireplaceService, emailSender); var user = new ApplicationUser { Id = "abc", FirstName = "Nikolay", LastName = "Doychev", Email = "*****@*****.**", EmailConfirmed = true, }; var fileName = "Img"; IFormFile file = new FormFile( new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, fileName, "dummy.png"); var comment = new CreateCommentInputModel() { FullName = "Павлина Якимова", Email = "*****@*****.**", Content = "Тестов коментар", ProductId = "abc1", ProductName = "Тестово име", }; var seeder = new DbContextTestsSeeder(); await seeder.SeedUsersAsync(context); await seeder.SeedGroupAsync(context); await seeder.SeedProdcutAsync(context); await seeder.SeedFireplacesAsync(context); // Act AutoMapperConfig.RegisterMappings(typeof(CreateCommentInputModel).Assembly); await Assert.ThrowsAsync <ArgumentNullException>(() => commentServices.Create(comment)); }
public IActionResult Add(int id) { var model = new CreateCommentInputModel { ProductId = id, UserId = _userManager.GetUserId(User) }; return(this.View(model)); }
public async Task <IActionResult> CreateComment(CreateCommentInputModel inputModel, string newsId) { var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); if (this.ModelState.IsValid) { await this.commentsService.CreateCommentAsync(inputModel.Content, userId, newsId); } return(this.Redirect($"/News/ById?id={newsId}")); }
public async Task <IActionResult> Add(CreateCommentInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var id = await this.commentsService.Add(model); return(this.RedirectToAction("Details", new { id = id })); }
public async Task <IActionResult> Create(string postId) { var user = await this.userManager.GetUserAsync(this.User); var model = new CreateCommentInputModel { UserUserName = user.UserName, PostId = postId, }; return(this.View(model)); }
public async Task CreateAsync(CreateCommentInputModel model) { var comment = new Comment() { ArticleId = model.ArticleId, UserId = model.UserId, Content = model.Content, }; await this.commentRepository.AddAsync(comment); await this.commentRepository.SaveChangesAsync(); }
public async Task <IActionResult> Add(CreateCommentInputModel inputModel) { var comment = new Comment { AuthorId = inputModel.AuthorId, PostId = inputModel.PostId, Content = inputModel.Content, }; await this.comments.Save(comment); return(this.Ok()); }
public async Task <IActionResult> Create(int id, CreateCommentInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var user = await this.userManager.FindByNameAsync(this.User.Identity.Name); await this.commentsService.Create(id, user.Id, model.Content); return(this.RedirectToAction("Details", "Articles", new { id = id })); }
public async Task CreateAsync(CreateCommentInputModel input) { Comment comment = new Comment { Content = input.Content, PostId = input.PostId, AuthorId = input.AuthorId, }; await this.commentsRepository.AddAsync(comment); await this.commentsRepository.SaveChangesAsync(); }
public async Task <IActionResult> CreateComment(CreateCommentInputModel model) { if (!this.ModelState.IsValid) { return(this.NoContent()); } var userId = this.userManager.GetUserId(this.User); await this.newsFeedCommentService.CreateAsync(model.PostId, userId, model.Content, null); return(this.RedirectToAction("NewsFeedContent", "NewsFeed")); }
public async Task <IActionResult> Create(CreateCommentInputModel inputModel) { var userId = this.userManager.GetUserId(this.User); await this.commentsService.Create(inputModel.BeatId, userId, inputModel.Content); var targetId = this.beatsService.FindUserIdByBeatId(inputModel.BeatId); var beatName = this.beatsService.GetBeatNameByBeatId(inputModel.BeatId); await this.notificationsService.SendNotificationAsync(targetId, string.Format(GlobalConstants.CommentNotification, $"{this.User.Identity.Name}", $"{beatName}"), "Comment"); return(this.RedirectToAction("ByName", "Beats", new { id = inputModel.BeatId })); }
public async Task CreateMethodShouldAddCorrectNewCommentToDbAndToArticle() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var dbContext = new ApplicationDbContext(optionsBuilder.Options); var commentsService = new CommentsService(dbContext); var comment = new Comment { UserUsername = "******", Content = "testContent", UserId = "Icaka99", }; var commentList = new List <Comment>(); commentList.Add(comment); var article = new Article { Id = 1, Comments = commentList, }; await dbContext.Articles.AddAsync(article); var user = new ApplicationUser { Id = "Icaka99", UserName = "******", }; await dbContext.Users.AddAsync(user); var commentToAdd = new CreateCommentInputModel { ArticleId = 1, PostId = 1, Content = "testContent", UserId = "Icaka99", UserUserName = "******", }; await commentsService.Create(commentToAdd); Assert.NotNull(dbContext.Comments.FirstOrDefaultAsync()); Assert.Equal("testContent", dbContext.Comments.FirstAsync().Result.Content); Assert.Equal("Icaka99", dbContext.Comments.FirstAsync().Result.UserId); Assert.Equal("Icaka99", dbContext.Comments.FirstAsync().Result.UserUsername); }
public async Task <IActionResult> Create(CreateCommentInputModel model) { if (!this.articlesService.ArticleExist(model.ArticleId)) { return(this.NotFound()); } var user = await this.userManager.GetUserAsync(this.User); model.UserId = user.Id; await this.commentsService.CreateAsync(model); return(this.RedirectToAction("Index", "Articles", new { id = model.ArticleId })); }
public async Task IsInArticleMethodShouldReturnTrueIfCommentIsInArticle() { var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var dbContext = new ApplicationDbContext(optionsBuilder.Options); var commentsService = new CommentsService(dbContext); var comment = new Comment { UserUsername = "******", Content = "testContent", UserId = "Icaka99", }; var commentList = new List <Comment>(); commentList.Add(comment); var article = new Article { Id = 1, Comments = commentList, }; await dbContext.Articles.AddAsync(article); var user = new ApplicationUser { Id = "Icaka99", UserName = "******", }; await dbContext.Users.AddAsync(user); var commentToAdd = new CreateCommentInputModel { ArticleId = 1, PostId = 1, Content = "testContent", UserId = "Icaka99", UserUserName = "******", }; await commentsService.Create(commentToAdd); var result = commentsService.IsInArticle(1, 1); Assert.True(result); }
public ActionResult Create(CreateCommentInputModel inputModel) { if (inputModel != null && this.ModelState.IsValid) { var authorId = this.User.Identity.GetUserId(); this.commentsData.AddCommentForPost(inputModel.PostId, inputModel.Content, authorId); // TODO: Extract Controller extension method JsonSuccess return this.Json(new { Message = "success" }); } // TODO: Extract Controller extension method JsonError return this.Json(new { Message = "error" }); }
public ActionResult CreateComment(int postId, bool isValidComment = true) { if (User.Identity.IsAuthenticated) { if (isValidComment == false) { ViewBag.Comment = "Invalid"; } var commentModel = new CreateCommentInputModel { PostId = postId }; return this.PartialView("_CreateCommentPartialView", commentModel); } return this.PartialView("_CommentsLoginPartialView", postId); }
public async Task <Comment> CreateComment(CreateCommentInputModel input) { var comment = new Comment { Content = input.Content, PostId = input.PostId, UserId = input.UserId, }; await this.commentsRepository.AddAsync(comment); await this.commentsRepository.SaveChangesAsync(); return(comment); }
public ActionResult CreateComment(CreateCommentInputModel inputComment) { if (ModelState.IsValid) { var currentUserId = this.User.Identity.GetUserId(); string content = HttpUtility.HtmlDecode(inputComment.Content); var comment = new Comment { Content = content, PostId = inputComment.PostId, AuthorId = currentUserId }; this.comments.Add(comment); this.comments.SaveChanges(); return this.RedirectToAction("CreateComment", new { postId = inputComment.PostId }); } return this.RedirectToAction("CreateComment", new { postId = inputComment.PostId, isValidComment = false }); }
public ActionResult Create(int id, CreateCommentInputModel commentInputModel) { if (this.ModelState.IsValid) { var comment = new Comment { PostId = id, Content = commentInputModel.Content, User = this.UserProfile, UserId = this.UserProfile.Id }; this.Data.Comments.Add(comment); this.Data.SaveChanges(); return this.RedirectToAction("Index", "Post", new { id = id }); } return this.Content("Content is required"); }