From 4ffd1dcb5658aee14c6a40f2eb4b4a1f4a140433 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 26 Feb 2025 14:36:59 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=B0=D0=B0=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TheWingsOfTheWorldProject.sln | 25 +++++++++ .../DataModels/AccessoriesDataModel.cs | 36 +++++++++++++ .../DataModels/AirplaneDataModel.cs | 35 ++++++++++++ .../DataModels/DeliveryDataModel.cs | 53 +++++++++++++++++++ .../DataModels/DeliveryHistoryDataModel.cs | 31 +++++++++++ .../DataModels/PostDataModel.cs | 53 +++++++++++++++++++ .../DataModels/SalaryDataModel.cs | 31 +++++++++++ .../DataModels/WorkerDataModel.cs | 52 ++++++++++++++++++ .../DataModels/СarrierСompanyDataModel.cs | 47 ++++++++++++++++ .../Enums/AccessoriesType.cs | 15 ++++++ WingsOfTheWorldContratcs/Enums/PostType.cs | 15 ++++++ .../Exceptions/ValidationException.cs | 11 ++++ .../Exstensions/StringExstensions.cs | 20 +++++++ .../Infrastructure/IValidation.cs | 12 +++++ .../WingsOfTheWorldContratcs.csproj | 9 ++++ 15 files changed, 445 insertions(+) create mode 100644 TheWingsOfTheWorldProject.sln create mode 100644 WingsOfTheWorldContratcs/DataModels/AccessoriesDataModel.cs create mode 100644 WingsOfTheWorldContratcs/DataModels/AirplaneDataModel.cs create mode 100644 WingsOfTheWorldContratcs/DataModels/DeliveryDataModel.cs create mode 100644 WingsOfTheWorldContratcs/DataModels/DeliveryHistoryDataModel.cs create mode 100644 WingsOfTheWorldContratcs/DataModels/PostDataModel.cs create mode 100644 WingsOfTheWorldContratcs/DataModels/SalaryDataModel.cs create mode 100644 WingsOfTheWorldContratcs/DataModels/WorkerDataModel.cs create mode 100644 WingsOfTheWorldContratcs/DataModels/СarrierСompanyDataModel.cs create mode 100644 WingsOfTheWorldContratcs/Enums/AccessoriesType.cs create mode 100644 WingsOfTheWorldContratcs/Enums/PostType.cs create mode 100644 WingsOfTheWorldContratcs/Exceptions/ValidationException.cs create mode 100644 WingsOfTheWorldContratcs/Exstensions/StringExstensions.cs create mode 100644 WingsOfTheWorldContratcs/Infrastructure/IValidation.cs create mode 100644 WingsOfTheWorldContratcs/WingsOfTheWorldContratcs.csproj diff --git a/TheWingsOfTheWorldProject.sln b/TheWingsOfTheWorldProject.sln new file mode 100644 index 0000000..ce0e633 --- /dev/null +++ b/TheWingsOfTheWorldProject.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.13.35806.99 d17.13 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WingsOfTheWorldContratcs", "WingsOfTheWorldContratcs\WingsOfTheWorldContratcs.csproj", "{BEAC542F-7E06-4942-A37D-583E87FAE7FF}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FDD9A46D-B6D6-40D9-AE18-3DF8480C20EB} + EndGlobalSection +EndGlobal diff --git a/WingsOfTheWorldContratcs/DataModels/AccessoriesDataModel.cs b/WingsOfTheWorldContratcs/DataModels/AccessoriesDataModel.cs new file mode 100644 index 0000000..0a40fe1 --- /dev/null +++ b/WingsOfTheWorldContratcs/DataModels/AccessoriesDataModel.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.Enums; +using WingsOfTheWorldContratcs.Exceptions; +using WingsOfTheWorldContratcs.Exstensions; +using WingsOfTheWorldContratcs.Infrastructure; + +namespace WingsOfTheWorldContratcs.DataModels; + +public class AccessoriesDataModel(string id, string name, AccessoriesType accessoriesType) : IValidation +{ + public string Id { get; private set; } = id; + + public string Name { get; private set; } = name; + + public AccessoriesType AccessoriesType { get; private set; } = accessoriesType; + + public void Validate() + { + if (Id.IsEmpty()) + throw new ValidationException("Field Id is empty"); + + if (!Id.IsGuid()) + throw new ValidationException("The value in the field Id is not a unique identifier"); + + if (Name.IsEmpty()) + throw new ValidationException("Field PostName is empty"); + + if (AccessoriesType == AccessoriesType.None) + throw new ValidationException("Field PostType is empty"); + + } +} diff --git a/WingsOfTheWorldContratcs/DataModels/AirplaneDataModel.cs b/WingsOfTheWorldContratcs/DataModels/AirplaneDataModel.cs new file mode 100644 index 0000000..609ca56 --- /dev/null +++ b/WingsOfTheWorldContratcs/DataModels/AirplaneDataModel.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.Exceptions; +using WingsOfTheWorldContratcs.Exstensions; +using WingsOfTheWorldContratcs.Infrastructure; + +namespace WingsOfTheWorldContratcs.DataModels; + +public class AirplaneDataModel(string id, string model) : IValidation +{ + public string Id { get; private set; } = id; + public string Model { get; private set; } = model; + + + + public void Validate() + { + if (Id.IsEmpty()) + throw new ValidationException("Field Id is empty"); + + if (!Id.IsGuid()) + throw new ValidationException("The value in the field Id is not a unique identifier"); + + if (Model.IsEmpty()) + throw new ValidationException("Field Model is empty"); + + if (!Model.IsGuid()) + throw new ValidationException("The value in the field Model is not a unique identifier"); + + } +} diff --git a/WingsOfTheWorldContratcs/DataModels/DeliveryDataModel.cs b/WingsOfTheWorldContratcs/DataModels/DeliveryDataModel.cs new file mode 100644 index 0000000..196e082 --- /dev/null +++ b/WingsOfTheWorldContratcs/DataModels/DeliveryDataModel.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; +using WingsOfTheWorldContratcs.Exceptions; +using WingsOfTheWorldContratcs.Exstensions; +using WingsOfTheWorldContratcs.Infrastructure; + +namespace WingsOfTheWorldContratcs.DataModels; + +public class DeliveryDataModel(string id, string airPlaneId, string place, int count, int price) : IValidation +{ + + public string Id { get; private set; } = id; + + public string AirPlaneId { get; private set; } = airPlaneId; + + public string Place { get; private set; } = place; + + public int Count { get; private set; } = count; + + public int Price { get; private set; } = price; + + public void Validate() + { + if (Id.IsEmpty()) + throw new ValidationException("Field Id is empty"); + + if (!Id.IsGuid()) + throw new ValidationException("The value in the field Id is not a unique identifier"); + + if (AirPlaneId.IsEmpty()) + throw new ValidationException("Field AirPlaneId is empty"); + + if (!AirPlaneId.IsGuid()) + throw new ValidationException("The value in the field AirPlaneId is not a unique identifier"); + + if (Place.IsEmpty()) + throw new ValidationException("Field Place is empty"); + + if (!Place.IsGuid()) + throw new ValidationException("The value in the field Place is not a unique identifier"); + + if (Count <= 0) + throw new ValidationException("Field Count is empty"); + + if (Price <= 0) + throw new ValidationException("Field Price is empty"); + } +} diff --git a/WingsOfTheWorldContratcs/DataModels/DeliveryHistoryDataModel.cs b/WingsOfTheWorldContratcs/DataModels/DeliveryHistoryDataModel.cs new file mode 100644 index 0000000..257755b --- /dev/null +++ b/WingsOfTheWorldContratcs/DataModels/DeliveryHistoryDataModel.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.Exceptions; +using WingsOfTheWorldContratcs.Exstensions; +using WingsOfTheWorldContratcs.Infrastructure; + +namespace WingsOfTheWorldContratcs.DataModels; + +public class DeliveryHistoryDataModel(string airplaneid, double oldPrice) : IValidation +{ + public string AirplaneId { get; private set; } = airplaneid; + + public double OldPrice { get; private set; } = oldPrice; + + public DateTime ChangeDate { get; private set; } = DateTime.UtcNow; + + public void Validate() + { + if (AirplaneId.IsEmpty()) + throw new ValidationException("Field ProductId is empty"); + + if (!AirplaneId.IsGuid()) + throw new ValidationException("The value in the field ProductId is not a unique identifier"); + + if (OldPrice <= 0) + throw new ValidationException("Field OldPrice is less than or equal to 0"); + } +} diff --git a/WingsOfTheWorldContratcs/DataModels/PostDataModel.cs b/WingsOfTheWorldContratcs/DataModels/PostDataModel.cs new file mode 100644 index 0000000..16a2be9 --- /dev/null +++ b/WingsOfTheWorldContratcs/DataModels/PostDataModel.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.Enums; +using WingsOfTheWorldContratcs.Exceptions; +using WingsOfTheWorldContratcs.Exstensions; +using WingsOfTheWorldContratcs.Infrastructure; + +namespace WingsOfTheWorldContratcs.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 ValidationException("Field Id is empty"); + + if (!Id.IsGuid()) + throw new ValidationException("The value in the field Id is not a unique identifier"); + + if (PostId.IsEmpty()) + throw new ValidationException("Field PostId is empty"); + + if (!PostId.IsGuid()) + throw new ValidationException("The value in the field PostId is not a unique identifier"); + + if (PostName.IsEmpty()) + throw new ValidationException("Field PostName is empty"); + + if (PostType == PostType.None) + throw new ValidationException("Field PostType is empty"); + + if (Salary <= 0) + throw new ValidationException("Field Salary is empty"); + } +} + diff --git a/WingsOfTheWorldContratcs/DataModels/SalaryDataModel.cs b/WingsOfTheWorldContratcs/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..b4d4d66 --- /dev/null +++ b/WingsOfTheWorldContratcs/DataModels/SalaryDataModel.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.Exceptions; +using WingsOfTheWorldContratcs.Exstensions; +using WingsOfTheWorldContratcs.Infrastructure; + +namespace WingsOfTheWorldContratcs.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 ValidationException("Field WorkerId is empty"); + + if (!WorkerId.IsGuid()) + throw new ValidationException("The value in the field WorkerId is not a unique identifier"); + + if (Salary <= 0) + throw new ValidationException("Field Salary is less than or equal to 0"); + } +} diff --git a/WingsOfTheWorldContratcs/DataModels/WorkerDataModel.cs b/WingsOfTheWorldContratcs/DataModels/WorkerDataModel.cs new file mode 100644 index 0000000..a0fea54 --- /dev/null +++ b/WingsOfTheWorldContratcs/DataModels/WorkerDataModel.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.Exceptions; +using WingsOfTheWorldContratcs.Exstensions; +using WingsOfTheWorldContratcs.Infrastructure; + +namespace WingsOfTheWorldContratcs.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 ValidationException("Field Id is empty"); + + if (!Id.IsGuid()) + throw new ValidationException("The value in the field Id is not a unique identifier"); + + if (FIO.IsEmpty()) + throw new ValidationException("Field FIO is empty"); + + if (PostId.IsEmpty()) + throw new ValidationException("Field PostId is empty"); + + if (!PostId.IsGuid()) + throw new ValidationException("The value in the field PostId is not a unique identifier"); + + if (BirthDate.Date > DateTime.Now.AddYears(-16).Date) + throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})"); + + if (EmploymentDate.Date < BirthDate.Date) + throw new ValidationException("The date of employment cannot be less than the date of birth"); + + if ((EmploymentDate - BirthDate).TotalDays / 365 < 16) // EmploymentDate.Year - BirthDate.Year + throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})"); + } +} diff --git a/WingsOfTheWorldContratcs/DataModels/СarrierСompanyDataModel.cs b/WingsOfTheWorldContratcs/DataModels/СarrierСompanyDataModel.cs new file mode 100644 index 0000000..6e2abd7 --- /dev/null +++ b/WingsOfTheWorldContratcs/DataModels/СarrierСompanyDataModel.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.Exceptions; +using WingsOfTheWorldContratcs.Exstensions; +using WingsOfTheWorldContratcs.Infrastructure; + +namespace WingsOfTheWorldContratcs.DataModels; + +public class СarrierСompanyDataModel(string id, string name, string phoneNumber, int count, int price) : IValidation +{ + public string Id { get; private set; } = id; + + public string Name { get; private set; } = name; + + public string PhoneNumber { get; private set; } = phoneNumber; + + public int Count { get; private set; } = count; + + public int Price { get; private set; } = price; + public void Validate() + { + if (Id.IsEmpty()) + throw new ValidationException("Field Id is empty"); + + if (!Id.IsGuid()) + throw new ValidationException("The value in the field Id is not a unique identifier"); + + if (Name.IsEmpty()) + throw new ValidationException("Field Name is empty"); + + if (PhoneNumber.IsEmpty()) + throw new ValidationException("Field PhoneNumber is empty"); + + if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$")) + throw new ValidationException("Field PhoneNumber is not a phone number"); + + if (Count <= 0) + throw new ValidationException("Field Count is empty"); + + if (Price <= 0) + throw new ValidationException("Field Price is empty"); + } +} diff --git a/WingsOfTheWorldContratcs/Enums/AccessoriesType.cs b/WingsOfTheWorldContratcs/Enums/AccessoriesType.cs new file mode 100644 index 0000000..3ebd5e7 --- /dev/null +++ b/WingsOfTheWorldContratcs/Enums/AccessoriesType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WingsOfTheWorldContratcs.Enums; + +public enum AccessoriesType +{ + None = 0, + Accessories = 1, + Salon = 2, + BodyWork = 3 +} diff --git a/WingsOfTheWorldContratcs/Enums/PostType.cs b/WingsOfTheWorldContratcs/Enums/PostType.cs new file mode 100644 index 0000000..cb00b13 --- /dev/null +++ b/WingsOfTheWorldContratcs/Enums/PostType.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WingsOfTheWorldContratcs.Enums; + +public enum PostType +{ + None = 0, + Supervisor = 1, + Master = 2, + Assistent = 3 +} diff --git a/WingsOfTheWorldContratcs/Exceptions/ValidationException.cs b/WingsOfTheWorldContratcs/Exceptions/ValidationException.cs new file mode 100644 index 0000000..c61aed4 --- /dev/null +++ b/WingsOfTheWorldContratcs/Exceptions/ValidationException.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WingsOfTheWorldContratcs.Exceptions; + +public class ValidationException(string message) : Exception(message) +{ +} diff --git a/WingsOfTheWorldContratcs/Exstensions/StringExstensions.cs b/WingsOfTheWorldContratcs/Exstensions/StringExstensions.cs new file mode 100644 index 0000000..bf50945 --- /dev/null +++ b/WingsOfTheWorldContratcs/Exstensions/StringExstensions.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WingsOfTheWorldContratcs.Exstensions; + +public static class StringExstensions +{ + public static bool IsEmpty(this string str) + { + return string.IsNullOrWhiteSpace(str); + } + + public static bool IsGuid(this string str) + { + return Guid.TryParse(str, out _); + } +} diff --git a/WingsOfTheWorldContratcs/Infrastructure/IValidation.cs b/WingsOfTheWorldContratcs/Infrastructure/IValidation.cs new file mode 100644 index 0000000..aea3890 --- /dev/null +++ b/WingsOfTheWorldContratcs/Infrastructure/IValidation.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WingsOfTheWorldContratcs.Infrastructure; + +public interface IValidation +{ + void Validate(); +} diff --git a/WingsOfTheWorldContratcs/WingsOfTheWorldContratcs.csproj b/WingsOfTheWorldContratcs/WingsOfTheWorldContratcs.csproj new file mode 100644 index 0000000..125f4c9 --- /dev/null +++ b/WingsOfTheWorldContratcs/WingsOfTheWorldContratcs.csproj @@ -0,0 +1,9 @@ + + + + net9.0 + enable + enable + + + -- 2.25.1 From ac01ab7d035d73daa0aa0659c97630a73139618f Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 26 Feb 2025 15:59:28 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=A2=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- TheWingsOfTheWorldProject.sln | 8 +- .../AccessoriesDataModelTest.cs | 68 +++++++++++ .../DataModelTests/AirplaneDataModelTest.cs | 65 +++++++++++ .../DataModelTests/DeliveryDataModelTest.cs | 109 ++++++++++++++++++ .../DeliveryHistoryDataModelTest.cs | 59 ++++++++++ .../DataModelTests/PostDataModelTest.cs | 97 ++++++++++++++++ .../DataModelTests/SalaryDataModelTests.cs | 56 +++++++++ .../DataModelTests/WorkerDataModelTest.cs | 90 +++++++++++++++ .../СarrierСompanyDataModelTest.cs | 106 +++++++++++++++++ .../WingsOfTheWorldTests.csproj | 27 +++++ 10 files changed, 684 insertions(+), 1 deletion(-) create mode 100644 WingsOfTheWorldTests/DataModelTests/AccessoriesDataModelTest.cs create mode 100644 WingsOfTheWorldTests/DataModelTests/AirplaneDataModelTest.cs create mode 100644 WingsOfTheWorldTests/DataModelTests/DeliveryDataModelTest.cs create mode 100644 WingsOfTheWorldTests/DataModelTests/DeliveryHistoryDataModelTest.cs create mode 100644 WingsOfTheWorldTests/DataModelTests/PostDataModelTest.cs create mode 100644 WingsOfTheWorldTests/DataModelTests/SalaryDataModelTests.cs create mode 100644 WingsOfTheWorldTests/DataModelTests/WorkerDataModelTest.cs create mode 100644 WingsOfTheWorldTests/DataModelTests/СarrierСompanyDataModelTest.cs create mode 100644 WingsOfTheWorldTests/WingsOfTheWorldTests.csproj diff --git a/TheWingsOfTheWorldProject.sln b/TheWingsOfTheWorldProject.sln index ce0e633..33b0cb5 100644 --- a/TheWingsOfTheWorldProject.sln +++ b/TheWingsOfTheWorldProject.sln @@ -1,10 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 -VisualStudioVersion = 17.13.35806.99 d17.13 +VisualStudioVersion = 17.13.35806.99 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WingsOfTheWorldContratcs", "WingsOfTheWorldContratcs\WingsOfTheWorldContratcs.csproj", "{BEAC542F-7E06-4942-A37D-583E87FAE7FF}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WingsOfTheWorldTests", "WingsOfTheWorldTests\WingsOfTheWorldTests.csproj", "{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU {BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU {BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.Build.0 = Release|Any CPU + {B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/WingsOfTheWorldTests/DataModelTests/AccessoriesDataModelTest.cs b/WingsOfTheWorldTests/DataModelTests/AccessoriesDataModelTest.cs new file mode 100644 index 0000000..34fdf6c --- /dev/null +++ b/WingsOfTheWorldTests/DataModelTests/AccessoriesDataModelTest.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.DataModels; +using WingsOfTheWorldContratcs.Enums; +using WingsOfTheWorldContratcs.Exceptions; + +namespace WingsOfTheWorldTests.DataModelTests; + +internal class AccessoriesDataModelTest +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var accessory = CreateDataModel(null, "AccessoryName", AccessoriesType.Salon); + Assert.That(() => accessory.Validate(), Throws.TypeOf()); + + accessory = CreateDataModel(string.Empty, "AccessoryName", AccessoriesType.Salon); + Assert.That(() => accessory.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var accessory = CreateDataModel("invalid_id", "AccessoryName", AccessoriesType.Salon); + Assert.That(() => accessory.Validate(), Throws.TypeOf()); + } + + [Test] + public void NameIsNullOrEmptyTest() + { + var accessory = CreateDataModel(Guid.NewGuid().ToString(), null, AccessoriesType.Salon); + Assert.That(() => accessory.Validate(), Throws.TypeOf()); + + accessory = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, AccessoriesType.Salon); + Assert.That(() => accessory.Validate(), Throws.TypeOf()); + } + + [Test] + public void AccessoriesTypeIsNoneTest() + { + var accessory = CreateDataModel(Guid.NewGuid().ToString(), "AccessoryName", AccessoriesType.None); + Assert.That(() => accessory.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsAreCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var name = "AccessoryName"; + var type = AccessoriesType.Salon; + var accessory = CreateDataModel(id, name, type); + + Assert.That(() => accessory.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(accessory.Id, Is.EqualTo(id)); + Assert.That(accessory.Name, Is.EqualTo(name)); + Assert.That(accessory.AccessoriesType, Is.EqualTo(type)); + }); + } + + private static AccessoriesDataModel CreateDataModel(string? id, string? name, AccessoriesType type) => + new(id, name, type); +} diff --git a/WingsOfTheWorldTests/DataModelTests/AirplaneDataModelTest.cs b/WingsOfTheWorldTests/DataModelTests/AirplaneDataModelTest.cs new file mode 100644 index 0000000..371ba53 --- /dev/null +++ b/WingsOfTheWorldTests/DataModelTests/AirplaneDataModelTest.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.DataModels; +using WingsOfTheWorldContratcs.Exceptions; + +namespace WingsOfTheWorldTests.DataModelTests; + +internal class AirplaneDataModelTest +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var airplane = CreateDataModel(null, "model"); + Assert.That(() => airplane.Validate(), Throws.TypeOf()); + + airplane = CreateDataModel(string.Empty, "model"); + Assert.That(() => airplane.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var airplane = CreateDataModel("invalid_id", "model"); + Assert.That(() => airplane.Validate(), Throws.TypeOf()); + } + + [Test] + public void ModelIsNullOrEmptyTest() + { + var airplane = CreateDataModel(Guid.NewGuid().ToString(), null); + Assert.That(() => airplane.Validate(), Throws.TypeOf()); + + airplane = CreateDataModel(Guid.NewGuid().ToString(), string.Empty); + Assert.That(() => airplane.Validate(), Throws.TypeOf()); + } + + [Test] + public void ModelIsNotGuidTest() + { + var airplane = CreateDataModel(Guid.NewGuid().ToString(), "invalid_model"); + Assert.That(() => airplane.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsAreCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var model = Guid.NewGuid().ToString(); + var airplane = CreateDataModel(id, model); + + Assert.That(() => airplane.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(airplane.Id, Is.EqualTo(id)); + Assert.That(airplane.Model, Is.EqualTo(model)); + }); + } + + private static AirplaneDataModel CreateDataModel(string? id, string? model) => + new(id, model); +} diff --git a/WingsOfTheWorldTests/DataModelTests/DeliveryDataModelTest.cs b/WingsOfTheWorldTests/DataModelTests/DeliveryDataModelTest.cs new file mode 100644 index 0000000..47142b5 --- /dev/null +++ b/WingsOfTheWorldTests/DataModelTests/DeliveryDataModelTest.cs @@ -0,0 +1,109 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.DataModels; +using WingsOfTheWorldContratcs.Exceptions; +using static NUnit.Framework.Internal.OSPlatform; + +namespace WingsOfTheWorldTests.DataModelTests; + +internal class DeliveryDataModelTest +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var delivery = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + + delivery = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var delivery = CreateDataModel("invalid_id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + } + + [Test] + public void AirPlaneIdIsNullOrEmptyTest() + { + var delivery = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + + delivery = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + } + + [Test] + public void AirPlaneIdIsNotGuidTest() + { + var delivery = CreateDataModel(Guid.NewGuid().ToString(), "invalid_id", Guid.NewGuid().ToString(), 10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + } + + [Test] + public void PlaceIsNullOrEmptyTest() + { + var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + + delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, 10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + } + + [Test] + public void PlaceIsNotGuidTest() + { + var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "invalid_place", 10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + + delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, 100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 0); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + + delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, -100); + Assert.That(() => delivery.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsAreCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var airPlaneId = Guid.NewGuid().ToString(); + var place = Guid.NewGuid().ToString(); + var count = 10; + var price = 100; + var delivery = CreateDataModel(id, airPlaneId, place, count, price); + + Assert.That(() => delivery.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(delivery.Id, Is.EqualTo(id)); + Assert.That(delivery.AirPlaneId, Is.EqualTo(airPlaneId)); + Assert.That(delivery.Place, Is.EqualTo(place)); + Assert.That(delivery.Count, Is.EqualTo(count)); + Assert.That(delivery.Price, Is.EqualTo(price)); + }); + } + + private static DeliveryDataModel CreateDataModel(string? id, string? airPlaneId, string? place, int count, int price) => + new(id, airPlaneId, place, count, price); +} diff --git a/WingsOfTheWorldTests/DataModelTests/DeliveryHistoryDataModelTest.cs b/WingsOfTheWorldTests/DataModelTests/DeliveryHistoryDataModelTest.cs new file mode 100644 index 0000000..4e13168 --- /dev/null +++ b/WingsOfTheWorldTests/DataModelTests/DeliveryHistoryDataModelTest.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.DataModels; +using WingsOfTheWorldContratcs.Exceptions; + +namespace WingsOfTheWorldTests.DataModelTests; + +internal class DeliveryHistoryDataModelTest +{ + [Test] + public void AirplaneIdIsNullOrEmptyTest() + { + var history = CreateDataModel(null, 100); + Assert.That(() => history.Validate(), Throws.TypeOf()); + + history = CreateDataModel(string.Empty, 100); + Assert.That(() => history.Validate(), Throws.TypeOf()); + } + + [Test] + public void AirplaneIdIsNotGuidTest() + { + var history = CreateDataModel("invalid_id", 100); + Assert.That(() => history.Validate(), Throws.TypeOf()); + } + + [Test] + public void OldPriceIsLessOrEqualZeroTest() + { + var history = CreateDataModel(Guid.NewGuid().ToString(), 0); + Assert.That(() => history.Validate(), Throws.TypeOf()); + + history = CreateDataModel(Guid.NewGuid().ToString(), -100); + Assert.That(() => history.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsAreCorrectTest() + { + var airplaneId = Guid.NewGuid().ToString(); + var oldPrice = 150.5; + var history = CreateDataModel(airplaneId, oldPrice); + + Assert.That(() => history.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(history.AirplaneId, Is.EqualTo(airplaneId)); + Assert.That(history.OldPrice, Is.EqualTo(oldPrice)); + Assert.That(history.ChangeDate, Is.LessThanOrEqualTo(DateTime.UtcNow)); + }); + } + + private static DeliveryHistoryDataModel CreateDataModel(string? airplaneId, double oldPrice) => + new(airplaneId, oldPrice); +} diff --git a/WingsOfTheWorldTests/DataModelTests/PostDataModelTest.cs b/WingsOfTheWorldTests/DataModelTests/PostDataModelTest.cs new file mode 100644 index 0000000..5a5d264 --- /dev/null +++ b/WingsOfTheWorldTests/DataModelTests/PostDataModelTest.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.DataModels; +using WingsOfTheWorldContratcs.Enums; +using WingsOfTheWorldContratcs.Exceptions; + +namespace WingsOfTheWorldTests.DataModelTests; + +internal class PostDataModelTest +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Assistent, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Assistent, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Assistent, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullEmptyTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Assistent, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Assistent, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Assistent, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostNameIsEmptyTest() + { + var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Assistent, 10, true, DateTime.UtcNow); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Assistent, 10, true, DateTime.UtcNow); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostTypeIsNoneTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void SalaryIsLessOrZeroTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Assistent, 0, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType. Assistent, -10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var postId = Guid.NewGuid().ToString(); + var postPostId = Guid.NewGuid().ToString(); + var postName = "name"; + var postType = PostType.Assistent; + var salary = 10; + var isActual = false; + var changeDate = DateTime.UtcNow.AddDays(-1); + var post = CreateDataModel(postId, postPostId, postName, postType, salary, isActual, changeDate); + Assert.That(() => post.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(post.Id, Is.EqualTo(postId)); + Assert.That(post.PostId, Is.EqualTo(postPostId)); + Assert.That(post.PostName, Is.EqualTo(postName)); + Assert.That(post.PostType, Is.EqualTo(postType)); + Assert.That(post.Salary, Is.EqualTo(salary)); + Assert.That(post.IsActual, Is.EqualTo(isActual)); + Assert.That(post.ChangeDate, Is.EqualTo(changeDate)); + }); + } + + private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) => + new(id, postId, postName, postType, salary, isActual, changeDate); +} diff --git a/WingsOfTheWorldTests/DataModelTests/SalaryDataModelTests.cs b/WingsOfTheWorldTests/DataModelTests/SalaryDataModelTests.cs new file mode 100644 index 0000000..b3c7766 --- /dev/null +++ b/WingsOfTheWorldTests/DataModelTests/SalaryDataModelTests.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.DataModels; +using WingsOfTheWorldContratcs.Exceptions; + +namespace WingsOfTheWorldTests.DataModelTests; + +internal class SalaryDataModelTests +{ + [Test] + public void WorkerIdIsEmptyTest() + { + var salary = CreateDataModel(null, DateTime.Now, 10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + salary = CreateDataModel(string.Empty, DateTime.Now, 10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void WorkerIdIsNotGuidTest() + { + var salary = CreateDataModel("workerId", DateTime.Now, 10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var workerId = Guid.NewGuid().ToString(); + var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5); + var workerSalary = 10; + var 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/WingsOfTheWorldTests/DataModelTests/WorkerDataModelTest.cs b/WingsOfTheWorldTests/DataModelTests/WorkerDataModelTest.cs new file mode 100644 index 0000000..8c286da --- /dev/null +++ b/WingsOfTheWorldTests/DataModelTests/WorkerDataModelTest.cs @@ -0,0 +1,90 @@ +using WingsOfTheWorldContratcs.DataModels; +using WingsOfTheWorldContratcs.Exceptions; + +namespace WingsOfTheWorldTests.DataModelTests; + +[TestFixture] +internal class WorkerDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var 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() + { + var worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void FIOIsNullOrEmptyTest() + { + var 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() + { + var 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() + { + var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void BirthDateIsNotCorrectTest() + { + var 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() + { + var 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() + { + var workerId = Guid.NewGuid().ToString(); + var fio = "fio"; + var postId = Guid.NewGuid().ToString(); + var birthDate = DateTime.Now.AddYears(-16).AddDays(-1); + var employmentDate = DateTime.Now; + var isDelete = false; + var 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); +} \ No newline at end of file diff --git a/WingsOfTheWorldTests/DataModelTests/СarrierСompanyDataModelTest.cs b/WingsOfTheWorldTests/DataModelTests/СarrierСompanyDataModelTest.cs new file mode 100644 index 0000000..da76b68 --- /dev/null +++ b/WingsOfTheWorldTests/DataModelTests/СarrierСompanyDataModelTest.cs @@ -0,0 +1,106 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using WingsOfTheWorldContratcs.DataModels; +using WingsOfTheWorldContratcs.Exceptions; + +namespace WingsOfTheWorldTests.DataModelTests; + + + +internal class CarrierCompanyDataModelTest +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var company = CreateDataModel(null, "CompanyName", "+79123456789", 10, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + + company = CreateDataModel(string.Empty, "CompanyName", "+79123456789", 10, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var company = CreateDataModel("invalid_id", "CompanyName", "+79123456789", 10, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void NameIsNullOrEmptyTest() + { + var company = CreateDataModel(Guid.NewGuid().ToString(), null, "+79123456789", 10, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + + company = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "+79123456789", 10, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void PhoneNumberIsNullOrEmptyTest() + { + var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", null, 10, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + + company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", string.Empty, 10, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void PhoneNumberIsInvalidTest() + { + var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "123456", 10, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + + company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "abcdefg", 10, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrEqualZeroTest() + { + var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", 0, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + + company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", -5, 1000); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrEqualZeroTest() + { + var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", 10, 0); + Assert.That(() => company.Validate(), Throws.TypeOf()); + + company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", 10, -100); + Assert.That(() => company.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsAreCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var name = "CompanyName"; + var phoneNumber = "+79123456789"; + var count = 10; + var price = 1000; + var company = CreateDataModel(id, name, phoneNumber, count, price); + + Assert.That(() => company.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(company.Id, Is.EqualTo(id)); + Assert.That(company.Name, Is.EqualTo(name)); + Assert.That(company.PhoneNumber, Is.EqualTo(phoneNumber)); + Assert.That(company.Count, Is.EqualTo(count)); + Assert.That(company.Price, Is.EqualTo(price)); + }); + } + + private static СarrierСompanyDataModel CreateDataModel(string? id, string? name, string? phoneNumber, int count, int price) => + new(id, name, phoneNumber, count, price); +} diff --git a/WingsOfTheWorldTests/WingsOfTheWorldTests.csproj b/WingsOfTheWorldTests/WingsOfTheWorldTests.csproj new file mode 100644 index 0000000..011c695 --- /dev/null +++ b/WingsOfTheWorldTests/WingsOfTheWorldTests.csproj @@ -0,0 +1,27 @@ + + + + net9.0 + latest + enable + enable + false + + + + + + + + + + + + + + + + + + + -- 2.25.1