Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .anima/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cache
7 changes: 5 additions & 2 deletions MyFirstBlog.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

Microsoft Visual Studio Solution File, Format Version 12.00
#
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyFirstBlog", "MyFirstBlog\MyFirstBlog.csproj", "{BB64A02C-C5D9-4D64-A357-7322C54B1419}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyFirstBlogTests", "MyFirstBlogTests\MyFirstBlogTests.csproj", "{84D99732-A7E9-4E69-B5C7-7DFAFE9815B7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -18,5 +17,9 @@ Global
{84D99732-A7E9-4E69-B5C7-7DFAFE9815B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84D99732-A7E9-4E69-B5C7-7DFAFE9815B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84D99732-A7E9-4E69-B5C7-7DFAFE9815B7}.Release|Any CPU.Build.0 = Release|Any CPU
{29489431-06DB-46F2-96A1-0965F8BF8E6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{29489431-06DB-46F2-96A1-0965F8BF8E6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{29489431-06DB-46F2-96A1-0965F8BF8E6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{29489431-06DB-46F2-96A1-0965F8BF8E6A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
22 changes: 22 additions & 0 deletions MyFirstBlog/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Mvc;
using MyFirstBlog.Models;

namespace MyFirstBlog.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class PostsController : ControllerBase
{
[HttpPost]
public IActionResult CreatePost([FromBody] PostDto postDto)
{
if (string.IsNullOrWhiteSpace(postDto.Title))
{
return BadRequest(new { errors = new[] { "Title cannot be blank" } });
}

var post = new { title = postDto.Title, description = postDto.Description };
return CreatedAtAction(nameof(CreatePost), new { post });
}
}
}
5 changes: 3 additions & 2 deletions MyFirstBlog/Controllers/PostsController.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace MyFirstBlog.Controllers;
/* namespace MyFirstBlog.Controllers;

using Microsoft.AspNetCore.Mvc;
using MyFirstBlog.Dtos;
using MyFirstBlog.Services;

[ApiController]
[ApiController]
[Route("posts")]

public class PostsController : ControllerBase {
Expand Down Expand Up @@ -32,3 +32,4 @@ public ActionResult<PostDto> GetPost(string slug) {
return post;
}
}
*/
8 changes: 8 additions & 0 deletions MyFirstBlog/Models/PostDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace MyFirstBlog.Models
{
public class PostDto
{
public string Title { get; set; }
public string Description { get; set; }
}
}
4 changes: 4 additions & 0 deletions MyFirstBlog/MyFirstBlog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions MyFirstBlog/Tests/PostControllerTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MyFirstBlog.Controllers;
using MyFirstBlog.Models;
using Microsoft.AspNetCore.Mvc;

namespace MyFirstBlog.Tests;

[TestClass]
public class PostsControllerTests
{
[TestMethod]
public void CreatePost_ShouldReturn201_WhenPostIsValid()
{
var controller = new PostsController();
var result = controller.CreatePost(new PostDto { Title = "Test Title", Description = "Test Description" });

Assert.IsInstanceOfType(result, typeof(CreatedAtActionResult));
}

[TestMethod]
public void CreatePost_ShouldReturn400_WhenTitleIsBlank()
{
var controller = new PostsController();
var result = controller.CreatePost(new PostDto { Title = "", Description = "Test Description" });

Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));
}
}
16 changes: 0 additions & 16 deletions MyFirstBlogTests/MyFirstBlogTests.csproj

This file was deleted.

18 changes: 0 additions & 18 deletions MyFirstBlogTests/UnitTest1.cs

This file was deleted.