Теперь все тесты в зелёной зоне
This commit is contained in:
parent
b969fedba2
commit
a06c65e3aa
@ -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()})");
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user