Compare commits

...

11 Commits

Author SHA1 Message Date
I1nur
ecce2c8cb9 checktyle: delete unneeded imports, add TestFixture 2025-02-10 23:23:46 +04:00
I1nur
df22a608d2 feauture: add warehouse and tests 2025-02-10 22:34:31 +04:00
I1nur
8634db837c fix: merge Task_1 2025-02-10 21:50:27 +04:00
I1nur
d959acdf1c fix: remove duplicate folder 2025-02-10 21:18:32 +04:00
I1nur
f4c2fdb4a6 fix: remove unnecessary folder 2025-02-10 20:49:43 +04:00
I1nur
351975ba2b fix: change folders 2025-02-10 20:47:17 +04:00
I1nur
e1f0e39b29 checkstyle: fix naming and spaces 2025-02-10 20:25:06 +04:00
I1nur
f49b15c9c4 feauture: add warehouse 2025-02-08 06:23:36 +04:00
I1nur
9c130e1eb4 style: fix programType cloud services
style: fix programType cloudServs
2025-02-07 19:57:41 +04:00
I1nur
d5ce733893 feature: add tests 2025-02-04 07:10:08 +04:00
I1nur
0d2982c770 feature: add models 2025-02-02 21:25:13 +04:00
34 changed files with 1610 additions and 2 deletions

2
.gitignore vendored
View File

@ -397,4 +397,4 @@ FodyWeavers.xsd
# JetBrains Rider
*.sln.iml
*/*.idea

View File

@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35514.174 d17.12
VisualStudioVersion = 17.12.35514.174
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationContracts", "SoftwareInstallationContracts\SoftwareInstallationContracts.csproj", "{B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationTests", "..\SoftwareInstallationTests\SoftwareInstallationTests.csproj", "{7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}.Release|Any CPU.Build.0 = Release|Any CPU
{7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,36 @@
using System.Text.RegularExpressions;
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class ClientDataModel(string id, string fio, string phoneNumber) : IValidation
{
public string Id { get; private set; } = id;
public string FIO { get; private set; } = fio;
public string PhoneNumber { get; private set; } = phoneNumber;
public void Validate()
{
if (Id.isEmpty())
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
if (FIO.isEmpty())
throw new ValidationFieldException("Field FIO is empty");
if (!Regex.IsMatch(FIO, @"^[A-ZА-ЯЁ][a-zа-яё]+(?:-[A-ZА-ЯЁ][a-zа-яё]+)?\s[A-ZА-ЯЁ][a-zа-яё]+(?:-[A-ZА-ЯЁ][a-zа-яё]+)?\s[A-ZА-ЯЁ][a-zа-яё]+(?:-[A-ZА-ЯЁ][a-zа-яё]+)?$"))
throw new ValidationFieldException("Field FIO is not a valid full name.");
if (PhoneNumber.isEmpty())
throw new ValidationFieldException("Field PhoneNumber is empty");
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
throw new ValidationFieldException("Field PhoneNumber is not a phone number");
}
}

View File

@ -0,0 +1,29 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class CompanyDataModel(string id, string companyName, string prevCompanyName,
string prevPrevCompanyName) : IValidation
{
public string Id { get; private set; } = id;
public string CompanyName { get; private set; } = companyName;
public string? PrevCompanyName { get; private set; } = prevCompanyName;
public string? PrevPrevCompanyName { get; private set; } = prevPrevCompanyName;
public void Validate()
{
if (Id.isEmpty())
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
if (CompanyName.isEmpty())
throw new ValidationFieldException("Field CompanyName is empty");
}
}

View File

@ -0,0 +1,47 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class InstallationDataModel(string id, string workerId, string clientId,
double sum, bool isCancel, List<InstallationSoftwareDataModel> programs) : IValidation
{
public string Id { get; private set; } = id;
public string WorkerId { get; private set; } = workerId;
public string? ClientId { get; private set; } = clientId;
public DateTime InstallationDate { get; private set; } = DateTime.UtcNow;
public double Sum { get; private set; } = sum;
public bool IsCancel { get; private set; } = isCancel;
public List<InstallationSoftwareDataModel> Programs { get; private set; } = programs;
public void Validate()
{
if (Id.isEmpty())
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
if (WorkerId.isEmpty())
throw new ValidationFieldException("Field WorkerId is empty");
if (!WorkerId.isGuid())
throw new ValidationFieldException("The value in the field WorkerId is not a unique identifier");
if (!ClientId?.isGuid() ?? !ClientId?.isEmpty() ?? false)
throw new ValidationFieldException("The value in the field ClientId is not a unique identifier");
if (Sum <= 0)
throw new ValidationFieldException("Field Sum is less than or wqual to 0");
if ((Programs?.Count() ?? 0) == 0)
throw new ValidationFieldException("The sale must include programs");
}
}

View File

@ -0,0 +1,32 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class InstallationSoftwareDataModel(string installationId, string programId, int count) : IValidation
{
public string ProgramId { get; private set; } = programId;
public string InstallationId { get; private set; } = installationId;
public int Count { get; private set; } = count;
public void Validate()
{
if (ProgramId.isEmpty())
throw new ValidationFieldException("Field ProgramId is empty");
if (!ProgramId.isGuid())
throw new ValidationFieldException("The value in the field ProgramId is not a unique identifier");
if (InstallationId.isEmpty())
throw new ValidationFieldException("Field InstallationId is empty");
if (!InstallationId.isGuid())
throw new ValidationFieldException("The value in the field InstallationId is not a unique identifier");
if (Count <= 0)
throw new ValidationFieldException("Field Count is less than or equal to 0");
}
}

View File

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

View File

@ -0,0 +1,26 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
{
public string WorkerId { get; private set; } = workerId;
public DateTime SalaryDate { get; private set; } = salaryDate;
public double Salary { get; private set; } = workerSalary;
public void Validate()
{
if (WorkerId.isEmpty())
throw new ValidationFieldException("Field WorkerId is empty");
if (!WorkerId.isGuid())
throw new ValidationFieldException("The value in the field WorkerId is not a unique identifier");
if (Salary <= 0)
throw new ValidationFieldException("Field Salary is less than or equal to 0");
}
}

View File

@ -0,0 +1,51 @@
using SoftwareInstallationContracts.Enums;
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType,
string companyId, double price, bool isDeleted, List<SoftwareWarehouseDataModel> warehouses) : IValidation
{
public string Id { get; private set; } = id;
public string SoftwareName { get; private set; } = softwareName;
public SoftwareType SoftwareType { get; private set; } = softwareType;
public string CompanyId { get; private set; } = companyId;
public double Price { get; private set; } = price;
public bool IsDeleted { get; private set; } = isDeleted;
public List<SoftwareWarehouseDataModel> Warehouses { get; private set; } = warehouses;
public void Validate()
{
if (Id.isEmpty())
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
if (SoftwareName.isEmpty())
throw new ValidationFieldException("Field SoftwareName is empty");
if (SoftwareType == SoftwareType.None)
throw new ValidationFieldException("Field SoftwareType is empty");
if (CompanyId.isEmpty())
throw new ValidationFieldException("Field CompanyId is empty");
if (!CompanyId.isGuid())
throw new ValidationFieldException("The value in the field CompanyId is not a unique identifier");
if (Price <= 0)
throw new ValidationFieldException("Field Price is less than or equal to 0");
if ((Warehouses?.Count() ?? 0) == 0)
throw new ValidationFieldException("The software must include warehouses");
}
}

View File

@ -0,0 +1,26 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IValidation
{
public string SoftwareId { get; private set; } = softwareId;
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public void Validate()
{
if (SoftwareId.isEmpty())
throw new ValidationFieldException("Field SoftwareId is empty");
if (!SoftwareId.isGuid())
throw new ValidationFieldException("The value in the field SoftwareId is not a unique identifier");
if (OldPrice <= 0)
throw new ValidationFieldException("Field OldPrice is less than or equal to 0");
}
}

View File

@ -0,0 +1,41 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class SoftwareSupplyDataModel(string id, int count, string softwareId, string supplyId) : IValidation
{
public string Id { get; private set; } = id;
public int Count { get; private set; } = count;
public string SoftwareId { get; private set; } = softwareId;
public string SupplyId { get; private set; } = supplyId;
public void Validate()
{
if (Id.isEmpty())
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
if (SoftwareId.isEmpty())
throw new ValidationFieldException("Field SoftwareId is empty");
if (!SoftwareId.isGuid())
throw new ValidationFieldException("The value in the field SoftwareId is not a unique identifier");
if (SupplyId.isEmpty())
throw new ValidationFieldException("Field SupplyId is empty");
if (!SupplyId.isGuid())
throw new ValidationFieldException("The value in the field SupplyId is not a unique identifier");
if (Count <= 0)
throw new ValidationFieldException("Field Count is less than or equal to 0");
}
}

View File

@ -0,0 +1,40 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class SoftwareWarehouseDataModel(string softwareId, string warehouseId, int minimalCount, int currentCount) : IValidation
{
public string SoftwareId { get; private set; } = softwareId;
public string WarehouseId { get; private set; } = warehouseId;
public int MinimalCount { get; private set; } = minimalCount;
public int CurrentCount { get; private set; } = currentCount;
public void Validate()
{
if (SoftwareId.isEmpty())
throw new ValidationFieldException("Field SoftwareId is empty");
if (!SoftwareId.isGuid())
throw new ValidationFieldException("The value in the field SoftwareId is not a unique identifier");
if (WarehouseId.isEmpty())
throw new ValidationFieldException("Field WarehouseId is empty");
if (!WarehouseId.isGuid())
throw new ValidationFieldException("The value in the field WarehouseId is not a unique identifier");
if (CurrentCount <= 0)
throw new ValidationFieldException("Field CurrentCount is less than or equal to 0");
if (MinimalCount <= 0)
throw new ValidationFieldException("Field MinimalCount is less than or equal to 0");
if (CurrentCount < MinimalCount)
throw new ValidationFieldException("Field CurrentCount is less than MinimalCount");
}
}

View File

@ -0,0 +1,39 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class SupplyDataModel(string id, string companyId, DateTime supplyDate, double totalCost, List<SoftwareSupplyDataModel> softwares) : IValidation
{
public string Id { get; private set; } = id;
public string CompanyId { get; private set; } = companyId;
public DateTime SupplyDate { get; private set; } = supplyDate;
public List<SoftwareSupplyDataModel> Softwares { get; private set; } = softwares;
public double TotalCost { get; private set; } = totalCost;
public void Validate()
{
if (Id.isEmpty())
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
if (CompanyId.isEmpty())
throw new ValidationFieldException("Field CompanyId is empty");
if (!CompanyId.isGuid())
throw new ValidationFieldException("The value in the field CompanyId is not a unique identifier");
if (TotalCost <= 0)
throw new ValidationFieldException("Field TotalCost is less than or equal to 0");
if ((Softwares?.Count ?? 0) == 0)
throw new ValidationFieldException("The supply must include softwares");
}
}

View File

@ -0,0 +1,26 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class WarehouseDataModel(string id, int totalCount, DateTime date) : IValidation
{
public string Id { get; private set; } = id;
public int TotalCount { get; private set; } = totalCount;
public DateTime ChangeDate { get; private set; } = date;
public void Validate()
{
if (Id.isEmpty())
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
if (TotalCount <= 0)
throw new ValidationFieldException("Field TotalCount is less than or equal to 0");
}
}

View File

@ -0,0 +1,50 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
namespace SoftwareInstallationContracts.DataModels;
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate,
bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string FIO { get; private set; } = fio;
public string PostId { get; private set; } = postId;
public DateTime BirthDate { get; private set; } = birthDate;
public DateTime EmploymentDate { get; private set; } = employmentDate;
public bool IsDeleted { get; private set; } = isDeleted;
public void Validate()
{
if (Id.isEmpty())
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
if (FIO.isEmpty())
throw new ValidationFieldException("Field FIO is empty");
if (PostId.isEmpty())
throw new ValidationFieldException("Field PostId is empty");
if (!PostId.isGuid())
throw new ValidationFieldException("The value in the field PostId is not a unique identifier");
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
throw new ValidationFieldException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()}");
if (EmploymentDate.Date < BirthDate.Date)
throw new ValidationFieldException("The date of employment cannot be less than the date of birth");
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
throw new ValidationFieldException($"Minors cannot be hired " +
$"(EmploymentDate - {EmploymentDate.ToShortDateString()}," +
$" BirthDate - {BirthDate.ToShortDateString()}");
}
}

View File

@ -0,0 +1,9 @@
namespace SoftwareInstallationContracts.Enums;
public enum PostType
{
None = 0,
Supervisor = 1,
Master = 2,
Stuff = 3
}

View File

@ -0,0 +1,10 @@
namespace SoftwareInstallationContracts.Enums;
public enum SoftwareType
{
None = 0,
SystemSoftware = 1,
ApplicationSoftware = 2,
UtilitySoftware = 3,
EnterpriseSoftware = 4
}

View File

@ -0,0 +1,5 @@
namespace SoftwareInstallationContracts.Exceptions;
public class ValidationFieldException(String message) : Exception(message)
{
}

View File

@ -0,0 +1,14 @@
namespace SoftwareInstallationContracts.Extensions;
public static class StringExceptions
{
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

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

View File

@ -0,0 +1,78 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class ClientDataModelTests
{
private ClientDataModel client;
[Test]
public void IdIsNullOrEmptyTest()
{
client = CreateDataModel(null, "Fio Fio Fio", "+7-777-777-77-77");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
client = CreateDataModel(string.Empty, "Fio Fio Fio", "+7-777-777-77-77");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
client = CreateDataModel("id", "Fio Fio Fio", "+7-777-777-77-77");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void FIOIsNullOrEmptyTest()
{
client = CreateDataModel(Guid.NewGuid().ToString(), null, "+7-777-777-77-77");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "+7-777-777-77-77");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void FIOIsIncorrectTest()
{
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "+7-777-777-77-77");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PhoneNumberIsNullOrEmptyTest()
{
client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", null);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", string.Empty);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PhoneNumberIsIncorrectTest()
{
client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", "777");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string phoneNumber = "+7-777-777-77-77";
string fio = "Vasiliy Vasiliev Vasilievich";
string id = Guid.NewGuid().ToString();
client = CreateDataModel(id, fio, phoneNumber);
Assert.That(() => client.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(client.Id, Is.EqualTo(id));
Assert.That(client.FIO, Is.EqualTo(fio));
Assert.That(client.PhoneNumber, Is.EqualTo(phoneNumber));
});
}
private static ClientDataModel CreateDataModel(string? id, string? fio, string? phoneNumber) =>
new(id, fio, phoneNumber);
}

View File

@ -0,0 +1,56 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class CompanyDataModelTests
{
private CompanyDataModel company;
[Test]
public void IdIsNullEmptyTest()
{
company = CreateDataModel(null, "name");
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
company = CreateDataModel(string.Empty, "name");
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
company = CreateDataModel("id", "name");
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void companyNameIsNullOrEmptyTest()
{
company = CreateDataModel(Guid.NewGuid().ToString(), null);
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
company = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string companyId = Guid.NewGuid().ToString();
string companyName = "name";
string prevcompanyName = "prevcompanyName";
string prevPrevcompanyName = "prevPrevcompanyName";
company = CreateDataModel(companyId, companyName, prevcompanyName, prevPrevcompanyName);
Assert.That(() => company.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(company.Id, Is.EqualTo(companyId));
Assert.That(company.CompanyName, Is.EqualTo(companyName));
Assert.That(company.PrevCompanyName, Is.EqualTo(prevcompanyName));
Assert.That(company.PrevPrevCompanyName, Is.EqualTo(prevPrevcompanyName));
});
}
private static CompanyDataModel CreateDataModel(string? id, string? companyName, string? prevcompanyName = null,
string? prevPrevcompanyName = null) => new(id, companyName, prevcompanyName, prevPrevcompanyName);
}

View File

@ -0,0 +1,94 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class InstallationDataModelTests
{
private InstallationDataModel installation;
[Test]
public void IdIsNullOrEmptyTest()
{
installation = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
installation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
installation = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void WorkerIdIsNullOrEmptyTest()
{
installation = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
installation = CreateDataModel(Guid.NewGuid().ToString(), "workerId", Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void ClientIdIsNotGuidTest()
{
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "clientId", 10, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SumIsLessOrZeroTest()
{
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, false, CreateSubDataModel());
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwaresIsNullOrEmptyTest()
{
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, null);
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, []);
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string installationId = Guid.NewGuid().ToString();
string workerId = Guid.NewGuid().ToString();
string clientId = Guid.NewGuid().ToString();
double sum = 10;
bool isCancel = true;
List<InstallationSoftwareDataModel> softwares = CreateSubDataModel();
installation = CreateDataModel(installationId, workerId, clientId, sum, isCancel, softwares);
Assert.That(() => installation.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(installation.Id, Is.EqualTo(installationId));
Assert.That(installation.WorkerId, Is.EqualTo(workerId));
Assert.That(installation.ClientId, Is.EqualTo(clientId));
Assert.That(installation.Sum, Is.EqualTo(sum));
Assert.That(installation.IsCancel, Is.EqualTo(isCancel));
Assert.That(installation.Programs, Is.EquivalentTo(softwares));
});
}
private static InstallationDataModel CreateDataModel(string? id, string? workerId, string? clientId, double sum, bool isCancel, List<InstallationSoftwareDataModel>? softwares) =>
new(id, workerId, clientId, sum, isCancel, softwares);
private static List<InstallationSoftwareDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

View File

@ -0,0 +1,70 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class InstallationSoftwareDataModelTests
{
private InstallationSoftwareDataModel installSoftware;
[Test]
public void InstallIdIsNullOrEmptyTest()
{
installSoftware = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
installSoftware = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void InstallIdIsNotGuidTest()
{
installSoftware = CreateDataModel("installId", Guid.NewGuid().ToString(), 10);
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwareIdIsNullOrEmptyTest()
{
installSoftware = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
installSoftware = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwareIdIsNotGuidTest()
{
installSoftware = CreateDataModel(Guid.NewGuid().ToString(), "softwareId", 10);
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
installSoftware = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
installSoftware = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string installId = Guid.NewGuid().ToString();
string softwareId = Guid.NewGuid().ToString();
int count = 10;
installSoftware = CreateDataModel(installId, softwareId, count);
Assert.That(() => installSoftware.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(installSoftware.InstallationId, Is.EqualTo(installId));
Assert.That(installSoftware.ProgramId, Is.EqualTo(softwareId));
Assert.That(installSoftware.Count, Is.EqualTo(count));
});
}
private static InstallationSoftwareDataModel CreateDataModel(string? installId, string? softwareId, int count) =>
new(installId, softwareId, count);
}

View File

@ -0,0 +1,96 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Enums;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class PostDataModelTests
{
private PostDataModel post;
[Test]
public void idIsNotNullOrEmpty()
{
post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostIdIsNullEmptyTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SalaryIsLessOrZeroTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Stuff, 0, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Stuff, -10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostTypeIsNoneTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostNameIsEmptyTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string postId = Guid.NewGuid().ToString();
string postPostId = Guid.NewGuid().ToString();
string postName = "name";
PostType postType = PostType.Stuff;
double salary = 10;
bool isActual = false;
DateTime changeDate = DateTime.UtcNow.AddDays(-1);
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

@ -0,0 +1,54 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class SalaryDataModelTests
{
private SalaryDataModel salary;
[Test]
public void WorkerIdIsEmptyTest()
{
salary = CreateDataModel(null, DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationFieldException>());
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
salary = CreateDataModel("workerId", DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationFieldException>());
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string workerId = Guid.NewGuid().ToString();
DateTime salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
double workerSalary = 10;
SalaryDataModel salary = CreateDataModel(workerId, salaryDate, workerSalary);
Assert.That(() => salary.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(salary.WorkerId, Is.EqualTo(workerId));
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
Assert.That(salary.Salary, Is.EqualTo(workerSalary));
});
}
private static SalaryDataModel CreateDataModel(string? workerId, DateTime date,
double workerSalary) => new(workerId, date, workerSalary);
}

View File

@ -0,0 +1,121 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Enums;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class SoftwareDataModelTests
{
private SoftwareDataModel software;
[Test]
public void IdIsNullOrEmptyTest()
{
software = CreateDataModel(null, "name", SoftwareType.ApplicationSoftware,
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
software = CreateDataModel(string.Empty, "name", SoftwareType.ApplicationSoftware,
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
software = CreateDataModel("id", "name", SoftwareType.ApplicationSoftware,
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwareNameIsEmptyTest()
{
software = CreateDataModel(Guid.NewGuid().ToString(), null, SoftwareType.ApplicationSoftware,
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
software = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwareTypeIsNoneTest()
{
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.None,
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CompanyIdIsNullOrEmptyTest()
{
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
null, 10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
string.Empty, 10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CompanyIdIsNotGuidTest()
{
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
"companyId", 10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
Guid.NewGuid().ToString(), 0, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
Guid.NewGuid().ToString(), -10, false, CreateSubDataModel());
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwaresIsNullOrEmptyTest()
{
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false, null);
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false, []);
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string softwareId = Guid.NewGuid().ToString();
string softwareName = "name";
SoftwareType softwareType = SoftwareType.ApplicationSoftware;
string softwareCompanyId = Guid.NewGuid().ToString();
double softwarePrice = 10;
bool softwareIsDelete = false;
List<SoftwareWarehouseDataModel> warehouses = CreateSubDataModel();
software = CreateDataModel(softwareId, softwareName, softwareType, softwareCompanyId,
softwarePrice, softwareIsDelete, warehouses);
Assert.That(() => software.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(software.Id, Is.EqualTo(softwareId));
Assert.That(software.SoftwareName, Is.EqualTo(softwareName));
Assert.That(software.SoftwareType, Is.EqualTo(softwareType));
Assert.That(software.CompanyId, Is.EqualTo(softwareCompanyId));
Assert.That(software.Price, Is.EqualTo(softwarePrice));
Assert.That(software.IsDeleted, Is.EqualTo(softwareIsDelete));
});
}
private static SoftwareDataModel CreateDataModel(string? id, string? softwareName, SoftwareType softwareType,
string? companyId, double price, bool isDeleted, List<SoftwareWarehouseDataModel> warehouses) =>
new(id, softwareName, softwareType, companyId, price, isDeleted, warehouses);
private static List<SoftwareWarehouseDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 20)];
}

View File

@ -0,0 +1,55 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class SoftwareHistoryDataModelTests
{
private SoftwareHistoryDataModel programHistory;
[Test]
public void programHistoryIdIsNullOrEmptyTest()
{
programHistory = CreateDataModel(null, 10);
Assert.That(() => programHistory.Validate(), Throws.TypeOf<ValidationFieldException>());
programHistory = CreateDataModel(string.Empty, 10);
Assert.That(() => programHistory.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void programHistoryIdIsNotGuidTest()
{
programHistory = CreateDataModel("id", 10);
Assert.That(() => programHistory.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void OldPriceIsLessOrZeroTest()
{
programHistory = CreateDataModel(Guid.NewGuid().ToString(), 0);
Assert.That(() => programHistory.Validate(), Throws.TypeOf<ValidationFieldException>());
programHistory = CreateDataModel(Guid.NewGuid().ToString(), -10);
Assert.That(() => programHistory.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string programHistoryId = Guid.NewGuid().ToString();
double oldPrice = 10;
programHistory = CreateDataModel(programHistoryId, oldPrice);
Assert.That(() => programHistory.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(programHistory.SoftwareId, Is.EqualTo(programHistoryId));
Assert.That(programHistory.OldPrice, Is.EqualTo(oldPrice));
Assert.That(programHistory.ChangeDate, Is.LessThan(DateTime.UtcNow));
Assert.That(programHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
});
}
private static SoftwareHistoryDataModel CreateDataModel(string? programHistoryId, double oldPrice) =>
new(programHistoryId, oldPrice);
}

View File

@ -0,0 +1,88 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class SoftwareSupplyDataModelTests
{
private SoftwareSupplyDataModel softwareSupply;
[Test]
public void IdIsNullOrEmptyTest()
{
softwareSupply = CreateDataModel(null, 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
softwareSupply = CreateDataModel(string.Empty, 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
softwareSupply = CreateDataModel("id", 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwareIdIsNullOrEmptyTest()
{
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, null, Guid.NewGuid().ToString());
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, string.Empty, Guid.NewGuid().ToString());
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwareIdIsNotGuidTest()
{
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, "softwareId", Guid.NewGuid().ToString());
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SupplyIdIsNullOrEmptyTest()
{
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), null);
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), string.Empty);
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SupplyIdIsNotGuidTest()
{
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), "supplyId");
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 0, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), -10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string id = Guid.NewGuid().ToString();
string softwareId = Guid.NewGuid().ToString();
string supplyId = Guid.NewGuid().ToString();
int count = 10;
softwareSupply = CreateDataModel(id, count, softwareId, supplyId);
Assert.That(() => softwareSupply.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(softwareSupply.Id, Is.EqualTo(id));
Assert.That(softwareSupply.SoftwareId, Is.EqualTo(softwareId));
Assert.That(softwareSupply.SupplyId, Is.EqualTo(supplyId));
Assert.That(softwareSupply.Count, Is.EqualTo(count));
});
}
private static SoftwareSupplyDataModel CreateDataModel(string? id, int count, string? softwareId, string? supplyId)
=> new(id, count, softwareId, supplyId);
}

View File

@ -0,0 +1,90 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class SoftwareWarehouseDataModelTests
{
private SoftwareWarehouseDataModel softwareWarehouse;
[Test]
public void SoftwareIdIsNullOrEmptyTest()
{
softwareWarehouse = CreateDataModel(null, Guid.NewGuid().ToString(), 10, 20);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
softwareWarehouse = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, 20);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwareIdIsNotGuidTest()
{
softwareWarehouse = CreateDataModel("softwareId", Guid.NewGuid().ToString(), 10, 20);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void WarehouseIdIsNullOrEmptyTest()
{
softwareWarehouse = CreateDataModel(Guid.NewGuid().ToString(), null, 10, 20);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
softwareWarehouse = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10, 20);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void WarehouseIdIsNotGuidTest()
{
softwareWarehouse = CreateDataModel(Guid.NewGuid().ToString(), "warehouseId", 10, 20);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void MinimalCountIsLessOrZeroTest()
{
softwareWarehouse = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, 20);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
softwareWarehouse = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, 20);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CurrentCountIsLessOrZeroTest()
{
softwareWarehouse = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 0);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
softwareWarehouse = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, -10);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CurrentCountIsLessThanMinimal()
{
softwareWarehouse = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 9);
Assert.That(() => softwareWarehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string softwareId = Guid.NewGuid().ToString();
string warehouseId = Guid.NewGuid().ToString();
int minimalCount = 10;
int currentCount = 20;
softwareWarehouse = CreateDataModel(softwareId, warehouseId, minimalCount, currentCount);
Assert.That(() => softwareWarehouse.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(softwareWarehouse.SoftwareId, Is.EqualTo(softwareId));
Assert.That(softwareWarehouse.WarehouseId, Is.EqualTo(warehouseId));
Assert.That(softwareWarehouse.MinimalCount, Is.EqualTo(minimalCount));
Assert.That(softwareWarehouse.CurrentCount, Is.EqualTo(currentCount));
});
}
private static SoftwareWarehouseDataModel CreateDataModel(string? softwareId, string? warehouseId, int minimalCount, int currentCount) =>
new(softwareId, warehouseId, minimalCount, currentCount);
}

View File

@ -0,0 +1,88 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class SupplyDataModelTests
{
private SupplyDataModel supply;
[Test]
public void IdIsEmptyTest()
{
supply = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.UtcNow, 10, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.UtcNow, 10, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
supply = CreateDataModel("Id", Guid.NewGuid().ToString(), DateTime.UtcNow, 10, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CompanyIdIsEmptyTest()
{
supply = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.UtcNow, 10, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.UtcNow, 10, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CompanyIdIsNotGuidTest()
{
supply = CreateDataModel(Guid.NewGuid().ToString(), "companyId", DateTime.UtcNow, 10, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 0, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, -10, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SoftwaresIsNullOrEmptyTest()
{
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 10, null);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 10, []);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string supplyId = Guid.NewGuid().ToString();
string companyId = Guid.NewGuid().ToString();
double totalCost = 10;
DateTime dateTime = DateTime.UtcNow;
List<SoftwareSupplyDataModel> softwares = CreateSubDataModel();
supply = CreateDataModel(supplyId, companyId, dateTime, totalCost, softwares);
Assert.That(() => supply.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(supply.Id, Is.EqualTo(supplyId));
Assert.That(supply.CompanyId, Is.EqualTo(companyId));
Assert.That(supply.TotalCost, Is.EqualTo(totalCost));
Assert.That(supply.SupplyDate, Is.EqualTo(dateTime));
Assert.That(supply.Softwares, Is.EquivalentTo(softwares));
});
}
private static SupplyDataModel CreateDataModel(string? id, string? companyId, DateTime supplyDate, double totalCost, List<SoftwareSupplyDataModel> softwares)
=> new(id, companyId, supplyDate, totalCost, softwares);
private static List<SoftwareSupplyDataModel> CreateSubDataModel()
=> [new (Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString())];
}

View File

@ -0,0 +1,54 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class WarehouseDataModelTests
{
private WarehouseDataModel warehouse;
[Test]
public void IdIsEmptyTest()
{
warehouse = CreateDataModel(null, 10, DateTime.Now);
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
warehouse = CreateDataModel(string.Empty, 10, DateTime.Now);
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
warehouse = CreateDataModel("id", 10, DateTime.Now);
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void TotalCountIsLessOrZeroTest()
{
warehouse = CreateDataModel(Guid.NewGuid().ToString(), 0, DateTime.Now);
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
warehouse = CreateDataModel(Guid.NewGuid().ToString(), -10, DateTime.Now);
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string warehouseId = Guid.NewGuid().ToString();
int totalCount = 10;
DateTime date = DateTime.UtcNow;
warehouse = CreateDataModel(warehouseId, totalCount, date);
Assert.That(() => warehouse.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(warehouse.Id, Is.EqualTo(warehouseId));
Assert.That(warehouse.TotalCount, Is.EqualTo(totalCount));
Assert.That(warehouse.ChangeDate, Is.EqualTo(date));
});
}
private static WarehouseDataModel CreateDataModel(string? id, int totalCount, DateTime date)
=> new(id, totalCount, date);
}

View File

@ -0,0 +1,94 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class WorkerDataModelTests
{
private WorkerDataModel worker;
[Test]
public void IdIsNullOrEmptyTest()
{
worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
worker = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void FIOIsNullOrEmptyTest()
{
worker = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostIdIsNullOrEmptyTest()
{
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void BirthDateIsNotCorrectTest()
{
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void BirthDateAndEmploymentDateIsNotCorrectTest()
{
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string workerId = Guid.NewGuid().ToString();
string fio = "vasiliy vasilievich";
string postId = Guid.NewGuid().ToString();
DateTime birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
DateTime employmentDate = DateTime.Now;
bool isDelete = false;
worker = CreateDataModel(workerId, fio, postId, birthDate, employmentDate, isDelete);
Assert.That(() => worker.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(worker.Id, Is.EqualTo(workerId));
Assert.That(worker.FIO, Is.EqualTo(fio));
Assert.That(worker.PostId, Is.EqualTo(postId));
Assert.That(worker.BirthDate, Is.EqualTo(birthDate));
Assert.That(worker.EmploymentDate, Is.EqualTo(employmentDate));
Assert.That(worker.IsDeleted, Is.EqualTo(isDelete));
});
}
private static WorkerDataModel CreateDataModel(string? id, string? fio, string? postId, DateTime birthDate,
DateTime employmentDate, bool isDeleted) =>
new(id, fio, postId, birthDate, employmentDate, isDeleted);
}

View File

@ -0,0 +1,27 @@
<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.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SoftwareInstallationContracts\SoftwareInstallationContracts\SoftwareInstallationContracts.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>