diff --git a/TheSoftBedProject/SoftBedContracts/DataModels/CollectDataModel.cs b/TheSoftBedProject/SoftBedContracts/DataModels/CollectDataModel.cs new file mode 100644 index 0000000..4e7beb5 --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/DataModels/CollectDataModel.cs @@ -0,0 +1,42 @@ +using SoftBedContracts.Exceptions; +using SoftBedContracts.Extensions; +using SoftBedContracts.Infrastructure; + +namespace SoftBedContracts.DataModels; + +public class CollectDataModel(string id, string workerId, string furnitureId, double sum) : IValidation +{ + public string Id { get; private set; } = id; + + public string WorkerId { get; private set; } = workerId; + + public string FurnitureId { get; private set; } = furnitureId; + + public DateTime SaleDate { get; private set; } = DateTime.UtcNow; + + public double Sum { get; private set; } = sum; + + 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 (FurnitureId.IsEmpty()) + throw new ValidationException("Field FurnitureId is empty"); + + if (!FurnitureId.IsGuid()) + throw new ValidationException("The value in the field FurnitureId is not a unique identifier"); + + if (Sum <= 0) + throw new ValidationException("Field Sum is less than or equal to 0"); + } +} diff --git a/TheSoftBedProject/SoftBedContracts/DataModels/FurnitureDataModel.cs b/TheSoftBedProject/SoftBedContracts/DataModels/FurnitureDataModel.cs new file mode 100644 index 0000000..7bafa6d --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/DataModels/FurnitureDataModel.cs @@ -0,0 +1,42 @@ +using SoftBedContracts.Enums; +using SoftBedContracts.Exceptions; +using SoftBedContracts.Extensions; +using SoftBedContracts.Infrastructure; + +namespace SoftBedContracts.DataModels; + +public class FurnitureDataModel(string id, string furnitureName, FurnitureType furnitureType, double price, bool isDeleted, List workPieces) : IValidation +{ + public string Id { get; private set; } = id; + + public string FurnitureName { get; private set; } = furnitureName; + + public FurnitureType FurnitureType { get; private set; } = furnitureType; + + public double Price { get; private set; } = price; + + public bool IsDeleted { get; private set; } = isDeleted; + + public List WorkPieces { get; private set; } = workPieces; + + 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 (FurnitureName.IsEmpty()) + throw new ValidationException("Field FurnitureName is empty"); + + if (FurnitureType == FurnitureType.None) + throw new ValidationException("Field FurnitureType is empty"); + + if (Price <= 0) + throw new ValidationException("Field Price is less than or equal to 0"); + + if ((WorkPieces?.Count ?? 0) == 0) + throw new ValidationException("The sale must include Work Pieces"); + } +} diff --git a/TheSoftBedProject/SoftBedContracts/DataModels/FurnitureHistoryDataModel.cs b/TheSoftBedProject/SoftBedContracts/DataModels/FurnitureHistoryDataModel.cs new file mode 100644 index 0000000..1b1d101 --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/DataModels/FurnitureHistoryDataModel.cs @@ -0,0 +1,26 @@ +using SoftBedContracts.Exceptions; +using SoftBedContracts.Extensions; +using SoftBedContracts.Infrastructure; + +namespace SoftBedContracts.DataModels; + +public class FurnitureHistoryDataModel(string furnitureId, double oldPrice) : IValidation +{ + public string FurnitureId { get; private set; } = furnitureId; + + public double OldPrice { get; private set; } = oldPrice; + + public DateTime ChangeDate { get; private set; } = DateTime.UtcNow; + + public void Validate() + { + if (FurnitureId.IsEmpty()) + throw new ValidationException("Field FurnitureId is empty"); + + if (!FurnitureId.IsGuid()) + throw new ValidationException("The value in the field FurnitureId is not a unique identifier"); + + if (OldPrice <= 0) + throw new ValidationException("Field OldPrice is less than or equal to 0"); + } +} diff --git a/TheSoftBedProject/SoftBedContracts/DataModels/FurnitureWorkPieceDataModel.cs b/TheSoftBedProject/SoftBedContracts/DataModels/FurnitureWorkPieceDataModel.cs new file mode 100644 index 0000000..eceb194 --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/DataModels/FurnitureWorkPieceDataModel.cs @@ -0,0 +1,31 @@ +using SoftBedContracts.Exceptions; +using SoftBedContracts.Extensions; +using SoftBedContracts.Infrastructure; + +namespace SoftBedContracts.DataModels; +public class FurnitureWorkPieceDataModel(string furnitureId, string workPieceId, int count) : IValidation +{ + public string FurnitureId { get; private set; } = furnitureId; + + public string WorkPieceId { get; private set; } = workPieceId; + + public int Count { get; private set; } = count; + + public void Validate() + { + if (FurnitureId.IsEmpty()) + throw new ValidationException("Field FurnitureId is empty"); + + if (!FurnitureId.IsGuid()) + throw new ValidationException("The value in the field FurnitureId is not a unique identifier"); + + if (WorkPieceId.IsEmpty()) + throw new ValidationException("Field WorkPieceId is empty"); + + if (!WorkPieceId.IsGuid()) + throw new ValidationException("The value in the field WorkPieceId 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/TheSoftBedProject/SoftBedContracts/DataModels/PostDataModel.cs b/TheSoftBedProject/SoftBedContracts/DataModels/PostDataModel.cs new file mode 100644 index 0000000..7ded264 --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/DataModels/PostDataModel.cs @@ -0,0 +1,39 @@ +using SoftBedContracts.Enums; +using SoftBedContracts.Exceptions; +using SoftBedContracts.Extensions; +using SoftBedContracts.Infrastructure; + +namespace SoftBedContracts.DataModels; + +public class PostDataModel(string id, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation +{ + public string Id { get; private set; } = id; + + 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 (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/TheSoftBedProject/SoftBedContracts/DataModels/SalaryDataModel.cs b/TheSoftBedProject/SoftBedContracts/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..43c1456 --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/DataModels/SalaryDataModel.cs @@ -0,0 +1,26 @@ +using SoftBedContracts.Exceptions; +using SoftBedContracts.Extensions; +using SoftBedContracts.Infrastructure; + +namespace SoftBedContracts.DataModels; + +public class SalaryDataModel(string workerId, DateTime salaryDate, double salary) : IValidation +{ + public string WorkerId { get; private set; } = workerId; + + public DateTime SalaryDate { get; private set; } = salaryDate; + + public double Salary { get; private set; } = salary; + + 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/TheSoftBedProject/SoftBedContracts/DataModels/WorkPieceDataModel.cs b/TheSoftBedProject/SoftBedContracts/DataModels/WorkPieceDataModel.cs new file mode 100644 index 0000000..3f864ec --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/DataModels/WorkPieceDataModel.cs @@ -0,0 +1,33 @@ +using SoftBedContracts.Exceptions; +using SoftBedContracts.Extensions; +using SoftBedContracts.Infrastructure; +using System.Text.RegularExpressions; + +namespace SoftBedContracts.DataModels; + +public class WorkPieceDataModel(string id, string size, double weight) : IValidation +{ + public string Id { get; private set; } = id; + + public string Size { get; private set; } = size; + + public double Weight { get; private set; } = weight; + + 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 (Size.IsEmpty()) + throw new ValidationException("Field Size is empty"); + + if (!Regex.IsMatch(Size, @"^\d+x\d+$")) + throw new ValidationException("Field Size has an invalid format. Expected format: number x number (e.g., '120x50')."); + + if (Weight <= 0) + throw new ValidationException("Field Weight is less than or equal to 0"); + } +} \ No newline at end of file diff --git a/TheSoftBedProject/SoftBedContracts/DataModels/WorkerDataModel.cs b/TheSoftBedProject/SoftBedContracts/DataModels/WorkerDataModel.cs new file mode 100644 index 0000000..43e1277 --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/DataModels/WorkerDataModel.cs @@ -0,0 +1,45 @@ +using SoftBedContracts.Exceptions; +using SoftBedContracts.Extensions; +using SoftBedContracts.Infrastructure; + +namespace SoftBedContracts.DataModels; + +public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate) : 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 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(-18).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 < 18) // EmploymentDate.Year - BirthDate.Year + throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})"); + } +} diff --git a/TheSoftBedProject/SoftBedContracts/Enums/FurnitureType.cs b/TheSoftBedProject/SoftBedContracts/Enums/FurnitureType.cs new file mode 100644 index 0000000..876628d --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/Enums/FurnitureType.cs @@ -0,0 +1,9 @@ +namespace SoftBedContracts.Enums; + +public enum FurnitureType +{ + None = 0, + UpholsteredFurniture = 1, + CabinetFurniture = 2, + FoldingFurniture = 3 +} \ No newline at end of file diff --git a/TheSoftBedProject/SoftBedContracts/Enums/MaterialType.cs b/TheSoftBedProject/SoftBedContracts/Enums/MaterialType.cs new file mode 100644 index 0000000..f612a4b --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/Enums/MaterialType.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SoftBedContracts.Enums +{ + internal class MaterialType + { + } +} diff --git a/TheSoftBedProject/SoftBedContracts/Enums/PostType.cs b/TheSoftBedProject/SoftBedContracts/Enums/PostType.cs new file mode 100644 index 0000000..bfe6526 --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/Enums/PostType.cs @@ -0,0 +1,9 @@ +namespace SoftBedContracts.Enums; + +public enum PostType +{ + None = 0, + Assembler = 1, + Loader = 2, + Assistent = 3 +} diff --git a/TheSoftBedProject/SoftBedContracts/Exceptions/ValidationException.cs b/TheSoftBedProject/SoftBedContracts/Exceptions/ValidationException.cs new file mode 100644 index 0000000..5598cdb --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/Exceptions/ValidationException.cs @@ -0,0 +1,5 @@ +namespace SoftBedContracts.Exceptions; + +public class ValidationException(string message) : Exception(message) +{ +} diff --git a/TheSoftBedProject/SoftBedContracts/Extensions/StringExtensions.cs b/TheSoftBedProject/SoftBedContracts/Extensions/StringExtensions.cs new file mode 100644 index 0000000..8dea688 --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/Extensions/StringExtensions.cs @@ -0,0 +1,14 @@ +namespace SoftBedContracts.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 _); + } +} diff --git a/TheSoftBedProject/SoftBedContracts/Infrastructure/IValidation.cs b/TheSoftBedProject/SoftBedContracts/Infrastructure/IValidation.cs new file mode 100644 index 0000000..377e5b3 --- /dev/null +++ b/TheSoftBedProject/SoftBedContracts/Infrastructure/IValidation.cs @@ -0,0 +1,6 @@ +namespace SoftBedContracts.Infrastructure; + +public interface IValidation +{ + void Validate(); +} diff --git a/TheSoftBedProject/SoftBedTests/DataModelsTests/CollectDataModelTests.cs b/TheSoftBedProject/SoftBedTests/DataModelsTests/CollectDataModelTests.cs new file mode 100644 index 0000000..00c67a4 --- /dev/null +++ b/TheSoftBedProject/SoftBedTests/DataModelsTests/CollectDataModelTests.cs @@ -0,0 +1,85 @@ +using SoftBedContracts.DataModels; +using SoftBedContracts.Enums; +using SoftBedContracts.Exceptions; + +namespace SoftBedTests.DataModelsTests; +[TestFixture] +internal class CollectDataModelTest +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var collect = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + collect = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var collect = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + } + [Test] + public void WorkerIdIsNullOrEmptyTest() + { + var collect = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + collect = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + } + + [Test] + public void WorkerIdIsNotGuidTest() + { + var collect = CreateDataModel(Guid.NewGuid().ToString(), "workerId", Guid.NewGuid().ToString(), 10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + } + + [Test] + public void FurnitureIdIsNullOrEmptyTest() + { + var collect = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + collect = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, 10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + } + + [Test] + public void FurnitureIdIsNotGuidTest() + { + var collect = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "furnitureId", 10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + } + + [Test] + public void SumIsLessOrZeroTest() + { + var collect = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + collect = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10); + Assert.That(() => collect.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var collectId = Guid.NewGuid().ToString(); + var workerId = Guid.NewGuid().ToString(); + var furnitureId = Guid.NewGuid().ToString(); + var sum = 10; + var collect = CreateDataModel(collectId, workerId, furnitureId, sum); + Assert.That(() => collect.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(collect.Id, Is.EqualTo(collectId)); + Assert.That(collect.WorkerId, Is.EqualTo(workerId)); + Assert.That(collect.FurnitureId, Is.EqualTo(furnitureId)); + Assert.That(collect.Sum, Is.EqualTo(sum)); + }); + } + + public static CollectDataModel CreateDataModel(string? id, string? workerId, string? furnitureId, double sum) => + new(id, workerId, furnitureId, sum); +} \ No newline at end of file diff --git a/TheSoftBedProject/SoftBedTests/DataModelsTests/FurnitureDataModelTests.cs b/TheSoftBedProject/SoftBedTests/DataModelsTests/FurnitureDataModelTests.cs new file mode 100644 index 0000000..ebac0c0 --- /dev/null +++ b/TheSoftBedProject/SoftBedTests/DataModelsTests/FurnitureDataModelTests.cs @@ -0,0 +1,82 @@ +using SoftBedContracts.DataModels; +using SoftBedContracts.Enums; +using SoftBedContracts.Exceptions; + +namespace SoftBedTests.DataModelsTests; + +[TestFixture] +internal class FurnitureDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var furniture = CreateDataModel(null, "furnitureName", FurnitureType.CabinetFurniture, 10, false, CreateSubDataModel()); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + furniture = CreateDataModel(string.Empty, "furnitureName", FurnitureType.CabinetFurniture, 10, false, CreateSubDataModel()); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var furniture = CreateDataModel("id", "furnitureName", FurnitureType.CabinetFurniture, 10, false, CreateSubDataModel()); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + } + [Test] + public void FurnitureNameIsEmptyTest() + { + var furniture = CreateDataModel(Guid.NewGuid().ToString(), null, FurnitureType.CabinetFurniture, 10, false, CreateSubDataModel()); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + furniture = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, FurnitureType.CabinetFurniture, 10, false, CreateSubDataModel()); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + } + + [Test] + public void FurnitureTypeIsNoneTest() + { + var furniture = CreateDataModel(Guid.NewGuid().ToString(), "furnitureName", FurnitureType.None, 10, false, CreateSubDataModel()); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + var furniture = CreateDataModel(Guid.NewGuid().ToString(), "furnitureName", FurnitureType.CabinetFurniture, 0, false, CreateSubDataModel()); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + furniture = CreateDataModel(Guid.NewGuid().ToString(), "furnitureName", FurnitureType.CabinetFurniture, -10, false, CreateSubDataModel()); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + } + [Test] + public void WorkPiecesIsNullOrEmptyTest() + { + var furniture = CreateDataModel(Guid.NewGuid().ToString(), "furnitureName", FurnitureType.CabinetFurniture, 0, false, null); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + furniture = CreateDataModel(Guid.NewGuid().ToString(), "furnitureName", FurnitureType.CabinetFurniture, 0, false, []); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + } + [Test] + public void AllFieldsIsCorrectTest() + { + var furnitureId = Guid.NewGuid().ToString(); + var furnitureName = "furnitureName"; + var furnitureType = FurnitureType.CabinetFurniture; + var price = 10; + var isDeleted = false; + var workPieces = CreateSubDataModel(); + var furniture = CreateDataModel(furnitureId, furnitureName, furnitureType, price, isDeleted, workPieces); + Assert.That(() => furniture.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(furniture.Id, Is.EqualTo(furnitureId)); + Assert.That(furniture.FurnitureName, Is.EqualTo(furnitureName)); + Assert.That(furniture.FurnitureType, Is.EqualTo(furnitureType)); + Assert.That(furniture.Price, Is.EqualTo(price)); + Assert.That(furniture.IsDeleted, Is.EqualTo(isDeleted)); + }); + } + + public static FurnitureDataModel CreateDataModel(string? id, string? furnitureName, FurnitureType furnitureType, double price, bool isDeleted, List workPieces) => + new(id, furnitureName, furnitureType, price, isDeleted, workPieces); + private static List CreateSubDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; +} diff --git a/TheSoftBedProject/SoftBedTests/DataModelsTests/FurnitureHistoryDataModelTests.cs b/TheSoftBedProject/SoftBedTests/DataModelsTests/FurnitureHistoryDataModelTests.cs new file mode 100644 index 0000000..45ea836 --- /dev/null +++ b/TheSoftBedProject/SoftBedTests/DataModelsTests/FurnitureHistoryDataModelTests.cs @@ -0,0 +1,52 @@ +using SoftBedContracts.DataModels; +using SoftBedContracts.Exceptions; + +namespace SoftBedTests.DataModelsTests; + +[TestFixture] +internal class FurnitureHistoryDataModelTests +{ + [Test] + public void ProductIdIsNullOrEmptyTest() + { + var furniture = CreateDataModel(null, 10); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + furniture = CreateDataModel(string.Empty, 10); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductIdIsNotGuidTest() + { + var furniture = CreateDataModel("id", 10); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + } + + [Test] + public void OldPriceIsLessOrZeroTest() + { + var furniture = CreateDataModel(Guid.NewGuid().ToString(), 0); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + furniture = CreateDataModel(Guid.NewGuid().ToString(), -10); + Assert.That(() => furniture.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var furnitureId = Guid.NewGuid().ToString(); + var oldPrice = 10; + var furnitureHistory = CreateDataModel(furnitureId, oldPrice); + Assert.That(() => furnitureHistory.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(furnitureHistory.FurnitureId, Is.EqualTo(furnitureId)); + Assert.That(furnitureHistory.OldPrice, Is.EqualTo(oldPrice)); + Assert.That(furnitureHistory.ChangeDate, Is.LessThan(DateTime.UtcNow)); + Assert.That(furnitureHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1))); + }); + } + + private static FurnitureHistoryDataModel CreateDataModel(string? furnitureId, double oldPrice) => + new(furnitureId, oldPrice); +} diff --git a/TheSoftBedProject/SoftBedTests/DataModelsTests/FurnitureWorkPieceDataModelTests.cs b/TheSoftBedProject/SoftBedTests/DataModelsTests/FurnitureWorkPieceDataModelTests.cs new file mode 100644 index 0000000..016c50c --- /dev/null +++ b/TheSoftBedProject/SoftBedTests/DataModelsTests/FurnitureWorkPieceDataModelTests.cs @@ -0,0 +1,66 @@ +using SoftBedContracts.DataModels; +using SoftBedContracts.Exceptions; + +namespace SoftBedTests.DataModelsTests; + +[TestFixture] +internal class FurnitureWorkPieceDataModelTests +{ + [Test] + public void FurnitureIdIsNullOrEmptyTest() + { + var furnitureWorkPiece = CreateDataModel(null, Guid.NewGuid().ToString(), 10); + Assert.That(() => furnitureWorkPiece.Validate(), Throws.TypeOf()); + furnitureWorkPiece = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => furnitureWorkPiece.Validate(), Throws.TypeOf()); + } + + [Test] + public void FurnitureIdIsNotGuidTest() + { + var furnitureWorkPiece = CreateDataModel("furnitureId", Guid.NewGuid().ToString(), 10); + Assert.That(() => furnitureWorkPiece.Validate(), Throws.TypeOf()); + } + [Test] + public void WorkPieceIdIsNullOrEmptyTest() + { + var furnitureWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), null, 10); + Assert.That(() => furnitureWorkPiece.Validate(), Throws.TypeOf()); + furnitureWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10); + Assert.That(() => furnitureWorkPiece.Validate(), Throws.TypeOf()); + } + + [Test] + public void WorkPieceIdIsNotGuidTest() + { + var furnitureWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), "workPieceId", 10); + Assert.That(() => furnitureWorkPiece.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var furnitureWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => furnitureWorkPiece.Validate(), Throws.TypeOf()); + furnitureWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10); + Assert.That(() => furnitureWorkPiece.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var furnitureId = Guid.NewGuid().ToString(); + var workPieceId = Guid.NewGuid().ToString(); + var count = 10; + var furnitureWorkPiece = CreateDataModel(furnitureId, workPieceId, count); + Assert.That(() => furnitureWorkPiece.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(furnitureWorkPiece.FurnitureId, Is.EqualTo(furnitureId)); + Assert.That(furnitureWorkPiece.WorkPieceId, Is.EqualTo(workPieceId)); + Assert.That(furnitureWorkPiece.Count, Is.EqualTo(count)); + }); + } + public static FurnitureWorkPieceDataModel CreateDataModel(string? furnitureId, string? workPieceId, int count) => + new(furnitureId, workPieceId, count); +} diff --git a/TheSoftBedProject/SoftBedTests/DataModelsTests/PostDataModelTests.cs b/TheSoftBedProject/SoftBedTests/DataModelsTests/PostDataModelTests.cs new file mode 100644 index 0000000..ed47a5a --- /dev/null +++ b/TheSoftBedProject/SoftBedTests/DataModelsTests/PostDataModelTests.cs @@ -0,0 +1,74 @@ +using SoftBedContracts.DataModels; +using SoftBedContracts.Enums; +using SoftBedContracts.Exceptions; +using System.Data; + +namespace SoftBedTests.DataModelsTests; + +[TestFixture] +internal class PostDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var post = CreateDataModel(null, "postName", PostType.Loader, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(string.Empty, "postName", PostType.Loader, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var post = CreateDataModel("id", "postName", PostType.Loader, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostNameIsEmptyTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Loader, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Loader, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostTypeIsNoneTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), "postName", PostType.None, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void SalaryIsLessOrZeroTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), "postName", PostType.Loader, 0, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + post = CreateDataModel(Guid.NewGuid().ToString(), "postName", PostType.Loader, -10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + [Test] + public void AllFieldsIsCorrectTest() + { + var postId = Guid.NewGuid().ToString(); + var postName = Guid.NewGuid().ToString(); + var postType = PostType.Loader; + var salary = 10; + var isActual = true; + var changeDate = DateTime.UtcNow.AddDays(-1); + var post = CreateDataModel(postId, postName, postType, salary, isActual, changeDate); + Assert.That(() => post.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(post.Id, Is.EqualTo(postId)); + 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? postName, PostType postType, double salary, bool isActual, DateTime changeDate) => + new(id, postName, postType, salary, isActual, changeDate); +} diff --git a/TheSoftBedProject/SoftBedTests/DataModelsTests/SalaryDataModelTests.cs b/TheSoftBedProject/SoftBedTests/DataModelsTests/SalaryDataModelTests.cs new file mode 100644 index 0000000..393d12f --- /dev/null +++ b/TheSoftBedProject/SoftBedTests/DataModelsTests/SalaryDataModelTests.cs @@ -0,0 +1,51 @@ +using SoftBedContracts.DataModels; +using SoftBedContracts.Exceptions; + +namespace SoftBedTests.DataModelsTests; + +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/TheSoftBedProject/SoftBedTests/DataModelsTests/WorkPieceDataModelTests.cs b/TheSoftBedProject/SoftBedTests/DataModelsTests/WorkPieceDataModelTests.cs new file mode 100644 index 0000000..afe2913 --- /dev/null +++ b/TheSoftBedProject/SoftBedTests/DataModelsTests/WorkPieceDataModelTests.cs @@ -0,0 +1,75 @@ +using SoftBedContracts.DataModels; +using SoftBedContracts.Exceptions; + +namespace SoftBedTests.DataModelsTests; +[TestFixture] +internal class WorkPieceDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var workPiece = CreateDataModel(null, "size", 10); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + workPiece = CreateDataModel(string.Empty, "size", 10); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var workPiece = CreateDataModel("id", "size", 10); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + } + + [Test] + public void SizeIsNullOrEmptyTest() + { + var workPiece = CreateDataModel(Guid.NewGuid().ToString(), null, 10); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + workPiece = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + } + + [Test] + public void SizeIsIncorrectTest() + { + var workPiece = CreateDataModel(Guid.NewGuid().ToString(), "1010", 10); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + var workPiece = CreateDataModel(Guid.NewGuid().ToString(), "size", 0); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + workPiece = CreateDataModel(Guid.NewGuid().ToString(), "size", -10); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductsIsNullOrEmptyTest() + { + var workPiece = CreateDataModel(Guid.NewGuid().ToString(), "size", 0); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + workPiece = CreateDataModel(Guid.NewGuid().ToString(), "size", 0); + Assert.That(() => workPiece.Validate(), Throws.TypeOf()); + } + [Test] + public void AllFieldsIsCorrectTest() + { + var workPieceId = Guid.NewGuid().ToString(); + var size = "10x10"; + var weight = 10; + var workPiece = CreateDataModel(workPieceId, size, weight); + Assert.That(() => workPiece.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(workPiece.Id, Is.EqualTo(workPieceId)); + Assert.That(workPiece.Size, Is.EqualTo(size)); + Assert.That(workPiece.Weight, Is.EqualTo(weight)); + }); + } + + private static WorkPieceDataModel CreateDataModel(string? id, string? size, double weight) => + new(id, size, weight); +} diff --git a/TheSoftBedProject/SoftBedTests/DataModelsTests/WorkerDataModelTests.cs b/TheSoftBedProject/SoftBedTests/DataModelsTests/WorkerDataModelTests.cs new file mode 100644 index 0000000..3c3addf --- /dev/null +++ b/TheSoftBedProject/SoftBedTests/DataModelsTests/WorkerDataModelTests.cs @@ -0,0 +1,88 @@ +using SoftBedContracts.DataModels; +using SoftBedContracts.Exceptions; + +namespace SoftBedTests.DataModelsTests; + +[TestFixture] +internal class WorkerDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + worker = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now); + 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); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullOrEmptyTest() + { + var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, DateTime.Now.AddYears(-18), DateTime.Now); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, DateTime.Now.AddYears(-18), DateTime.Now); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", DateTime.Now.AddYears(-18), DateTime.Now); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + } + + [Test] + public void BirthDateIsNotCorrectTest() + { + var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18).AddDays(1), DateTime.Now); + 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)); + Assert.That(() => worker.Validate(), Throws.TypeOf()); + worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16)); + 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(-18).AddDays(-1); + var employmentDate = DateTime.Now; + var worker = CreateDataModel(workerId, fio, postId, birthDate, employmentDate); + 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)); + }); + } + + private static WorkerDataModel CreateDataModel(string? id, string? fio, string? postId, DateTime birthDate, DateTime employmentDate) => + new(id, fio, postId, birthDate, employmentDate); +} diff --git a/TheSoftBedProject/SoftBedTests/SoftBedTests.csproj b/TheSoftBedProject/SoftBedTests/SoftBedTests.csproj new file mode 100644 index 0000000..3bc0e7c --- /dev/null +++ b/TheSoftBedProject/SoftBedTests/SoftBedTests.csproj @@ -0,0 +1,28 @@ + + + + net8.0 + enable + enable + + false + true + + + + + + + + + + + + + + + + + + + diff --git a/TheSoftBedProject/TheSoftBedProject.sln b/TheSoftBedProject/TheSoftBedProject.sln index a900dbb..16d749c 100644 --- a/TheSoftBedProject/TheSoftBedProject.sln +++ b/TheSoftBedProject/TheSoftBedProject.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34728.123 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftBedContracts", "SoftBedContracts\SoftBedContracts.csproj", "{B0AF813F-CC99-4892-AA65-4CDB225B7AA3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SoftBedContracts", "SoftBedContracts\SoftBedContracts.csproj", "{B0AF813F-CC99-4892-AA65-4CDB225B7AA3}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftBedTests", "SoftBedTests\SoftBedTests.csproj", "{0E56A9DB-177A-4114-B437-DE0F6C9711F4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {B0AF813F-CC99-4892-AA65-4CDB225B7AA3}.Debug|Any CPU.Build.0 = Debug|Any CPU {B0AF813F-CC99-4892-AA65-4CDB225B7AA3}.Release|Any CPU.ActiveCfg = Release|Any CPU {B0AF813F-CC99-4892-AA65-4CDB225B7AA3}.Release|Any CPU.Build.0 = Release|Any CPU + {0E56A9DB-177A-4114-B437-DE0F6C9711F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {0E56A9DB-177A-4114-B437-DE0F6C9711F4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {0E56A9DB-177A-4114-B437-DE0F6C9711F4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0E56A9DB-177A-4114-B437-DE0F6C9711F4}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE