Skip to content

Commit

Permalink
simplify mappers and make them private
Browse files Browse the repository at this point in the history
  • Loading branch information
Barsonax committed Apr 28, 2024
1 parent d03d097 commit 7e53d04
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public async Task GetDepartmentById_ReturnsExpectedDepartment()
//Assert
await response.AssertStatusCode(HttpStatusCode.OK);
var departmentDto = await response.Content.ReadFromJsonAsync<DepartmentDto>();
departmentDto.Should().BeEquivalentTo(department.ToDto());
departmentDto.Should().BeEquivalentTo(new
{
Id = department.Id
});
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public async Task GetEmployeeById_ReturnsExpectedEmployee()
//Assert
await response.AssertStatusCode(HttpStatusCode.OK);
var employeeDto = await response.Content.ReadFromJsonAsync<EmployeeDto>();
employeeDto.Should().BeEquivalentTo(employee.ToDto());
employeeDto.Should().BeEquivalentTo(new
{
Id = employee.Id
});
}

[Test]
Expand Down
5 changes: 4 additions & 1 deletion CleanAspCore.Api.Tests/Features/Jobs/JobControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public async Task GetJobById_ReturnsExpectedJob()
//Assert
await response.AssertStatusCode(HttpStatusCode.OK);
var jobDto = await response.Content.ReadFromJsonAsync<JobDto>();
jobDto.Should().BeEquivalentTo(job.ToDto());
jobDto.Should().BeEquivalentTo(new
{
Id = job.Id
});
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ internal static async Task<Ok<DepartmentDto>> Handle(Guid id, HrContext context,

return TypedResults.Ok(department);
}
}

public static class DepartmentMapper
{
public static DepartmentDto ToDto(this Department department) => new
private static DepartmentDto ToDto(this Department department) => new
(
department.Id,
department.Name,
Expand Down
5 changes: 1 addition & 4 deletions CleanAspCore/Features/Employees/Endpoints/GetEmployeeById.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ internal static async Task<JsonHttpResult<EmployeeDto>> Handle(Guid id, HrContex
.FirstAsync(cancellationToken);
return TypedResults.Json(result);
}
}

public static class EmployeeMapper
{
public static EmployeeDto ToDto(this Employee employee) => new(
private static EmployeeDto ToDto(this Employee employee) => new(
employee.FirstName,
employee.LastName,
employee.Email.ToString(),
Expand Down
5 changes: 1 addition & 4 deletions CleanAspCore/Features/Jobs/Endpoints/GetJobById.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ internal static async Task<JsonHttpResult<JobDto>> Handle(Guid id, HrContext con
.FirstAsync(cancellationToken);
return TypedResults.Json(results);
}
}

public static class JobMapper
{
public static JobDto ToDto(this Job department) => new(
private static JobDto ToDto(this Job department) => new(
department.Id,
department.Name
);
Expand Down

0 comments on commit 7e53d04

Please sign in to comment.