diff --git a/HamContract/HamContract/DataModels/EmployeeDataModel.cs b/HamContract/HamContract/DataModels/EmployeeDataModel.cs index 30535fb..994312b 100644 --- a/HamContract/HamContract/DataModels/EmployeeDataModel.cs +++ b/HamContract/HamContract/DataModels/EmployeeDataModel.cs @@ -27,11 +27,17 @@ public class EmployeeDataModel(string id, string name, string phone, string post if (!Id.IsGuid()) throw new ValidationException("The value in the field Id is not a unique identifier"); - + if (Name.IsEmpty()) - throw new ValidationException("Field Name is empty"); + throw new ValidationException("Field Name is empty"); - if (Phone.IsEmpty()) { throw new ValidationException("Field PhoneNumber is empty"); } + if (!Regex.IsMatch(name, @"^[A-Za-zА\s]+$")) + { + throw new ValidationException("Field Name is not valid"); + } + + + if (Phone.IsEmpty()) { throw new ValidationException("Field Phone is empty"); } if (!Regex.IsMatch(Phone, @"^\+7[\s-]?\d{3}[\s-]?\d{3}[\s-]?\d{2}[\s-]?\d{2}$")) { throw new ValidationException("Field PhoneNumber is not a phone number"); } @@ -47,7 +53,7 @@ public class EmployeeDataModel(string id, string name, string phone, string post if (EmploymentDate.Date < Dateofbirth.Date) throw new ValidationException("The date of employment cannot be less than the date of birth"); - if ((EmploymentDate - Dateofbirth).TotalDays / 365 < 16) // EmploymentDate.Year - BirthDate.Year + if ((EmploymentDate - Dateofbirth).TotalDays / 365 < 18) throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - BirthDate.ToShortDateString())"); } } diff --git a/HamContract/HamContract/DataModels/PostDataModel.cs b/HamContract/HamContract/DataModels/PostDataModel.cs index b961b46..56b3dd5 100644 --- a/HamContract/HamContract/DataModels/PostDataModel.cs +++ b/HamContract/HamContract/DataModels/PostDataModel.cs @@ -10,13 +10,12 @@ using HamContract.Infrastructure; namespace HamContract.DataModels; -public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation +public class PostDataModel(string id, string postId, string postName, PostType postType, bool isActual, DateTime changeDate) : IValidation { public string Id { get; private set; } = id; public string PostId { get; private set; } = postId; public string PostName { get; private set; } = postName; public PostType PostType { get; private set; } = postType; - public double Salary { get; private set; } = salary; public bool IsActual { get; private set; } = isActual; public DateTime ChangeDate { get; private set; } = changeDate; @@ -40,7 +39,6 @@ public class PostDataModel(string id, string postId, string postName, PostType p if (PostType == PostType.None) throw new ValidationException("Field PostType is empty"); - if (Salary <= 0) - throw new ValidationException("Field Salary is empty"); + } } \ No newline at end of file diff --git a/HamContract/HamTests/DataModelsTest/EmployeeDataModelTest.cs b/HamContract/HamTests/DataModelsTest/EmployeeDataModelTest.cs index f023404..56f0ffd 100644 --- a/HamContract/HamTests/DataModelsTest/EmployeeDataModelTest.cs +++ b/HamContract/HamTests/DataModelsTest/EmployeeDataModelTest.cs @@ -7,11 +7,9 @@ using System.Threading.Tasks; using HamContract.DataModels; namespace HamTests.DataModelsTest; -[TestFixture] -internal class EmployeeDataModelTest -{ + [TestFixture] - internal class WorkerDataModelTests + internal class EmployeeDataModelTest { [Test] public void IdIsNullOrEmptyTest() @@ -49,13 +47,24 @@ internal class EmployeeDataModelTest } [Test] - public void PhoneIsIncorrectTest() + public void NameIsIncorrectTest() { - var employee = CreateDataModel(Guid.NewGuid().ToString(), "name", "777", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); + var employee = CreateDataModel(Guid.NewGuid().ToString(), "name","777", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); } - [Test] + [Test] + public void PhoneIsIncorrectTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "name", "777", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + + + + + [Test] public void PostIdIsNullOrEmptyTest() { var employee = CreateDataModel(Guid.NewGuid().ToString(), "name", "number", null, DateTime.Now.AddYears(-18), DateTime.Now, false); @@ -92,7 +101,7 @@ internal class EmployeeDataModelTest { var employeeId = Guid.NewGuid().ToString(); var name = "name"; - var phone = "+7-777-777-77-77"; + var phone = "+7-732-234-23-77"; var postId = Guid.NewGuid().ToString(); var dateofbirth = DateTime.Now.AddYears(-18).AddDays(-1); var employmentDate = DateTime.Now; @@ -114,4 +123,4 @@ internal class EmployeeDataModelTest new(id, name, phone, postId, dateofbirth, employmentDate, isDeleted); } -} + diff --git a/HamContract/HamTests/DataModelsTest/PostDataModelTest.cs b/HamContract/HamTests/DataModelsTest/PostDataModelTest.cs index 7f7cdca..a39c909 100644 --- a/HamContract/HamTests/DataModelsTest/PostDataModelTest.cs +++ b/HamContract/HamTests/DataModelsTest/PostDataModelTest.cs @@ -62,15 +62,8 @@ internal class PostDataModelTests } [Test] - public void SalaryIsLessOrZeroTest() - { - var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Butcher, 0, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), Throws.TypeOf()); - post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Butcher, -10, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), Throws.TypeOf()); - } - [Test] + public void AllFieldsIsCorrectTest() { var postId = Guid.NewGuid().ToString(); @@ -89,11 +82,10 @@ internal class PostDataModelTests Assert.That(post.PostId, Is.EqualTo(postPostId)); Assert.That(post.PostName, Is.EqualTo(postName)); Assert.That(post.PostType, Is.EqualTo(postType)); - Assert.That(post.Salary, Is.EqualTo(salary)); Assert.That(post.IsActual, Is.EqualTo(isActual)); Assert.That(post.ChangeDate, Is.EqualTo(changeDate)); }); } private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) => - new(id, postId, postName, postType, salary, isActual, changeDate); + new(id, postId, postName, postType,isActual, changeDate); } \ No newline at end of file