Delete a post

This commit is contained in:
Robert Marshall 2020-04-10 13:16:44 +01:00
parent d2080679fd
commit 0d29e9494a
2 changed files with 15 additions and 2 deletions

View file

@ -233,5 +233,15 @@ namespace Robware.Api.Blog.Tests {
var controller = new BlogController(logger, repo); var controller = new BlogController(logger, repo);
(await controller.GetAllPosts()).Value.Should().BeEquivalentTo(new BlogPost[10]); (await controller.GetAllPosts()).Value.Should().BeEquivalentTo(new BlogPost[10]);
} }
[Fact]
public async Task DeletePost_WithId_Returns200() {
var logger = Substitute.For<ILogger<BlogController>>();
var repo = Substitute.For<IBlogRepository>();
var controller = new BlogController(logger, repo);
(await controller.DeletePost(1)).Should().BeOfType<OkResult>();
await repo.Received(1).DeletePostAsync(1);
}
} }
} }

View file

@ -100,7 +100,10 @@ namespace Robware.Api.Blog.Controllers {
[HttpGet(nameof(GetAllPosts))] [HttpGet(nameof(GetAllPosts))]
public async Task<ActionResult<BlogPost[]>> GetAllPosts() => (await _blogRepository.GetAllPostsAsync()).ToArray(); public async Task<ActionResult<BlogPost[]>> GetAllPosts() => (await _blogRepository.GetAllPostsAsync()).ToArray();
//[HttpGet] [HttpPost(nameof(DeletePost))]
//Task DeletePost(int id); public async Task<ActionResult> DeletePost([FromBody] int id) {
await _blogRepository.DeletePostAsync(id);
return Ok();
}
} }
} }