예제 #1
0
        public async Task GetArticleAsync_ReturnsBadRequestResultWhenIdIsNull()
        {
            var controller = new ArticlesController(_articleServiceMock.Object);

            var result = await controller.GetArticleAsync(null);

            Assert.IsType <BadRequestObjectResult>(result.Result);
        }
예제 #2
0
        public async Task GetArticleAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _articleDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new Exception());
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetArticleAsync("1");

            await result.Should().ThrowExactlyAsync <Exception>();
        }
예제 #3
0
        public async Task GetArticleAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string id)
        {
            _articleDbServiceMock.Setup(x => x.GetAsync(id)).ThrowsAsync(new ArgumentException());
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetArticleAsync(id);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
예제 #4
0
        public async Task GetArticleAsync__Element_not_found__Should_return_404NotFound_response_with_error()
        {
            _articleDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ThrowsAsync(new InvalidOperationException());
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetArticleAsync("1");

            (result as ObjectResult).StatusCode.Should().Be(404);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
예제 #5
0
        public async Task GetArticleAsync__An_internal_error_reffered_to_the_database_occurred__Should_throw_InternalDbServiceException()
        {
            // Example of these errors: database does not exist, table does not exist etc.

            _articleDbServiceMock.Setup(x => x.GetAsync(It.IsAny <string>())).ThrowsAsync(new InternalDbServiceException());
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

            Func <Task> result = async() => await controller.GetArticleAsync("1");

            await result.Should().ThrowExactlyAsync <InternalDbServiceException>();
        }
예제 #6
0
        public async Task GetArticleAsync__Data_retrieve_succeeded__Should_return_200Ok_response_with_data()
        {
            string id = "15891fb0-faec-43c6-9e83-04a4a17c3660";

            _articleDbServiceMock.Setup(x => x.GetAsync(It.IsNotNull <string>())).ReturnsAsync(_validArticle);
            _mapperMock.Setup(x => x.Map <ArticleDto>(It.IsNotNull <Article>())).Returns(new ArticleDto {
                Id = id, Title = "new mapped Article"
            });
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.GetArticleAsync(id);

            (result as ObjectResult).StatusCode.Should().Be(200);
            ((result as ObjectResult).Value as ResponseWrapper).Data.Should().NotBeNull();
        }
예제 #7
0
        public async Task GetArticleAsync_ReturnsAActionResultWithAArticle()
        {
            string testArticleId = "1";
            var    article       = GetFaceArticles().FirstOrDefault(art => art.Id == testArticleId);

            _articleServiceMock.Setup(services => services.GetByIdAsync(testArticleId)).
            ReturnsAsync(article);

            var controller = new ArticlesController(_articleServiceMock.Object);

            var result = await controller.GetArticleAsync(testArticleId);

            var actionResult = Assert.IsType <ActionResult <Article> >(result);
            var returnValue  = Assert.IsType <Article>(actionResult.Value);

            Assert.Equal(article.Text, returnValue.Text);
            Assert.Equal(article.Title, returnValue.Title);
            Assert.Equal(testArticleId, returnValue.Id);
        }