Compare commits

..

No commits in common. "Task_1_Models" and "main" have entirely different histories.

19 changed files with 0 additions and 894 deletions

View File

@ -1,38 +0,0 @@
using TheCyclopsContracts.Enums;
using TheCyclopsContracts.Exceptions;
using TheCyclopsContracts.Extensions;
using TheCyclopsContracts.Infrastructure;
namespace TheCyclopsContracts.DataModels;
public class ComponentDataModel(string id, string componentName,
ComponentType componentType, double price, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string ComponentName { get; private set; } = componentName;
public ComponentType ComponentType { get; private set; } = componentType;
public double Price { get; private set; } = price;
public bool IsDeleted { get; private set; } = isDeleted;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (ComponentName.IsEmpty())
throw new ValidationException("Field ComponentName is empty");
if (ComponentType == ComponentType.None)
throw new ValidationException("Field ComponentType is empty");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}

View File

@ -1,57 +0,0 @@
using System.Text.RegularExpressions;
using TheCyclopsContracts.Exceptions;
using TheCyclopsContracts.Extensions;
using TheCyclopsContracts.Infrastructure;
namespace TheCyclopsContracts.DataModels;
public class EmployeeDataModel(string id, string fio, string email, string postId,
DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string FIO { get; private set; } = fio;
public string Email { get; private set; } = email;
public string PostId { get; private set; } = postId;
public DateTime BirthDate { get; private set; } = birthDate;
public DateTime EmploymentDate { get; private set; } = employmentDate;
public bool IsDeleted { get; private set; } = isDeleted;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (FIO.IsEmpty())
throw new ValidationException("Field FIO is empty");
if (Email.IsEmpty())
throw new ValidationException("Field Email is empty");
if (!Regex.IsMatch(Email, @"^\S+@\S+\.\S+$"))
throw new ValidationException("Field Email is not an email address");
if (PostId.IsEmpty())
throw new ValidationException("Field PostId is empty");
if (!PostId.IsGuid())
throw new ValidationException("The value in the field PostId is not a unique identifier");
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
if (EmploymentDate.Date < BirthDate.Date)
throw new ValidationException("The date of employment cannot be less than the date of birth");
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
}
}

View File

@ -1,33 +0,0 @@
using TheCyclopsContracts.Exceptions;
using TheCyclopsContracts.Extensions;
using TheCyclopsContracts.Infrastructure;
namespace TheCyclopsContracts.DataModels;
public class InstallationComponentDataModel(string installationId,
string componentId, int count) : IValidation
{
public string InstallationId { get; private set; } = installationId;
public string ComponentId { get; private set; } = componentId;
public int Count { get; private set; } = count;
public void Validate()
{
if (InstallationId.IsEmpty())
throw new ValidationException("Field InstallationId is empty");
if (!InstallationId.IsGuid())
throw new ValidationException("The value in the field InstallationId is not a unique identifier");
if (ComponentId.IsEmpty())
throw new ValidationException("Field ComponentId is empty");
if (!ComponentId.IsGuid())
throw new ValidationException("The value in the field ComponentId is not a unique identifier");
if (Count <= 0)
throw new ValidationException("Field Count is less than or equal to 0");
}
}

View File

@ -1,50 +0,0 @@
using TheCyclopsContracts.Exceptions;
using TheCyclopsContracts.Extensions;
using TheCyclopsContracts.Infrastructure;
namespace TheCyclopsContracts.DataModels;
public class InstallationDataModel(string id, string employeeId,
DateTime installationDate, double installationPrice, double sum, bool isCanceled,
List<InstallationComponentDataModel> components) : IValidation
{
public string Id { get; private set; } = id;
public string EmployeeId { get; private set; } = employeeId;
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
public DateTime InstallationDate { get; private set; } = installationDate;
public double InstallationPrice { get; private set; } = installationPrice;
public double Sum { get; private set; } = sum;
public bool IsCanceled { get; private set; } = isCanceled;
public List<InstallationComponentDataModel> Components { get; private set; } = components;
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 (EmployeeId.IsEmpty())
throw new ValidationException("Field EmployeeId is empty");
if (!EmployeeId.IsGuid())
throw new ValidationException("The value in the field EmployeeId is not a unique identifier");
if (InstallationPrice <= 0)
throw new ValidationException("Field InstallationPrice is less than or equal to 0");
if (Sum <= 0)
throw new ValidationException("Field Sum is less than or equal to 0");
if ((Components?.Count ?? 0) == 0)
throw new ValidationException("The installation must include components");
}
}

View File

@ -1,46 +0,0 @@
using TheCyclopsContracts.Enums;
using TheCyclopsContracts.Exceptions;
using TheCyclopsContracts.Extensions;
namespace TheCyclopsContracts.DataModels;
public class PostDataModel(string id, string PostId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate)
{
public string Id { get; private set; } = id;
public string PostId { get; private set; } = PostId;
public string PostName { get; private set; } = postName;
public PostType PostType { get; private set; } = postType;
public double Salary { get; private set; } = salary;
public bool IsActual { get; private set; } = isActual;
public DateTime ChangeDate { get; private set; } = changeDate;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (PostId.IsEmpty())
throw new ValidationException("Field PostId is empty");
if (!PostId.IsGuid())
throw new ValidationException("The value in the field PostId is not a unique identifier");
if (PostName.IsEmpty())
throw new ValidationException("Field PostName is empty");
if (PostType == PostType.None)
throw new ValidationException("Field PostType is empty");
if (Salary <= 0)
throw new ValidationException("Field Salary is empty");
}
}

View File

@ -1,26 +0,0 @@
using TheCyclopsContracts.Exceptions;
using TheCyclopsContracts.Extensions;
using TheCyclopsContracts.Infrastructure;
namespace TheCyclopsContracts.DataModels;
public class SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary) : IValidation
{
public string EmployeeId { get; private set; } = employeeId;
public DateTime SalaryDate { get; private set; } = salaryDate;
public double Salary { get; private set; } = employeeSalary;
public void Validate()
{
if (EmployeeId.IsEmpty())
throw new ValidationException("Field EmployeeId is empty");
if (!EmployeeId.IsGuid())
throw new ValidationException("The value in the field EmployeeId is not a unique identifier");
if (Salary <= 0)
throw new ValidationException("Field Salary is less than or equal to 0");
}
}

View File

@ -1,11 +0,0 @@
namespace TheCyclopsContracts.Enums;
public enum ComponentType
{
None = 0,
Camera = 1,
Sensor = 2,
ContropPanel = 3,
Cable = 4,
Other = 5
}

View File

@ -1,10 +0,0 @@
namespace TheCyclopsContracts.Enums;
public enum PostType
{
None = 0,
Designer = 1,
Installer = 2,
Seller = 3,
Administrator = 4
}

View File

@ -1,5 +0,0 @@
namespace TheCyclopsContracts.Exceptions;
public class ValidationException(string message) : Exception(message)
{
}

View File

@ -1,14 +0,0 @@
namespace TheCyclopsContracts.Extensions;
public static class StringExtensions
{
public static bool IsEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}
public static bool IsGuid(this string str)
{
return Guid.TryParse(str, out _);
}
}

View File

@ -1,6 +0,0 @@
namespace TheCyclopsContracts.Infrastructure;
public interface IValidation
{
void Validate();
}

View File

@ -5,8 +5,6 @@ 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
@ -17,10 +15,6 @@ 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

View File

@ -1,80 +0,0 @@
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<ValidationException>());
component = CreateDataModel(string.Empty, "name", ComponentType.Other, 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var component = CreateDataModel("id", "name", ComponentType.Other, 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductNameIsEmptyTest()
{
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Other, 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Other, 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ComponentTypeIsNoneTest()
{
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.None, 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Other, 0, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Other, -10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[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);
}

View File

@ -1,130 +0,0 @@
using TheCyclopsContracts.DataModels;
using TheCyclopsContracts.Exceptions;
namespace TheCyclopsTests.DataModelsTests;
[TestFixture]
internal class EmployeeDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var employee = CreateDataModel(null, "fio", "mail@mail.com", Guid.NewGuid().ToString(),
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
employee = CreateDataModel(null, "fio", "mail@mail.com", Guid.NewGuid().ToString(),
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var employee = CreateDataModel("id", "fio", "mail@mail.com", Guid.NewGuid().ToString(),
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void FIOIsNullOrEmptyTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), null, "mail@mail.com", Guid.NewGuid().ToString(),
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "mail@mail.com", Guid.NewGuid().ToString(),
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmailIsNullOrEmptyTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, Guid.NewGuid().ToString(),
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, Guid.NewGuid().ToString(),
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmailIsIncorrectTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail", Guid.NewGuid().ToString(),
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullOrEmptyTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", null,
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", string.Empty,
DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com",
"postId", DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BirthDateIsNotCorrectTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BirthDateAndEmploymentDateIsNotCorrectTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var employeeId = Guid.NewGuid().ToString();
var fio = "fio";
var email = "mail@mail.com";
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, email, 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.Email, Is.EqualTo(email));
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? email,
string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
new(id, fio, email, postId, birthDate, employmentDate, isDeleted);
}

View File

@ -1,73 +0,0 @@
using TheCyclopsContracts.DataModels;
using TheCyclopsContracts.Exceptions;
namespace TheCyclopsTests.DataModelsTests;
[TestFixture]
internal class InstallationComponentDataModelTests
{
[Test]
public void InstallationIdIsNullOrEmptyTest()
{
var installationComponent = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
Assert.That(() => installationComponent.Validate(), Throws.TypeOf<ValidationException>());
installationComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => installationComponent.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void InstallationIdIsNotGuidTest()
{
var installationComponent = CreateDataModel("installationId", Guid.NewGuid().ToString(), 10);
Assert.That(() => installationComponent.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ComponentIdIsNullOrEmptyTest()
{
var installationComponent = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
Assert.That(() => installationComponent.Validate(), Throws.TypeOf<ValidationException>());
installationComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => installationComponent.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ComponentIdIsNotGuidTest()
{
var installationComponent = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 10);
Assert.That(() => installationComponent.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
var installationComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => installationComponent.Validate(), Throws.TypeOf<ValidationException>());
installationComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
Assert.That(() => installationComponent.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var installationId = Guid.NewGuid().ToString();
var componentId = Guid.NewGuid().ToString();
var count = 10;
var installationComponent = CreateDataModel(installationId, componentId, count);
Assert.That(() => installationComponent.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(installationComponent.InstallationId, Is.EqualTo(installationId));
Assert.That(installationComponent.ComponentId, Is.EqualTo(componentId));
Assert.That(installationComponent.Count, Is.EqualTo(count));
});
}
private static InstallationComponentDataModel CreateDataModel(string? installationId, string? componentId, int count) =>
new(installationId, componentId, count);
}

View File

@ -1,116 +0,0 @@
using TheCyclopsContracts.DataModels;
using TheCyclopsContracts.Exceptions;
namespace TheCyclopsTests.DataModelsTests;
[TestFixture]
internal class InstallationDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var installation = CreateDataModel(null, Guid.NewGuid().ToString(),
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
installation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var installation = CreateDataModel("id", Guid.NewGuid().ToString(),
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmployeeIdIsNullOrEmptyTest()
{
var installation = CreateDataModel(Guid.NewGuid().ToString(), null,
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmployeeIdIsNotGuidTest()
{
var installation = CreateDataModel(Guid.NewGuid().ToString(), "employeeId",
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void InstallationPriceIsLessOrZeroTest()
{
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
DateTime.UtcNow, 0, 20, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
DateTime.UtcNow, -10, 20, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SumIsLessOrZeroTest()
{
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
DateTime.UtcNow, 10, 0, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
DateTime.UtcNow, 10, -20, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductsIsNullOrEmptyTest()
{
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
DateTime.UtcNow, 10, 20, false, null);
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
DateTime.UtcNow, 10, 20, false, []);
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var installationId = Guid.NewGuid().ToString();
var employeeId = Guid.NewGuid().ToString();
var installationPrice = 10;
var sum = 20;
var isCanceled = true;
var components = CreateSubDataModel();
var installation = CreateDataModel(installationId, employeeId,
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.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,
DateTime installationDate, double installationPrice, double sum, bool isCanceled,
List<InstallationComponentDataModel> components) =>
new(id, employeeId, installationDate, installationPrice, sum, isCanceled, components);
private static List<InstallationComponentDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

View File

@ -1,110 +0,0 @@
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<ValidationException>());
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "post",
PostType.Designer, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "post",
PostType.Designer, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "post",
PostType.Designer, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "post",
PostType.Designer, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "post",
PostType.Designer, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[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<ValidationException>());
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty,
PostType.Designer, 10, true, DateTime.UtcNow);
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
}
[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<ValidationException>());
}
[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<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post",
PostType.Designer, -10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[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);
}

View File

@ -1,56 +0,0 @@
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<ValidationException>());
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
var salary = CreateDataModel("employeeId", DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[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);
}

View File

@ -1,27 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TheCyclopsContracts\TheCyclopsContracts.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>