public async Task Get_ById_When_Called_Should_Return_OkObjectResult()
        {
            commentServiceMock.Setup(x => x.GetArticleComments(It.IsAny <int>())).Returns(MockData.TestArticleCommentsMock());
            int id     = 1;
            var result = await commentController.Get(id) as OkObjectResult;

            result.Should().BeOfType <OkObjectResult>().Which.StatusCode.Should().Be(200);
        }
        public void GetAll_Returns_All_Comments_For_Given_Todo()
        {
            var reviewId      = 42;
            var expectedModel = new List <Comment>();
            var commentRepo   = Substitute.For <ICommentRepository>();

            commentRepo.GetCommentsForReviewId(reviewId).Returns(expectedModel);
            var underTest = new CommentController(commentRepo);

            var model = underTest.Get(reviewId);

            Assert.Same(expectedModel, model);
        }
        public void CountComments_AllComments_TwoCommentsReturned()
        {
            // arrange
            var mock = new Mock <ICommentService>();

            mock.Setup(r => r.GetComments());
            var controller = new CommentController(mock.Object);

            // act
            var res = controller.Get();

            // assert

            Assert.AreEqual(res, 2);
        }
Beispiel #4
0
        public async void Get_Not_Exists()
        {
            CommentControllerMockFacade mock = new CommentControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult <ApiCommentServerResponseModel>(null));
            CommentController controller = new CommentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <StatusCodeResult>();
            (response as StatusCodeResult).StatusCode.Should().Be((int)HttpStatusCode.NotFound);
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }
Beispiel #5
0
        public async void Get_Exists()
        {
            CommentControllerMockFacade mock = new CommentControllerMockFacade();

            mock.ServiceMock.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new ApiCommentResponseModel()));
            CommentController controller = new CommentController(mock.ApiSettingsMoc.Object, mock.LoggerMock.Object, mock.TransactionCoordinatorMock.Object, mock.ServiceMock.Object, mock.ModelMapperMock.Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            IActionResult response = await controller.Get(default(int));

            response.Should().BeOfType <OkObjectResult>();
            (response as OkObjectResult).StatusCode.Should().Be((int)HttpStatusCode.OK);
            var record = (response as OkObjectResult).Value as ApiCommentResponseModel;

            record.Should().NotBeNull();
            mock.ServiceMock.Verify(x => x.Get(It.IsAny <int>()));
        }