diff --git a/CleanAspCore.Api.Tests/Features/Employees/DeleteEmployeeByIdTests.cs b/CleanAspCore.Api.Tests/Features/Employees/DeleteEmployeeByIdTests.cs index 17e6adf..5740839 100644 --- a/CleanAspCore.Api.Tests/Features/Employees/DeleteEmployeeByIdTests.cs +++ b/CleanAspCore.Api.Tests/Features/Employees/DeleteEmployeeByIdTests.cs @@ -19,7 +19,7 @@ public async Task DeleteEmployeeById_IsDeleted() var response = await Sut.CreateClientFor().DeleteEmployeeById(employee.Id); //Assert - await response.AssertStatusCode(HttpStatusCode.OK); + await response.AssertStatusCode(HttpStatusCode.NoContent); Sut.AssertDatabase(context => { context.Employees.Should().BeEmpty(); }); } diff --git a/CleanAspCore.Api.Tests/HttpAssertionExtensions.cs b/CleanAspCore.Api.Tests/HttpAssertionExtensions.cs index 07e1858..76e43e2 100644 --- a/CleanAspCore.Api.Tests/HttpAssertionExtensions.cs +++ b/CleanAspCore.Api.Tests/HttpAssertionExtensions.cs @@ -31,6 +31,7 @@ public static async Task AssertStatusCode(this HttpResponseMessage response, Htt public static async Task AssertJsonBodyIsEquivalentTo(this HttpResponseMessage response, T expected) { + using var scope = new AssertionScope(); response.Content.Headers.ContentType.Should().NotBeNull(); response.Content.Headers.ContentType!.MediaType.Should().Be("application/json"); response.Content.Headers.ContentType!.CharSet.Should().Be("utf-8"); diff --git a/CleanAspCore/Features/Departments/Endpoints/GetDepartmentById.cs b/CleanAspCore/Features/Departments/Endpoints/GetDepartmentById.cs index 5fd3a96..a1bdb32 100644 --- a/CleanAspCore/Features/Departments/Endpoints/GetDepartmentById.cs +++ b/CleanAspCore/Features/Departments/Endpoints/GetDepartmentById.cs @@ -5,7 +5,12 @@ namespace CleanAspCore.Features.Departments.Endpoints; -public sealed record DepartmentDto(Guid Id, string Name, string City); +public sealed class DepartmentDto +{ + public required Guid Id { get; init; } + public required string Name { get; init; } + public required string City { get; init; } +} internal static class GetDepartmentById { @@ -19,10 +24,10 @@ internal static async Task> Handle(Guid id, HrContext context, return TypedResults.Ok(department); } - private static DepartmentDto ToDto(this Department department) => new - ( - department.Id, - department.Name, - department.City - ); + private static DepartmentDto ToDto(this Department department) => new() + { + Id = department.Id, + Name = department.Name, + City = department.City + }; } diff --git a/CleanAspCore/Features/Employees/Endpoints/DeleteEmployeeById.cs b/CleanAspCore/Features/Employees/Endpoints/DeleteEmployeeById.cs index a2d43ea..a1f127c 100644 --- a/CleanAspCore/Features/Employees/Endpoints/DeleteEmployeeById.cs +++ b/CleanAspCore/Features/Employees/Endpoints/DeleteEmployeeById.cs @@ -6,7 +6,7 @@ namespace CleanAspCore.Features.Employees.Endpoints; internal static class DeleteEmployeeById { - internal static async Task> Handle(Guid id, HrContext context, CancellationToken cancellationToken) + internal static async Task> Handle(Guid id, HrContext context, CancellationToken cancellationToken) { var result = await context.Employees .Where(x => x.Id == id) @@ -14,7 +14,7 @@ internal static async Task> Handle(Guid id, HrContext cont return result switch { - 1 => TypedResults.Ok(), + 1 => TypedResults.NoContent(), _ => TypedResults.NotFound() }; } diff --git a/CleanAspCore/Features/Employees/Endpoints/GetEmployeeById.cs b/CleanAspCore/Features/Employees/Endpoints/GetEmployeeById.cs index 2c4260a..befa147 100644 --- a/CleanAspCore/Features/Employees/Endpoints/GetEmployeeById.cs +++ b/CleanAspCore/Features/Employees/Endpoints/GetEmployeeById.cs @@ -5,11 +5,20 @@ namespace CleanAspCore.Features.Employees.Endpoints; -public sealed record EmployeeDto(Guid Id, string FirstName, string LastName, string Email, string Gender, Guid DepartmentId, Guid JobId); +public sealed class GetEmployeeResponse +{ + public required Guid Id { get; init; } + public required string FirstName { get; init; } + public required string LastName { get; init; } + public required string Email { get; init; } + public required string Gender { get; init; } + public required Guid DepartmentId { get; init; } + public required Guid JobId { get; init; } +} internal static class GetEmployeeById { - internal static async Task> Handle(Guid id, HrContext context, CancellationToken cancellationToken) + internal static async Task> Handle(Guid id, HrContext context, CancellationToken cancellationToken) { var result = await context.Employees .Where(x => x.Id == id) @@ -18,13 +27,14 @@ internal static async Task> Handle(Guid id, HrContex return TypedResults.Json(result); } - private static EmployeeDto ToDto(this Employee employee) => new( - employee.Id, - employee.FirstName, - employee.LastName, - employee.Email.ToString(), - employee.Gender, - employee.DepartmentId, - employee.JobId - ); + private static GetEmployeeResponse ToDto(this Employee employee) => new() + { + Id = employee.Id, + FirstName = employee.FirstName, + LastName = employee.LastName, + Email = employee.Email.ToString(), + Gender = employee.Gender, + DepartmentId = employee.DepartmentId, + JobId = employee.JobId + }; } diff --git a/CleanAspCore/Features/Employees/Endpoints/UpdateEmployeeById.cs b/CleanAspCore/Features/Employees/Endpoints/UpdateEmployeeById.cs index e32a26f..400968d 100644 --- a/CleanAspCore/Features/Employees/Endpoints/UpdateEmployeeById.cs +++ b/CleanAspCore/Features/Employees/Endpoints/UpdateEmployeeById.cs @@ -19,7 +19,7 @@ public sealed class UpdateEmployeeRequest internal static class UpdateEmployeeById { - internal static async Task> Handle( + internal static async Task> Handle( Guid id, [FromBody] UpdateEmployeeRequest updateEmployeeRequest, HrContext context, CancellationToken cancellationToken) { var builder = new SetPropertyBuilder() diff --git a/CleanAspCore/Features/Jobs/Endpoints/GetJobById.cs b/CleanAspCore/Features/Jobs/Endpoints/GetJobById.cs index bc0b61a..e506597 100644 --- a/CleanAspCore/Features/Jobs/Endpoints/GetJobById.cs +++ b/CleanAspCore/Features/Jobs/Endpoints/GetJobById.cs @@ -5,7 +5,11 @@ namespace CleanAspCore.Features.Jobs.Endpoints; -public sealed record JobDto(Guid Id, string Name); +public sealed class JobDto +{ + public Guid Id { get; init; } + public string Name { get; init; } +} internal static class GetJobById { @@ -18,8 +22,9 @@ internal static async Task> Handle(Guid id, HrContext con return TypedResults.Json(results); } - private static JobDto ToDto(this Job department) => new( - department.Id, - department.Name - ); + private static JobDto ToDto(this Job department) => new() + { + Id = department.Id, + Name = department.Name + }; }