Initial commit

This commit is contained in:
github-classroom[bot] 2025-02-25 16:55:29 +00:00 committed by GitHub
commit b9c04768e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 4696 additions and 0 deletions

View file

@ -0,0 +1,34 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<Using Include="FluentAssertions" />
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AwesomeAssertions" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Employees\Employees.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,21 @@
namespace Employees.Test;
public sealed class ManagerTests
{
[Fact]
public void Construction()
{
const string Name = "Lisa";
const string Department = "Logistics";
const Gender Gender = Gender.Female;
const decimal BaseSalary = 4500.89M;
var manager = new Manager(Name, Gender, Department, BaseSalary);
manager.Name.Should().Be(Name);
manager.Department.Should().Be(Department);
manager.Gender.Should().Be(Gender);
manager.Salary.Should().Be(5401.068M, "managers earn 20% more");
manager.ToString().Should().Be("My name is Lisa and I'm head of the Logistics department");
}
}

View file

@ -0,0 +1,44 @@
namespace Employees.Test;
public sealed class OfficeEmployeeTests
{
[Fact]
public void Construction_Simple()
{
const string Name = "Mia";
const string Department = "Accounting";
const Gender Gender = Gender.Female;
const decimal Salary = 3211.99M;
var employee = new OfficeEmployee(Name, Gender, Department, Salary);
employee.Name.Should().Be(Name);
employee.Department.Should().Be(Department);
employee.Gender.Should().Be(Gender);
employee.ToString().Should()
.Be("My name is Mia, I identify as female and I work at the department Accounting as an employee");
employee.Salary.Should().Be(Salary);
}
[Theory]
[InlineData("T", "too short, at least two characters")]
[InlineData("lo", "has to start uppercase")]
[InlineData("1g", "first character has to be a letter")]
public void Construction_NameInvalid(string name, string reason)
{
var employee = new OfficeEmployee(name, Gender.Divers, "Canteen", 12.34M);
employee.Name
.Should()
.NotBe(name)
.And.Be("ERROR", reason);
}
[Fact]
public void Construction_InvalidSalary()
{
var employee = new OfficeEmployee("Moritz", Gender.Male, "Sales", -123.45M);
employee.Salary.Should().Be(0M, "invalid value, set to zero");
}
}

View file

@ -0,0 +1,104 @@
namespace Employees.Test;
public sealed class WorkerTests
{
[Fact]
public void Construction_Minimal()
{
const string Name = "Sepp";
const Gender Gender = Gender.Divers;
const string Department = "Sawmill";
var worker = new Worker(Name, Gender, Department);
worker.Name.Should().Be(Name);
worker.Gender.Should().Be(Gender);
worker.Department.Should().Be(Department);
worker.ToString()
.Should().Be("My name is Sepp and I work at the department Sawmill as a worker");
worker.Hours.Should().Be(0D, "no value set yet");
worker.HourlyWage.Should().Be(0M, "no value set yet");
}
[Fact]
public void Construction_Full()
{
const double Hours = 34.5D;
const decimal HourlyWage = 112.68M;
var worker = new Worker("Sepp", Gender.Divers, "Sawmill", Hours, HourlyWage);
worker.ToString()
.Should().Be("My name is Sepp and I work at the department Sawmill as a worker",
"not affected by hours or wage");
worker.Hours.Should().Be(Hours);
worker.HourlyWage.Should().Be(HourlyWage);
}
[Theory]
[InlineData(12.34D, 12.34D, "valid value")]
[InlineData(-12.34D, 0D, "invalid value, set to zero")]
[InlineData(17 * 32D, Worker.MaxMonthlyWorkHours, "too big value, set to max")]
public void Hours(double hours, double expectedHours, string reason)
{
var worker = new Worker("Susi", Gender.Divers, "Lasercutting",
hours, 0M);
worker.Hours.Should().Be(expectedHours, reason);
worker.Hours = hours;
worker.Hours.Should().Be(expectedHours, reason);
}
[Theory]
[MemberData(nameof(HourlyWageData))]
public void HourlyWage(decimal hourlyWage, decimal expectedWage, string reason)
{
var worker = new Worker("Susi", Gender.Divers, "Lasercutting",
0D, hourlyWage);
worker.HourlyWage.Should().Be(expectedWage, reason);
worker.HourlyWage = hourlyWage;
worker.HourlyWage.Should().Be(expectedWage, reason);
}
[Theory]
[MemberData(nameof(SalaryData))]
public void Salary(double hours, decimal hourlyWage, decimal expectedSalary, string reason)
{
var worker = new Worker("Susi", Gender.Divers, "Lasercutting")
{
Hours = hours,
HourlyWage = hourlyWage
};
worker.Salary.Should().Be(expectedSalary, reason);
}
[Fact]
public void StringRepresentation()
{
var worker1 = new Worker("Sepp", Gender.Male, "Sawmill");
var worker2 = new Worker("Susi", Gender.Female, "Welding");
worker1.ToString()
.Should().Be("My name is Sepp, I identify as male and I work at the department Sawmill as a worker");
worker2.ToString()
.Should().Be("My name is Susi, I identify as female and I work at the department Welding as a worker");
}
public static TheoryData<decimal, decimal, string> HourlyWageData =>
new()
{
{ 98.79M, 98.79M, "valid value" },
{ -19.99M, 0M, "invalid value, set to zero" }
};
public static TheoryData<double, decimal, decimal, string> SalaryData =>
new()
{
{ 8.5D * 20, 25.29M, 4299.30M, "valid values" },
{ -4D * 30, 10M, 0M, "invalid hours, set to zero so total salary is zero" },
{ 20D * 30, 10M, 4960M, "too many hours, set to max allowed" },
{ 160D, -12M, 0M, "invalid hourly wage, set to zero so total salary is zero" }
};
}