diff --git a/TheCyclopsProject/TheCyclopsProject.sln b/TheCyclopsProject/TheCyclopsProject.sln index 0fc1d92..4fa5a94 100644 --- a/TheCyclopsProject/TheCyclopsProject.sln +++ b/TheCyclopsProject/TheCyclopsProject.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 17.12.35707.178 d17.12 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheCyclopsContracts", "TheCyclopsContracts\TheCyclopsContracts.csproj", "{01934235-715E-4B95-B859-48E8C89DA7CB}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheCyclopsTests", "TheCyclopsTests\TheCyclopsTests.csproj", "{78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {01934235-715E-4B95-B859-48E8C89DA7CB}.Debug|Any CPU.Build.0 = Debug|Any CPU {01934235-715E-4B95-B859-48E8C89DA7CB}.Release|Any CPU.ActiveCfg = Release|Any CPU {01934235-715E-4B95-B859-48E8C89DA7CB}.Release|Any CPU.Build.0 = Release|Any CPU + {78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Debug|Any CPU.Build.0 = Debug|Any CPU + {78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Release|Any CPU.ActiveCfg = Release|Any CPU + {78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs new file mode 100644 index 0000000..886ea3a --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ClientDataModelTests.cs @@ -0,0 +1,73 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class ClientDataModelTests +{ + [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 IdIsNotGuidTest() + { + var client = CreateDataModel("id", "fio", "email"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void FIOIsNullOrEmptyTest() + { + 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 EmailIsNullOrEmptyTest() + { + 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 EmailIsIncorrectTest() + { + var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "email"); + Assert.That(() => client.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var clientId = Guid.NewGuid().ToString(); + var fio = "Fio"; + var email = "email.email@email.com"; + var client = CreateDataModel(clientId, fio, email); + + Assert.That(() => client.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(client.Id, Is.EqualTo(clientId)); + Assert.That(client.FIO, Is.EqualTo(fio)); + Assert.That(client.Email, Is.EqualTo(email)); + }); + } + + private static ClientDataModel CreateDataModel(string? id, string? fio, string? email) => + new(id, fio, email); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ComponentDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ComponentDataModelTests.cs new file mode 100644 index 0000000..f0c233a --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/ComponentDataModelTests.cs @@ -0,0 +1,80 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Enums; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class ComponentDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var component = CreateDataModel(null, "name", ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + + component = CreateDataModel(string.Empty, "name", ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var component = CreateDataModel("id", "name", ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductNameIsEmptyTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + + component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Other, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentTypeIsNoneTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.None, 10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void PriceIsLessOrZeroTest() + { + var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Other, 0, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + + component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Other, -10, false); + Assert.That(() => component.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var componentId = Guid.NewGuid().ToString(); + var componentName = "name"; + var componentType = ComponentType.Other; + var componentManufacturerId = Guid.NewGuid().ToString(); + var componentPrice = 10; + var componentIsDelete = false; + var component = CreateDataModel(componentId, componentName, componentType, 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.Price, Is.EqualTo(componentPrice)); + Assert.That(component.IsDeleted, Is.EqualTo(componentIsDelete)); + }); + } + + private static ComponentDataModel CreateDataModel(string? id, string? componentName, + ComponentType componentType, double price, bool isDeleted) => + new(id, componentName, componentType, price, isDeleted); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs new file mode 100644 index 0000000..24d7b12 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/EmployeeDataModelTests.cs @@ -0,0 +1,108 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class EmployeeDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var employee = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var employee = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void FIOIsNullOrEmptyTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullOrEmptyTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", + DateTime.Now.AddYears(-18), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void BirthDateIsNotCorrectTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void BirthDateAndEmploymentDateIsNotCorrectTest() + { + var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + + employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), + DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false); + Assert.That(() => employee.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var employeeId = Guid.NewGuid().ToString(); + var fio = "fio"; + var postId = Guid.NewGuid().ToString(); + var birthDate = DateTime.Now.AddYears(-16).AddDays(-1); + var employmentDate = DateTime.Now; + var isDeleted = false; + var employee = CreateDataModel(employeeId, fio, postId, birthDate, employmentDate, isDeleted); + + Assert.That(() => employee.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(employee.Id, Is.EqualTo(employeeId)); + Assert.That(employee.FIO, Is.EqualTo(fio)); + Assert.That(employee.PostId, Is.EqualTo(postId)); + Assert.That(employee.BirthDate, Is.EqualTo(birthDate)); + Assert.That(employee.EmploymentDate, Is.EqualTo(employmentDate)); + Assert.That(employee.IsDeleted, Is.EqualTo(isDeleted)); + }); + } + + private static EmployeeDataModel CreateDataModel(string? id, string? fio, string? postId, + DateTime birthDate, DateTime employmentDate, bool isDeleted) => + new(id, fio, postId, birthDate, employmentDate, isDeleted); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs new file mode 100644 index 0000000..6b55343 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationComponentDataModelTests.cs @@ -0,0 +1,73 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class InstallationComponentDataModelTests +{ + [Test] + public void InstallationIdIsNullOrEmptyTest() + { + 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 InstallationIdIsNotGuidTest() + { + var saleProduct = CreateDataModel("installationId", Guid.NewGuid().ToString(), 10); + Assert.That(() => saleProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentIdIsNullOrEmptyTest() + { + 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 ComponentIdIsNotGuidTest() + { + var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 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 installationId = Guid.NewGuid().ToString(); + var componentId = Guid.NewGuid().ToString(); + var count = 10; + var saleProduct = CreateDataModel(installationId, componentId, count); + + Assert.That(() => saleProduct.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(saleProduct.InstallationId, Is.EqualTo(installationId)); + Assert.That(saleProduct.ComponentId, Is.EqualTo(componentId)); + Assert.That(saleProduct.Count, Is.EqualTo(count)); + }); + } + + private static InstallationComponentDataModel CreateDataModel(string? installationId, string? componentId, int count) => + new(installationId, componentId, count); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs new file mode 100644 index 0000000..71289f9 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/InstallationDataModelTests.cs @@ -0,0 +1,126 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class InstallationDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var installation = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + + installation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var installation = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmployeeIdIsNullOrEmptyTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + + installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void EmployeeIdIsNotGuidTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(), + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void ClientIdIsNotGuidTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void InstallationPriceIsLessOrZeroTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 0, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, -10, 20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void SumIsLessOrZeroTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 10, 0, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 10, -20, false, CreateSubDataModel()); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductsIsNullOrEmptyTest() + { + var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 10, 20, false, null); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + + installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", + DateTime.UtcNow, 10, 20, false, []); + Assert.That(() => installation.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var installationId = Guid.NewGuid().ToString(); + var employeeId = Guid.NewGuid().ToString(); + var client = Guid.NewGuid().ToString(); + var installationPrice = 10; + var sum = 20; + var isCanceled = true; + var components = CreateSubDataModel(); + var installation = CreateDataModel(installationId, employeeId, client, + DateTime.UtcNow, installationPrice, sum, isCanceled, components); + + Assert.That(() => installation.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(installation.Id, Is.EqualTo(installationId)); + Assert.That(installation.EmployeeId, Is.EqualTo(employeeId)); + Assert.That(installation.ClientId, Is.EqualTo(client)); + Assert.That(installation.Sum, Is.EqualTo(sum)); + Assert.That(installation.IsCanceled, Is.EqualTo(isCanceled)); + Assert.That(installation.Components, Is.EquivalentTo(components)); + }); + } + + private static InstallationDataModel CreateDataModel(string id, string employeeId, string? clientId, + DateTime installationDate, double installationPrice, double sum, bool isCanceled, + List components) => + new(id, employeeId, clientId, installationDate, installationPrice, sum, isCanceled, components); + + private static List CreateSubDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/PostDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/PostDataModelTests.cs new file mode 100644 index 0000000..d942348 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/PostDataModelTests.cs @@ -0,0 +1,110 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Enums; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class PostDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var post = CreateDataModel(null, Guid.NewGuid().ToString(), "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + + post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var post = CreateDataModel("id", Guid.NewGuid().ToString(), "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNullEmptyTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), null, "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + + post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "post", + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostIdIsNotGuidTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "post", + PostType.Designer, 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.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + + manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, + PostType.Designer, 10, true, DateTime.UtcNow); + Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); + } + + [Test] + public void PostTypeIsNoneTest() + { + var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post", + 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(), "post", + PostType.Designer, 0, true, DateTime.UtcNow); + Assert.That(() => post.Validate(), Throws.TypeOf()); + + post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post", + PostType.Designer, -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.Designer; + var salary = 10; + var isActual = false; + var changeDate = DateTime.UtcNow.AddDays(-1); + var post = CreateDataModel(postId, postPostId, postName, postType, salary, isActual, changeDate); + + Assert.That(() => post.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(post.Id, Is.EqualTo(postId)); + Assert.That(post.PostId, Is.EqualTo(postPostId)); + Assert.That(post.PostName, Is.EqualTo(postName)); + Assert.That(post.PostType, Is.EqualTo(postType)); + Assert.That(post.Salary, Is.EqualTo(salary)); + Assert.That(post.IsActual, Is.EqualTo(isActual)); + Assert.That(post.ChangeDate, Is.EqualTo(changeDate)); + }); + } + + private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) => + new(id, postId, postName, postType, salary, isActual, changeDate); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SalaryDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SalaryDataModelTests.cs new file mode 100644 index 0000000..bb63037 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SalaryDataModelTests.cs @@ -0,0 +1,56 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.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("employeeId", 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 employeeId = Guid.NewGuid().ToString(); + var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5); + var employeeSalary = 10; + var salary = CreateDataModel(employeeId, salaryDate, employeeSalary); + + Assert.That(() => salary.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(salary.EmployeeId, Is.EqualTo(employeeId)); + Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate)); + Assert.That(salary.Salary, Is.EqualTo(employeeSalary)); + }); + } + + private static SalaryDataModel CreateDataModel(string? employeeId, DateTime salaryDate, double workerSalary) => + new(employeeId, salaryDate, workerSalary); +} diff --git a/TheCyclopsProject/TheCyclopsTests/TheCyclopsTests.csproj b/TheCyclopsProject/TheCyclopsTests/TheCyclopsTests.csproj new file mode 100644 index 0000000..349b926 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/TheCyclopsTests.csproj @@ -0,0 +1,27 @@ + + + + net9.0 + latest + enable + enable + false + + + + + + + + + + + + + + + + + + +