diff --git a/.gitignore b/.gitignore index ca1c7a3..2578d88 100644 --- a/.gitignore +++ b/.gitignore @@ -397,4 +397,4 @@ FodyWeavers.xsd # JetBrains Rider *.sln.iml - +*/*.idea \ No newline at end of file diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts.sln b/SoftwareInstallationContracts/SoftwareInstallationContracts.sln index 44f8d7b..d62a56b 100644 --- a/SoftwareInstallationContracts/SoftwareInstallationContracts.sln +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts.sln @@ -1,10 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.12.35514.174 d17.12 +VisualStudioVersion = 17.12.35514.174 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationContracts", "SoftwareInstallationContracts\SoftwareInstallationContracts.csproj", "{B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationTests", "..\SoftwareInstallationTests\SoftwareInstallationTests.csproj", "{7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}.Debug|Any CPU.Build.0 = Debug|Any CPU {B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}.Release|Any CPU.ActiveCfg = Release|Any CPU {B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}.Release|Any CPU.Build.0 = Release|Any CPU + {7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/ClientDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/ClientDataModel.cs new file mode 100644 index 0000000..676ca02 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/ClientDataModel.cs @@ -0,0 +1,36 @@ +using System.Text.RegularExpressions; +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Extensions; +using SoftwareInstallationContracts.Infrastucture; + +namespace SoftwareInstallationContracts.DataModels; + +public class ClientDataModel(string id, string fio, string phoneNumber) : IValidation +{ + public string Id { get; private set; } = id; + + public string FIO { get; private set; } = fio; + + public string PhoneNumber { get; private set; } = phoneNumber; + + public void Validate() + { + if (Id.isEmpty()) + throw new ValidationFieldException("Field Id is empty"); + + if (!Id.isGuid()) + throw new ValidationFieldException("The value in the field Id is not a unique identifier"); + + if (FIO.isEmpty()) + throw new ValidationFieldException("Field FIO is empty"); + + if (!Regex.IsMatch(FIO, @"^[A-ZА-ЯЁ][a-zа-яё]+(?:-[A-ZА-ЯЁ][a-zа-яё]+)?\s[A-ZА-ЯЁ][a-zа-яё]+(?:-[A-ZА-ЯЁ][a-zа-яё]+)?\s[A-ZА-ЯЁ][a-zа-яё]+(?:-[A-ZА-ЯЁ][a-zа-яё]+)?$")) + throw new ValidationFieldException("Field FIO is not a valid full name."); + + if (PhoneNumber.isEmpty()) + throw new ValidationFieldException("Field PhoneNumber is empty"); + + if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$")) + throw new ValidationFieldException("Field PhoneNumber is not a phone number"); + } +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/CompanyDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/CompanyDataModel.cs new file mode 100644 index 0000000..1de0a15 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/CompanyDataModel.cs @@ -0,0 +1,29 @@ +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Extensions; +using SoftwareInstallationContracts.Infrastucture; + +namespace SoftwareInstallationContracts.DataModels; + +public class CompanyDataModel(string id, string companyName, string prevCompanyName, + string prevPrevCompanyName) : IValidation +{ + public string Id { get; private set; } = id; + + public string CompanyName { get; private set; } = companyName; + + public string? PrevCompanyName { get; private set; } = prevCompanyName; + + public string? PrevPrevCompanyName { get; private set; } = prevPrevCompanyName; + + public void Validate() + { + if (Id.isEmpty()) + throw new ValidationFieldException("Field Id is empty"); + + if (!Id.isGuid()) + throw new ValidationFieldException("The value in the field Id is not a unique identifier"); + + if (CompanyName.isEmpty()) + throw new ValidationFieldException("Field CompanyName is empty"); + } +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationDataModel.cs new file mode 100644 index 0000000..ec8d353 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationDataModel.cs @@ -0,0 +1,47 @@ +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Extensions; +using SoftwareInstallationContracts.Infrastucture; + +namespace SoftwareInstallationContracts.DataModels; + +public class InstallationDataModel(string id, string workerId, string clientId, + double sum, bool isCancel, List programs) : IValidation +{ + public string Id { get; private set; } = id; + + public string WorkerId { get; private set; } = workerId; + + public string? ClientId { get; private set; } = clientId; + + public DateTime InstallationDate { get; private set; } = DateTime.UtcNow; + + public double Sum { get; private set; } = sum; + + public bool IsCancel { get; private set; } = isCancel; + + public List Programs { get; private set; } = programs; + + public void Validate() + { + if (Id.isEmpty()) + throw new ValidationFieldException("Field Id is empty"); + + if (!Id.isGuid()) + throw new ValidationFieldException("The value in the field Id is not a unique identifier"); + + if (WorkerId.isEmpty()) + throw new ValidationFieldException("Field WorkerId is empty"); + + if (!WorkerId.isGuid()) + throw new ValidationFieldException("The value in the field WorkerId is not a unique identifier"); + + if (!ClientId?.isGuid() ?? !ClientId?.isEmpty() ?? false) + throw new ValidationFieldException("The value in the field ClientId is not a unique identifier"); + + if (Sum <= 0) + throw new ValidationFieldException("Field Sum is less than or wqual to 0"); + + if ((Programs?.Count() ?? 0) == 0) + throw new ValidationFieldException("The sale must include programs"); + } +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationSoftwareDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationSoftwareDataModel.cs new file mode 100644 index 0000000..da2d979 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationSoftwareDataModel.cs @@ -0,0 +1,32 @@ +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Extensions; +using SoftwareInstallationContracts.Infrastucture; + +namespace SoftwareInstallationContracts.DataModels; + +public class InstallationSoftwareDataModel(string installationId, string programId, int count) : IValidation +{ + public string ProgramId { get; private set; } = programId; + + public string InstallationId { get; private set; } = installationId; + + public int Count { get; private set; } = count; + + public void Validate() + { + if (ProgramId.isEmpty()) + throw new ValidationFieldException("Field ProgramId is empty"); + + if (!ProgramId.isGuid()) + throw new ValidationFieldException("The value in the field ProgramId is not a unique identifier"); + + if (InstallationId.isEmpty()) + throw new ValidationFieldException("Field InstallationId is empty"); + + if (!InstallationId.isGuid()) + throw new ValidationFieldException("The value in the field InstallationId is not a unique identifier"); + + if (Count <= 0) + throw new ValidationFieldException("Field Count is less than or equal to 0"); + } +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/PostDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/PostDataModel.cs new file mode 100644 index 0000000..c88641a --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/PostDataModel.cs @@ -0,0 +1,50 @@ +using SoftwareInstallationContracts.Enums; +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Extensions; +using SoftwareInstallationContracts.Infrastucture; + +namespace SoftwareInstallationContracts.DataModels; + +public class PostDataModel(string id, string postId, string postName, PostType postType, + double salary, bool isActual, DateTime changeDate) : IValidation +{ + + public string Id { get; private set; } = id; + + public string PostId { get; private set; } = postId; + + public string PostName { get; private set; } = postName; + + public PostType PostType { get; private set; } = postType; + + public double Salary { get; private set; } = salary; + + public bool IsActual { get; private set; } = isActual; + + public DateTime ChangeDate { get; private set; } = changeDate; + + public void Validate() + { + if (Id.isEmpty()) + throw new ValidationFieldException("Field Id is empty"); + + if (!Id.isGuid()) + throw new ValidationFieldException("The value in the field Id is not a unique identifier"); + + if (PostId.isEmpty()) + throw new ValidationFieldException("Field PostId is empty"); + + if (!PostId.isGuid()) + throw new ValidationFieldException("The value in the field PostId is not a unique identifier"); + + if (Salary <= 0) + throw new ValidationFieldException("Field Salary is empty"); + + if (PostType == PostType.None) + throw new ValidationFieldException("Field PostType is empty"); + + if (PostName.isEmpty()) + throw new ValidationFieldException("Field PostName is empty"); + } + +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SalaryDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..f5523b4 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SalaryDataModel.cs @@ -0,0 +1,26 @@ +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Extensions; +using SoftwareInstallationContracts.Infrastucture; + +namespace SoftwareInstallationContracts.DataModels; + +public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation +{ + public string WorkerId { get; private set; } = workerId; + + public DateTime SalaryDate { get; private set; } = salaryDate; + + public double Salary { get; private set; } = workerSalary; + + public void Validate() + { + if (WorkerId.isEmpty()) + throw new ValidationFieldException("Field WorkerId is empty"); + + if (!WorkerId.isGuid()) + throw new ValidationFieldException("The value in the field WorkerId is not a unique identifier"); + + if (Salary <= 0) + throw new ValidationFieldException("Field Salary is less than or equal to 0"); + } +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareDataModel.cs new file mode 100644 index 0000000..1ca9021 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareDataModel.cs @@ -0,0 +1,46 @@ +using SoftwareInstallationContracts.Enums; +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Extensions; +using SoftwareInstallationContracts.Infrastucture; + +namespace SoftwareInstallationContracts.DataModels; + +public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, + string companyId, double price, bool isDeleted) : IValidation +{ + public string Id { get; private set; } = id; + + public string SoftwareName { get; private set; } = softwareName; + + public SoftwareType SoftwareType { get; private set; } = softwareType; + + public string CompanyId { get; private set; } = companyId; + + public double Price { get; private set; } = price; + + public bool IsDeleted { get; private set; } = isDeleted; + + public void Validate() + { + if (Id.isEmpty()) + throw new ValidationFieldException("Field Id is empty"); + + if (!Id.isGuid()) + throw new ValidationFieldException("The value in the field Id is not a unique identifier"); + + if (SoftwareName.isEmpty()) + throw new ValidationFieldException("Field SoftwareName is empty"); + + if (SoftwareType == SoftwareType.None) + throw new ValidationFieldException("Field SoftwareType is empty"); + + if (CompanyId.isEmpty()) + throw new ValidationFieldException("Field CompanyId is empty"); + + if (!CompanyId.isGuid()) + throw new ValidationFieldException("The value in the field CompanyId is not a unique identifier"); + + if (Price <= 0) + throw new ValidationFieldException("Field Price is less than or equal to 0"); + } +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareHistoryDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareHistoryDataModel.cs new file mode 100644 index 0000000..5f96b32 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareHistoryDataModel.cs @@ -0,0 +1,26 @@ +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Extensions; +using SoftwareInstallationContracts.Infrastucture; + +namespace SoftwareInstallationContracts.DataModels; + +public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IValidation +{ + public string SoftwareId { get; private set; } = softwareId; + + public double OldPrice { get; private set; } = oldPrice; + + public DateTime ChangeDate { get; private set; } = DateTime.UtcNow; + + public void Validate() + { + if (SoftwareId.isEmpty()) + throw new ValidationFieldException("Field SoftwareId is empty"); + + if (!SoftwareId.isGuid()) + throw new ValidationFieldException("The value in the field SoftwareId is not a unique identifier"); + + if (OldPrice <= 0) + throw new ValidationFieldException("Field OldPrice is less than or equal to 0"); + } +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/WorkerDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/WorkerDataModel.cs new file mode 100644 index 0000000..188403a --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/WorkerDataModel.cs @@ -0,0 +1,50 @@ +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Extensions; +using SoftwareInstallationContracts.Infrastucture; + +namespace SoftwareInstallationContracts.DataModels; + +public class WorkerDataModel(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 ValidationFieldException("Field Id is empty"); + + if (!Id.isGuid()) + throw new ValidationFieldException("The value in the field Id is not a unique identifier"); + + if (FIO.isEmpty()) + throw new ValidationFieldException("Field FIO is empty"); + + if (PostId.isEmpty()) + throw new ValidationFieldException("Field PostId is empty"); + + if (!PostId.isGuid()) + throw new ValidationFieldException("The value in the field PostId is not a unique identifier"); + + if (BirthDate.Date > DateTime.Now.AddYears(-16).Date) + throw new ValidationFieldException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()}"); + + if (EmploymentDate.Date < BirthDate.Date) + throw new ValidationFieldException("The date of employment cannot be less than the date of birth"); + + if ((EmploymentDate - BirthDate).TotalDays / 365 < 16) + throw new ValidationFieldException($"Minors cannot be hired " + + $"(EmploymentDate - {EmploymentDate.ToShortDateString()}," + + $" BirthDate - {BirthDate.ToShortDateString()}"); + } +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/Enums/PostType.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/Enums/PostType.cs new file mode 100644 index 0000000..2022698 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/Enums/PostType.cs @@ -0,0 +1,9 @@ +namespace SoftwareInstallationContracts.Enums; + +public enum PostType +{ + None = 0, + Supervisor = 1, + Master = 2, + Stuff = 3 +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/Enums/SoftwareType.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/Enums/SoftwareType.cs new file mode 100644 index 0000000..ab997cb --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/Enums/SoftwareType.cs @@ -0,0 +1,10 @@ +namespace SoftwareInstallationContracts.Enums; + +public enum SoftwareType +{ + None = 0, + SystemSoftware = 1, + ApplicationSoftware = 2, + UtilitySoftware = 3, + EnterpriseSoftware = 4 +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/Exceptions/ValidationFieldException.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/Exceptions/ValidationFieldException.cs new file mode 100644 index 0000000..be3a17e --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/Exceptions/ValidationFieldException.cs @@ -0,0 +1,5 @@ +namespace SoftwareInstallationContracts.Exceptions; + +public class ValidationFieldException(String message) : Exception(message) +{ +} diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/Extensions/StringExceptions.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/Extensions/StringExceptions.cs new file mode 100644 index 0000000..c059f31 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/Extensions/StringExceptions.cs @@ -0,0 +1,14 @@ +namespace SoftwareInstallationContracts.Extensions; + +public static class StringExceptions +{ + 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/SoftwareInstallationContracts/SoftwareInstallationContracts/Infrastucture/IValidation.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/Infrastucture/IValidation.cs new file mode 100644 index 0000000..e0e0cd4 --- /dev/null +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/Infrastucture/IValidation.cs @@ -0,0 +1,6 @@ +namespace SoftwareInstallationContracts.Infrastucture; + +public interface IValidation +{ + void Validate(); +} diff --git a/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs new file mode 100644 index 0000000..3e642a3 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs @@ -0,0 +1,78 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; + +namespace SoftwareInstallationTests.DataModelsTests; + +[TestFixture] +internal class ClientDataModelTests +{ + private ClientDataModel client; + + [Test] + public void IdIsNullOrEmptyTest() + { + client = CreateDataModel(null, "Fio Fio Fio", "+7-777-777-77-77"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + client = CreateDataModel(string.Empty, "Fio Fio Fio", "+7-777-777-77-77"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + client = CreateDataModel("id", "Fio Fio Fio", "+7-777-777-77-77"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void FIOIsNullOrEmptyTest() + { + client = CreateDataModel(Guid.NewGuid().ToString(), null, "+7-777-777-77-77"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "+7-777-777-77-77"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void FIOIsIncorrectTest() + { + client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "+7-777-777-77-77"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void PhoneNumberIsNullOrEmptyTest() + { + client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", null); + Assert.That(() => client.Validate(), Throws.TypeOf()); + client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", string.Empty); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void PhoneNumberIsIncorrectTest() + { + client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", "777"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + string phoneNumber = "+7-777-777-77-77"; + string fio = "Vasiliy Vasiliev Vasilievich"; + string id = Guid.NewGuid().ToString(); + client = CreateDataModel(id, fio, phoneNumber); + Assert.That(() => client.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(client.Id, Is.EqualTo(id)); + Assert.That(client.FIO, Is.EqualTo(fio)); + Assert.That(client.PhoneNumber, Is.EqualTo(phoneNumber)); + }); + } + + private static ClientDataModel CreateDataModel(string? id, string? fio, string? phoneNumber) => +new(id, fio, phoneNumber); +} diff --git a/SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs new file mode 100644 index 0000000..48cccbd --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs @@ -0,0 +1,56 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; + +namespace SoftwareInstallationTests.DataModelsTests; + +[TestFixture] +internal class CompanyDataModelTests +{ + private CompanyDataModel company; + + [Test] + public void IdIsNullEmptyTest() + { + company = CreateDataModel(null, "name"); + Assert.That(() => company.Validate(), Throws.TypeOf()); + company = CreateDataModel(string.Empty, "name"); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + company = CreateDataModel("id", "name"); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void CompanyNameIsNullOrEmptyTest() + { + company = CreateDataModel(Guid.NewGuid().ToString(), null); + Assert.That(() => company.Validate(), Throws.TypeOf()); + company = CreateDataModel(Guid.NewGuid().ToString(), string.Empty); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + string companyId = Guid.NewGuid().ToString(); + string companyName = "name"; + string prevcompanyName = "prevcompanyName"; + string prevPrevcompanyName = "prevPrevcompanyName"; + company = CreateDataModel(companyId, companyName, prevcompanyName, prevPrevcompanyName); + Assert.That(() => company.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(company.Id, Is.EqualTo(companyId)); + Assert.That(company.CompanyName, Is.EqualTo(companyName)); + Assert.That(company.PrevCompanyName, Is.EqualTo(prevcompanyName)); + Assert.That(company.PrevPrevCompanyName, Is.EqualTo(prevPrevcompanyName)); + }); + } + + private static CompanyDataModel CreateDataModel(string? id, string? companyName, string? prevcompanyName = null, string? prevPrevcompanyName = null) => + new(id, companyName, prevcompanyName, prevPrevcompanyName); +} diff --git a/SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs new file mode 100644 index 0000000..31707ef --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs @@ -0,0 +1,94 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; + +namespace SoftwareInstallationTests.DataModelsTests; + +[TestFixture] +internal class InstallationDataModelTests +{ + private InstallationDataModel installation; + + [Test] + public void IdIsNullOrEmptyTest() + { + installation = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + installation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + installation = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + [Test] + public void WorkerIdIsNullOrEmptyTest() + { + installation = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void WorkerIdIsNotGuidTest() + { + installation = CreateDataModel(Guid.NewGuid().ToString(), "workerId", Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void ClientIdIsNotGuidTest() + { + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "clientId", 10, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void SumIsLessOrZeroTest() + { + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void SoftwaresIsNullOrEmptyTest() + { + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, null); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, []); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + string installationId = Guid.NewGuid().ToString(); + string workerId = Guid.NewGuid().ToString(); + string clientId = Guid.NewGuid().ToString(); + double sum = 10; + bool isCancel = true; + List softwares = CreateSubDataModel(); + installation = CreateDataModel(installationId, workerId, clientId, sum, isCancel, softwares); + Assert.That(() => installation.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(installation.Id, Is.EqualTo(installationId)); + Assert.That(installation.WorkerId, Is.EqualTo(workerId)); + Assert.That(installation.ClientId, Is.EqualTo(clientId)); + Assert.That(installation.Sum, Is.EqualTo(sum)); + Assert.That(installation.IsCancel, Is.EqualTo(isCancel)); + Assert.That(installation.Programs, Is.EquivalentTo(softwares)); + }); + } + + private static InstallationDataModel CreateDataModel(string? id, string? workerId, string? clientId, double sum, bool isCancel, List? softwares) => + new(id, workerId, clientId, sum, isCancel, softwares); + + private static List CreateSubDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; +} diff --git a/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs new file mode 100644 index 0000000..1329297 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs @@ -0,0 +1,70 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; + +namespace SoftwareInstallationTests.DataModelsTests; + +[TestFixture] +internal class InstallationSoftwareDataModelTests +{ + private InstallationSoftwareDataModel installSoftware; + + [Test] + public void InstallIdIsNullOrEmptyTest() + { + installSoftware = CreateDataModel(null, Guid.NewGuid().ToString(), 10); + Assert.That(() => installSoftware.Validate(), Throws.TypeOf()); + installSoftware = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => installSoftware.Validate(), Throws.TypeOf()); + } + + [Test] + public void InstallIdIsNotGuidTest() + { + installSoftware = CreateDataModel("installId", Guid.NewGuid().ToString(), 10); + Assert.That(() => installSoftware.Validate(), Throws.TypeOf()); + } + + [Test] + public void SoftwareIdIsNullOrEmptyTest() + { + installSoftware = CreateDataModel(Guid.NewGuid().ToString(), null, 10); + Assert.That(() => installSoftware.Validate(), Throws.TypeOf()); + installSoftware = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => installSoftware.Validate(), Throws.TypeOf()); + } + + [Test] + public void SoftwareIdIsNotGuidTest() + { + installSoftware = CreateDataModel(Guid.NewGuid().ToString(), "softwareId", 10); + Assert.That(() => installSoftware.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + installSoftware = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => installSoftware.Validate(), Throws.TypeOf()); + installSoftware = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10); + Assert.That(() => installSoftware.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + string installId = Guid.NewGuid().ToString(); + string softwareId = Guid.NewGuid().ToString(); + int count = 10; + installSoftware = CreateDataModel(installId, softwareId, count); + Assert.That(() => installSoftware.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(installSoftware.InstallationId, Is.EqualTo(installId)); + Assert.That(installSoftware.ProgramId, Is.EqualTo(softwareId)); + Assert.That(installSoftware.Count, Is.EqualTo(count)); + }); + } + + private static InstallationSoftwareDataModel CreateDataModel(string? installId, string? softwareId, int count) => + new(installId, softwareId, count); +} diff --git a/SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs new file mode 100644 index 0000000..c073206 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs @@ -0,0 +1,96 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Enums; +using SoftwareInstallationContracts.Exceptions; + +namespace SoftwareInstallationTests.DataModelsTests; + +[TestFixture] +internal class PostDataModelTests +{ + private PostDataModel post; + + [Test] + public void idIsNotNullOrEmpty() + { + post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullEmptyTest() + { + post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Stuff, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Stuff, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Stuff, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void SalaryIsLessOrZeroTest() + { + post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Stuff, 0, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Stuff, -10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostTypeIsNoneTest() + { + post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostNameIsEmptyTest() + { + post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Stuff, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Stuff, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + string postId = Guid.NewGuid().ToString(); + string postPostId = Guid.NewGuid().ToString(); + string postName = "name"; + PostType postType = PostType.Stuff; + double salary = 10; + bool isActual = false; + DateTime changeDate = DateTime.UtcNow.AddDays(-1); + 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/SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs new file mode 100644 index 0000000..094b839 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs @@ -0,0 +1,54 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; + +namespace SoftwareInstallationTests.DataModelsTests; + +[TestFixture] +internal class SalaryDataModelTests +{ + private SalaryDataModel salary; + + [Test] + public void WorkerIdIsEmptyTest() + { + 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() + { + salary = CreateDataModel("workerId", DateTime.Now, 10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + 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() + { + string workerId = Guid.NewGuid().ToString(); + DateTime salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5); + double workerSalary = 10; + SalaryDataModel salary = CreateDataModel(workerId, salaryDate, workerSalary); + Assert.That(() => salary.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(salary.WorkerId, Is.EqualTo(workerId)); + Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate)); + Assert.That(salary.Salary, Is.EqualTo(workerSalary)); + }); + } + + private static SalaryDataModel CreateDataModel(string? workerId, DateTime salaryDate, + double workerSalary) => new(workerId, salaryDate, workerSalary); +} diff --git a/SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs new file mode 100644 index 0000000..5414585 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs @@ -0,0 +1,94 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Enums; +using SoftwareInstallationContracts.Exceptions; + +namespace SoftwareInstallationTests.DataModelsTests; + +[TestFixture] +internal class SoftwareDataModelTests +{ + private SoftwareDataModel software; + + [Test] + public void IdIsNullOrEmptyTest() + { + software = CreateDataModel(null, "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + software = CreateDataModel(string.Empty, "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + software = CreateDataModel("id", "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + } + + [Test] + public void SoftwareNameIsEmptyTest() + { + software = CreateDataModel(Guid.NewGuid().ToString(), null, SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + software = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + } + + [Test] + public void SoftwareTypeIsNoneTest() + { + software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.None, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + } + + [Test] + public void CompanyIdIsNullOrEmptyTest() + { + software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, null, 10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, string.Empty, 10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + } + + [Test] + public void CompanyIdIsNotGuidTest() + { + software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, "companyId", 10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 0, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), -10, false); + Assert.That(() => software.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + string softwareId = Guid.NewGuid().ToString(); + string softwareName = "name"; + SoftwareType softwareType = SoftwareType.ApplicationSoftware; + string softwareCompanyId = Guid.NewGuid().ToString(); + double softwarePrice = 10; + bool softwareIsDelete = false; + SoftwareDataModel software = CreateDataModel(softwareId, softwareName, softwareType, softwareCompanyId, softwarePrice, softwareIsDelete); + Assert.That(() => software.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(software.Id, Is.EqualTo(softwareId)); + Assert.That(software.SoftwareName, Is.EqualTo(softwareName)); + Assert.That(software.SoftwareType, Is.EqualTo(softwareType)); + Assert.That(software.CompanyId, Is.EqualTo(softwareCompanyId)); + Assert.That(software.Price, Is.EqualTo(softwarePrice)); + Assert.That(software.IsDeleted, Is.EqualTo(softwareIsDelete)); + }); + } + + private static SoftwareDataModel CreateDataModel(string? id, string? softwareName, SoftwareType softwareType, + string? companyId, double price, bool isDeleted) => + new(id, softwareName, softwareType, companyId, price, isDeleted); +} diff --git a/SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs new file mode 100644 index 0000000..8a701de --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs @@ -0,0 +1,55 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; + +namespace SoftwareInstallationTests.DataModelsTests; + +[TestFixture] +internal class SoftwareHistoryDataModelTests +{ + private SoftwareHistoryDataModel programHistory; + + [Test] + public void programHistoryIdIsNullOrEmptyTest() + { + programHistory = CreateDataModel(null, 10); + Assert.That(() => programHistory.Validate(), Throws.TypeOf()); + programHistory = CreateDataModel(string.Empty, 10); + Assert.That(() => programHistory.Validate(), Throws.TypeOf()); + } + + [Test] + public void programHistoryIdIsNotGuidTest() + { + programHistory = CreateDataModel("id", 10); + Assert.That(() => programHistory.Validate(), Throws.TypeOf()); + } + + [Test] + public void OldPriceIsLessOrZeroTest() + { + programHistory = CreateDataModel(Guid.NewGuid().ToString(), 0); + Assert.That(() => programHistory.Validate(), Throws.TypeOf()); + programHistory = CreateDataModel(Guid.NewGuid().ToString(), -10); + Assert.That(() => programHistory.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + string programHistoryId = Guid.NewGuid().ToString(); + double oldPrice = 10; + programHistory = CreateDataModel(programHistoryId, oldPrice); + Assert.That(() => programHistory.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(programHistory.SoftwareId, Is.EqualTo(programHistoryId)); + Assert.That(programHistory.OldPrice, Is.EqualTo(oldPrice)); + Assert.That(programHistory.ChangeDate, Is.LessThan(DateTime.UtcNow)); + Assert.That(programHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1))); + }); + } + + + private static SoftwareHistoryDataModel CreateDataModel(string? programHistoryId, double oldPrice) => + new(programHistoryId, oldPrice); +} diff --git a/SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs new file mode 100644 index 0000000..4882eb2 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs @@ -0,0 +1,94 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; + +namespace SoftwareInstallationTests.DataModelsTests; + +[TestFixture] +internal class WorkerDataModelTests +{ + private WorkerDataModel worker; + + [Test] + public void IdIsNullOrEmptyTest() + { + worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + worker = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void FIOIsNullOrEmptyTest() + { + worker = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullOrEmptyTest() + { + worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void BirthDateIsNotCorrectTest() + { + worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void BirthDateAndEmploymentDateIsNotCorrectTest() + { + worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + string workerId = Guid.NewGuid().ToString(); + string fio = "vasiliy vasilievich"; + string postId = Guid.NewGuid().ToString(); + DateTime birthDate = DateTime.Now.AddYears(-16).AddDays(-1); + DateTime employmentDate = DateTime.Now; + bool isDelete = false; + worker = CreateDataModel(workerId, fio, 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.PostId, Is.EqualTo(postId)); + Assert.That(worker.BirthDate, Is.EqualTo(birthDate)); + Assert.That(worker.EmploymentDate, Is.EqualTo(employmentDate)); + Assert.That(worker.IsDeleted, Is.EqualTo(isDelete)); + }); + } + + + private static WorkerDataModel CreateDataModel(string? id, string? fio, string? postId, DateTime birthDate, + DateTime employmentDate, bool isDeleted) => + new(id, fio, postId, birthDate, employmentDate, isDeleted); +} diff --git a/SoftwareInstallationTests/SoftwareInstallationTests.csproj b/SoftwareInstallationTests/SoftwareInstallationTests.csproj new file mode 100644 index 0000000..96c6b73 --- /dev/null +++ b/SoftwareInstallationTests/SoftwareInstallationTests.csproj @@ -0,0 +1,27 @@ + + + + net9.0 + latest + enable + enable + false + + + + + + + + + + + + + + + + + + +