public async Task CommentPost_ModelStateIsNotValid_ReturnJsonResultWithJsonResultModelAndModelStateIsNotValidStatusCode() { _controller.ModelState.AddModelError(nameof(PostCommentFormViewModel.PostId), "Error"); var result = await _controller.CommentPost(new PostCommentFormViewModel()); result.Should().BeOfType <JsonResult>(); var jsonResult = result as JsonResult; jsonResult?.Value.Should().BeOfType <JsonResultModel>(); if (jsonResult != null) { var jsonResultModel = jsonResult.Value as JsonResultModel; jsonResultModel?.StatusCode .Should().Be(JsonResultStatusCode.ModelStateIsNotValid); } }