From 5790aecef298b266bebe4f9fb2a77e5bbf35211c Mon Sep 17 00:00:00 2001 From: Ivan Gutorov Date: Mon, 3 Feb 2025 01:12:40 +0400 Subject: [PATCH 1/6] add data models --- .../DataModels/ClientDataModel.cs | 33 +++++++++++ .../DataModels/ComponentDataModel.cs | 38 +++++++++++++ .../DataModels/EmployeeDataModel.cs | 47 ++++++++++++++++ .../InstallationComponentDataModel.cs | 33 +++++++++++ .../DataModels/InstallationDataModel.cs | 55 +++++++++++++++++++ .../DataModels/PostDataModel.cs | 46 ++++++++++++++++ .../DataModels/SalaryDataModel.cs | 26 +++++++++ .../Enums/ComponentType.cs | 11 ++++ .../TheCyclopsContracts/Enums/PostType.cs | 10 ++++ .../Exceptions/ValidationException.cs | 5 ++ .../Extensions/StringExtension.cs | 14 +++++ .../Infrastructure/IValidation.cs | 6 ++ 12 files changed, 324 insertions(+) create mode 100644 TheCyclopsProject/TheCyclopsContracts/DataModels/ClientDataModel.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/DataModels/ComponentDataModel.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/DataModels/EmployeeDataModel.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationComponentDataModel.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/DataModels/PostDataModel.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/DataModels/SalaryDataModel.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/Enums/ComponentType.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/Enums/PostType.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/Exceptions/ValidationException.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtension.cs create mode 100644 TheCyclopsProject/TheCyclopsContracts/Infrastructure/IValidation.cs diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/ClientDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/ClientDataModel.cs new file mode 100644 index 0000000..8669f11 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/ClientDataModel.cs @@ -0,0 +1,33 @@ +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/ComponentDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/ComponentDataModel.cs new file mode 100644 index 0000000..fe8ddaa --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/ComponentDataModel.cs @@ -0,0 +1,38 @@ +using TheCyclopsContracts.Enums; +using TheCyclopsContracts.Exceptions; +using TheCyclopsContracts.Extensions; +using TheCyclopsContracts.Infrastructure; + +namespace TheCyclopsContracts.DataModels; + +public class ComponentDataModel(string id, string componentName, + ComponentType componentType, double price, bool isDeleted) : IValidation +{ + public string Id { get; private set; } = id; + + public string ComponentName { get; private set; } = componentName; + + public ComponentType ComponentType { get; private set; } = componentType; + + public double Price { get; private set; } = price; + + public bool IsDeleted { get; private set; } = isDeleted; + + 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 (ComponentName.IsEmpty()) + throw new ValidationException("Field ComponentName is empty"); + + if (ComponentType == ComponentType.None) + throw new ValidationException("Field ComponentType is empty"); + + if (Price <= 0) + throw new ValidationException("Field Price is less than or equal to 0"); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/EmployeeDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/EmployeeDataModel.cs new file mode 100644 index 0000000..6e1f24e --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/EmployeeDataModel.cs @@ -0,0 +1,47 @@ +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 string Id { get; private set; } = id; + + public string FIO { get; private set; } = fio; + + public string PostId { get; private set; } = postId; + + public DateTime BirthDate { get; private set; } = birthDate; + + public DateTime EmploymentDate { get; private set; } = employmentDate; + + public bool IsDeleted { get; private set; } = isDeleted; + + 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 (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 (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) + throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})"); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationComponentDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationComponentDataModel.cs new file mode 100644 index 0000000..baf7f7d --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationComponentDataModel.cs @@ -0,0 +1,33 @@ +using TheCyclopsContracts.Exceptions; +using TheCyclopsContracts.Extensions; +using TheCyclopsContracts.Infrastructure; + +namespace TheCyclopsContracts.DataModels; + +public class InstallationComponentDataModel(string installationId, + string componentId, int count) : IValidation +{ + public string InstallationId { get; private set; } = installationId; + + public string ComponentId { get; private set; } = componentId; + + public int Count { get; private set; } = count; + + public void Validate() + { + if (InstallationId.IsEmpty()) + throw new ValidationException("Field InstallationId is empty"); + + if (!InstallationId.IsGuid()) + throw new ValidationException("The value in the field InstallationId is not a unique identifier"); + + if (ComponentId.IsEmpty()) + throw new ValidationException("Field ComponentId is empty"); + + if (!ComponentId.IsGuid()) + throw new ValidationException("The value in the field ComponentId is not a unique identifier"); + + if (Count <= 0) + throw new ValidationException("Field Count is less than or equal to 0"); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs new file mode 100644 index 0000000..9e39d32 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs @@ -0,0 +1,55 @@ +using TheCyclopsContracts.Exceptions; +using TheCyclopsContracts.Extensions; +using TheCyclopsContracts.Infrastructure; + +namespace TheCyclopsContracts.DataModels; + +public class InstallationDataModel(string id, string employeeId, string? clientId, + DateTime installationDate, double installationPrice, double sum, bool isCanceled, + List components) : IValidation +{ + public string Id { get; private set; } = id; + + 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; + + public double InstallationPrice { get; private set; } = installationPrice; + + public double Sum { get; private set; } = sum; + + public bool IsCanceled { get; private set; } = isCanceled; + + public List Components { get; private set; } = components; + + 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 (EmployeeId.IsEmpty()) + throw new ValidationException("Field EmployeeId is empty"); + + 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"); + + if (Sum <= 0) + throw new ValidationException("Field Sum is less than or equal to 0"); + + if ((Components?.Count ?? 0) == 0) + throw new ValidationException("The sale must include components"); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/PostDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/PostDataModel.cs new file mode 100644 index 0000000..6025af1 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/PostDataModel.cs @@ -0,0 +1,46 @@ +using TheCyclopsContracts.Enums; +using TheCyclopsContracts.Exceptions; +using TheCyclopsContracts.Extensions; + +namespace TheCyclopsContracts.DataModels; + +public class PostDataModel(string id, string PostId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) +{ + 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; + + 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 (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 (PostName.IsEmpty()) + throw new ValidationException("Field PostName is empty"); + + if (PostType == PostType.None) + throw new ValidationException("Field PostType is empty"); + + if (Salary <= 0) + throw new ValidationException("Field Salary is empty"); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/SalaryDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..d45c4c4 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/SalaryDataModel.cs @@ -0,0 +1,26 @@ +using TheCyclopsContracts.Exceptions; +using TheCyclopsContracts.Extensions; +using TheCyclopsContracts.Infrastructure; + +namespace TheCyclopsContracts.DataModels; + +public class SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary) : IValidation +{ + public string EmployeeId { get; private set; } = employeeId; + + public DateTime SalaryDate { get; private set; } = salaryDate; + + public double Salary { get; private set; } = employeeSalary; + + public void Validate() + { + if (EmployeeId.IsEmpty()) + throw new ValidationException("Field EmployeeId is empty"); + + if (!EmployeeId.IsGuid()) + throw new ValidationException("The value in the field EmployeeId is not a unique identifier"); + + if (Salary <= 0) + throw new ValidationException("Field Salary is less than or equal to 0"); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/Enums/ComponentType.cs b/TheCyclopsProject/TheCyclopsContracts/Enums/ComponentType.cs new file mode 100644 index 0000000..ca2cb65 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/Enums/ComponentType.cs @@ -0,0 +1,11 @@ +namespace TheCyclopsContracts.Enums; + +public enum ComponentType +{ + None = 0, + Camera = 1, + Sensor = 2, + ContropPanel = 3, + Cable = 4, + Other = 5 +} diff --git a/TheCyclopsProject/TheCyclopsContracts/Enums/PostType.cs b/TheCyclopsProject/TheCyclopsContracts/Enums/PostType.cs new file mode 100644 index 0000000..51e142a --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/Enums/PostType.cs @@ -0,0 +1,10 @@ +namespace TheCyclopsContracts.Enums; + +public enum PostType +{ + None = 0, + Designer = 1, + Installer = 2, + Seller = 3, + Administrator = 4 +} diff --git a/TheCyclopsProject/TheCyclopsContracts/Exceptions/ValidationException.cs b/TheCyclopsProject/TheCyclopsContracts/Exceptions/ValidationException.cs new file mode 100644 index 0000000..b601647 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/Exceptions/ValidationException.cs @@ -0,0 +1,5 @@ +namespace TheCyclopsContracts.Exceptions; + +public class ValidationException(string message) : Exception(message) +{ +} diff --git a/TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtension.cs b/TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtension.cs new file mode 100644 index 0000000..5617a8f --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtension.cs @@ -0,0 +1,14 @@ +namespace TheCyclopsContracts.Extensions; + +public static class StringExtension +{ + public static bool IsEmpty(this string str) + { + return string.IsNullOrEmpty(str); + } + + public static bool IsGuid(this string str) + { + return Guid.TryParse(str, out _); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/Infrastructure/IValidation.cs b/TheCyclopsProject/TheCyclopsContracts/Infrastructure/IValidation.cs new file mode 100644 index 0000000..ec8eb55 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/Infrastructure/IValidation.cs @@ -0,0 +1,6 @@ +namespace TheCyclopsContracts.Infrastructure; + +public interface IValidation +{ + void Validate(); +} -- 2.25.1 From 8d3154953b6c34dee2836a9dd02d6f033a360bc2 Mon Sep 17 00:00:00 2001 From: Ivan Gutorov Date: Mon, 3 Feb 2025 01:12:50 +0400 Subject: [PATCH 2/6] add tests --- TheCyclopsProject/TheCyclopsProject.sln | 6 + .../DataModelsTests/ClientDataModelTests.cs | 73 ++++++++++ .../ComponentDataModelTests.cs | 80 +++++++++++ .../DataModelsTests/EmployeeDataModelTests.cs | 108 +++++++++++++++ .../InstallationComponentDataModelTests.cs | 73 ++++++++++ .../InstallationDataModelTests.cs | 126 ++++++++++++++++++ .../DataModelsTests/PostDataModelTests.cs | 110 +++++++++++++++ .../DataModelsTests/SalaryDataModelTests.cs | 56 ++++++++ .../TheCyclopsTests/TheCyclopsTests.csproj | 27 ++++ 9 files changed, 659 insertions(+) create mode 100644 TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs create mode 100644 TheCyclopsProject/TheCyclopsTests/DataModelsTests/ComponentDataModelTests.cs create mode 100644 TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs create mode 100644 TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs create mode 100644 TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs create mode 100644 TheCyclopsProject/TheCyclopsTests/DataModelsTests/PostDataModelTests.cs create mode 100644 TheCyclopsProject/TheCyclopsTests/DataModelsTests/SalaryDataModelTests.cs create mode 100644 TheCyclopsProject/TheCyclopsTests/TheCyclopsTests.csproj diff --git a/TheCyclopsProject/TheCyclopsProject.sln b/TheCyclopsProject/TheCyclopsProject.sln index 0fc1d92..4fa5a94 100644 --- a/TheCyclopsProject/TheCyclopsProject.sln +++ b/TheCyclopsProject/TheCyclopsProject.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.12.35707.178 d17.12 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheCyclopsContracts", "TheCyclopsContracts\TheCyclopsContracts.csproj", "{01934235-715E-4B95-B859-48E8C89DA7CB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheCyclopsTests", "TheCyclopsTests\TheCyclopsTests.csproj", "{78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {01934235-715E-4B95-B859-48E8C89DA7CB}.Debug|Any CPU.Build.0 = Debug|Any CPU {01934235-715E-4B95-B859-48E8C89DA7CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {01934235-715E-4B95-B859-48E8C89DA7CB}.Release|Any CPU.Build.0 = Release|Any CPU + {78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs new file mode 100644 index 0000000..886ea3a --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs @@ -0,0 +1,73 @@ +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/ComponentDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ComponentDataModelTests.cs new file mode 100644 index 0000000..f0c233a --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ComponentDataModelTests.cs @@ -0,0 +1,80 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Enums; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class ComponentDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var component = CreateDataModel(null, "name", ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + + component = CreateDataModel(string.Empty, "name", ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var component = CreateDataModel("id", "name", ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductNameIsEmptyTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + + component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentTypeIsNoneTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.None, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Other, 0, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + + component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Other, -10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var componentId = Guid.NewGuid().ToString(); + var componentName = "name"; + var componentType = ComponentType.Other; + var componentManufacturerId = Guid.NewGuid().ToString(); + var componentPrice = 10; + var componentIsDelete = false; + var component = CreateDataModel(componentId, componentName, componentType, componentPrice, componentIsDelete); + + Assert.That(() => component.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(component.Id, Is.EqualTo(componentId)); + Assert.That(component.ComponentName, Is.EqualTo(componentName)); + Assert.That(component.ComponentType, Is.EqualTo(componentType)); + Assert.That(component.Price, Is.EqualTo(componentPrice)); + Assert.That(component.IsDeleted, Is.EqualTo(componentIsDelete)); + }); + } + + private static ComponentDataModel CreateDataModel(string? id, string? componentName, + ComponentType componentType, double price, bool isDeleted) => + new(id, componentName, componentType, price, isDeleted); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs new file mode 100644 index 0000000..24d7b12 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs @@ -0,0 +1,108 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class EmployeeDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var employee = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var employee = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void FIOIsNullOrEmptyTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), null, 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(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullOrEmptyTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "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); + 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); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var employeeId = Guid.NewGuid().ToString(); + var fio = "fio"; + 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); + + Assert.That(() => employee.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(employee.Id, Is.EqualTo(employeeId)); + Assert.That(employee.FIO, Is.EqualTo(fio)); + Assert.That(employee.PostId, Is.EqualTo(postId)); + Assert.That(employee.BirthDate, Is.EqualTo(birthDate)); + Assert.That(employee.EmploymentDate, Is.EqualTo(employmentDate)); + Assert.That(employee.IsDeleted, Is.EqualTo(isDeleted)); + }); + } + + private static EmployeeDataModel CreateDataModel(string? id, string? fio, string? postId, + DateTime birthDate, DateTime employmentDate, bool isDeleted) => + new(id, fio, postId, birthDate, employmentDate, isDeleted); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs new file mode 100644 index 0000000..6b55343 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs @@ -0,0 +1,73 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class InstallationComponentDataModelTests +{ + [Test] + public void InstallationIdIsNullOrEmptyTest() + { + var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + + saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void InstallationIdIsNotGuidTest() + { + var saleProduct = CreateDataModel("installationId", Guid.NewGuid().ToString(), 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentIdIsNullOrEmptyTest() + { + var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + + saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentIdIsNotGuidTest() + { + var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + + saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var installationId = Guid.NewGuid().ToString(); + var componentId = Guid.NewGuid().ToString(); + var count = 10; + var saleProduct = CreateDataModel(installationId, componentId, count); + + Assert.That(() => saleProduct.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(saleProduct.InstallationId, Is.EqualTo(installationId)); + Assert.That(saleProduct.ComponentId, Is.EqualTo(componentId)); + Assert.That(saleProduct.Count, Is.EqualTo(count)); + }); + } + + private static InstallationComponentDataModel CreateDataModel(string? installationId, string? componentId, int count) => + new(installationId, componentId, count); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs new file mode 100644 index 0000000..71289f9 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs @@ -0,0 +1,126 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class InstallationDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var installation = CreateDataModel(null, Guid.NewGuid().ToString(), 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(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var installation = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmployeeIdIsNullOrEmptyTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + + installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [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", + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void InstallationPriceIsLessOrZeroTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 0, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, -10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void SumIsLessOrZeroTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 10, 0, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 10, -20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductsIsNullOrEmptyTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 10, 20, false, null); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 10, 20, false, []); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + 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, + DateTime.UtcNow, installationPrice, sum, isCanceled, components); + + Assert.That(() => installation.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + 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, + DateTime installationDate, double installationPrice, double sum, bool isCanceled, + List components) => + new(id, employeeId, clientId, installationDate, installationPrice, sum, isCanceled, components); + + private static List CreateSubDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/PostDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/PostDataModelTests.cs new file mode 100644 index 0000000..d942348 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/PostDataModelTests.cs @@ -0,0 +1,110 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Enums; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class PostDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var post = CreateDataModel(null, Guid.NewGuid().ToString(), "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + + post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var post = CreateDataModel("id", Guid.NewGuid().ToString(), "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullEmptyTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), null, "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + + post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostNameIsEmptyTest() + { + var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + + manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostTypeIsNoneTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post", + PostType.None, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void SalaryIsLessOrZeroTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post", + PostType.Designer, 0, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + + post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post", + PostType.Designer, -10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var postId = Guid.NewGuid().ToString(); + var postPostId = Guid.NewGuid().ToString(); + var postName = "name"; + var postType = PostType.Designer; + var salary = 10; + var isActual = false; + var changeDate = DateTime.UtcNow.AddDays(-1); + var post = CreateDataModel(postId, postPostId, postName, postType, salary, isActual, changeDate); + + Assert.That(() => post.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(post.Id, Is.EqualTo(postId)); + 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); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SalaryDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SalaryDataModelTests.cs new file mode 100644 index 0000000..bb63037 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SalaryDataModelTests.cs @@ -0,0 +1,56 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class SalaryDataModelTests +{ + [Test] + public void WorkerIdIsEmptyTest() + { + var salary = CreateDataModel(null, DateTime.Now, 10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + + salary = CreateDataModel(string.Empty, DateTime.Now, 10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void WorkerIdIsNotGuidTest() + { + var salary = CreateDataModel("employeeId", DateTime.Now, 10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + + salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var employeeId = Guid.NewGuid().ToString(); + var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5); + var employeeSalary = 10; + var salary = CreateDataModel(employeeId, salaryDate, employeeSalary); + + Assert.That(() => salary.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(salary.EmployeeId, Is.EqualTo(employeeId)); + Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate)); + Assert.That(salary.Salary, Is.EqualTo(employeeSalary)); + }); + } + + private static SalaryDataModel CreateDataModel(string? employeeId, DateTime salaryDate, double workerSalary) => + new(employeeId, salaryDate, workerSalary); +} diff --git a/TheCyclopsProject/TheCyclopsTests/TheCyclopsTests.csproj b/TheCyclopsProject/TheCyclopsTests/TheCyclopsTests.csproj new file mode 100644 index 0000000..349b926 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/TheCyclopsTests.csproj @@ -0,0 +1,27 @@ + + + + net9.0 + latest + enable + enable + false + + + + + + + + + + + + + + + + + + + -- 2.25.1 From 4141cca5d8f99311bed381ea699882a66e5e5316 Mon Sep 17 00:00:00 2001 From: Ivan Gutorov Date: Mon, 3 Feb 2025 16:15:42 +0400 Subject: [PATCH 3/6] delete client model --- .../DataModels/ClientDataModel.cs | 33 --------- .../DataModels/EmployeeDataModel.cs | 14 +++- .../DataModels/InstallationDataModel.cs | 7 +- .../DataModelsTests/ClientDataModelTests.cs | 73 ------------------- .../DataModelsTests/EmployeeDataModelTests.cs | 60 ++++++++++----- .../InstallationDataModelTests.cs | 40 ++++------ 6 files changed, 69 insertions(+), 158 deletions(-) delete mode 100644 TheCyclopsProject/TheCyclopsContracts/DataModels/ClientDataModel.cs delete mode 100644 TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs 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)]; -- 2.25.1 From c265a2a22614b20f8d5630c58b7398465612ba99 Mon Sep 17 00:00:00 2001 From: Ivan Gutorov Date: Sun, 16 Feb 2025 12:45:44 +0400 Subject: [PATCH 4/6] fix extensions class naming --- .../Extensions/{StringExtension.cs => StringExtensions.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename TheCyclopsProject/TheCyclopsContracts/Extensions/{StringExtension.cs => StringExtensions.cs} (87%) diff --git a/TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtension.cs b/TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtensions.cs similarity index 87% rename from TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtension.cs rename to TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtensions.cs index 5617a8f..09942d1 100644 --- a/TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtension.cs +++ b/TheCyclopsProject/TheCyclopsContracts/Extensions/StringExtensions.cs @@ -1,6 +1,6 @@ namespace TheCyclopsContracts.Extensions; -public static class StringExtension +public static class StringExtensions { public static bool IsEmpty(this string str) { -- 2.25.1 From a7358fb837b1e06f69771c342eebd4e46872287c Mon Sep 17 00:00:00 2001 From: Ivan Gutorov Date: Sun, 16 Feb 2025 22:52:35 +0400 Subject: [PATCH 5/6] fix variable name in installation model tests --- .../InstallationComponentDataModelTests.cs | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs index 6b55343..a8e594b 100644 --- a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs @@ -9,45 +9,45 @@ internal class InstallationComponentDataModelTests [Test] public void InstallationIdIsNullOrEmptyTest() { - var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10); - Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + var installationComponent = CreateDataModel(null, Guid.NewGuid().ToString(), 10); + Assert.That(() => installationComponent.Validate(), Throws.TypeOf()); - saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); - Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + installationComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => installationComponent.Validate(), Throws.TypeOf()); } [Test] public void InstallationIdIsNotGuidTest() { - var saleProduct = CreateDataModel("installationId", Guid.NewGuid().ToString(), 10); - Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + var installationComponent = CreateDataModel("installationId", Guid.NewGuid().ToString(), 10); + Assert.That(() => installationComponent.Validate(), Throws.TypeOf()); } [Test] public void ComponentIdIsNullOrEmptyTest() { - var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10); - Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + var installationComponent = CreateDataModel(Guid.NewGuid().ToString(), null, 10); + Assert.That(() => installationComponent.Validate(), Throws.TypeOf()); - saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); - Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + installationComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => installationComponent.Validate(), Throws.TypeOf()); } [Test] public void ComponentIdIsNotGuidTest() { - var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 10); - Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + var installationComponent = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 10); + Assert.That(() => installationComponent.Validate(), Throws.TypeOf()); } [Test] public void CountIsLessOrZeroTest() { - var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); - Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + var installationComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => installationComponent.Validate(), Throws.TypeOf()); - saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10); - Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + installationComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10); + Assert.That(() => installationComponent.Validate(), Throws.TypeOf()); } [Test] @@ -56,15 +56,15 @@ internal class InstallationComponentDataModelTests var installationId = Guid.NewGuid().ToString(); var componentId = Guid.NewGuid().ToString(); var count = 10; - var saleProduct = CreateDataModel(installationId, componentId, count); + var installationComponent = CreateDataModel(installationId, componentId, count); - Assert.That(() => saleProduct.Validate(), Throws.Nothing); + Assert.That(() => installationComponent.Validate(), Throws.Nothing); Assert.Multiple(() => { - Assert.That(saleProduct.InstallationId, Is.EqualTo(installationId)); - Assert.That(saleProduct.ComponentId, Is.EqualTo(componentId)); - Assert.That(saleProduct.Count, Is.EqualTo(count)); + Assert.That(installationComponent.InstallationId, Is.EqualTo(installationId)); + Assert.That(installationComponent.ComponentId, Is.EqualTo(componentId)); + Assert.That(installationComponent.Count, Is.EqualTo(count)); }); } -- 2.25.1 From 5e91a0fc281252076cf90c350eab15ec3c2eba71 Mon Sep 17 00:00:00 2001 From: Ivan Gutorov Date: Mon, 17 Feb 2025 16:18:13 +0400 Subject: [PATCH 6/6] fix exception message --- .../TheCyclopsContracts/DataModels/InstallationDataModel.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs index 3730e21..04e6642 100644 --- a/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/InstallationDataModel.cs @@ -45,6 +45,6 @@ public class InstallationDataModel(string id, string employeeId, throw new ValidationException("Field Sum is less than or equal to 0"); if ((Components?.Count ?? 0) == 0) - throw new ValidationException("The sale must include components"); + throw new ValidationException("The installation must include components"); } } -- 2.25.1