Get all posts

This commit is contained in:
Robert Marshall 2020-04-10 13:10:38 +01:00
parent 2c7ccae412
commit d2080679fd
3 changed files with 13 additions and 3 deletions

View file

@ -223,5 +223,15 @@ namespace Robware.Api.Blog.Tests {
var controller = new BlogController(logger, repo); var controller = new BlogController(logger, repo);
(await controller.SavePost(submission)).Should().BeOfType<BadRequestObjectResult>(); (await controller.SavePost(submission)).Should().BeOfType<BadRequestObjectResult>();
} }
[Fact]
public async Task GetAllPosts_ReturnsBlogPostCollection() {
var logger = Substitute.For<ILogger<BlogController>>();
var repo = Substitute.For<IBlogRepository>();
repo.GetAllPostsAsync().Returns(new BlogPost[10]);
var controller = new BlogController(logger, repo);
(await controller.GetAllPosts()).Value.Should().BeEquivalentTo(new BlogPost[10]);
}
} }
} }

View file

@ -97,8 +97,8 @@ namespace Robware.Api.Blog.Controllers {
} }
} }
//[HttpGet] [HttpGet(nameof(GetAllPosts))]
//Task<IEnumerable<BlogPost>> GetAllPosts(); public async Task<ActionResult<BlogPost[]>> GetAllPosts() => (await _blogRepository.GetAllPostsAsync()).ToArray();
//[HttpGet] //[HttpGet]
//Task DeletePost(int id); //Task DeletePost(int id);

View file

@ -90,7 +90,7 @@ namespace Robware.Data
using (var connection = _dbProvider.NewConnection()) { using (var connection = _dbProvider.NewConnection()) {
connection.Open(); connection.Open();
var result = await DoQuery<BlogPostState>(connection, query); var result = await connection.QueryAsync<BlogPostState>(query);
return result.Select(MapBlogPost); return result.Select(MapBlogPost);
} }
} }