diff --git a/NorthBridge/NorthBridge.sln b/NorthBridge/NorthBridge.sln index a54dd2a..63c4e27 100644 --- a/NorthBridge/NorthBridge.sln +++ b/NorthBridge/NorthBridge.sln @@ -3,7 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.10.35013.160 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NorthBridgeContract", "NorthBridgeContract\NorthBridgeContract.csproj", "{28744C88-4DE9-429F-83DA-CA3670CE2D70}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NorthBridgeContract", "NorthBridgeContract\NorthBridgeContract.csproj", "{28744C88-4DE9-429F-83DA-CA3670CE2D70}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NorthBridgeTest", "NorthBridgeTest\NorthBridgeTest.csproj", "{0105777C-5918-452B-9321-ECAEB1767753}" + ProjectSection(ProjectDependencies) = postProject + {28744C88-4DE9-429F-83DA-CA3670CE2D70} = {28744C88-4DE9-429F-83DA-CA3670CE2D70} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +20,10 @@ Global {28744C88-4DE9-429F-83DA-CA3670CE2D70}.Debug|Any CPU.Build.0 = Debug|Any CPU {28744C88-4DE9-429F-83DA-CA3670CE2D70}.Release|Any CPU.ActiveCfg = Release|Any CPU {28744C88-4DE9-429F-83DA-CA3670CE2D70}.Release|Any CPU.Build.0 = Release|Any CPU + {0105777C-5918-452B-9321-ECAEB1767753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0105777C-5918-452B-9321-ECAEB1767753}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0105777C-5918-452B-9321-ECAEB1767753}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0105777C-5918-452B-9321-ECAEB1767753}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/NorthBridge/NorthBridgeContract/DataModels/BuyerDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/BuyerDataModel.cs new file mode 100644 index 0000000..22b6755 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/BuyerDataModel.cs @@ -0,0 +1,36 @@ +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; +using System.Text.RegularExpressions; + +namespace NorthBridgeContract.DataModels; + +public class BuyerDataModel(string id, string fio, string phoneNumber) : IValidation +{ + public string Id { get; private set; } = id; + + public string FIO { get; private set; } = fio; + + public string PhoneNumber { get; private set; } = phoneNumber; + + public void Validate() + { + if (Id.IsEmpty()) + throw new 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 (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 (!Regex.IsMatch(FIO, @"^[А-ЯЁ][а-яё]+(?:-[А-ЯЁ][а-яё]+)?\s[А-ЯЁ][а-яё]+(?:\s[А-ЯЁ][а-яё]+)?$")) + throw new ValidationException("Field FIO is not a fio"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/DataModels/ComponentDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/ComponentDataModel.cs new file mode 100644 index 0000000..ecd4311 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/ComponentDataModel.cs @@ -0,0 +1,45 @@ +using NorthBridgeContract.Enums; +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.DataModels; + +public class ComponentDataModel(string id, string componentName, ComponentType componentType, string manufacturerId, double price, bool isDeleted) : IValidation +{ + public string Id { get; private set; } = id; + + public string ComponentName { get; private set; } = componentName; + + public ComponentType ComponentType { get; private set; } = componentType; + + public string ManufacturerId { get; private set; } = manufacturerId; + + public double Price { get; private set; } = price; + + public bool IsDeleted { get; private set; } = isDeleted; + + public void Validate() + { + if (Id.IsEmpty()) + throw new ValidationException("Field Id is empty"); + + if (!Id.IsGuid()) + throw new ValidationException("The value in the field Id is not a unique identifier"); + + if (ComponentName.IsEmpty()) + throw new ValidationException("Field ProductName is empty"); + + if (ComponentType == ComponentType.None) + throw new ValidationException("Field ProductType is empty"); + + if (ManufacturerId.IsEmpty()) + throw new ValidationException("Field ManufacturerId is empty"); + + if (!ManufacturerId.IsGuid()) + throw new ValidationException("The value in the field ManufacturerId is not a unique identifier"); + + if (Price <= 0) + throw new ValidationException("Field Price is less than or equal to 0"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/DataModels/ComponentHistoryDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/ComponentHistoryDataModel.cs new file mode 100644 index 0000000..bc0554c --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/ComponentHistoryDataModel.cs @@ -0,0 +1,26 @@ +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.DataModels; + +public class ComponentHistoryDataModel(string componentId, double oldPrice) : IValidation +{ + public string ComponentId { get; private set; } = componentId; + + public double OldPrice { get; private set; } = oldPrice; + + public DateTime ChangeDate { get; private set; } = DateTime.UtcNow; + + public void Validate() + { + if (ComponentId.IsEmpty()) + throw new ValidationException("Field ComponentId is empty"); + + if (!ComponentId.IsGuid()) + throw new ValidationException("The value in the field ComponentId is not a unique identifier"); + + if (OldPrice <= 0) + throw new ValidationException("Field OldPrice is less than or equal to 0"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/DataModels/ComponentInProductDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/ComponentInProductDataModel.cs new file mode 100644 index 0000000..8bfe648 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/ComponentInProductDataModel.cs @@ -0,0 +1,28 @@ +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.DataModels +{ + public class ComponentInProductDataModel(string componentId, string productId) : IValidation + { + public string ComponentId { get; private set; } = componentId; + public string ProductId { get; private set;} = productId; + + public void Validate() + { + if (ComponentId.IsEmpty()) + throw new ValidationException("Field ComponentId is empty"); + + if (!ComponentId.IsGuid()) + throw new ValidationException("The value in the field ComponentId is not a unique identifier"); + + if (ProductId.IsEmpty()) + throw new ValidationException("Field ProductId is empty"); + + if (!ProductId.IsGuid()) + throw new ValidationException("The value in the field ProductId is not a unique identifier"); + + } + } +} diff --git a/NorthBridge/NorthBridgeContract/DataModels/ManufacturerDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/ManufacturerDataModel.cs new file mode 100644 index 0000000..be5ce08 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/ManufacturerDataModel.cs @@ -0,0 +1,28 @@ +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.DataModels; + +public class ManufacturerDataModel(string id, string manufacturerName, string? prevManufacturerName, string? prevPrevManufacturerName) : IValidation +{ + public string Id { get; private set; } = id; + + public string ManufacturerName { get; private set; } = manufacturerName; + + public string? PrevManufacturerName { get; private set; } = prevManufacturerName; + + public string? PrevPrevManufacturerName { get; private set; } = prevPrevManufacturerName; + + 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 (ManufacturerName.IsEmpty()) + throw new ValidationException("Field ManufacturerName is empty"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/DataModels/PostDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/PostDataModel.cs new file mode 100644 index 0000000..44d3ac9 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/PostDataModel.cs @@ -0,0 +1,47 @@ +using NorthBridgeContract.Enums; +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.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"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/DataModels/ProductDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/ProductDataModel.cs new file mode 100644 index 0000000..1f2b9f0 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/ProductDataModel.cs @@ -0,0 +1,47 @@ +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.DataModels; + +public class ProductDataModel(string id, string productName, string workerId, bool isDeleted, List components) : IValidation +{ + public string Id { get; private set; } = id; + + public string ProductName { get; private set; } = productName; + + public string WorkerId { get; private set; } = workerId; + + public bool IsDeleted { get; private set; } = isDeleted; + + public List Components { get; private set; } = components; + + public double TotalPrice => Components.Sum(x => x.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 (ProductName.IsEmpty()) + throw new ValidationException("Field ProductName is empty"); + + if (WorkerId.IsEmpty()) + throw new ValidationException("Field ManufacturerId is empty"); + + if (!WorkerId.IsGuid()) + throw new ValidationException("The value in the field ManufacturerId is not a unique identifier"); + + if (TotalPrice <= 0) + throw new ValidationException("Field Price is less than or equal to 0"); + + if (TotalPrice != Components.Sum(x => x.Price)) + throw new ValidationException("The total price of the components does not match"); + + if (Components.Count == 0) + throw new ValidationException("At least 1 component is needed"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/DataModels/SalaryDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..d16d8bb --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/SalaryDataModel.cs @@ -0,0 +1,26 @@ +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.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"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/DataModels/SaleDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/SaleDataModel.cs new file mode 100644 index 0000000..f35e5c3 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/SaleDataModel.cs @@ -0,0 +1,47 @@ +using NorthBridgeContract.Enums; +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.DataModels; + +public class SaleDataModel(string id, string workerId, string? buyerId, double sum, bool isCancel, List products) : IValidation +{ + public string Id { get; private set; } = id; + + public string WorkerId { get; private set; } = workerId; + + public string? BuyerId { get; private set; } = buyerId; + + public DateTime SaleDate { get; private set; } = DateTime.UtcNow; + + public double Sum { get; private set; } = sum; + + public bool IsCancel { get; private set; } = isCancel; + + public List Products { get; private set; } = products; + + 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 (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 (!BuyerId?.IsGuid() ?? !BuyerId?.IsEmpty() ?? false) + throw new ValidationException("The value in the field BuyerId is not a unique identifier"); + + if (Sum <= 0) + throw new ValidationException("Field Sum is less than or equal to 0"); + + if ((Products?.Count ?? 0) == 0) + throw new ValidationException("The sale must include products"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/DataModels/SaleProductDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/SaleProductDataModel.cs new file mode 100644 index 0000000..6bdb092 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/SaleProductDataModel.cs @@ -0,0 +1,32 @@ +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.DataModels; + +public class SaleProductDataModel(string saleId, string productId, int count) : IValidation +{ + public string SaleId { get; private set; } = saleId; + + public string ProductId { get; private set; } = productId; + + public int Count { get; private set; } = count; + + public void Validate() + { + if (SaleId.IsEmpty()) + throw new ValidationException("Field SaleId is empty"); + + if (!SaleId.IsGuid()) + throw new ValidationException("The value in the field SaleId is not a unique identifier"); + + if (ProductId.IsEmpty()) + throw new ValidationException("Field ProductId is empty"); + + if (!ProductId.IsGuid()) + throw new ValidationException("The value in the field ProductId is not a unique identifier"); + + if (Count <= 0) + throw new ValidationException("Field Count is less than or equal to 0"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/DataModels/WorkerDataModel.cs b/NorthBridge/NorthBridgeContract/DataModels/WorkerDataModel.cs new file mode 100644 index 0000000..2d1a3f1 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/DataModels/WorkerDataModel.cs @@ -0,0 +1,47 @@ +using NorthBridgeContract.Exceptions; +using NorthBridgeContract.Extensions; +using NorthBridgeContract.Infrastructure; + +namespace NorthBridgeContract.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()})"); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/Enums/ComponentType.cs b/NorthBridge/NorthBridgeContract/Enums/ComponentType.cs new file mode 100644 index 0000000..6e683f3 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/Enums/ComponentType.cs @@ -0,0 +1,14 @@ +namespace NorthBridgeContract.Enums; + +public enum ComponentType +{ + None = 0, + GraphicsCard = 1, + Motherboard = 2, + RAM = 3, + Storage = 4, + PowerSupply = 5, + CoolingSystem = 6, + Case = 7, + Processor = 8 +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/Enums/PostType.cs b/NorthBridge/NorthBridgeContract/Enums/PostType.cs new file mode 100644 index 0000000..b7a1935 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/Enums/PostType.cs @@ -0,0 +1,9 @@ +namespace NorthBridgeContract.Enums; + +public enum PostType +{ + None = 0, + Supervisor = 1, + CashierConsultant = 2, + Assistant = 3 +} diff --git a/NorthBridge/NorthBridgeContract/Exceptions/ValidationException.cs b/NorthBridge/NorthBridgeContract/Exceptions/ValidationException.cs new file mode 100644 index 0000000..9d739a2 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/Exceptions/ValidationException.cs @@ -0,0 +1,5 @@ +namespace NorthBridgeContract.Exceptions; + +public class ValidationException(string message) : Exception(message) +{ +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/Extensions/StringExtensions.cs b/NorthBridge/NorthBridgeContract/Extensions/StringExtensions.cs new file mode 100644 index 0000000..6681894 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/Extensions/StringExtensions.cs @@ -0,0 +1,14 @@ +namespace NorthBridgeContract.Extensions; + +public static class StringExtensions +{ + public static bool IsEmpty(this string str) + { + return string.IsNullOrWhiteSpace(str); + } + + public static bool IsGuid(this string str) + { + return Guid.TryParse(str, out _); + } +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeContract/Infrastructure/IValidation.cs b/NorthBridge/NorthBridgeContract/Infrastructure/IValidation.cs new file mode 100644 index 0000000..3a500f8 --- /dev/null +++ b/NorthBridge/NorthBridgeContract/Infrastructure/IValidation.cs @@ -0,0 +1,8 @@ +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeContract.Infrastructure; + +public interface IValidation +{ + void Validate(); +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/BuyerDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/BuyerDataModelTests.cs new file mode 100644 index 0000000..6773c50 --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/BuyerDataModelTests.cs @@ -0,0 +1,69 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests; + +[TestFixture] +internal class BuyerDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var buyer = CreateDataModel(null, "Иванов Иван Иванович", "number"); + Assert.That(() => buyer.Validate(), Throws.TypeOf()); + buyer = CreateDataModel(string.Empty, "Иванов Иван Иванович", "number"); + Assert.That(() => buyer.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var buyer = CreateDataModel("id", "Иванов Иван Иванович", "number"); + Assert.That(() => buyer.Validate(), Throws.TypeOf()); + } + + [Test] + public void FIOIsNullOrEmptyTest() + { + var buyer = CreateDataModel(Guid.NewGuid().ToString(), null, "number"); + Assert.That(() => buyer.Validate(), Throws.TypeOf()); + buyer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number"); + Assert.That(() => buyer.Validate(), Throws.TypeOf()); + } + + [Test] + public void PhoneNumberIsNullOrEmptyTest() + { + var buyer = CreateDataModel(Guid.NewGuid().ToString(), "Иванов Иван Иванович", null); + Assert.That(() => buyer.Validate(), Throws.TypeOf()); + buyer = CreateDataModel(Guid.NewGuid().ToString(), "Иванов Иван Иванович", string.Empty); + Assert.That(() => buyer.Validate(), Throws.TypeOf()); + } + + [Test] + public void PhoneNumberIsIncorrectTest() + { + var buyer = CreateDataModel(Guid.NewGuid().ToString(), "Иванов Иван Иванович", "777"); + Assert.That(() => buyer.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var buyerId = Guid.NewGuid().ToString(); + var fio = "Иванов Иван Иванович"; + var phoneNumber = "+7-777-777-77-77"; + var buyer = CreateDataModel(buyerId, fio, phoneNumber); + Assert.That(() => buyer.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(buyer.Id, Is.EqualTo(buyerId)); + Assert.That(buyer.FIO, Is.EqualTo(fio)); + Assert.That(buyer.PhoneNumber, Is.EqualTo(phoneNumber)); + }); + } + + private static BuyerDataModel CreateDataModel(string? id, string? fio, string? phoneNumber) => + new(id, fio, phoneNumber); + +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/ComponentDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/ComponentDataModelTests.cs new file mode 100644 index 0000000..14d0e39 --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/ComponentDataModelTests.cs @@ -0,0 +1,91 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Enums; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests; + +[TestFixture] +internal class ComponentDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var component = CreateDataModel(null, "name", ComponentType.Processor, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + component = CreateDataModel(string.Empty, "name", ComponentType.Processor, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var component = CreateDataModel("id", "name", ComponentType.Processor, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentNameIsEmptyTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Processor, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Processor, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentTypeIsNoneTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.None, Guid.NewGuid().ToString(), 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void ManufacturerIdIsNullOrEmptyTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, null, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, string.Empty, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void ManufacturerIdIsNotGuidTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, "manufacturerId", 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, Guid.NewGuid().ToString(), 0, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, Guid.NewGuid().ToString(), -10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var componentId = Guid.NewGuid().ToString(); + var componentName = "name"; + var componentType = ComponentType.Processor; + var componentManufacturerId = Guid.NewGuid().ToString(); + var componentPrice = 10; + var componentIsDelete = false; + var component = CreateDataModel(componentId, componentName, componentType, componentManufacturerId, componentPrice, componentIsDelete); + Assert.That(() => component.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(component.Id, Is.EqualTo(componentId)); + Assert.That(component.ComponentName, Is.EqualTo(componentName)); + Assert.That(component.ComponentType, Is.EqualTo(componentType)); + Assert.That(component.ManufacturerId, Is.EqualTo(componentManufacturerId)); + Assert.That(component.Price, Is.EqualTo(componentPrice)); + Assert.That(component.IsDeleted, Is.EqualTo(componentIsDelete)); + }); + } + + private static ComponentDataModel CreateDataModel(string? id, string? componentName, ComponentType componentType, string? manufacturerId, double price, bool isDeleted) => + new(id, componentName, componentType, manufacturerId, price, isDeleted); +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/ComponentHistoryDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/ComponentHistoryDataModelTests.cs new file mode 100644 index 0000000..fb3b2c3 --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/ComponentHistoryDataModelTests.cs @@ -0,0 +1,52 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests; + +[TestFixture] +internal class ComponentHistoryDataModelTests +{ + [Test] + public void ComponentIdIsNullOrEmptyTest() + { + var product = CreateDataModel(null, 10); + Assert.That(() => product.Validate(), Throws.TypeOf()); + product = CreateDataModel(string.Empty, 10); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentIdIsNotGuidTest() + { + var product = CreateDataModel("id", 10); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void OldPriceIsLessOrZeroTest() + { + var product = CreateDataModel(Guid.NewGuid().ToString(), 0); + Assert.That(() => product.Validate(), Throws.TypeOf()); + product = CreateDataModel(Guid.NewGuid().ToString(), -10); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var componentId = Guid.NewGuid().ToString(); + var oldPrice = 10; + var productHistory = CreateDataModel(componentId, oldPrice); + Assert.That(() => productHistory.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(productHistory.ComponentId, Is.EqualTo(componentId)); + Assert.That(productHistory.OldPrice, Is.EqualTo(oldPrice)); + Assert.That(productHistory.ChangeDate, Is.LessThan(DateTime.UtcNow)); + Assert.That(productHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1))); + }); + } + + private static ComponentHistoryDataModel CreateDataModel(string? componentId, double oldPrice) => + new(componentId, oldPrice); +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/ComponentInProductDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/ComponentInProductDataModelTests.cs new file mode 100644 index 0000000..2519d2b --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/ComponentInProductDataModelTests.cs @@ -0,0 +1,63 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Exceptions; +using NUnit.Framework; +using System; + +namespace NorthBridgeTest.DataModelsTests +{ + [TestFixture] + internal class ComponentInProductDataModelTests + { + [Test] + public void ComponentIdIsNullOrEmptyTest() + { + var componentInProduct = CreateDataModel(null, Guid.NewGuid().ToString()); + Assert.That(() => componentInProduct.Validate(), Throws.TypeOf()); + + componentInProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString()); + Assert.That(() => componentInProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentIdIsNotGuidTest() + { + var componentInProduct = CreateDataModel("invalid_id", Guid.NewGuid().ToString()); + Assert.That(() => componentInProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductIdIsNullOrEmptyTest() + { + var componentInProduct = CreateDataModel(Guid.NewGuid().ToString(), null); + Assert.That(() => componentInProduct.Validate(), Throws.TypeOf()); + + componentInProduct = CreateDataModel(Guid.NewGuid().ToString(), string.Empty); + Assert.That(() => componentInProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductIdIsNotGuidTest() + { + var componentInProduct = CreateDataModel(Guid.NewGuid().ToString(), "invalid_id"); + Assert.That(() => componentInProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsAreCorrectTest() + { + var componentId = Guid.NewGuid().ToString(); + var productId = Guid.NewGuid().ToString(); + var componentInProduct = CreateDataModel(componentId, productId); + + Assert.That(() => componentInProduct.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(componentInProduct.ComponentId, Is.EqualTo(componentId)); + Assert.That(componentInProduct.ProductId, Is.EqualTo(productId)); + }); + } + + private static ComponentInProductDataModel CreateDataModel(string? componentId, string? productId) => + new(componentId, productId); + } +} diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/ManufacturerDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/ManufacturerDataModelTests.cs new file mode 100644 index 0000000..811db55 --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/ManufacturerDataModelTests.cs @@ -0,0 +1,54 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests; + +[TestFixture] +internal class ManufacturerDataModelTests +{ + [Test] + public void IdIsNullEmptyTest() + { + var manufacturer = CreateDataModel(null, "name"); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + manufacturer = CreateDataModel(string.Empty, "name"); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var manufacturer = CreateDataModel("id", "name"); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + } + + [Test] + public void ManufacturerNameIsNullOrEmptyTest() + { + var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var manufacturerId = Guid.NewGuid().ToString(); + var manufacturerName = "name"; + var prevManufacturerName = "prevManufacturerName"; + var prevPrevManufacturerName = "prevPrevManufacturerName"; + var manufacturer = CreateDataModel(manufacturerId, manufacturerName, prevManufacturerName, prevPrevManufacturerName); + Assert.That(() => manufacturer.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(manufacturer.Id, Is.EqualTo(manufacturerId)); + Assert.That(manufacturer.ManufacturerName, Is.EqualTo(manufacturerName)); + Assert.That(manufacturer.PrevManufacturerName, Is.EqualTo(prevManufacturerName)); + Assert.That(manufacturer.PrevPrevManufacturerName, Is.EqualTo(prevPrevManufacturerName)); + }); + } + + private static ManufacturerDataModel CreateDataModel(string? id, string? manufacturerName, string? prevManufacturerName = null, string? prevPrevManufacturerName = null) => + new(id, manufacturerName, prevManufacturerName, prevPrevManufacturerName); +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/PostDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/PostDataModelTests.cs new file mode 100644 index 0000000..56888c8 --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/PostDataModelTests.cs @@ -0,0 +1,93 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Enums; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests; + +[TestFixture] +internal class PostDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullEmptyTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Assistant, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Assistant, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Assistant, 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.Assistant, 10, true, DateTime.UtcNow); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Assistant, 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.Assistant, 0, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Assistant, -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.Assistant; + 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); +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/ProductDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/ProductDataModelTests.cs new file mode 100644 index 0000000..f255755 --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/ProductDataModelTests.cs @@ -0,0 +1,75 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Enums; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests +{ + [TestFixture] + internal class ProductDataModelTests + { + [Test] + public void IdIsNullOrEmptyTest() + { + var product = CreateDataModel(null, "Processor", Guid.NewGuid().ToString(), false, new List { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) }); + Assert.That(() => product.Validate(), Throws.TypeOf()); + product = CreateDataModel(string.Empty, "Processor", Guid.NewGuid().ToString(), false, new List { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) }); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var product = CreateDataModel("id", "Processor", Guid.NewGuid().ToString(), false, new List { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) }); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductNameIsNullOrEmptyTest() + { + var product = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), false, new List { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) }); + Assert.That(() => product.Validate(), Throws.TypeOf()); + product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), false, new List { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) }); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void WorkerIdIsNullOrEmptyTest() + { + var product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", null, false, new List { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) }); + Assert.That(() => product.Validate(), Throws.TypeOf()); + product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", string.Empty, false, new List { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) }); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void WorkerIdIsNotGuidTest() + { + var product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", "workerId", false, new List { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) }); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentsAreNullOrEmptyTest() + { + var product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", Guid.NewGuid().ToString(), false, null); + Assert.That(() => product.Validate(), Throws.TypeOf()); + product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", Guid.NewGuid().ToString(), false, new List()); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void TotalPriceIsIncorrectTest() + { + var components = new List + { + new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false), + new ComponentDataModel(Guid.NewGuid().ToString(), "GPU", ComponentType.GraphicsCard, Guid.NewGuid().ToString(), 300, false) + }; + var product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", Guid.NewGuid().ToString(), false, components); + Assert.That(product.TotalPrice, Is.EqualTo(500)); + } + + private static ProductDataModel CreateDataModel(string? id, string? productName, string? workerId, bool isDeleted, List? components) => + new(id, productName, workerId, isDeleted, components ?? new List()); + } +} diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/SalaryDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/SalaryDataModelTests.cs new file mode 100644 index 0000000..88bf3ca --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/SalaryDataModelTests.cs @@ -0,0 +1,52 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests; + +[TestFixture] +internal class SalaryDataModelTests +{ + [Test] + public void WorkerIdIsEmptyTest() + { + var salary = CreateDataModel(null, DateTime.Now, 10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + salary = CreateDataModel(string.Empty, DateTime.Now, 10); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void WorkerIdIsNotGuidTest() + { + var salary = CreateDataModel("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); +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/SaleDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/SaleDataModelTests.cs new file mode 100644 index 0000000..12d84cc --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/SaleDataModelTests.cs @@ -0,0 +1,93 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Enums; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests; + +[TestFixture] +internal class SaleDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + } + [Test] + public void WorkerIdIsNullOrEmptyTest() + { + var sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + } + + [Test] + public void WorkerIdIsNotGuidTest() + { + var sale = CreateDataModel(Guid.NewGuid().ToString(), "workerId", Guid.NewGuid().ToString(), 10, false, CreateSubDataModel()); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + } + + [Test] + public void BuyerIdIsNotGuidTest() + { + var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", 10, false, CreateSubDataModel()); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + } + + [Test] + public void SumIsLessOrZeroTest() + { + var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false, CreateSubDataModel()); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, false, CreateSubDataModel()); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductsIsNullOrEmptyTest() + { + var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, null); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, []); + Assert.That(() => sale.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var saleId = Guid.NewGuid().ToString(); + var workerId = Guid.NewGuid().ToString(); + var buyerId = Guid.NewGuid().ToString(); + var sum = 10; + var isCancel = true; + var products = CreateSubDataModel(); + var sale = CreateDataModel(saleId, workerId, buyerId, sum, isCancel, products); + Assert.That(() => sale.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(sale.Id, Is.EqualTo(saleId)); + Assert.That(sale.WorkerId, Is.EqualTo(workerId)); + Assert.That(sale.BuyerId, Is.EqualTo(buyerId)); + Assert.That(sale.Sum, Is.EqualTo(sum)); + Assert.That(sale.IsCancel, Is.EqualTo(isCancel)); + Assert.That(sale.Products, Is.EquivalentTo(products)); + }); + } + + private static SaleDataModel CreateDataModel(string? id, string? workerId, string? buyerId, double sum, bool isCancel, List? products) => + new(id, workerId, buyerId, sum, isCancel, products); + + private static List CreateSubDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/SaleProductDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/SaleProductDataModelTests.cs new file mode 100644 index 0000000..7547e13 --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/SaleProductDataModelTests.cs @@ -0,0 +1,68 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests; + +[TestFixture] +internal class SaleProductDataModelTests +{ + [Test] + public void SaleIdIsNullOrEmptyTest() + { + var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void SaleIdIsNotGuidTest() + { + var saleProduct = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductIdIsNullOrEmptyTest() + { + var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductIdIsNotGuidTest() + { + var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var saleId = Guid.NewGuid().ToString(); + var productId = Guid.NewGuid().ToString(); + var count = 10; + var saleProduct = CreateDataModel(saleId, productId, count); + Assert.That(() => saleProduct.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(saleProduct.SaleId, Is.EqualTo(saleId)); + Assert.That(saleProduct.ProductId, Is.EqualTo(productId)); + Assert.That(saleProduct.Count, Is.EqualTo(count)); + }); + } + + private static SaleProductDataModel CreateDataModel(string? saleId, string? productId, int count) => + new(saleId, productId, count); +} \ No newline at end of file diff --git a/NorthBridge/NorthBridgeTest/DataModelsTests/WorkerDataModelTests.cs b/NorthBridge/NorthBridgeTest/DataModelsTests/WorkerDataModelTests.cs new file mode 100644 index 0000000..ee7f830 --- /dev/null +++ b/NorthBridge/NorthBridgeTest/DataModelsTests/WorkerDataModelTests.cs @@ -0,0 +1,90 @@ +using NorthBridgeContract.DataModels; +using NorthBridgeContract.Exceptions; + +namespace NorthBridgeTest.DataModelsTests; + +[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/NorthBridge/NorthBridgeTest/NorthBridgeTest.csproj b/NorthBridge/NorthBridgeTest/NorthBridgeTest.csproj new file mode 100644 index 0000000..994fcf4 --- /dev/null +++ b/NorthBridge/NorthBridgeTest/NorthBridgeTest.csproj @@ -0,0 +1,28 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + +