Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Add some sample unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleMcMaster committed Mar 8, 2022
1 parent b6571de commit 2b1e3cb
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
csharp_style_namespace_declarations = file_scoped:warning
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<EmployeePayrollRecord> employeePayrolls;

public EmployeeRecordMapTests()
{
var fixture = new Fixture();

employeeRecord = fixture.Create<EmployeeRecord>();

employeePayrolls = fixture
.Build<EmployeePayrollRecord>()
.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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.5.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="NSubstitute" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand All @@ -22,10 +23,7 @@

<ItemGroup>
<ProjectReference Include="..\PayrollProcessor.Data.Persistence\PayrollProcessor.Data.Persistence.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Features\Employees\" />
<ProjectReference Include="..\PayrollProcessor.Tests\PayrollProcessor.Tests.csproj" />
</ItemGroup>

</Project>
7 changes: 5 additions & 2 deletions api/PayrollProcessor.sln
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2b1e3cb

Please sign in to comment.