From a06c65e3aaf257c71231266cbc2b08a3989589d7 Mon Sep 17 00:00:00 2001 From: 145Game Date: Mon, 17 Feb 2025 12:02:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=B2?= =?UTF-8?q?=D1=81=D0=B5=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B2=20=D0=B7?= =?UTF-8?q?=D0=B5=D0=BB=D1=91=D0=BD=D0=BE=D0=B9=20=D0=B7=D0=BE=D0=BD=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataModels/WorkerDataModel.cs | 19 +++++++++++-------- .../DataModelsTests/WorkerDataModelTests.cs | 12 ++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/North_Bridge/North_Bridge_Contract/DataModels/WorkerDataModel.cs b/North_Bridge/North_Bridge_Contract/DataModels/WorkerDataModel.cs index b09cd89..cf18981 100644 --- a/North_Bridge/North_Bridge_Contract/DataModels/WorkerDataModel.cs +++ b/North_Bridge/North_Bridge_Contract/DataModels/WorkerDataModel.cs @@ -20,7 +20,7 @@ public class WorkerDataModel : IValidation public bool IsDeleted { get; private set; } - public WorkerDataModel(string id, string email, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) + public WorkerDataModel(string id, string fio, string email, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) { Id = id; FIO = fio; @@ -42,22 +42,25 @@ public class WorkerDataModel : IValidation if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty"); + if (Email.IsEmpty()) + throw new ValidationException("Field Email is empty"); + + if (!Regex.IsMatch(Email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$")) + throw new ValidationException("Field Email is not a valid email address"); + if (PostId.IsEmpty()) throw new ValidationException("Field PostId is empty"); if (!PostId.IsGuid()) throw new ValidationException("The value in the field PostId is not a unique identifier"); - if (BirthDate.Date > DateTime.Now.AddYears(-16).Date) - throw new ValidationException($"Minors cannot be hired (BirthDate = { BirthDate.ToShortDateString() })"); + if (BirthDate.Date > DateTime.Now.AddYears(-18).Date) + throw new ValidationException($"Only adults can be hired (BirthDate = {BirthDate.ToShortDateString()})"); if (EmploymentDate.Date < BirthDate.Date) throw new ValidationException("The date of employment cannot be less than the date of birth"); - if ((EmploymentDate - BirthDate).TotalDays / 365 < 16) // EmploymentDate.Year - BirthDate.Year - throw new ValidationException($"Minors cannot be hired (EmploymentDate - { EmploymentDate.ToShortDateString() }, BirthDate - { BirthDate.ToShortDateString()})"); - - if (!Regex.IsMatch(Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$")) // example@example.com - throw new ValidationException("Field Email is not a email"); + if ((EmploymentDate - BirthDate).TotalDays / 365 < 18) + throw new ValidationException($"Only adults can be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})"); } } \ No newline at end of file diff --git a/North_Bridge/North_Bridge_Tests/DataModelsTests/WorkerDataModelTests.cs b/North_Bridge/North_Bridge_Tests/DataModelsTests/WorkerDataModelTests.cs index 751a89c..0baf001 100644 --- a/North_Bridge/North_Bridge_Tests/DataModelsTests/WorkerDataModelTests.cs +++ b/North_Bridge/North_Bridge_Tests/DataModelsTests/WorkerDataModelTests.cs @@ -99,26 +99,26 @@ internal class WorkerDataModelTests { var workerId = Guid.NewGuid().ToString(); var fio = "fio"; - var email = "example@example.com"; + var Email = "example@example.com"; var postId = Guid.NewGuid().ToString(); - var birthDate = DateTime.Now.AddYears(-16).AddDays(-1); + var birthDate = DateTime.Now.AddYears(-18).AddDays(-1); var employmentDate = DateTime.Now; var isDelete = false; - var worker = CreateDataModel(workerId, fio, email, postId, birthDate, employmentDate, isDelete); + var worker = CreateDataModel(workerId, fio, Email, postId, birthDate, employmentDate, isDelete); Assert.That(() => worker.Validate(), Throws.Nothing); Assert.Multiple(() => { Assert.That(worker.Id, Is.EqualTo(workerId)); Assert.That(worker.FIO, Is.EqualTo(fio)); - Assert.That(worker.Email, Is.EqualTo(email)); + Assert.That(worker.Email, Is.EqualTo(Email)); Assert.That(worker.PostId, Is.EqualTo(postId)); Assert.That(worker.BirthDate, Is.EqualTo(birthDate)); - Assert.That(worker.EmploymentDate,Is.EqualTo(employmentDate)); + Assert.That(worker.EmploymentDate, Is.EqualTo(employmentDate)); Assert.That(worker.IsDeleted, Is.EqualTo(isDelete)); }); } - private static WorkerDataModel CreateDataModel(string? id, string? fio, string email, + private static WorkerDataModel CreateDataModel(string? id, string? fio, string? email, string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) => new(id, fio, email, postId, birthDate, employmentDate, isDeleted); } \ No newline at end of file