diff --git a/CleanAspCore.Api.Tests/Features/Departments/DepartmentControllerTests.cs b/CleanAspCore.Api.Tests/Features/Departments/DepartmentControllerTests.cs index d4beac9..a34a6aa 100644 --- a/CleanAspCore.Api.Tests/Features/Departments/DepartmentControllerTests.cs +++ b/CleanAspCore.Api.Tests/Features/Departments/DepartmentControllerTests.cs @@ -1,4 +1,5 @@ -using CleanAspCore.Domain.Departments; +using CleanAspCore.Domain; +using CleanAspCore.Domain.Departments; namespace CleanAspCore.Api.Tests.Features.Departments; @@ -24,7 +25,7 @@ public async Task SearchDepartments_ReturnsExpectedDepartments() //Assert result.Should().BeEquivalentTo(new[] { - department.ToDto() - }); + department + }, c => c.ComparingByMembers().ExcludingMissingMembers()); } } \ No newline at end of file diff --git a/CleanAspCore.Api.Tests/Features/Employees/EmployeeControllerTests.cs b/CleanAspCore.Api.Tests/Features/Employees/EmployeeControllerTests.cs index 3c51615..264feb9 100644 --- a/CleanAspCore.Api.Tests/Features/Employees/EmployeeControllerTests.cs +++ b/CleanAspCore.Api.Tests/Features/Employees/EmployeeControllerTests.cs @@ -1,4 +1,5 @@ -using CleanAspCore.Domain.Employees; +using CleanAspCore.Domain; +using CleanAspCore.Domain.Employees; namespace CleanAspCore.Api.Tests.Features.Employees; @@ -24,8 +25,8 @@ public async Task SearchEmployee_ReturnsExpectedJobs() //Assert result.Should().BeEquivalentTo(new[] { - employee.ToDto() - }); + employee + }, c => c.ComparingByMembers().ExcludingMissingMembers()); } [Fact] @@ -38,11 +39,9 @@ public async Task AddEmployee_IsAdded() context.Departments.Add(employee.Department); context.Jobs.Add(employee.Job); }); - - var newEmployee = employee.ToDto(); - + //Act - var result = await _api.CreateClient().PostAsJsonAsync("Employee", newEmployee); + var result = await _api.CreateClient().PostAsJsonAsync("Employee", employee.ToDto()); //Assert result.EnsureSuccessStatusCode(); @@ -50,7 +49,7 @@ public async Task AddEmployee_IsAdded() { context.Employees.Should().BeEquivalentTo(new[] { - newEmployee.ToDomain() + employee }); }); } @@ -78,7 +77,7 @@ public async Task UpdateEmployee_IsUpdated() context.Employees.Should().BeEquivalentTo(new[] { updatedEmployee.ToDomain() - }, c => c.ComparingByMembers()); + }); }); } diff --git a/CleanAspCore.Api.Tests/Features/Jobs/JobControllerTests.cs b/CleanAspCore.Api.Tests/Features/Jobs/JobControllerTests.cs index 7ae281c..6a5c166 100644 --- a/CleanAspCore.Api.Tests/Features/Jobs/JobControllerTests.cs +++ b/CleanAspCore.Api.Tests/Features/Jobs/JobControllerTests.cs @@ -1,3 +1,4 @@ +using CleanAspCore.Domain; using CleanAspCore.Domain.Jobs; namespace CleanAspCore.Api.Tests.Features.Jobs; @@ -25,7 +26,7 @@ public async Task SearchJobs_ReturnsExpectedJobs() //Assert result.Should().BeEquivalentTo(new[] { - job.ToDto() - }); + job + }, c => c.ComparingByMembers().ExcludingMissingMembers()); } } \ No newline at end of file diff --git a/CleanAspCore/Domain/Departments/DepartmentDto.cs b/CleanAspCore/Domain/Departments/DepartmentDto.cs index 09f7cde..0750f42 100644 --- a/CleanAspCore/Domain/Departments/DepartmentDto.cs +++ b/CleanAspCore/Domain/Departments/DepartmentDto.cs @@ -1,8 +1,3 @@ namespace CleanAspCore.Domain.Departments; -public class DepartmentDto -{ - public int Id { get; set; } - public string Name { get; set; } - public string City { get; set; } -} \ No newline at end of file +public sealed record DepartmentDto(int Id, string Name, string City); \ No newline at end of file diff --git a/CleanAspCore/Domain/Employees/EmailAddress.cs b/CleanAspCore/Domain/Employees/EmailAddress.cs index dff7840..d23f773 100644 --- a/CleanAspCore/Domain/Employees/EmailAddress.cs +++ b/CleanAspCore/Domain/Employees/EmailAddress.cs @@ -9,17 +9,9 @@ public EmailAddress(string email) Email = email; Validator.Instance.ValidateAndThrow(this); } - - public static bool operator ==(EmailAddress emailAddress, string email) => emailAddress.Equals(email); - - public static bool operator !=(EmailAddress emailAddress, string email) => !emailAddress.Equals(email); - public bool Equals(string email) => Email == email; - public static implicit operator string(EmailAddress emailAddress) => emailAddress.Email; - - public static implicit operator EmailAddress(string emailAddress) => new(emailAddress); - + public override string ToString() => Email; private class Validator : AbstractValidator diff --git a/CleanAspCore/Domain/Employees/EmployeeDto.cs b/CleanAspCore/Domain/Employees/EmployeeDto.cs index 42a6dc5..d1b7d9a 100644 --- a/CleanAspCore/Domain/Employees/EmployeeDto.cs +++ b/CleanAspCore/Domain/Employees/EmployeeDto.cs @@ -1,12 +1,3 @@ namespace CleanAspCore.Domain.Employees; -public record class EmployeeDto -{ - public int Id { get; set; } - public string FirstName { get; set; } - public string LastName { get; set; } - public string Email { get; set; } - public string Gender {get; set; } - public int DepartmentId { get; set; } - public int JobId { get; set; } -} \ No newline at end of file +public sealed record EmployeeDto(int Id, string FirstName, string LastName, string Email, string Gender, int DepartmentId, int JobId); \ No newline at end of file diff --git a/CleanAspCore/Domain/Jobs/JobDto.cs b/CleanAspCore/Domain/Jobs/JobDto.cs index 41e0c72..22b1c0a 100644 --- a/CleanAspCore/Domain/Jobs/JobDto.cs +++ b/CleanAspCore/Domain/Jobs/JobDto.cs @@ -1,7 +1,3 @@ namespace CleanAspCore.Domain.Jobs; -public class JobDto -{ - public int Id { get; set; } - public string Name { get; set; } -} \ No newline at end of file +public sealed record JobDto(int Id, string Name); \ No newline at end of file