From 1ebb95b7b1cf2faff9e5c35b65f08985525ed97c Mon Sep 17 00:00:00 2001 From: ne_kroman Date: Thu, 13 Feb 2025 18:16:23 +0400 Subject: [PATCH] lab1 --- .../ElectricalRepairService.sln | 8 +- .../ElectricalRepairServiceContract/Class1.cs | 7 -- .../DataModels/ClientDataModel.cs | 35 ++++++ .../DataModels/DetailsDataModel.cs | 45 ++++++++ .../DataModels/DetailsUseDataModel.cs | 39 +++++++ .../DataModels/EmploeeDataModel.cs | 40 +++++++ .../DataModels/PostDataModel.cs | 38 +++++++ .../DataModels/RequestDataModel.cs | 64 +++++++++++ .../DataModels/SalaryDataModel.cs | 44 ++++++++ .../Enums/PostType.cs | 16 +++ .../Enums/RequestType.cs | 17 +++ .../Enums/SalaryType.cs | 16 +++ .../Exceptions/ValidationException.cs | 12 ++ .../Extensions/StringExtensions.cs | 14 +++ .../Infrastructure/IValidation.cs | 13 +++ .../DataModelsTests/ClientDataModelTest.cs | 70 ++++++++++++ .../DataModelsTests/DetailsDataModelTest.cs | 72 ++++++++++++ .../DetailsUseDataModelTest.cs | 71 ++++++++++++ .../DataModelsTests/EmploeeDataModelTest.cs | 72 ++++++++++++ .../DataModelsTests/PostDataModelTest.cs | 60 ++++++++++ .../DataModelsTests/RequestDataModelTest.cs | 105 ++++++++++++++++++ .../DataModelsTests/SalaryDataModelTest.cs | 72 ++++++++++++ .../ElectricalRepairServiceTests.csproj | 34 ++++++ 23 files changed, 956 insertions(+), 8 deletions(-) delete mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/Class1.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/DataModels/ClientDataModel.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/DataModels/DetailsDataModel.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/DataModels/DetailsUseDataModel.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/DataModels/EmploeeDataModel.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/DataModels/PostDataModel.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/DataModels/RequestDataModel.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/DataModels/SalaryDataModel.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/Enums/PostType.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/Enums/RequestType.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/Enums/SalaryType.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/Exceptions/ValidationException.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/Extensions/StringExtensions.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceContract/Infrastructure/IValidation.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/ClientDataModelTest.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/DetailsDataModelTest.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/DetailsUseDataModelTest.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/EmploeeDataModelTest.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/PostDataModelTest.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/RequestDataModelTest.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/SalaryDataModelTest.cs create mode 100644 ElectricalRepairService/ElectricalRepairServiceTests/ElectricalRepairServiceTests.csproj diff --git a/ElectricalRepairService/ElectricalRepairService.sln b/ElectricalRepairService/ElectricalRepairService.sln index 22f43bd..0eba961 100644 --- a/ElectricalRepairService/ElectricalRepairService.sln +++ b/ElectricalRepairService/ElectricalRepairService.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.9.34701.34 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectricalRepairServiceContract", "ElectricalRepairServiceContract\ElectricalRepairServiceContract.csproj", "{2D09B01A-09E9-4538-83F9-C26AB93A9D63}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ElectricalRepairServiceContract", "ElectricalRepairServiceContract\ElectricalRepairServiceContract.csproj", "{2D09B01A-09E9-4538-83F9-C26AB93A9D63}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ElectricalRepairServiceTests", "ElectricalRepairServiceTests\ElectricalRepairServiceTests.csproj", "{37C14277-69C3-4C2F-8D51-B594A5D4183F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {2D09B01A-09E9-4538-83F9-C26AB93A9D63}.Debug|Any CPU.Build.0 = Debug|Any CPU {2D09B01A-09E9-4538-83F9-C26AB93A9D63}.Release|Any CPU.ActiveCfg = Release|Any CPU {2D09B01A-09E9-4538-83F9-C26AB93A9D63}.Release|Any CPU.Build.0 = Release|Any CPU + {37C14277-69C3-4C2F-8D51-B594A5D4183F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37C14277-69C3-4C2F-8D51-B594A5D4183F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37C14277-69C3-4C2F-8D51-B594A5D4183F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37C14277-69C3-4C2F-8D51-B594A5D4183F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/Class1.cs b/ElectricalRepairService/ElectricalRepairServiceContract/Class1.cs deleted file mode 100644 index 52064a0..0000000 --- a/ElectricalRepairService/ElectricalRepairServiceContract/Class1.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace ElectricalRepairServiceContract -{ - public class Class1 - { - - } -} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/ClientDataModel.cs b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/ClientDataModel.cs new file mode 100644 index 0000000..020cda7 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/ClientDataModel.cs @@ -0,0 +1,35 @@ +using System.Text.RegularExpressions; +using ElectricalRepairServiceContract.Exceptions; +using ElectricalRepairServiceContract.Extensions; +using ElectricalRepairServiceContract.Interfaces; + +namespace ElectricalRepairServiceContract.DataModels +{ + public class ClientDataModel : IValidation + { + public string Id { get; private set; } + public string Name { get; private set; } + public string Email { get; private set; } + + public ClientDataModel(string id, string name, string email) + { + Id = id; + Name = name; + Email = email; + } + + public void Validate() + { + if (Id.IsEmpty()) + throw new ValidationException("Field DetailsId is empty"); + if (!Id.IsGuid()) + throw new ValidationException("The value in the field DetailsId is not a unique identifier"); + if (Name.IsEmpty()) + throw new ValidationException("Field Description is empty"); + if (Email.IsEmpty()) + throw new ValidationException("Field Cost is empty"); + if (!Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$")) + throw new ValidationException("Field Cost is not a valid email address"); + } + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/DetailsDataModel.cs b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/DetailsDataModel.cs new file mode 100644 index 0000000..fc1ffb5 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/DetailsDataModel.cs @@ -0,0 +1,45 @@ +using ElectricalRepairServiceContract.Exceptions; +using ElectricalRepairServiceContract.Extensions; +using ElectricalRepairServiceContract.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.DataModels +{ + public class DetailsDataModel : IValidation + { + public string Id { get; private set; } + public string Name { get; private set; } + public int Count { get; private set; } + public int OldCount { get; private set; } + + public DateTime UpdateDate { get; private set; } + + public DetailsDataModel(string id, string name, int count, int oldCount, DateTime updateDate) + { + Id = id; + Name = name; + Count = count; + OldCount = oldCount; + UpdateDate = updateDate; + } + + public void Validate() + { + if (Id.IsEmpty()) + throw new ValidationException("Field Id is empty"); + if (!Id.IsGuid()) + throw new ValidationException("The value in the field Id is not a unique identifier"); + if (Name.IsEmpty()) + throw new ValidationException("Field Description is empty"); + if (Count < 0) + throw new ValidationException("The count must be more then 0"); + if (OldCount < 0) + throw new ValidationException("The count must be more then 0"); + } + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/DetailsUseDataModel.cs b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/DetailsUseDataModel.cs new file mode 100644 index 0000000..17d60a2 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/DetailsUseDataModel.cs @@ -0,0 +1,39 @@ +using ElectricalRepairServiceContract.Exceptions; +using ElectricalRepairServiceContract.Extensions; +using ElectricalRepairServiceContract.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.DataModels +{ + public class DetailsUseDataModel : IValidation + { + public string DetailsId { get; private set; } + public string RequestId { get; private set; } + public int Count { get; private set; } + + public DetailsUseDataModel(string detailsId, string requestId, int count) + { + DetailsId = detailsId; + RequestId = requestId; + Count = count; + } + + public void Validate() + { + if (DetailsId.IsEmpty()) + throw new ValidationException("Field DetailsId is empty"); + if (!DetailsId.IsGuid()) + throw new ValidationException("The value in the field DetailsId is not a unique identifier"); + if (RequestId.IsEmpty()) + throw new ValidationException("Field RequestId is empty"); + if (!RequestId.IsGuid()) + throw new ValidationException("The value in the field RequestId is not a unique identifier"); + if (Count <= 0) + throw new ValidationException("The count must be positive"); + } + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/EmploeeDataModel.cs b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/EmploeeDataModel.cs new file mode 100644 index 0000000..4d145f2 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/EmploeeDataModel.cs @@ -0,0 +1,40 @@ +using ElectricalRepairServiceContract.Exceptions; +using ElectricalRepairServiceContract.Extensions; +using ElectricalRepairServiceContract.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.DataModels +{ + public class EmploeeDataModel : IValidation + { + public string Id { get; private set; } + public string Name { get; private set; } + public string PostId { get; private set; } + + public EmploeeDataModel(string id, string name, string postId) + { + Id = id; + Name = name; + PostId = postId; + } + + public void Validate() + { + if (Id.IsEmpty()) + throw new ValidationException("Field Id is empty"); + if (!Id.IsGuid()) + throw new ValidationException("The value in the field Id is not a unique identifier"); + if (Name.IsEmpty()) + throw new ValidationException("Field Name is empty"); + if (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"); + } + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/PostDataModel.cs b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/PostDataModel.cs new file mode 100644 index 0000000..7822b63 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/PostDataModel.cs @@ -0,0 +1,38 @@ +using ElectricalRepairServiceContract.Enums; +using ElectricalRepairServiceContract.Exceptions; +using ElectricalRepairServiceContract.Extensions; +using ElectricalRepairServiceContract.Interfaces; +using System.Text.RegularExpressions; + +namespace ElectricalRepairServiceContract.DataModels +{ + public class PostDataModel : IValidation + { + public string Id { get; private set; } + public PostType PostType { get; private set; } + + public string Description { get; private set; } + + public bool IsActual { get; private set; } + public DateTime ChangeDate { get; private set; } + + public PostDataModel(string id, PostType name, bool isActual, DateTime changeDate, string description) + { + Id = id; + PostType = name; + IsActual = isActual; + ChangeDate = changeDate; + Description = description; + } + + 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 (Description.IsEmpty()) + throw new ValidationException("Field Description is empty"); + } + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/RequestDataModel.cs b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/RequestDataModel.cs new file mode 100644 index 0000000..4e2cfec --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/RequestDataModel.cs @@ -0,0 +1,64 @@ +using ElectricalRepairServiceContract.Enums; +using ElectricalRepairServiceContract.Exceptions; +using ElectricalRepairServiceContract.Extensions; +using ElectricalRepairServiceContract.Interfaces; +using System; +using System.Collections.Generic; +using System.Diagnostics.Metrics; +using System.Linq; +using System.Text; +using System.Text.RegularExpressions; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.DataModels +{ + public class RequestDataModel : IValidation + { + public string Id { get; private set; } + public string Description { get; private set; } + public int Cost { get; private set; } + public DateTime DateComplete { get; private set; } + public RequestType RequestType { get; private set; } + public string EmploeeId { get; private set; } + public string? ClientId { get; private set; } + public List? DetailsUse { get; private set; } + + public RequestDataModel(string id, RequestType requestType, string? description, int cost, + DateTime dateComplete, string emploeeId, string? clientId, List? detailsUses) + { + Id = id; + Description = description; + RequestType = requestType; + Cost = cost; + DateComplete = dateComplete; + EmploeeId = emploeeId; + ClientId = clientId; + DetailsUse = detailsUses; + } + + 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 (EmploeeId.IsEmpty()) + throw new ValidationException("Field EmploeeId is empty"); + if (!EmploeeId.IsGuid()) + throw new ValidationException("The value in the field EmploeeId is not a unique identifier"); + + if (!ClientId?.IsGuid() ?? false) + throw new ValidationException("The value in the field ClientId is not a unique identifier"); + + if (Description.IsEmpty()) + throw new ValidationException("Field Description is empty"); + + if (DetailsUse?.Count == 0) + throw new ValidationException("The request must include detailsUses"); + if (Cost < 0) + throw new ValidationException("The count must be positive"); + + } + } +} \ No newline at end of file diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/SalaryDataModel.cs b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..252e916 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/DataModels/SalaryDataModel.cs @@ -0,0 +1,44 @@ +using ElectricalRepairServiceContract.Enums; +using ElectricalRepairServiceContract.Exceptions; +using ElectricalRepairServiceContract.Extensions; +using ElectricalRepairServiceContract.Interfaces; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.DataModels +{ + public class SalaryDataModel : IValidation + { + public string Id { get; private set; } + public SalaryType SalaryType { get; private set; } + public int Amount { get; private set; } + public string EmploeeId { get; private set; } + public DateTime Date { get; private set; } + + public SalaryDataModel(string id, string postId, SalaryType type, int amount, DateTime date) + { + Id = id; + SalaryType = type; + Amount = amount; + EmploeeId = postId; + Date = date; + } + + 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 (EmploeeId.IsEmpty()) + throw new ValidationException("Field EmploeeId is empty"); + if (!EmploeeId.IsGuid()) + throw new ValidationException("The value in the field EmploeeId is not a unique identifier"); + if (Amount < 0) + throw new ValidationException("The amount must be positive"); + } + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/Enums/PostType.cs b/ElectricalRepairService/ElectricalRepairServiceContract/Enums/PostType.cs new file mode 100644 index 0000000..5d23c3c --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/Enums/PostType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.Enums +{ + public enum PostType + { + None = 0, + Manager = 1, + Worker = 2, + Admin = 3 + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/Enums/RequestType.cs b/ElectricalRepairService/ElectricalRepairServiceContract/Enums/RequestType.cs new file mode 100644 index 0000000..d4623d4 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/Enums/RequestType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.Enums +{ + [Flags] + public enum RequestType + { + None = 0, + Repair = 1, + Buy = 4, + Refund = 8 + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/Enums/SalaryType.cs b/ElectricalRepairService/ElectricalRepairServiceContract/Enums/SalaryType.cs new file mode 100644 index 0000000..24ef1bb --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/Enums/SalaryType.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.Enums +{ + public enum SalaryType + { + None = 0, + Salary = 1, + Fine = 2, + Bonus = 3 + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/Exceptions/ValidationException.cs b/ElectricalRepairService/ElectricalRepairServiceContract/Exceptions/ValidationException.cs new file mode 100644 index 0000000..c9e982a --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/Exceptions/ValidationException.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.Exceptions +{ + public class ValidationException(string message) : Exception(message) + { + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceContract/Extensions/StringExtensions.cs b/ElectricalRepairService/ElectricalRepairServiceContract/Extensions/StringExtensions.cs new file mode 100644 index 0000000..f3a7fe6 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/Extensions/StringExtensions.cs @@ -0,0 +1,14 @@ +namespace ElectricalRepairServiceContract.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/ElectricalRepairService/ElectricalRepairServiceContract/Infrastructure/IValidation.cs b/ElectricalRepairService/ElectricalRepairServiceContract/Infrastructure/IValidation.cs new file mode 100644 index 0000000..f21c1c8 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceContract/Infrastructure/IValidation.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceContract.Interfaces +{ + internal interface IValidation + { + void Validate(); + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/ClientDataModelTest.cs b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/ClientDataModelTest.cs new file mode 100644 index 0000000..a6ab97d --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/ClientDataModelTest.cs @@ -0,0 +1,70 @@ +using ElectricalRepairServiceContract.DataModels; +using ElectricalRepairServiceContract.Exceptions; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ElectricalRepairServiceTests.DataModelsTests +{ + [TestFixture] + internal class ClientDataModelTest + { + [Test] + public void IdIsNullOrEmptyTest() + { + var client = CreateDataModel(null, "fio", "email"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + client = CreateDataModel(string.Empty, "fio", "email"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuid() + { + var client = CreateDataModel("id", "fio", "email"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void NameIsNullOrEmptty() + { + var client = CreateDataModel(Guid.NewGuid().ToString(), null, "email"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "email"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmailIsNUllOrEmpty() + { + var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", null); + Assert.That(() => client.Validate(), Throws.TypeOf()); + client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmailInvalid() + { + var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "null"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsCorrect() + { + var id = Guid.NewGuid().ToString(); + var fio = "fio"; + var email = "some@gmail.com"; + var client = CreateDataModel(id, fio, email); + Assert.That(client.Id, Is.EqualTo(id)); + Assert.That(client.Name, Is.EqualTo(fio)); + Assert.That(client.Email, Is.EqualTo(email)); + } + + private ClientDataModel CreateDataModel(string id, string name, string email) + => new ClientDataModel(id, name, email); + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/DetailsDataModelTest.cs b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/DetailsDataModelTest.cs new file mode 100644 index 0000000..3df99f5 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/DetailsDataModelTest.cs @@ -0,0 +1,72 @@ +using ElectricalRepairServiceContract.DataModels; +using ElectricalRepairServiceContract.Exceptions; + + +namespace ElectricalRepairServiceTests.DataModelsTests +{ + [TestFixture] + internal class DetailsDataModelTest + { + [Test] + public void IdIsNullOrEmptyTest() + { + var details = CreateDataModel(null, "name", 1, 1, DateTime.Now); + Assert.That(() => details.Validate(), Throws.TypeOf()); + + details = CreateDataModel(string.Empty, "name", 1, 1, DateTime.Now); + Assert.That(() => details.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var details = CreateDataModel("invalid-id", "name", 1, 1, DateTime.Now); + Assert.That(() => details.Validate(), Throws.TypeOf()); + } + + [Test] + public void NameIsNullOrEmptyTest() + { + var details = CreateDataModel(Guid.NewGuid().ToString(), null, 1, 1, DateTime.Now); + Assert.That(() => details.Validate(), Throws.TypeOf()); + + details = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1, 1, DateTime.Now); + Assert.That(() => details.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsNegativeTest() + { + var details = CreateDataModel(Guid.NewGuid().ToString(), "name", -1, 10, DateTime.Now); + Assert.That(() => details.Validate(), Throws.TypeOf()); + } + + [Test] + public void OldCountIsNegativeTest() + { + var details = CreateDataModel(Guid.NewGuid().ToString(), "name", 10, -1, DateTime.Now); + Assert.That(() => details.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var name = "ValidName"; + var count = 10; + var oldCount = 10; + var dateTime = DateTime.Now; + + var details = CreateDataModel(id, name, count, oldCount, dateTime); + + Assert.That(details.Id, Is.EqualTo(id)); + Assert.That(details.Name, Is.EqualTo(name)); + Assert.That(details.Count, Is.EqualTo(count)); + Assert.That(details.OldCount, Is.EqualTo(oldCount)); + Assert.That(details.UpdateDate, Is.EqualTo(dateTime)); + } + + private DetailsDataModel CreateDataModel(string id, string name, int count, int oldCount, DateTime dateTime) + => new DetailsDataModel(id, name, count, oldCount, dateTime); + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/DetailsUseDataModelTest.cs b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/DetailsUseDataModelTest.cs new file mode 100644 index 0000000..1028aef --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/DetailsUseDataModelTest.cs @@ -0,0 +1,71 @@ +using ElectricalRepairServiceContract.DataModels; +using ElectricalRepairServiceContract.Exceptions; + + +namespace ElectricalRepairServiceTests.DataModelsTests +{ + [TestFixture] + internal class DetailsUseDataModelTest + { + [Test] + public void DetailsIdIsNullOrEmptyTest() + { + var detailsUse = CreateDataModel(null, Guid.NewGuid().ToString(), 1); + Assert.That(() => detailsUse.Validate(), Throws.TypeOf()); + + detailsUse = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1); + Assert.That(() => detailsUse.Validate(), Throws.TypeOf()); + } + + [Test] + public void DetailsIdIsNotGuidTest() + { + var detailsUse = CreateDataModel("invalid-id", Guid.NewGuid().ToString(), 1); + Assert.That(() => detailsUse.Validate(), Throws.TypeOf()); + } + + [Test] + public void RequestIdIsNullOrEmptyTest() + { + var detailsUse = CreateDataModel(Guid.NewGuid().ToString(), null, 1); + Assert.That(() => detailsUse.Validate(), Throws.TypeOf()); + + detailsUse = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1); + Assert.That(() => detailsUse.Validate(), Throws.TypeOf()); + } + + [Test] + public void RequestIdIsNotGuidTest() + { + var detailsUse = CreateDataModel(Guid.NewGuid().ToString(), "invalid-id", 1); + Assert.That(() => detailsUse.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsZeroOrNegativeTest() + { + var detailsUse = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1); + Assert.That(() => detailsUse.Validate(), Throws.TypeOf()); + + detailsUse = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => detailsUse.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsCorrectTest() + { + var detailsId = Guid.NewGuid().ToString(); + var requestId = Guid.NewGuid().ToString(); + var count = 10; + + var detailsUse = CreateDataModel(detailsId, requestId, count); + + Assert.That(detailsUse.DetailsId, Is.EqualTo(detailsId)); + Assert.That(detailsUse.RequestId, Is.EqualTo(requestId)); + Assert.That(detailsUse.Count, Is.EqualTo(count)); + } + + private DetailsUseDataModel CreateDataModel(string detailsId, string requestId, int count) + => new DetailsUseDataModel(detailsId, requestId, count); + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/EmploeeDataModelTest.cs b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/EmploeeDataModelTest.cs new file mode 100644 index 0000000..fd06999 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/EmploeeDataModelTest.cs @@ -0,0 +1,72 @@ +using ElectricalRepairServiceContract.DataModels; +using ElectricalRepairServiceContract.Exceptions; +using NUnit.Framework; +using System; + +namespace ElectricalRepairServiceTests.DataModelsTests +{ + [TestFixture] + internal class EmploeeDataModelTest + { + [Test] + public void IdIsNullOrEmptyTest() + { + var employee = CreateDataModel(null, "ValidName", Guid.NewGuid().ToString()); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(string.Empty, "ValidName", Guid.NewGuid().ToString()); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var employee = CreateDataModel("invalid-id", "ValidName", Guid.NewGuid().ToString()); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void NameIsNullOrEmptyTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString()); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString()); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullOrEmptyTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "ValidName", null); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(Guid.NewGuid().ToString(), "ValidName", string.Empty); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "ValidName", "invalid-post-id"); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var name = "ValidName"; + var postId = Guid.NewGuid().ToString(); + + var employee = CreateDataModel(id, name, postId); + + Assert.That(employee.Id, Is.EqualTo(id)); + Assert.That(employee.Name, Is.EqualTo(name)); + Assert.That(employee.PostId, Is.EqualTo(postId)); + } + + private EmploeeDataModel CreateDataModel(string id, string name, string postId) + => new EmploeeDataModel(id, name, postId); + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/PostDataModelTest.cs b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/PostDataModelTest.cs new file mode 100644 index 0000000..7ac6645 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/PostDataModelTest.cs @@ -0,0 +1,60 @@ +using ElectricalRepairServiceContract.DataModels; +using ElectricalRepairServiceContract.Enums; +using ElectricalRepairServiceContract.Exceptions; +using NUnit.Framework; +using System; + +namespace ElectricalRepairServiceTests.DataModelsTests +{ + [TestFixture] + internal class PostDataModelTest + { + [Test] + public void IdIsNullOrEmptyTest() + { + var post = CreateDataModel(null, PostType.Manager, true, DateTime.Now, "Valid description"); + Assert.That(() => post.Validate(), Throws.TypeOf()); + + post = CreateDataModel(string.Empty, PostType.Manager, true, DateTime.Now, "Valid description"); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var post = CreateDataModel("invalid-id", PostType.Manager, true, DateTime.Now, "Valid description"); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void DescriptionIsNullOrEmptyTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), PostType.Manager, true, DateTime.Now, null); + Assert.That(() => post.Validate(), Throws.TypeOf()); + + post = CreateDataModel(Guid.NewGuid().ToString(), PostType.Manager, true, DateTime.Now, string.Empty); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var postType = PostType.Manager; + var isActual = true; + var changeDate = DateTime.Now; + var description = "Responsible for managing the team"; + + var post = CreateDataModel(id, postType, isActual, changeDate, description); + + Assert.That(post.Id, Is.EqualTo(id)); + Assert.That(post.PostType, Is.EqualTo(postType)); + Assert.That(post.IsActual, Is.EqualTo(isActual)); + Assert.That(post.ChangeDate, Is.EqualTo(changeDate)); + Assert.That(post.Description, Is.EqualTo(description)); + } + + private PostDataModel CreateDataModel(string id, PostType postType, bool isActual, DateTime changeDate, string description) + => new PostDataModel(id, postType, isActual, changeDate, description); + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/RequestDataModelTest.cs b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/RequestDataModelTest.cs new file mode 100644 index 0000000..8476381 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/RequestDataModelTest.cs @@ -0,0 +1,105 @@ +using ElectricalRepairServiceContract.DataModels; +using ElectricalRepairServiceContract.Enums; +using ElectricalRepairServiceContract.Exceptions; +using NUnit.Framework; +using System; +using System.Collections.Generic; + +namespace ElectricalRepairServiceTests.DataModelsTests +{ + [TestFixture] + internal class RequestDataModelTest + { + [Test] + public void IdIsNullOrEmptyTest() + { + var request = CreateDataModel(null, RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + + request = CreateDataModel(string.Empty, RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var request = CreateDataModel("invalid-id", RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmploeeIdIsNullOrEmptyTest() + { + var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, null, Guid.NewGuid().ToString(), new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + + request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, string.Empty, Guid.NewGuid().ToString(), new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmploeeIdIsNotGuidTest() + { + var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, "invalid-id", Guid.NewGuid().ToString(), new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + } + + [Test] + public void ClientIdIsNotGuidTest() + { + var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), "invalid-client-id", new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + } + + [Test] + public void CostIsNegativeTest() + { + var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", -1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + } + + [Test] + public void DescriptionIsEmptyTest() + { + var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, string.Empty, 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + } + + [Test] + public void DetailsUseIsEmptyTest() + { + var request = CreateDataModel(Guid.NewGuid().ToString(), RequestType.Repair, "Description", 1000, DateTime.Now, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), new List()); + Assert.That(() => request.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var requestType = RequestType.Repair; + var description = "Valid description"; + var cost = 1500; + var dateComplete = DateTime.Now; + var emploeeId = Guid.NewGuid().ToString(); + var clientId = Guid.NewGuid().ToString(); + var detailsUses = new List + { + new DetailsUseDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10) + }; + + var request = CreateDataModel(id, requestType, description, cost, dateComplete, emploeeId, clientId, detailsUses); + + Assert.That(request.Id, Is.EqualTo(id)); + Assert.That(request.RequestType, Is.EqualTo(requestType)); + Assert.That(request.Description, Is.EqualTo(description)); + Assert.That(request.Cost, Is.EqualTo(cost)); + Assert.That(request.DateComplete, Is.EqualTo(dateComplete)); + Assert.That(request.EmploeeId, Is.EqualTo(emploeeId)); + Assert.That(request.ClientId, Is.EqualTo(clientId)); + Assert.That(request.DetailsUse, Is.EqualTo(detailsUses)); + } + + private RequestDataModel CreateDataModel(string id, RequestType requestType, string? description, int cost, DateTime dateComplete, string emploeeId, string? clientId, List? detailsUses) + => new RequestDataModel(id, requestType, description, cost, dateComplete, emploeeId, clientId, detailsUses); + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/SalaryDataModelTest.cs b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/SalaryDataModelTest.cs new file mode 100644 index 0000000..ba9fbd2 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceTests/DataModelsTests/SalaryDataModelTest.cs @@ -0,0 +1,72 @@ +using ElectricalRepairServiceContract.DataModels; +using ElectricalRepairServiceContract.Enums; +using ElectricalRepairServiceContract.Exceptions; + +namespace ElectricalRepairServiceTests.DataModelsTests +{ + [TestFixture] + internal class SalaryDataModelTest + { + [Test] + public void IdIsNullOrEmptyTest() + { + var salary = CreateDataModel(null, SalaryType.Salary, 1000, Guid.NewGuid().ToString(), DateTime.Now); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + + salary = CreateDataModel(string.Empty, SalaryType.Salary, 1000, Guid.NewGuid().ToString(), DateTime.Now); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var salary = CreateDataModel("invalid-id", SalaryType.Salary, 1000, Guid.NewGuid().ToString(), DateTime.Now); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmploeeIdIsNullOrEmptyTest() + { + var salary = CreateDataModel(Guid.NewGuid().ToString(), SalaryType.Salary, 1000, null, DateTime.Now); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + + salary = CreateDataModel(Guid.NewGuid().ToString(), SalaryType.Salary, 1000, string.Empty, DateTime.Now); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmploeeIdIsNotGuidTest() + { + var salary = CreateDataModel(Guid.NewGuid().ToString(), SalaryType.Salary, 1000, "invalid-id", DateTime.Now); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void AmountIsNegativeTest() + { + var salary = CreateDataModel(Guid.NewGuid().ToString(), SalaryType.Salary, -1000, Guid.NewGuid().ToString(), DateTime.Now); + Assert.That(() => salary.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var salaryType = SalaryType.Salary; + var amount = 1500; + var emploeeId = Guid.NewGuid().ToString(); + var date = DateTime.Now; + + var salary = CreateDataModel(id, salaryType, amount, emploeeId, date); + + Assert.That(salary.Id, Is.EqualTo(id)); + Assert.That(salary.SalaryType, Is.EqualTo(salaryType)); + Assert.That(salary.Amount, Is.EqualTo(amount)); + Assert.That(salary.EmploeeId, Is.EqualTo(emploeeId)); + Assert.That(salary.Date, Is.EqualTo(date)); + } + + private SalaryDataModel CreateDataModel(string id, SalaryType salaryType, int amount, string emploeeId, DateTime date) + => new SalaryDataModel(id, emploeeId, salaryType, amount, date); + } +} diff --git a/ElectricalRepairService/ElectricalRepairServiceTests/ElectricalRepairServiceTests.csproj b/ElectricalRepairService/ElectricalRepairServiceTests/ElectricalRepairServiceTests.csproj new file mode 100644 index 0000000..3356534 --- /dev/null +++ b/ElectricalRepairService/ElectricalRepairServiceTests/ElectricalRepairServiceTests.csproj @@ -0,0 +1,34 @@ + + + + net8.0 + enable + enable + + false + true + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + +