public async Task Should_Put_A_Like_To_A_Post() { Result likeResult; var author = new User((Nickname)"author2", (FullName)"author two", Password.Create("password").Value, (Email)"*****@*****.**", "my bio"); var reader = new User((Nickname)"reader1", (FullName)"reader one", Password.Create("password").Value, (Email)"*****@*****.**", "my bio"); var post = new Post(author, (Picture)Convert.FromBase64String(DatabaseFixture.GetTestPictureBase64()), (PostText)"test post"); using (var session = _testFixture.OpenSession(_output)) { await session.SaveAsync(author); await session.SaveAsync(reader); await session.SaveAsync(post); } var command = new LikePostCommand(post.ID, reader.ID); using (var session = _testFixture.OpenSession(_output)) { var sut = new LikeOrDislikePostCommandHandler(session, Log.Logger); likeResult = await sut.Handle(command, default); } using (new AssertionScope()) { likeResult.IsSuccess.Should().BeTrue(); using (var session = _testFixture.OpenSession(_output)) { (await session.GetAsync <Post>(post.ID)).Likes.Count().Should().Be(1); } } }
public async Task Cannot_Like_A_Post_Twice() { Result likeResult; var author = new User((Nickname)"author5", (FullName)"author five", Password.Create("password").Value, (Email)"*****@*****.**", "my bio"); var reader = new User((Nickname)"reader4", (FullName)"reader four", Password.Create("password").Value, (Email)"*****@*****.**", "my bio"); var post = new Post(author, (Picture)Convert.FromBase64String(DatabaseFixture.GetTestPictureBase64()), (PostText)"test post"); using (var session = _testFixture.OpenSession(_output)) { await session.SaveAsync(author); await session.SaveAsync(reader); await session.SaveAsync(post); } var command = new LikePostCommand(post.ID, reader.ID); using (var session = _testFixture.OpenSession(_output)) { var sut = new LikeOrDislikePostCommandHandler(session, Log.Logger); await sut.Handle(command, default); likeResult = await sut.Handle(command, default); } likeResult.IsSuccess.Should().BeFalse($"User [{reader.Nickname}] already 'Liked' this post."); }
public async Task <IActionResult> Like(LikePostModel like) { var command = new LikePostCommand(like.PostID, like.UserID); var commandResult = await _dispatcher.Send(command); if (commandResult.IsSuccess) { var postLikedNotification = new PostLikedEvent( User.Identity.Name, Url.Action("Profile", "Account", new { id = User.Identity.Name }), like.PostID, Url.Action("Detail", "Post", new { id = like.PostID }) ); await _dispatcher.Publish(postLikedNotification); } return(commandResult.IsSuccess ? Ok() : StatusCode(StatusCodes.Status500InternalServerError)); }
public async Task Author_Cannot_Put_Likes_On_Their_Own_Posts() { Result likeResult; var author = new User((Nickname)"author6", (FullName)"author six", Password.Create("password").Value, (Email)"*****@*****.**", "my bio"); var post = new Post(author, (Picture)Convert.FromBase64String(DatabaseFixture.GetTestPictureBase64()), (PostText)"test post"); using (var session = _testFixture.OpenSession(_output)) { await session.SaveAsync(author); await session.SaveAsync(post); } var command = new LikePostCommand(post.ID, author.ID); using (var session = _testFixture.OpenSession(_output)) { var sut = new LikeOrDislikePostCommandHandler(session, Log.Logger); likeResult = await sut.Handle(command, default); } likeResult.IsSuccess.Should().BeFalse("You cannot put a 'Like' on your own posts."); }
public void LikePost(int id) { LikePostCommand.Execute(new { Id = id }); }
public async Task <ActionResult <int> > Like(LikePostCommand command) { return(await Mediator.Send(command)); }