diff --git a/.editorconfig b/.editorconfig index 635066b6..ab4fa5dd 100644 --- a/.editorconfig +++ b/.editorconfig @@ -18,6 +18,9 @@ indent_size = 4 indent_style = space tab_width = 4 +# IDE0005: Remove unnecessary imports +dotnet_diagnostic.IDE0005.severity = warning + #### .NET Coding Conventions #### # Organize usings @@ -201,4 +204,4 @@ dotnet_naming_style.begins_with_i.word_separator = dotnet_naming_style.begins_with_i.capitalization = pascal_case # File Scoped Namespaces -csharp_style_namespace_declarations = file_scoped:warning \ No newline at end of file +csharp_style_namespace_declarations = file_scoped:warning diff --git a/api/PayrollProcessor.Core.Domain.Tests/Features/Employees/EmployeePayrollCreateCommandTests.cs b/api/PayrollProcessor.Core.Domain.Tests/Features/Employees/EmployeePayrollCreateCommandTests.cs new file mode 100644 index 00000000..f9122be5 --- /dev/null +++ b/api/PayrollProcessor.Core.Domain.Tests/Features/Employees/EmployeePayrollCreateCommandTests.cs @@ -0,0 +1,29 @@ +using System; +using AutoFixture.Idioms; +using FluentAssertions; +using PayrollProcessor.Core.Domain.Features.Employees; +using PayrollProcessor.Tests.Fixtures; +using Xunit; + +namespace PayrollProcessor.Core.Domain.Tests.Features.Employees; + +public class EmployeePayrollCreateCommandTests +{ + [Fact] + public void Constructor_Guards_Against_Invalid_Parameters() + { + var assertion = new GuardClauseAssertion(new DomainFixture()); + + assertion.Verify(typeof(EmployeePayrollCreateCommand).GetConstructors()); + } + + [Theory, AutoDomainData] + public void ConstructorAssignsPropertiesFromParameters(Guid newPayrollId, Employee employee, EmployeePayrollNew employeePayroll) + { + var sut = new EmployeePayrollCreateCommand(employee, newPayrollId, employeePayroll); + + sut.Employee.Should().Be(employee); + sut.NewPayrollId.Should().Be(newPayrollId); + sut.NewPayroll.Should().Be(employeePayroll); + } +} \ No newline at end of file diff --git a/api/PayrollProcessor.Data.Persistence.Tests/Features/Employees/EmployeeRecordMapTests.cs b/api/PayrollProcessor.Data.Persistence.Tests/Features/Employees/EmployeeRecordMapTests.cs new file mode 100644 index 00000000..3d3a1759 --- /dev/null +++ b/api/PayrollProcessor.Data.Persistence.Tests/Features/Employees/EmployeeRecordMapTests.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using AutoFixture; +using FluentAssertions; +using PayrollProcessor.Data.Persistence.Features.Employees; +using Xunit; + +namespace PayrollProcessor.Data.Persistence.Tests.Features.Employees; + +public class EmployeeRecordMapTests +{ + private readonly EmployeeRecord employeeRecord; + private readonly IEnumerable employeePayrolls; + + public EmployeeRecordMapTests() + { + var fixture = new Fixture(); + + employeeRecord = fixture.Create(); + + employeePayrolls = fixture + .Build() + .With(epr => epr.PartitionKey, employeeRecord.Id.ToString()) + .With(epr => epr.PartitionKey, Guid.NewGuid().ToString()) + .CreateMany(); + } + + [Fact] + public void ToEmployeeMapsValues() + { + var employee = EmployeeRecord.Map.ToEmployee(employeeRecord); + + employee.Id.Should().Be(employeeRecord.Id); + employee.Department.Should().Be(employeeRecord.Department); + employee.Email.Should().Be(employeeRecord.Email); + employee.EmploymentStartedOn.Should().Be(employeeRecord.EmploymentStartedOn); + employee.FirstName.Should().Be(employeeRecord.FirstName); + employee.LastName.Should().Be(employeeRecord.LastName); + employee.Phone.Should().Be(employeeRecord.Phone); + employee.Status.Should().Be(employeeRecord.Status); + employee.Title.Should().Be(employeeRecord.Title); + } + + [Fact] + public void ToEmployeeDetailsMapsValues() + { + var employee = EmployeeRecord.Map.ToEmployeeDetails(employeeRecord, employeePayrolls); + + employee.Id.Should().Be(employeeRecord.Id); + employee.Department.Should().Be(employeeRecord.Department); + employee.Email.Should().Be(employeeRecord.Email); + employee.EmploymentStartedOn.Should().Be(employeeRecord.EmploymentStartedOn); + employee.FirstName.Should().Be(employeeRecord.FirstName); + employee.LastName.Should().Be(employeeRecord.LastName); + employee.Phone.Should().Be(employeeRecord.Phone); + employee.Status.Should().Be(employeeRecord.Status); + employee.Title.Should().Be(employeeRecord.Title); + + employee.Payrolls.Should().HaveCount(employeePayrolls.Count()); + + var employeePayroll = employee.Payrolls.First(); + employeePayroll.Id.Should().Be(employeePayrolls.First().Id); + employeePayroll.CheckDate.Should().Be(employeePayrolls.First().CheckDate); + employeePayroll.EmployeeId.Should().Be(Guid.Parse(employeePayrolls.First().PartitionKey)); + employeePayroll.GrossPayroll.Should().Be(employeePayrolls.First().GrossPayroll); + employeePayroll.PayrollPeriod.Should().Be(employeePayrolls.First().PayrollPeriod); + } +} diff --git a/api/PayrollProcessor.Data.Persistence.Tests/PayrollProcessor.Data.Persistence.Tests.csproj b/api/PayrollProcessor.Data.Persistence.Tests/PayrollProcessor.Data.Persistence.Tests.csproj index 9e7ce4c2..1ac129bf 100644 --- a/api/PayrollProcessor.Data.Persistence.Tests/PayrollProcessor.Data.Persistence.Tests.csproj +++ b/api/PayrollProcessor.Data.Persistence.Tests/PayrollProcessor.Data.Persistence.Tests.csproj @@ -7,6 +7,7 @@ + @@ -22,10 +23,7 @@ - - - - + diff --git a/api/PayrollProcessor.sln b/api/PayrollProcessor.sln index 0282f028..f4b5d047 100644 --- a/api/PayrollProcessor.sln +++ b/api/PayrollProcessor.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.29613.14 +# Visual Studio Version 17 +VisualStudioVersion = 17.1.32210.238 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PayrollProcessor.Web.Api", "PayrollProcessor.Web.Api\PayrollProcessor.Web.Api.csproj", "{C433B9C9-EC9D-43EA-A50A-7CBC33862073}" EndProject @@ -83,6 +83,9 @@ Global {878D546E-91B6-4781-AAD3-A7DCA0B79AF0} = {D252B6E1-0E49-45DF-96D0-A23B29A44A0B} {52AF1EB7-A608-480F-AB05-9F7E761F6CB8} = {D252B6E1-0E49-45DF-96D0-A23B29A44A0B} {640B9DD8-6E8B-4801-AA2B-6F0030A8744C} = {C3B323A1-AF4A-495E-A40C-5F5DC4274DEE} + {9B9DDB90-137E-4467-AA07-6BF13D612F49} = {C3B323A1-AF4A-495E-A40C-5F5DC4274DEE} + {DDD370FE-D4FA-472C-BEAD-22E1FA929E36} = {D252B6E1-0E49-45DF-96D0-A23B29A44A0B} + {E2BE1D75-56ED-4BF5-A262-0DB7D386DB8E} = {C3B323A1-AF4A-495E-A40C-5F5DC4274DEE} {84C26AF9-A586-474B-A4D4-6CEBB85F266C} = {D252B6E1-0E49-45DF-96D0-A23B29A44A0B} {E45503C8-D55D-4FDD-AF0F-B01458A15828} = {D252B6E1-0E49-45DF-96D0-A23B29A44A0B} EndGlobalSection