Небольшие изменения в сущности Работника (и не только)

This commit is contained in:
Павел Ладягин 2025-02-08 14:13:31 +04:00
parent bf8eece4e6
commit 34d784392f
5 changed files with 68 additions and 2 deletions

View File

@ -5,11 +5,14 @@ using PimpMyRideContracts.Infrastructure;
namespace PimpMyRideContracts.DataModels; namespace PimpMyRideContracts.DataModels;
public class WorkerDataModel(string workerId, string workerFIO, PostType postType) : IValidation public class WorkerDataModel(string workerId, string workerFIO, PostType postType, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
{ {
public string WorkerId { get; private set; } = workerId; public string WorkerId { get; private set; } = workerId;
public string WorkerFIO { get; private set; } = workerFIO; public string WorkerFIO { get; private set; } = workerFIO;
public PostType PostType { get; private set; } = postType; public PostType PostType { get; private set; } = postType;
public DateTime BirthDate { get; private set; } = birthDate;
public DateTime EmploymentDate { get; private set; } = employmentDate;
public bool IsDeleted { get; private set; } = isDeleted;
public void Validate() public void Validate()
{ {
@ -24,5 +27,11 @@ public class WorkerDataModel(string workerId, string workerFIO, PostType postTyp
if (PostType == PostType.None) if (PostType == PostType.None)
throw new ValidationException("Field PostType is empty"); throw new ValidationException("Field PostType is empty");
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
throw new ValidationException("The date of employment cannot be less than the date of birth");
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
} }
} }

View File

@ -6,4 +6,8 @@
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="4.3.2" />
</ItemGroup>
</Project> </Project>

View File

@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.10.35013.160 VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PimpMyRideContracts", "PimpMyRideContracts\PimpMyRideContracts.csproj", "{DEFE53D7-DCB1-482C-8881-180886CEE5DB}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PimpMyRideContracts", "PimpMyRideContracts\PimpMyRideContracts.csproj", "{DEFE53D7-DCB1-482C-8881-180886CEE5DB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PimpMyRideTests", "PimpMyRideTests\PimpMyRideTests.csproj", "{4ECD058E-8F44-452B-B9E0-7536CB42C98F}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +17,10 @@ Global
{DEFE53D7-DCB1-482C-8881-180886CEE5DB}.Debug|Any CPU.Build.0 = Debug|Any CPU {DEFE53D7-DCB1-482C-8881-180886CEE5DB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DEFE53D7-DCB1-482C-8881-180886CEE5DB}.Release|Any CPU.ActiveCfg = Release|Any CPU {DEFE53D7-DCB1-482C-8881-180886CEE5DB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DEFE53D7-DCB1-482C-8881-180886CEE5DB}.Release|Any CPU.Build.0 = Release|Any CPU {DEFE53D7-DCB1-482C-8881-180886CEE5DB}.Release|Any CPU.Build.0 = Release|Any CPU
{4ECD058E-8F44-452B-B9E0-7536CB42C98F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4ECD058E-8F44-452B-B9E0-7536CB42C98F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4ECD058E-8F44-452B-B9E0-7536CB42C98F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4ECD058E-8F44-452B-B9E0-7536CB42C98F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PimpMyRideTests.DataModelsTests;
[TestFixture]
internal class CarDataModelTest
{
[Test]
public void Test()
{
var model = new { test = "sfdg" };
Assert.That(model, Is.Not.Null);
Assert.That(model.test, Is.EqualTo("sfdg"));
}
}

View File

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="4.3.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PimpMyRideContracts\PimpMyRideContracts.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>