fix: merge Task_1
This commit is contained in:
commit
8634db837c
2
.gitignore
vendored
2
.gitignore
vendored
@ -397,4 +397,4 @@ FodyWeavers.xsd
|
|||||||
|
|
||||||
# JetBrains Rider
|
# JetBrains Rider
|
||||||
*.sln.iml
|
*.sln.iml
|
||||||
|
*/*.idea
|
@ -20,17 +20,17 @@ public class ClientDataModel(string id, string fio, string phoneNumber) : IValid
|
|||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
{
|
{
|
||||||
if (id.isEmpty())
|
if (Id.isEmpty())
|
||||||
throw new ValidationFieldException("Field Id is empty");
|
throw new ValidationFieldException("Field Id is empty");
|
||||||
|
|
||||||
if (!id.isGuid())
|
if (!Id.isGuid())
|
||||||
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
|
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
|
||||||
|
|
||||||
if (FIO.isEmpty())
|
if (FIO.isEmpty())
|
||||||
throw new ValidationFieldException("Field FIO is empty");
|
throw new ValidationFieldException("Field FIO is empty");
|
||||||
|
|
||||||
if (!Regex.IsMatch(FIO, @"^[A-ZА-ЯЁ][a-zа-яё]+ [A-ZА-ЯЁ][a-zа-яё]+ [A-ZA-ЯЁ][a-zа-яё]+$"))
|
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 fio");
|
throw new ValidationFieldException("Field FIO is not a valid full name.");
|
||||||
|
|
||||||
if (PhoneNumber.isEmpty())
|
if (PhoneNumber.isEmpty())
|
||||||
throw new ValidationFieldException("Field PhoneNumber is empty");
|
throw new ValidationFieldException("Field PhoneNumber is empty");
|
||||||
|
@ -11,12 +11,17 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SoftwareInstallationContracts.DataModels;
|
namespace SoftwareInstallationContracts.DataModels;
|
||||||
|
|
||||||
public class CompanyDataModel(string id, string companyName, string prevCompanyName, string prevPrevCompanyName) : IValidation
|
public class CompanyDataModel(string id, string companyName, string prevCompanyName,
|
||||||
|
string prevPrevCompanyName) : IValidation
|
||||||
{
|
{
|
||||||
public string Id { get; private set; } = id;
|
public string Id { get; private set; } = id;
|
||||||
|
|
||||||
public string CompanyName { get; private set; } = companyName;
|
public string CompanyName { get; private set; } = companyName;
|
||||||
|
|
||||||
public string? PrevCompanyName { get; private set; } = prevCompanyName;
|
public string? PrevCompanyName { get; private set; } = prevCompanyName;
|
||||||
|
|
||||||
public string? PrevPrevCompanyName { get; private set; } = prevPrevCompanyName;
|
public string? PrevPrevCompanyName { get; private set; } = prevPrevCompanyName;
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
{
|
{
|
||||||
if (Id.isEmpty())
|
if (Id.isEmpty())
|
||||||
|
@ -10,7 +10,8 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SoftwareInstallationContracts.DataModels;
|
namespace SoftwareInstallationContracts.DataModels;
|
||||||
|
|
||||||
public class InstallationDataModel(string id, string workerId, string clientId, double sum, bool isCancel, List<InstallationSoftwareDataModel> programs) : IValidation
|
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 Id { get; private set; } = id;
|
||||||
|
|
||||||
@ -18,7 +19,7 @@ public class InstallationDataModel(string id, string workerId, string clientId,
|
|||||||
|
|
||||||
public string? ClientId { get; private set; } = clientId;
|
public string? ClientId { get; private set; } = clientId;
|
||||||
|
|
||||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
public DateTime InstallationDate { get; private set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
public double Sum { get; private set; } = sum;
|
public double Sum { get; private set; } = sum;
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SoftwareInstallationContracts.DataModels;
|
namespace SoftwareInstallationContracts.DataModels;
|
||||||
|
|
||||||
public class InstallationSoftwareDataModel(string saleId, string programId, int count) : IValidation
|
public class InstallationSoftwareDataModel(string installationId, string programId, int count) : IValidation
|
||||||
{
|
{
|
||||||
public string ProgramId { get; private set; } = programId;
|
public string ProgramId { get; private set; } = programId;
|
||||||
|
|
||||||
public string SaleId { get; private set; } = saleId;
|
public string InstallationId { get; private set; } = installationId;
|
||||||
|
|
||||||
public int Count { get; private set; } = count;
|
public int Count { get; private set; } = count;
|
||||||
|
|
||||||
@ -25,11 +25,11 @@ public class InstallationSoftwareDataModel(string saleId, string programId, int
|
|||||||
if (!ProgramId.isGuid())
|
if (!ProgramId.isGuid())
|
||||||
throw new ValidationFieldException("The value in the field ProgramId is not a unique identifier");
|
throw new ValidationFieldException("The value in the field ProgramId is not a unique identifier");
|
||||||
|
|
||||||
if (SaleId.isEmpty())
|
if (InstallationId.isEmpty())
|
||||||
throw new ValidationFieldException("Field SaleId is empty");
|
throw new ValidationFieldException("Field InstallationId is empty");
|
||||||
|
|
||||||
if (!SaleId.isGuid())
|
if (!InstallationId.isGuid())
|
||||||
throw new ValidationFieldException("The value in the field SaleId is not a unique identifier");
|
throw new ValidationFieldException("The value in the field InstallationId is not a unique identifier");
|
||||||
|
|
||||||
if (Count <= 0)
|
if (Count <= 0)
|
||||||
throw new ValidationFieldException("Field Count is less than or equal to 0");
|
throw new ValidationFieldException("Field Count is less than or equal to 0");
|
||||||
|
@ -10,7 +10,8 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SoftwareInstallationContracts.DataModels;
|
namespace SoftwareInstallationContracts.DataModels;
|
||||||
|
|
||||||
public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
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 Id { get; private set; } = id;
|
||||||
|
@ -10,7 +10,8 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SoftwareInstallationContracts.DataModels;
|
namespace SoftwareInstallationContracts.DataModels;
|
||||||
|
|
||||||
public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string companyId, double price, bool isDeleted) : IValidation
|
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 Id { get; private set; } = id;
|
||||||
|
|
||||||
@ -33,10 +34,10 @@ public class SoftwareDataModel(string id, string softwareName, SoftwareType soft
|
|||||||
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
|
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
|
||||||
|
|
||||||
if (SoftwareName.isEmpty())
|
if (SoftwareName.isEmpty())
|
||||||
throw new ValidationFieldException("Field ProgramName is empty");
|
throw new ValidationFieldException("Field SoftwareName is empty");
|
||||||
|
|
||||||
if (SoftwareType == SoftwareType.None)
|
if (SoftwareType == SoftwareType.None)
|
||||||
throw new ValidationFieldException("Field ProgramType is empty");
|
throw new ValidationFieldException("Field SoftwareType is empty");
|
||||||
|
|
||||||
if (CompanyId.isEmpty())
|
if (CompanyId.isEmpty())
|
||||||
throw new ValidationFieldException("Field CompanyId is empty");
|
throw new ValidationFieldException("Field CompanyId is empty");
|
||||||
|
@ -21,10 +21,10 @@ public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IVal
|
|||||||
public void Validate()
|
public void Validate()
|
||||||
{
|
{
|
||||||
if (SoftwareId.isEmpty())
|
if (SoftwareId.isEmpty())
|
||||||
throw new ValidationFieldException("Field ProgramId is empty");
|
throw new ValidationFieldException("Field SoftwareId is empty");
|
||||||
|
|
||||||
if (!SoftwareId.isGuid())
|
if (!SoftwareId.isGuid())
|
||||||
throw new ValidationFieldException("The value in the field ProgramId is not a unique identifier");
|
throw new ValidationFieldException("The value in the field SoftwareId is not a unique identifier");
|
||||||
|
|
||||||
if (OldPrice <= 0)
|
if (OldPrice <= 0)
|
||||||
throw new ValidationFieldException("Field OldPrice is less than or equal to 0");
|
throw new ValidationFieldException("Field OldPrice is less than or equal to 0");
|
||||||
|
@ -10,13 +10,19 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace SoftwareInstallationContracts.DataModels;
|
namespace SoftwareInstallationContracts.DataModels;
|
||||||
|
|
||||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
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 Id { get; private set; } = id;
|
||||||
|
|
||||||
public string FIO { get; private set; } = fio;
|
public string FIO { get; private set; } = fio;
|
||||||
|
|
||||||
public string PostId { get; private set; } = postId;
|
public string PostId { get; private set; } = postId;
|
||||||
|
|
||||||
public DateTime BirthDate { get; private set; } = birthDate;
|
public DateTime BirthDate { get; private set; } = birthDate;
|
||||||
|
|
||||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||||
|
|
||||||
public bool IsDeleted { get; private set; } = isDeleted;
|
public bool IsDeleted { get; private set; } = isDeleted;
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
@ -43,6 +49,8 @@ public class WorkerDataModel(string id, string fio, string postId, DateTime birt
|
|||||||
throw new ValidationFieldException("The date of employment cannot be less than the date of birth");
|
throw new ValidationFieldException("The date of employment cannot be less than the date of birth");
|
||||||
|
|
||||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||||
throw new ValidationFieldException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()}");
|
throw new ValidationFieldException($"Minors cannot be hired " +
|
||||||
|
$"(EmploymentDate - {EmploymentDate.ToShortDateString()}," +
|
||||||
|
$" BirthDate - {BirthDate.ToShortDateString()}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,48 +16,48 @@ internal class ClientDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
client = CreateDataModel(null, "fio", "number");
|
client = CreateDataModel(null, "Fio Fio Fio", "+7-777-777-77-77");
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
client = CreateDataModel(string.Empty, "fio", "number");
|
client = CreateDataModel(string.Empty, "Fio Fio Fio", "+7-777-777-77-77");
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IdIsNotGuidTest()
|
public void IdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
client = CreateDataModel("id", "fio", "number");
|
client = CreateDataModel("id", "Fio Fio Fio", "+7-777-777-77-77");
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void FIOIsNullOrEmptyTest()
|
public void FIOIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
client = CreateDataModel(Guid.NewGuid().ToString(), null, "number");
|
client = CreateDataModel(Guid.NewGuid().ToString(), null, "+7-777-777-77-77");
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number");
|
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "+7-777-777-77-77");
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void FIOIsIncorrectTest()
|
public void FIOIsIncorrectTest()
|
||||||
{
|
{
|
||||||
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "number");
|
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "+7-777-777-77-77");
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void PhoneNumberIsNullOrEmptyTest()
|
public void PhoneNumberIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", null);
|
client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", null);
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty);
|
client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", string.Empty);
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void PhoneNumberIsIncorrectTest()
|
public void PhoneNumberIsIncorrectTest()
|
||||||
{
|
{
|
||||||
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777");
|
client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", "777");
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ internal class ClientDataModelTests
|
|||||||
public void AllFieldsIsCorrectTest()
|
public void AllFieldsIsCorrectTest()
|
||||||
{
|
{
|
||||||
string phoneNumber = "+7-777-777-77-77";
|
string phoneNumber = "+7-777-777-77-77";
|
||||||
string fio = "Василий Васильевич Васильев";
|
string fio = "Vasiliy Vasiliev Vasilievich";
|
||||||
string id = Guid.NewGuid().ToString();
|
string id = Guid.NewGuid().ToString();
|
||||||
client = CreateDataModel(id, fio, phoneNumber);
|
client = CreateDataModel(id, fio, phoneNumber);
|
||||||
Assert.That(() => client.Validate(), Throws.Nothing);
|
Assert.That(() => client.Validate(), Throws.Nothing);
|
@ -56,6 +56,6 @@ internal class CompanyDataModelTests
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CompanyDataModel CreateDataModel(string? id, string? companyName, string? prevcompanyName = null, string? prevPrevcompanyName = null) =>
|
private static CompanyDataModel CreateDataModel(string? id, string? companyName, string? prevcompanyName = null,
|
||||||
new(id, companyName, prevcompanyName, prevPrevcompanyName);
|
string? prevPrevcompanyName = null) => new(id, companyName, prevcompanyName, prevPrevcompanyName);
|
||||||
}
|
}
|
@ -64,7 +64,7 @@ internal class InstallationSoftwareDataModelTests
|
|||||||
Assert.That(() => installSoftware.Validate(), Throws.Nothing);
|
Assert.That(() => installSoftware.Validate(), Throws.Nothing);
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
{
|
{
|
||||||
Assert.That(installSoftware.SaleId, Is.EqualTo(installId));
|
Assert.That(installSoftware.InstallationId, Is.EqualTo(installId));
|
||||||
Assert.That(installSoftware.ProgramId, Is.EqualTo(softwareId));
|
Assert.That(installSoftware.ProgramId, Is.EqualTo(softwareId));
|
||||||
Assert.That(installSoftware.Count, Is.EqualTo(count));
|
Assert.That(installSoftware.Count, Is.EqualTo(count));
|
||||||
});
|
});
|
@ -54,5 +54,6 @@ internal class SalaryDataModelTests
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SalaryDataModel CreateDataModel(string? workerId, DateTime date, double workerSalary) => new(workerId, date, workerSalary);
|
private static SalaryDataModel CreateDataModel(string? workerId, DateTime date,
|
||||||
|
double workerSalary) => new(workerId, date, workerSalary);
|
||||||
}
|
}
|
@ -17,7 +17,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\SoftwareInstallationContracts\SoftwareInstallationContracts\SoftwareInstallationContracts.csproj" />
|
<ProjectReference Include="..\SoftwareInstallationContracts\SoftwareInstallationContracts\SoftwareInstallationContracts.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
Loading…
x
Reference in New Issue
Block a user