public void GetPostReaction_ReturnsOkObjectResult_WithReactionData() { //Arrange var reaction = GetTestPostData().ElementAt(0); _mockPostService.Setup(Service => Service.CheckIfPostExists(It.IsAny <Guid>())) .Returns(true) .Verifiable(); _mockReactionService.Setup(Service => Service.GetPostReaction(It.IsAny <Guid>())) .Returns(reaction) .Verifiable(); var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = controller.GetPostReaction(ConstIds.ExamplePostId, ConstIds.ExampleReactionId); //Assert var actionResult = Assert.IsType <OkObjectResult>(result.Result); var model = Assert.IsType <PostReactionDto>(actionResult.Value); Assert.Equal(reaction, model); _mockPostService.Verify(); _mockReactionService.Verify(); }
public async void AddPostReaction_ReturnsCreatedAtRouteResult_WithReactionData() { //Arrange _mockPostService.Setup(Service => Service.CheckIfPostExists(It.IsAny <Guid>())) .Returns(true) .Verifiable(); _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>())) .ReturnsAsync(true) .Verifiable(); PostReactionDto reactionEntity = _mapper.Map <PostReactionDto>(_postReactionToAdd); reactionEntity.Id = new Guid(ConstIds.ExampleReactionId); reactionEntity.PostId = new Guid(ConstIds.ExamplePostId); _mockReactionService.Setup(Service => Service.AddPostReactionAsync(It.IsAny <Guid>(), It.IsAny <PostReactionToAddDto>())) .ReturnsAsync(reactionEntity) .Verifiable(); var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = await controller.AddPostReaction(ConstIds.ExampleUserId, ConstIds.ExamplePostId, _postReactionToAdd); //Assert var redirectToActionResult = Assert.IsType <CreatedAtRouteResult>(result.Result); Assert.Equal(ConstIds.ExampleUserId, redirectToActionResult.RouteValues["userId"].ToString()); Assert.Equal(ConstIds.ExamplePostId, redirectToActionResult.RouteValues["postId"].ToString()); Assert.Equal(ConstIds.ExampleReactionId, redirectToActionResult.RouteValues["reactionId"].ToString()); Assert.Equal("GetReaction", redirectToActionResult.RouteName); _mockUserService.Verify(); _mockReactionService.Verify(); _mockPostService.Verify(); }
public async void DeletePostReaction_ReturnsNotFoundResult_WhenTheUserOrPostDoesntyExist(bool doesTheUserExists, bool doesThePostExists) { //Arrange _mockPostService.Setup(Service => Service.CheckIfPostExists(It.IsAny <Guid>())) .Returns(doesThePostExists) .Verifiable(); _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>())) .ReturnsAsync(doesTheUserExists) .Verifiable(); var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = await controller.DeletePostReaction(ConstIds.ExamplePostId, ConstIds.ExampleFromWhoId); //Assert var notFoundObjectResult = Assert.IsType <NotFoundObjectResult>(result); Assert.Equal($"User: {ConstIds.ExampleFromWhoId} or post {ConstIds.ExamplePostId} not found.", notFoundObjectResult.Value); _mockPostService.Verify(); //if post doesnt exist the user will not be checked if (doesThePostExists) { _mockUserService.Verify(); } }
public void GetPostReaction_ReturnsBadRequestObjectResult_WhenThePostOrReactionIdIsInvalid(string testPostId, string testReactionId) { //Arrange var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = controller.GetPostReaction(testPostId, testReactionId); //Assert var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result.Result); Assert.Equal($"{testPostId} or {testReactionId} is not valid guid.", badRequestObjectResult.Value); }
public async void DeletePostReaction_ReturnsBadRequestObjectResult_WhenThePostOrUserIdIsInvalid(string userTestId, string postTestId) { //Arrange var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = await controller.DeletePostReaction(postTestId, userTestId); //Assert var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result); Assert.Equal($"{userTestId} or {postTestId} is not valid guid.", badRequestObjectResult.Value); }
public async void PartiallyUpdatePostReaction_ReturnsBadRequestObjectResult_WhenTheReactionIdIsInvalid() { //Arrange var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = await controller.PartiallyUpdatePostReaction(ConstIds.InvalidGuid, GetJsonPatchDocument()); //Assert var badRequestObjectResult = Assert.IsType <BadRequestObjectResult>(result); Assert.Equal($"{ConstIds.InvalidGuid} is not valid guid.", badRequestObjectResult.Value); }
public async void DeletePostReaction_ReturnsInternalServerErrorResult_WhenExceptionThrownInService() { //Arrange _mockPostService.Setup(Service => Service.CheckIfPostExists(It.IsAny <Guid>())) .Throws(new ArgumentNullException(nameof(Guid))) .Verifiable(); var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = await controller.DeletePostReaction(ConstIds.ExampleReactionId, ConstIds.ExampleFromWhoId); //Assert var internalServerErrorResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal(StatusCodes.Status500InternalServerError, internalServerErrorResult.StatusCode); _mockPostService.Verify(); }
public void GetPostReactions_ReturnsNotFoundObjectResult_WhenThePostDoesntExist() { //Arrange _mockPostService.Setup(Service => Service.CheckIfPostExists(It.IsAny <Guid>())) .Returns(false) .Verifiable(); var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = controller.GetPostReactions(ConstIds.ExamplePostId); //Assert var notFoundResult = Assert.IsType <NotFoundObjectResult>(result.Result); Assert.Equal($"Post: {ConstIds.ExamplePostId} doesnt exists.", notFoundResult.Value); _mockPostService.Verify(); }
public async void PartiallyUpdatePostReaction_ReturnsBadRequestResult_WhenTheReactionHasNotBeenUpdated() { //Arrange _mockReactionService.Setup(Service => Service.TryUpdatePostReactionAsync(It.IsAny <Guid>(), It.IsAny <JsonPatchDocument <PostReactionToUpdateDto> >())) .ReturnsAsync(false) .Verifiable(); var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = await controller.PartiallyUpdatePostReaction(ConstIds.ExampleReactionId, GetJsonPatchDocument()); //Assert var badRequestResult = Assert.IsType <BadRequestResult>(result); _mockReactionService.Verify(); }
public async void PartiallyUpdatePostReaction_ReturnsInternalServerErrorResult_WhenExceptionThrownInService() { //Arrange _mockReactionService.Setup(Service => Service.TryUpdatePostReactionAsync(It.IsAny <Guid>(), It.IsAny <JsonPatchDocument <PostReactionToUpdateDto> >())) .Throws(new ArgumentNullException(nameof(Guid))) .Verifiable(); var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = await controller.PartiallyUpdatePostReaction(ConstIds.ExampleReactionId, GetJsonPatchDocument()); //Assert var internalServerErrorResult = Assert.IsType <StatusCodeResult>(result); Assert.Equal(StatusCodes.Status500InternalServerError, internalServerErrorResult.StatusCode); _mockReactionService.Verify(); }
public async void DeletePostReaction_ReturnsNoContentResult_WhenThePostHasBeenRemoved() { //Arrange _mockPostService.Setup(Service => Service.CheckIfPostExists(It.IsAny <Guid>())) .Returns(true) .Verifiable(); _mockUserService.Setup(Service => Service.CheckIfUserExists(It.IsAny <Guid>())) .ReturnsAsync(true) .Verifiable(); _mockReactionService.Setup(Service => Service.DeletePostReactionAsync(It.IsAny <Guid>(), It.IsAny <Guid>())) .Verifiable(); var controller = new PostReactionsController(_loggerMock.Object, _mockPostService.Object, _mockUserService.Object, _mockReactionService.Object); //Act var result = await controller.DeletePostReaction(ConstIds.ExampleReactionId, ConstIds.ExampleFromWhoId); //Act var noContentResult = Assert.IsType <NoContentResult>(result); _mockPostService.Verify(); _mockUserService.Verify(); _mockReactionService.Verify(); }