diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/ClientDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/ClientDataModel.cs deleted file mode 100644 index 8669f11..0000000 --- a/TheCyclopsProject/TheCyclopsContracts/DataModels/ClientDataModel.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Text.RegularExpressions; -using TheCyclopsContracts.Exceptions; -using TheCyclopsContracts.Extensions; -using TheCyclopsContracts.Infrastructure; - -namespace TheCyclopsContracts.DataModels; - -public class ClientDataModel(string id, string fio, string email) : IValidation -{ - public string Id { get; private set; } = id; - - public string FIO { get; private set; } = fio; - - public string Email { get; private set; } = email; - - public void Validate() - { - if (Id.IsEmpty()) - throw new ValidationException("Field Id is empty"); - - if (!Id.IsGuid()) - throw new ValidationException("The value in the field Id is not a unique identifier"); - - if (FIO.IsEmpty()) - throw new ValidationException("Field FIO is empty"); - - if (Email.IsEmpty()) - throw new ValidationException("Field Email is empty"); - - if (!Regex.IsMatch(Email, @"^\S+@\S+\.\S+$")) - throw new ValidationException("Field Email is not an email address"); - } -} diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/EmployeeDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/EmployeeDataModel.cs index 6e1f24e..03a03df 100644 --- a/TheCyclopsProject/TheCyclopsContracts/DataModels/EmployeeDataModel.cs +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/EmployeeDataModel.cs @@ -1,15 +1,19 @@ -using TheCyclopsContracts.Exceptions; +using System.Text.RegularExpressions; +using TheCyclopsContracts.Exceptions; using TheCyclopsContracts.Extensions; using TheCyclopsContracts.Infrastructure; namespace TheCyclopsContracts.DataModels; -public class EmployeeDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation +public class EmployeeDataModel(string id, string fio, string email, string postId, + DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation { public string Id { get; private set; } = id; public string FIO { get; private set; } = fio; + public string Email { get; private set; } = email; + public string PostId { get; private set; } = postId; public DateTime BirthDate { get; private set; } = birthDate; @@ -29,6 +33,12 @@ public class EmployeeDataModel(string id, string fio, string postId, DateTime bi if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty"); + if (Email.IsEmpty()) + throw new ValidationException("Field Email is empty"); + + if (!Regex.IsMatch(Email, @"^\S+@\S+\.\S+$")) + throw new ValidationException("Field Email is not an email address"); + if (PostId.IsEmpty()) throw new ValidationException("Field PostId is empty"); diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs index 9e39d32..3730e21 100644 --- a/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs @@ -4,7 +4,7 @@ using TheCyclopsContracts.Infrastructure; namespace TheCyclopsContracts.DataModels; -public class InstallationDataModel(string id, string employeeId, string? clientId, +public class InstallationDataModel(string id, string employeeId, DateTime installationDate, double installationPrice, double sum, bool isCanceled, List components) : IValidation { @@ -12,8 +12,6 @@ public class InstallationDataModel(string id, string employeeId, string? clientI public string EmployeeId { get; private set; } = employeeId; - public string? ClientId { get; private set; } = clientId; - public DateTime SaleDate { get; private set; } = DateTime.UtcNow; public DateTime InstallationDate { get; private set; } = installationDate; @@ -40,9 +38,6 @@ public class InstallationDataModel(string id, string employeeId, string? clientI if (!EmployeeId.IsGuid()) throw new ValidationException("The value in the field EmployeeId is not a unique identifier"); - if (!ClientId?.IsGuid() ?? !ClientId?.IsEmpty() ?? false) - throw new ValidationException("The value in the field ClientId is not a unique identifier"); - if (InstallationPrice <= 0) throw new ValidationException("Field InstallationPrice is less than or equal to 0"); diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs deleted file mode 100644 index 886ea3a..0000000 --- a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs +++ /dev/null @@ -1,73 +0,0 @@ -using TheCyclopsContracts.DataModels; -using TheCyclopsContracts.Exceptions; - -namespace TheCyclopsTests.DataModelsTests; - -[TestFixture] -internal class ClientDataModelTests -{ - [Test] - public void IdIsNullOrEmptyTest() - { - var client = CreateDataModel(null, "fio", "email"); - Assert.That(() => client.Validate(), Throws.TypeOf()); - - client = CreateDataModel(string.Empty, "fio", "email"); - Assert.That(() => client.Validate(), Throws.TypeOf()); - } - - [Test] - public void IdIsNotGuidTest() - { - var client = CreateDataModel("id", "fio", "email"); - Assert.That(() => client.Validate(), Throws.TypeOf()); - } - - [Test] - public void FIOIsNullOrEmptyTest() - { - var client = CreateDataModel(Guid.NewGuid().ToString(), null, "email"); - Assert.That(() => client.Validate(), Throws.TypeOf()); - - client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "email"); - Assert.That(() => client.Validate(), Throws.TypeOf()); - } - - [Test] - public void EmailIsNullOrEmptyTest() - { - var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", null); - Assert.That(() => client.Validate(), Throws.TypeOf()); - - client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty); - Assert.That(() => client.Validate(), Throws.TypeOf()); - } - - [Test] - public void EmailIsIncorrectTest() - { - var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "email"); - Assert.That(() => client.Validate(), Throws.TypeOf()); - } - - [Test] - public void AllFieldsIsCorrectTest() - { - var clientId = Guid.NewGuid().ToString(); - var fio = "Fio"; - var email = "email.email@email.com"; - var client = CreateDataModel(clientId, fio, email); - - Assert.That(() => client.Validate(), Throws.Nothing); - - Assert.Multiple(() => - { - Assert.That(client.Id, Is.EqualTo(clientId)); - Assert.That(client.FIO, Is.EqualTo(fio)); - Assert.That(client.Email, Is.EqualTo(email)); - }); - } - - private static ClientDataModel CreateDataModel(string? id, string? fio, string? email) => - new(id, fio, email); -} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs index 24d7b12..c83268f 100644 --- a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs @@ -9,11 +9,11 @@ internal class EmployeeDataModelTests [Test] public void IdIsNullOrEmptyTest() { - var employee = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), + var employee = CreateDataModel(null, "fio", "mail@mail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); - employee = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), + employee = CreateDataModel(null, "fio", "mail@mail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); } @@ -21,7 +21,7 @@ internal class EmployeeDataModelTests [Test] public void IdIsNotGuidTest() { - var employee = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), + var employee = CreateDataModel("id", "fio", "mail@mail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); } @@ -29,11 +29,31 @@ internal class EmployeeDataModelTests [Test] public void FIOIsNullOrEmptyTest() { - var employee = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), + var employee = CreateDataModel(Guid.NewGuid().ToString(), null, "mail@mail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); - employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), + employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "mail@mail.com", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmailIsNullOrEmptyTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmailIsIncorrectTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); } @@ -41,11 +61,11 @@ internal class EmployeeDataModelTests [Test] public void PostIdIsNullOrEmptyTest() { - var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", null, DateTime.Now.AddYears(-18), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); - employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, + employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); } @@ -53,28 +73,28 @@ internal class EmployeeDataModelTests [Test] public void PostIdIsNotGuidTest() { - var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", - DateTime.Now.AddYears(-18), DateTime.Now, false); + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", + "postId", DateTime.Now.AddYears(-18), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); } [Test] public void BirthDateIsNotCorrectTest() { - var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), - DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false); + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false); Assert.That(() => employee.Validate(), Throws.TypeOf()); } [Test] public void BirthDateAndEmploymentDateIsNotCorrectTest() { - var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), - DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false); + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false); Assert.That(() => employee.Validate(), Throws.TypeOf()); - employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), - DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false); + employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false); Assert.That(() => employee.Validate(), Throws.TypeOf()); } @@ -83,11 +103,12 @@ internal class EmployeeDataModelTests { var employeeId = Guid.NewGuid().ToString(); var fio = "fio"; + var email = "mail@mail.com"; var postId = Guid.NewGuid().ToString(); var birthDate = DateTime.Now.AddYears(-16).AddDays(-1); var employmentDate = DateTime.Now; var isDeleted = false; - var employee = CreateDataModel(employeeId, fio, postId, birthDate, employmentDate, isDeleted); + var employee = CreateDataModel(employeeId, fio, email, postId, birthDate, employmentDate, isDeleted); Assert.That(() => employee.Validate(), Throws.Nothing); @@ -95,6 +116,7 @@ internal class EmployeeDataModelTests { Assert.That(employee.Id, Is.EqualTo(employeeId)); Assert.That(employee.FIO, Is.EqualTo(fio)); + Assert.That(employee.Email, Is.EqualTo(email)); Assert.That(employee.PostId, Is.EqualTo(postId)); Assert.That(employee.BirthDate, Is.EqualTo(birthDate)); Assert.That(employee.EmploymentDate, Is.EqualTo(employmentDate)); @@ -102,7 +124,7 @@ internal class EmployeeDataModelTests }); } - private static EmployeeDataModel CreateDataModel(string? id, string? fio, string? postId, - DateTime birthDate, DateTime employmentDate, bool isDeleted) => - new(id, fio, postId, birthDate, employmentDate, isDeleted); + private static EmployeeDataModel CreateDataModel(string? id, string? fio, string? email, + string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) => + new(id, fio, email, postId, birthDate, employmentDate, isDeleted); } diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs index 71289f9..968e447 100644 --- a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs @@ -9,11 +9,11 @@ internal class InstallationDataModelTests [Test] public void IdIsNullOrEmptyTest() { - var installation = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), + var installation = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); - installation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), + installation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); } @@ -21,7 +21,7 @@ internal class InstallationDataModelTests [Test] public void IdIsNotGuidTest() { - var installation = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), + var installation = CreateDataModel("id", Guid.NewGuid().ToString(), DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); } @@ -29,11 +29,11 @@ internal class InstallationDataModelTests [Test] public void EmployeeIdIsNullOrEmptyTest() { - var installation = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), + var installation = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); - installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), + installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); } @@ -41,15 +41,7 @@ internal class InstallationDataModelTests [Test] public void EmployeeIdIsNotGuidTest() { - var installation = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(), - DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); - Assert.That(() => installation.Validate(), Throws.TypeOf()); - } - - [Test] - public void ClientIdIsNotGuidTest() - { - var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + var installation = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); } @@ -57,11 +49,11 @@ internal class InstallationDataModelTests [Test] public void InstallationPriceIsLessOrZeroTest() { - var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 0, 20, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); - installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, -10, 20, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); } @@ -69,11 +61,11 @@ internal class InstallationDataModelTests [Test] public void SumIsLessOrZeroTest() { - var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 10, 0, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); - installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 10, -20, false, CreateSubDataModel()); Assert.That(() => installation.Validate(), Throws.TypeOf()); } @@ -81,11 +73,11 @@ internal class InstallationDataModelTests [Test] public void ProductsIsNullOrEmptyTest() { - var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 10, 20, false, null); Assert.That(() => installation.Validate(), Throws.TypeOf()); - installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 10, 20, false, []); Assert.That(() => installation.Validate(), Throws.TypeOf()); } @@ -95,12 +87,11 @@ internal class InstallationDataModelTests { var installationId = Guid.NewGuid().ToString(); var employeeId = Guid.NewGuid().ToString(); - var client = Guid.NewGuid().ToString(); var installationPrice = 10; var sum = 20; var isCanceled = true; var components = CreateSubDataModel(); - var installation = CreateDataModel(installationId, employeeId, client, + var installation = CreateDataModel(installationId, employeeId, DateTime.UtcNow, installationPrice, sum, isCanceled, components); Assert.That(() => installation.Validate(), Throws.Nothing); @@ -109,17 +100,16 @@ internal class InstallationDataModelTests { Assert.That(installation.Id, Is.EqualTo(installationId)); Assert.That(installation.EmployeeId, Is.EqualTo(employeeId)); - Assert.That(installation.ClientId, Is.EqualTo(client)); Assert.That(installation.Sum, Is.EqualTo(sum)); Assert.That(installation.IsCanceled, Is.EqualTo(isCanceled)); Assert.That(installation.Components, Is.EquivalentTo(components)); }); } - private static InstallationDataModel CreateDataModel(string id, string employeeId, string? clientId, + private static InstallationDataModel CreateDataModel(string id, string employeeId, DateTime installationDate, double installationPrice, double sum, bool isCanceled, List components) => - new(id, employeeId, clientId, installationDate, installationPrice, sum, isCanceled, components); + new(id, employeeId, installationDate, installationPrice, sum, isCanceled, components); private static List CreateSubDataModel() => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];