public async Task MentionUser_Duplicate_Test() { string user1 = "UnitTestUser05"; string user2 = "UnitTestUser06"; var user = TestHelper.SetPrincipal(user1); string mentionTwiceContent = $"Hello @{user2}, I am mentioning you twice using two different forms ok. So here: /u/{user2} ha ha"; var cmd = new CreateCommentCommand(submission.ID, null, mentionTwiceContent).SetUserContext(user); var result = await cmd.Execute(); Assert.IsTrue(result.Success, result.Message); using (var db = new VoatDataContext()) { var count = db.Message.Where(x => x.Sender == user1 && x.Recipient == user2 && x.CommentID == result.Response.ID).Count(); Assert.AreEqual(1, count, "Received duplicates and now users are annoyed and burning down the village! Run!"); } //change casing test user = TestHelper.SetPrincipal(user2); mentionTwiceContent = $"Hello @{user1.ToLower()}, I am mentioning you twice using two different forms ok. So here: /u/{user1.ToUpper()} ha ha"; cmd = new CreateCommentCommand(submission.ID, null, mentionTwiceContent).SetUserContext(user); result = await cmd.Execute(); Assert.IsTrue(result.Success, result.Message); using (var db = new VoatDataContext()) { var count = db.Message.Where(x => x.Sender == user2 && x.Recipient == user1 && x.CommentID == result.Response.ID).Count(); Assert.AreEqual(1, count, "Received duplicates and now users are annoyed and burning down the village! Run!"); } }
public async Task Handler_ShouldAddComment() { // Arrange var comment = new CommentDTO { Id = 7, PostId = 1, Text = "Comment_test", AuthorId = 1, Date = new DateTime(2020, 03, 01), }; var command = new CreateCommentCommand { Model = comment }; // Act var handler = new CreateCommentCommand.CreateCommentCommandHandler(Mapper, Context); await handler.Handle(command, CancellationToken.None); var entity = Context.Comments.Find(comment.Id); // Assert entity.ShouldNotBeNull(); entity.Id.ShouldBe(command.Model.Id); entity.PostId.ShouldBe(command.Model.PostId); entity.Text.ShouldBe(command.Model.Text); entity.AuthorId.ShouldBe(command.Model.AuthorId); entity.Date.ShouldBe(command.Model.Date); }
public async Task <IActionResult> PostComment(int id, [FromBody] CreateCommentCommand command) { //_projectService.CreateComment(inputModel); await _mediator.Send(command); return(NoContent()); }
public async Task <ActionResult <CommentDetailVm> > Create([FromBody] CreateCommentCommand command) { var res = await Mediator.Send(command); return(Ok(await Mediator.Send(new GetCommentDetailQuery { Id = res }))); }
public async Task SendComment(CreateCommentCommand command) { command.Username = GetUsername(); var comment = await this.mediator.Send(command); await Clients.Group($"{command.ActivityId}").SendAsync("ReceiveComment", comment); }
public async Task SendCommentAsync(CreateCommentCommand command) { string username = _userAccessor.GetCurrentUsername(); command.Username = username; var comment = await _mediator.Send(command); await Clients.Group(command.PhotoId).SendAsync("ReceiveCommentAsync", comment); }