-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
184 additions
and
156 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
CleanAspCore.Api.Tests/Features/Departments/AddDepartmentsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using CleanAspCore.Features.Departments; | ||
using CleanAspCore.Features.Import; | ||
|
||
namespace CleanAspCore.Api.Tests.Features.Departments; | ||
|
||
public class AddDepartmentsTests : TestBase | ||
{ | ||
[Test] | ||
public async Task CreateDepartment_IsAdded() | ||
{ | ||
//Arrange | ||
var department = new CreateDepartmentRequestFaker().Generate(); | ||
|
||
//Act | ||
var response = await Sut.CreateClientFor<IDepartmentApiClient>().CreateDepartment(department); | ||
|
||
//Assert | ||
await response.AssertStatusCode(HttpStatusCode.Created); | ||
var createdId = response.GetGuidFromLocationHeader(); | ||
Sut.AssertDatabase(context => | ||
{ | ||
context.Departments.Should().BeEquivalentTo(new[] | ||
{ | ||
new | ||
{ | ||
Id = createdId | ||
} | ||
}); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
CleanAspCore.Api.Tests/Features/Employees/CreateEmployeeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using CleanAspCore.Features.Employees; | ||
using CleanAspCore.Features.Import; | ||
|
||
namespace CleanAspCore.Api.Tests.Features.Employees; | ||
|
||
public class CreateEmployeeTests : TestBase | ||
{ | ||
[Test] | ||
public async Task CreateEmployee_IsAdded() | ||
{ | ||
//Arrange | ||
var createEmployeeRequest = new CreateEmployeeRequestFaker().Generate(); | ||
Sut.SeedData(context => | ||
{ | ||
context.Departments.Add(new DepartmentFaker().RuleFor(x => x.Id, createEmployeeRequest.DepartmentId).Generate()); | ||
context.Jobs.Add(new JobFaker().RuleFor(x => x.Id, createEmployeeRequest.JobId).Generate()); | ||
}); | ||
|
||
//Act | ||
var response = await Sut.CreateClientFor<IEmployeeApiClient>().CreateEmployee(createEmployeeRequest); | ||
|
||
//Assert | ||
await response.AssertStatusCode(HttpStatusCode.Created); | ||
var createdId = response.GetGuidFromLocationHeader(); | ||
Sut.AssertDatabase(context => | ||
{ | ||
context.Employees.Should().BeEquivalentTo(new[] { new { Id = createdId } }); | ||
}); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
CleanAspCore.Api.Tests/Features/Employees/DeleteEmployeeByIdTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using CleanAspCore.Features.Employees; | ||
using CleanAspCore.Features.Import; | ||
|
||
namespace CleanAspCore.Api.Tests.Features.Employees; | ||
|
||
public class DeleteEmployeeByIdTests : TestBase | ||
{ | ||
[Test] | ||
public async Task DeleteEmployeeById_IsDeleted() | ||
{ | ||
//Arrange | ||
var employee = new EmployeeFaker().Generate(); | ||
Sut.SeedData(context => | ||
{ | ||
context.Employees.Add(employee); | ||
}); | ||
|
||
//Act | ||
var response = await Sut.CreateClientFor<IEmployeeApiClient>().DeleteEmployeeById(employee.Id); | ||
|
||
//Assert | ||
await response.AssertStatusCode(HttpStatusCode.OK); | ||
Sut.AssertDatabase(context => { context.Employees.Should().BeEmpty(); }); | ||
} | ||
} |
107 changes: 0 additions & 107 deletions
107
CleanAspCore.Api.Tests/Features/Employees/EmployeeControllerTests.cs
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
CleanAspCore.Api.Tests/Features/Employees/GetEmployeeByIdTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using CleanAspCore.Features.Employees; | ||
using CleanAspCore.Features.Employees.Endpoints; | ||
using CleanAspCore.Features.Import; | ||
|
||
namespace CleanAspCore.Api.Tests.Features.Employees; | ||
|
||
public class GetEmployeeByIdTests : TestBase | ||
{ | ||
[Test] | ||
public async Task GetEmployeeById_ReturnsExpectedEmployee() | ||
{ | ||
//Arrange | ||
var employee = new EmployeeFaker().Generate(); | ||
Sut.SeedData(context => | ||
{ | ||
context.Employees.Add(employee); | ||
}); | ||
|
||
//Act | ||
var response = await Sut.CreateClientFor<IEmployeeApiClient>().GetEmployeeById(employee.Id); | ||
|
||
//Assert | ||
await response.AssertStatusCode(HttpStatusCode.OK); | ||
var employeeDto = await response.Content.ReadFromJsonAsync<EmployeeDto>(); | ||
employeeDto.Should().BeEquivalentTo(new { Id = employee.Id }); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
CleanAspCore.Api.Tests/Features/Employees/UpdateEmployeeByIdTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using CleanAspCore.Features.Employees; | ||
using CleanAspCore.Features.Employees.Endpoints; | ||
using CleanAspCore.Features.Import; | ||
|
||
namespace CleanAspCore.Api.Tests.Features.Employees; | ||
|
||
public class UpdateEmployeeByIdTests : TestBase | ||
{ | ||
[Test] | ||
public async Task UpdateEmployeeById_IsUpdated() | ||
{ | ||
//Arrange | ||
var employee = new EmployeeFaker().Generate(); | ||
Sut.SeedData(context => { context.Employees.Add(employee); }); | ||
|
||
UpdateEmployeeRequest updateEmployeeRequest = new() | ||
{ | ||
FirstName = "Updated" | ||
}; | ||
|
||
//Act | ||
var response = await Sut.CreateClientFor<IEmployeeApiClient>().UpdateEmployeeById(employee.Id, updateEmployeeRequest); | ||
|
||
//Assert | ||
await response.AssertStatusCode(HttpStatusCode.NoContent); | ||
Sut.AssertDatabase(context => | ||
{ | ||
context.Employees.Should().BeEquivalentTo(new[] | ||
{ | ||
new | ||
{ | ||
FirstName = "Updated", | ||
LastName = employee.LastName, | ||
} | ||
}); | ||
}); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../Features/Import/ImportControllerTests.cs → ....Api.Tests/Features/Import/ImportTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using CleanAspCore.Features.Import; | ||
using CleanAspCore.Features.Jobs; | ||
using CleanAspCore.Features.Jobs.Endpoints; | ||
|
||
namespace CleanAspCore.Api.Tests.Features.Jobs; | ||
|
||
public class GetJobByIdTests : TestBase | ||
{ | ||
[Test] | ||
public async Task GetJobById_ReturnsExpectedJob() | ||
{ | ||
//Arrange | ||
var job = new JobFaker().Generate(); | ||
Sut.SeedData(context => | ||
{ | ||
context.Jobs.Add(job); | ||
}); | ||
|
||
//Act | ||
var response = await Sut.CreateClientFor<IJobApiClient>().GetJobById(job.Id); | ||
|
||
//Assert | ||
await response.AssertStatusCode(HttpStatusCode.OK); | ||
var jobDto = await response.Content.ReadFromJsonAsync<JobDto>(); | ||
jobDto.Should().BeEquivalentTo(new | ||
{ | ||
Id = job.Id | ||
}); | ||
} | ||
} |