From e1f0e39b29f0c31a4163fa65ffd50e32610a5001 Mon Sep 17 00:00:00 2001 From: I1nur Date: Mon, 10 Feb 2025 20:25:06 +0400 Subject: [PATCH 1/4] checkstyle: fix naming and spaces --- .../DataModels/ClientDataModel.cs | 8 ++++---- .../DataModels/CompanyDataModel.cs | 7 ++++++- .../DataModels/InstallationDataModel.cs | 5 +++-- .../DataModels/InstallationSoftwareDataModel.cs | 12 ++++++------ .../DataModels/PostDataModel.cs | 3 ++- .../DataModels/SoftwareDataModel.cs | 7 ++++--- .../DataModels/SoftwareHistoryDataModel.cs | 4 ++-- .../DataModels/WorkerDataModel.cs | 12 ++++++++++-- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/ClientDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/ClientDataModel.cs index 54f2779..74960d7 100644 --- a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/ClientDataModel.cs +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/ClientDataModel.cs @@ -20,17 +20,17 @@ public class ClientDataModel(string id, string fio, string phoneNumber) : IValid public void Validate() { - if (id.isEmpty()) + if (Id.isEmpty()) throw new ValidationFieldException("Field Id is empty"); - if (!id.isGuid()) + 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а-яё]+ [A-ZA-ЯЁ][a-zа-яё]+$")) - throw new ValidationFieldException("Field FIO is not a fio"); + 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"); diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/CompanyDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/CompanyDataModel.cs index 5fc8066..135ad43 100644 --- a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/CompanyDataModel.cs +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/CompanyDataModel.cs @@ -11,12 +11,17 @@ using System.Threading.Tasks; namespace SoftwareInstallationContracts.DataModels; -public class CompanyDataModel(string id, string companyName, string prevCompanyName, string prevPrevCompanyName) : IValidation +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()) diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationDataModel.cs index 57af1db..6406171 100644 --- a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationDataModel.cs +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationDataModel.cs @@ -10,7 +10,8 @@ using System.Threading.Tasks; namespace SoftwareInstallationContracts.DataModels; -public class InstallationDataModel(string id, string workerId, string clientId, double sum, bool isCancel, List programs) : IValidation +public class InstallationDataModel(string id, string workerId, string clientId, + double sum, bool isCancel, List programs) : IValidation { public string Id { get; private set; } = id; @@ -18,7 +19,7 @@ public class InstallationDataModel(string id, string workerId, string clientId, public string? ClientId { get; private set; } = clientId; - public DateTime SaleDate { get; private set; } = DateTime.UtcNow; + public DateTime InstallationDate { get; private set; } = DateTime.UtcNow; public double Sum { get; private set; } = sum; diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationSoftwareDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationSoftwareDataModel.cs index ce61a22..e69e364 100644 --- a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationSoftwareDataModel.cs +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/InstallationSoftwareDataModel.cs @@ -9,11 +9,11 @@ using System.Threading.Tasks; namespace SoftwareInstallationContracts.DataModels; -public class InstallationSoftwareDataModel(string saleId, string programId, int count) : IValidation +public class InstallationSoftwareDataModel(string installationId, string programId, int count) : IValidation { public string ProgramId { get; private set; } = programId; - public string SaleId { get; private set; } = saleId; + public string InstallationId { get; private set; } = installationId; public int Count { get; private set; } = count; @@ -25,11 +25,11 @@ public class InstallationSoftwareDataModel(string saleId, string programId, int if (!ProgramId.isGuid()) throw new ValidationFieldException("The value in the field ProgramId is not a unique identifier"); - if (SaleId.isEmpty()) - throw new ValidationFieldException("Field SaleId is empty"); + if (InstallationId.isEmpty()) + throw new ValidationFieldException("Field InstallationId is empty"); - if (!SaleId.isGuid()) - throw new ValidationFieldException("The value in the field SaleId is not a unique identifier"); + 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 index a2f02d8..562ad9f 100644 --- a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/PostDataModel.cs +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/PostDataModel.cs @@ -10,7 +10,8 @@ using System.Threading.Tasks; namespace SoftwareInstallationContracts.DataModels; -public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation +public class PostDataModel(string id, string postId, string postName, PostType postType, + double salary, bool isActual, DateTime changeDate) : IValidation { public string Id { get; private set; } = id; diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareDataModel.cs index bcacf82..6d633be 100644 --- a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareDataModel.cs +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareDataModel.cs @@ -10,7 +10,8 @@ using System.Threading.Tasks; namespace SoftwareInstallationContracts.DataModels; -public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string companyId, double price, bool isDeleted) : IValidation +public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, + string companyId, double price, bool isDeleted) : IValidation { public string Id { get; private set; } = id; @@ -33,10 +34,10 @@ public class SoftwareDataModel(string id, string softwareName, SoftwareType soft throw new ValidationFieldException("The value in the field Id is not a unique identifier"); if (SoftwareName.isEmpty()) - throw new ValidationFieldException("Field ProgramName is empty"); + throw new ValidationFieldException("Field SoftwareName is empty"); if (SoftwareType == SoftwareType.None) - throw new ValidationFieldException("Field ProgramType is empty"); + throw new ValidationFieldException("Field SoftwareType is empty"); if (CompanyId.isEmpty()) throw new ValidationFieldException("Field CompanyId is empty"); diff --git a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareHistoryDataModel.cs b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareHistoryDataModel.cs index b0ea582..d3a7cfe 100644 --- a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareHistoryDataModel.cs +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/SoftwareHistoryDataModel.cs @@ -21,10 +21,10 @@ public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IVal public void Validate() { if (SoftwareId.isEmpty()) - throw new ValidationFieldException("Field ProgramId is empty"); + throw new ValidationFieldException("Field SoftwareId is empty"); if (!SoftwareId.isGuid()) - throw new ValidationFieldException("The value in the field ProgramId is not a unique identifier"); + 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 index a0376b7..c752cc2 100644 --- a/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/WorkerDataModel.cs +++ b/SoftwareInstallationContracts/SoftwareInstallationContracts/DataModels/WorkerDataModel.cs @@ -10,13 +10,19 @@ using System.Threading.Tasks; namespace SoftwareInstallationContracts.DataModels; -public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation +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() @@ -43,6 +49,8 @@ public class WorkerDataModel(string id, string fio, string postId, DateTime birt 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()}"); + throw new ValidationFieldException($"Minors cannot be hired " + + $"(EmploymentDate - {EmploymentDate.ToShortDateString()}," + + $" BirthDate - {BirthDate.ToShortDateString()}"); } } From 351975ba2b8ff53f6c31f13fd58bb5b14f97dd17 Mon Sep 17 00:00:00 2001 From: I1nur Date: Mon, 10 Feb 2025 20:47:17 +0400 Subject: [PATCH 2/4] fix: change folders --- .gitignore | 2 +- .../DataModelsTests/ClientDataModelTests.cs | 83 ++++++++++++++ .../DataModelsTests/CompanyDataModelTests.cs | 62 +++++++++++ .../InstallationDataModelTests.cs | 99 +++++++++++++++++ .../InstallationSoftwareDataModelTests.cs | 76 +++++++++++++ .../DataModelsTests/PostDataModelTests.cs | 101 ++++++++++++++++++ .../DataModelsTests/SalaryDataModelTests.cs | 60 +++++++++++ .../DataModelsTests/SoftwareDataModelTests.cs | 100 +++++++++++++++++ .../SoftwareHistoryDataModelTests.cs | 61 +++++++++++ .../DataModelsTests/WorkerDataModelTests.cs | 100 +++++++++++++++++ .../SoftwareInstallationTests.csproj | 27 +++++ .../DataModelsTests/ClientDataModelTests.cs | 20 ++-- .../InstallationSoftwareDataModelTests.cs | 2 +- 13 files changed, 781 insertions(+), 12 deletions(-) create mode 100644 SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs create mode 100644 SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs create mode 100644 SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs create mode 100644 SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs create mode 100644 SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs create mode 100644 SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs create mode 100644 SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs create mode 100644 SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs create mode 100644 SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs create mode 100644 SoftwareInstallationTests/SoftwareInstallationTests.csproj 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/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs new file mode 100644 index 0000000..7cd2460 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs @@ -0,0 +1,83 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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 Vasilievich Vasiliev"; + 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..b65cd25 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +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..981e8b1 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs @@ -0,0 +1,99 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..b81e079 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs @@ -0,0 +1,76 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..a780697 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs @@ -0,0 +1,101 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..a57f26d --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs @@ -0,0 +1,60 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..fb43cab --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs @@ -0,0 +1,100 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Enums; +using SoftwareInstallationContracts.Exceptions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static NUnit.Framework.Internal.OSPlatform; + +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..c24c97c --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs @@ -0,0 +1,61 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; +using SoftwareInstallationContracts.Enums; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..6ddc839 --- /dev/null +++ b/SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs @@ -0,0 +1,100 @@ +using SoftwareInstallationContracts.DataModels; +using SoftwareInstallationContracts.Exceptions; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +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..561fc18 --- /dev/null +++ b/SoftwareInstallationTests/SoftwareInstallationTests.csproj @@ -0,0 +1,27 @@ + + + + net9.0 + latest + enable + enable + false + + + + + + + + + + + + + + + + + + + diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs b/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs index 98aa58a..5fee08f 100644 --- a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs +++ b/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs @@ -16,48 +16,48 @@ internal class ClientDataModelTests [Test] public void IdIsNullOrEmptyTest() { - client = CreateDataModel(null, "fio", "number"); + client = CreateDataModel(null, "fio", "+7-777-777-77-77"); Assert.That(() => client.Validate(), Throws.TypeOf()); - client = CreateDataModel(string.Empty, "fio", "number"); + client = CreateDataModel(string.Empty, "fio", "+7-777-777-77-77"); Assert.That(() => client.Validate(), Throws.TypeOf()); } [Test] public void IdIsNotGuidTest() { - client = CreateDataModel("id", "fio", "number"); + 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, "number"); + client = CreateDataModel(Guid.NewGuid().ToString(), null, "+7-777-777-77-77"); Assert.That(() => client.Validate(), Throws.TypeOf()); - client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number"); + 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", "number"); + 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", null); + client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", null); Assert.That(() => client.Validate(), Throws.TypeOf()); - client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty); + 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", "777"); + client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", "777"); Assert.That(() => client.Validate(), Throws.TypeOf()); } @@ -65,7 +65,7 @@ internal class ClientDataModelTests public void AllFieldsIsCorrectTest() { string phoneNumber = "+7-777-777-77-77"; - string fio = "Василий Васильевич Васильев"; + string fio = "Vasiliy Vasiliev Vasilievich"; string id = Guid.NewGuid().ToString(); client = CreateDataModel(id, fio, phoneNumber); Assert.That(() => client.Validate(), Throws.Nothing); diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs b/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs index ca9dd3c..a42fbb5 100644 --- a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs +++ b/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs @@ -64,7 +64,7 @@ internal class InstallationSoftwareDataModelTests Assert.That(() => installSoftware.Validate(), Throws.Nothing); Assert.Multiple(() => { - Assert.That(installSoftware.SaleId, Is.EqualTo(installId)); + Assert.That(installSoftware.InstallationId, Is.EqualTo(installId)); Assert.That(installSoftware.ProgramId, Is.EqualTo(softwareId)); Assert.That(installSoftware.Count, Is.EqualTo(count)); }); From f4c2fdb4a6d86e6d32dfce218621f4b5f5413a60 Mon Sep 17 00:00:00 2001 From: I1nur Date: Mon, 10 Feb 2025 20:49:43 +0400 Subject: [PATCH 3/4] fix: remove unnecessary folder --- .../DataModelsTests/ClientDataModelTests.cs | 83 -------------- .../DataModelsTests/CompanyDataModelTests.cs | 62 ----------- .../InstallationDataModelTests.cs | 99 ----------------- .../InstallationSoftwareDataModelTests.cs | 76 ------------- .../DataModelsTests/PostDataModelTests.cs | 101 ------------------ .../DataModelsTests/SalaryDataModelTests.cs | 60 ----------- .../DataModelsTests/SoftwareDataModelTests.cs | 100 ----------------- .../SoftwareHistoryDataModelTests.cs | 61 ----------- .../DataModelsTests/WorkerDataModelTests.cs | 100 ----------------- 9 files changed, 742 deletions(-) delete mode 100644 SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs delete mode 100644 SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs delete mode 100644 SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs delete mode 100644 SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs delete mode 100644 SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs delete mode 100644 SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs delete mode 100644 SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs delete mode 100644 SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs delete mode 100644 SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs diff --git a/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs deleted file mode 100644 index 7cd2460..0000000 --- a/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs +++ /dev/null @@ -1,83 +0,0 @@ -using SoftwareInstallationContracts.DataModels; -using SoftwareInstallationContracts.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -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 Vasilievich Vasiliev"; - 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 deleted file mode 100644 index b65cd25..0000000 --- a/SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -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 deleted file mode 100644 index 981e8b1..0000000 --- a/SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs +++ /dev/null @@ -1,99 +0,0 @@ -using SoftwareInstallationContracts.DataModels; -using SoftwareInstallationContracts.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -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 deleted file mode 100644 index b81e079..0000000 --- a/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs +++ /dev/null @@ -1,76 +0,0 @@ -using SoftwareInstallationContracts.DataModels; -using SoftwareInstallationContracts.Exceptions; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -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 deleted file mode 100644 index a780697..0000000 --- a/SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs +++ /dev/null @@ -1,101 +0,0 @@ -using SoftwareInstallationContracts.DataModels; -using SoftwareInstallationContracts.Exceptions; -using SoftwareInstallationContracts.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -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 deleted file mode 100644 index a57f26d..0000000 --- a/SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs +++ /dev/null @@ -1,60 +0,0 @@ -using SoftwareInstallationContracts.DataModels; -using SoftwareInstallationContracts.Exceptions; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -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 deleted file mode 100644 index fb43cab..0000000 --- a/SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs +++ /dev/null @@ -1,100 +0,0 @@ -using SoftwareInstallationContracts.DataModels; -using SoftwareInstallationContracts.Enums; -using SoftwareInstallationContracts.Exceptions; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using static NUnit.Framework.Internal.OSPlatform; - -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 deleted file mode 100644 index c24c97c..0000000 --- a/SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs +++ /dev/null @@ -1,61 +0,0 @@ -using SoftwareInstallationContracts.DataModels; -using SoftwareInstallationContracts.Exceptions; -using SoftwareInstallationContracts.Enums; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -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 deleted file mode 100644 index 6ddc839..0000000 --- a/SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs +++ /dev/null @@ -1,100 +0,0 @@ -using SoftwareInstallationContracts.DataModels; -using SoftwareInstallationContracts.Exceptions; -using System; -using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -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); -} From d959acdf1ce39019bfe556ce50091d70501e74ff Mon Sep 17 00:00:00 2001 From: I1nur Date: Mon, 10 Feb 2025 21:18:32 +0400 Subject: [PATCH 4/4] fix: remove duplicate folder --- .../DataModelsTests/ClientDataModelTests.cs | 4 +-- .../DataModelsTests/CompanyDataModelTests.cs | 0 .../InstallationDataModelTests.cs | 0 .../InstallationSoftwareDataModelTests.cs | 0 .../DataModelsTests/PostDataModelTests.cs | 0 .../DataModelsTests/SalaryDataModelTests.cs | 0 .../DataModelsTests/SoftwareDataModelTests.cs | 0 .../SoftwareHistoryDataModelTests.cs | 0 .../DataModelsTests/WorkerDataModelTests.cs | 0 .../SoftwareInstallationTests.csproj | 2 +- .../SoftwareInstallationTests.csproj | 27 ------------------- 11 files changed, 3 insertions(+), 30 deletions(-) rename SoftwareInstallationTests/{SoftwareInstallationTests => }/DataModelsTests/ClientDataModelTests.cs (95%) rename SoftwareInstallationTests/{SoftwareInstallationTests => }/DataModelsTests/CompanyDataModelTests.cs (100%) rename SoftwareInstallationTests/{SoftwareInstallationTests => }/DataModelsTests/InstallationDataModelTests.cs (100%) rename SoftwareInstallationTests/{SoftwareInstallationTests => }/DataModelsTests/InstallationSoftwareDataModelTests.cs (100%) rename SoftwareInstallationTests/{SoftwareInstallationTests => }/DataModelsTests/PostDataModelTests.cs (100%) rename SoftwareInstallationTests/{SoftwareInstallationTests => }/DataModelsTests/SalaryDataModelTests.cs (100%) rename SoftwareInstallationTests/{SoftwareInstallationTests => }/DataModelsTests/SoftwareDataModelTests.cs (100%) rename SoftwareInstallationTests/{SoftwareInstallationTests => }/DataModelsTests/SoftwareHistoryDataModelTests.cs (100%) rename SoftwareInstallationTests/{SoftwareInstallationTests => }/DataModelsTests/WorkerDataModelTests.cs (100%) delete mode 100644 SoftwareInstallationTests/SoftwareInstallationTests/SoftwareInstallationTests.csproj diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs similarity index 95% rename from SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs rename to SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs index 5fee08f..cd6d011 100644 --- a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs +++ b/SoftwareInstallationTests/DataModelsTests/ClientDataModelTests.cs @@ -16,9 +16,9 @@ internal class ClientDataModelTests [Test] public void IdIsNullOrEmptyTest() { - client = CreateDataModel(null, "fio", "+7-777-777-77-77"); + client = CreateDataModel(null, "Fio Fio Fio", "+7-777-777-77-77"); Assert.That(() => client.Validate(), Throws.TypeOf()); - client = CreateDataModel(string.Empty, "fio", "+7-777-777-77-77"); + client = CreateDataModel(string.Empty, "Fio Fio Fio", "+7-777-777-77-77"); Assert.That(() => client.Validate(), Throws.TypeOf()); } diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs similarity index 100% rename from SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs rename to SoftwareInstallationTests/DataModelsTests/CompanyDataModelTests.cs diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs similarity index 100% rename from SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs rename to SoftwareInstallationTests/DataModelsTests/InstallationDataModelTests.cs diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs similarity index 100% rename from SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs rename to SoftwareInstallationTests/DataModelsTests/InstallationSoftwareDataModelTests.cs diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs similarity index 100% rename from SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs rename to SoftwareInstallationTests/DataModelsTests/PostDataModelTests.cs diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs similarity index 100% rename from SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs rename to SoftwareInstallationTests/DataModelsTests/SalaryDataModelTests.cs diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs similarity index 100% rename from SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs rename to SoftwareInstallationTests/DataModelsTests/SoftwareDataModelTests.cs diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs similarity index 100% rename from SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs rename to SoftwareInstallationTests/DataModelsTests/SoftwareHistoryDataModelTests.cs diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs b/SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs similarity index 100% rename from SoftwareInstallationTests/SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs rename to SoftwareInstallationTests/DataModelsTests/WorkerDataModelTests.cs diff --git a/SoftwareInstallationTests/SoftwareInstallationTests.csproj b/SoftwareInstallationTests/SoftwareInstallationTests.csproj index 561fc18..96c6b73 100644 --- a/SoftwareInstallationTests/SoftwareInstallationTests.csproj +++ b/SoftwareInstallationTests/SoftwareInstallationTests.csproj @@ -17,7 +17,7 @@ - + diff --git a/SoftwareInstallationTests/SoftwareInstallationTests/SoftwareInstallationTests.csproj b/SoftwareInstallationTests/SoftwareInstallationTests/SoftwareInstallationTests.csproj deleted file mode 100644 index 561fc18..0000000 --- a/SoftwareInstallationTests/SoftwareInstallationTests/SoftwareInstallationTests.csproj +++ /dev/null @@ -1,27 +0,0 @@ - - - - net9.0 - latest - enable - enable - false - - - - - - - - - - - - - - - - - - -