Exemplo n.º 1
0
        public async Task DeleteArticleAsync__An_unexpected_internal_error_occurred__Should_throw_Exception()
        {
            _articleDbServiceMock.Setup(x => x.DeleteAsync(It.IsAny <string>())).ThrowsAsync(new Exception());
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

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

            await result.Should().ThrowExactlyAsync <Exception>();
        }
Exemplo n.º 2
0
        public async Task DeleteArticleAsync__Delete_succeeded__Should_return_200OK_response()
        {
            _articleDbServiceMock.Setup(x => x.DeleteAsync(It.IsNotNull <string>()));
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

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

            (result as ObjectResult).StatusCode.Should().Be(200);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().BeEquivalentTo(new ApiError());
        }
Exemplo n.º 3
0
        public async Task DeleteArticleAsync__Argument_id_is_null_or_empty__Should_return_400BadRequest_response([Values(null, "")] string id)
        {
            _articleDbServiceMock.Setup(x => x.DeleteAsync(id)).ThrowsAsync(new ArgumentException());
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.DeleteArticleAsync(id);

            (result as ObjectResult).StatusCode.Should().Be(400);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }
Exemplo n.º 4
0
        public async Task DeleteArticleAsync__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.DeleteAsync(It.IsAny <string>())).ThrowsAsync(new InternalDbServiceException());
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

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

            await result.Should().ThrowExactlyAsync <InternalDbServiceException>();
        }
Exemplo n.º 5
0
        public async Task DeleteArticleAsync__Element_not_found__Should_return_404NotFound_response_with_error()
        {
            string id = "-1";

            _articleDbServiceMock.Setup(x => x.DeleteAsync(id)).ThrowsAsync(new InvalidOperationException());
            var controller = new ArticlesController(_articleDbServiceMock.Object, _logger, _mapperMock.Object);

            var result = await controller.DeleteArticleAsync(id);

            (result as ObjectResult).StatusCode.Should().Be(404);
            ((result as ObjectResult).Value as ResponseWrapper).Error.Should().NotBeNull();
        }