Compare commits
9 Commits
main
...
Task1_Mode
Author | SHA1 | Date | |
---|---|---|---|
|
baa55fa66c | ||
|
6ec6b2dbf6 | ||
|
d959acdf1c | ||
|
f4c2fdb4a6 | ||
|
351975ba2b | ||
|
e1f0e39b29 | ||
|
9c130e1eb4 | ||
|
d5ce733893 | ||
|
0d2982c770 |
2
.gitignore
vendored
2
.gitignore
vendored
@ -397,4 +397,4 @@ FodyWeavers.xsd
|
|||||||
|
|
||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
*/*.idea
|
@ -1,10 +1,12 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.12.35514.174 d17.12
|
VisualStudioVersion = 17.12.35514.174
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationContracts", "SoftwareInstallationContracts\SoftwareInstallationContracts.csproj", "{B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationContracts", "SoftwareInstallationContracts\SoftwareInstallationContracts.csproj", "{B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SoftwareInstallationTests", "..\SoftwareInstallationTests\SoftwareInstallationTests.csproj", "{7D2F4C92-7578-46BA-96C3-3B1B7E2B5340}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
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}.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.ActiveCfg = Release|Any CPU
|
||||||
{B893E5AA-FB0B-4FFD-B918-87FB0CE540FC}.Release|Any CPU.Build.0 = 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
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
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) : 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 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");
|
||||||
|
}
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
@ -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()}");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace SoftwareInstallationContracts.Enums;
|
||||||
|
|
||||||
|
public enum PostType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Supervisor = 1,
|
||||||
|
Master = 2,
|
||||||
|
Stuff = 3
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
namespace SoftwareInstallationContracts.Enums;
|
||||||
|
|
||||||
|
public enum SoftwareType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
SystemSoftware = 1,
|
||||||
|
ApplicationSoftware = 2,
|
||||||
|
UtilitySoftware = 3,
|
||||||
|
EnterpriseSoftware = 4
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
namespace SoftwareInstallationContracts.Exceptions;
|
||||||
|
|
||||||
|
public class ValidationFieldException(String message) : Exception(message)
|
||||||
|
{
|
||||||
|
}
|
@ -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 _);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
namespace SoftwareInstallationContracts.Infrastucture;
|
||||||
|
|
||||||
|
public interface IValidation
|
||||||
|
{
|
||||||
|
void Validate();
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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)];
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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 salaryDate,
|
||||||
|
double workerSalary) => new(workerId, salaryDate, workerSalary);
|
||||||
|
}
|
@ -0,0 +1,94 @@
|
|||||||
|
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);
|
||||||
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
|
software = CreateDataModel(string.Empty, "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false);
|
||||||
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
software = CreateDataModel("id", "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false);
|
||||||
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SoftwareNameIsEmptyTest()
|
||||||
|
{
|
||||||
|
software = CreateDataModel(Guid.NewGuid().ToString(), null, SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false);
|
||||||
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
|
software = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false);
|
||||||
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SoftwareTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.None, Guid.NewGuid().ToString(), 10, false);
|
||||||
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CompanyIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, null, 10, false);
|
||||||
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, string.Empty, 10, false);
|
||||||
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CompanyIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, "companyId", 10, false);
|
||||||
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PriceIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 0, false);
|
||||||
|
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;
|
||||||
|
SoftwareDataModel software = CreateDataModel(softwareId, softwareName, softwareType, softwareCompanyId, softwarePrice, softwareIsDelete);
|
||||||
|
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) =>
|
||||||
|
new(id, softwareName, softwareType, companyId, price, isDeleted);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
@ -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);
|
||||||
|
}
|
27
SoftwareInstallationTests/SoftwareInstallationTests.csproj
Normal file
27
SoftwareInstallationTests/SoftwareInstallationTests.csproj
Normal 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>
|
Loading…
x
Reference in New Issue
Block a user