PIbd-22. Tukhtarov I.N. First lab #1

Closed
Ilnur wants to merge 9 commits from Task1_Models into main
22 changed files with 873 additions and 104 deletions
Showing only changes of commit d5ce733893 - Show all commits

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\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

@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace SoftwareInstallationContracts.DataModels;
public class BuyerDataModel(string id, string fio, string phoneNumber) : IValidation
public class ClientDataModel(string id, string fio, string phoneNumber) : IValidation
{
public string Id { get; private set; } = id;
@ -21,21 +21,21 @@ public class BuyerDataModel(string id, string fio, string phoneNumber) : IValida
public void Validate()
{
if (id.isEmpty())
throw new ValidatonException("Field Id is empty");
throw new ValidationFieldException("Field Id is empty");
if (!id.isGuid())
throw new ValidatonException("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())
throw new ValidatonException("Field FIO is empty");
throw new ValidationFieldException("Field FIO is empty");
if (!Regex.IsMatch(FIO, @"/^([а-яa-zё\-]{2,})++([ ][а-яa-zё\-]{2,})++(?:[ ][а-яa-zё\-]{2,})?$"))
throw new ValidatonException("Field FIO is not a fio");
if (!Regex.IsMatch(FIO, @"^[A-ZА-ЯЁ][a-zа-яё]+ [A-ZА-ЯЁ][a-zа-яё]+ [A-ZA-ЯЁ][a-zа-яё]+$"))
throw new ValidationFieldException("Field FIO is not a fio");
if (PhoneNumber.isEmpty())
throw new ValidatonException("Field PhoneNumber is empty");
throw new ValidationFieldException("Field PhoneNumber is empty");
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
throw new ValidatonException("Field PhoneNumber is not a phone number");
throw new ValidationFieldException("Field PhoneNumber is not a phone number");
}
}

View File

@ -11,21 +11,21 @@ using System.Threading.Tasks;
namespace SoftwareInstallationContracts.DataModels;
public class СompanyDataModel(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 СompanyName { get; private set; } = companyName;
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 ValidatonException("Field Id is empty");
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidatonException("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 (СompanyName.isEmpty())
throw new ValidatonException("Field СompanyName is empty");
if (CompanyName.isEmpty())
throw new ValidationFieldException("Field CompanyName is empty");
}
}

View File

@ -0,0 +1,52 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationContracts.DataModels;
public class InstallationServiceDataModel(string id, string workerId, string clientId, double sum, bool isCancel, List<InstallationServiceProgramDataModel> 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 SaleDate { get; private set; } = DateTime.UtcNow;
public double Sum { get; private set; } = sum;
public bool IsCancel { get; private set; } = isCancel;
public List<InstallationServiceProgramDataModel> 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

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace SoftwareInstallationContracts.DataModels;
public class SaleProgramDataModel(string programId, string saleId, int count) : IValidation
public class InstallationServiceProgramDataModel(string saleId, string programId, int count) : IValidation
{
public string ProgramId { get; private set; } = programId;
@ -20,18 +20,18 @@ public class SaleProgramDataModel(string programId, string saleId, int count) :
public void Validate()
{
if (ProgramId.isEmpty())
throw new ValidatonException("Field ProgramId is empty");
throw new ValidationFieldException("Field ProgramId is empty");
if (!ProgramId.isGuid())
throw new ValidatonException("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())
throw new ValidatonException("Field SaleId is empty");
throw new ValidationFieldException("Field SaleId is empty");
if (!SaleId.isGuid())
throw new ValidatonException("The value in the field SaleId is not a unique identifier");
throw new ValidationFieldException("The value in the field SaleId is not a unique identifier");
if (Count <= 0)
throw new ValidatonException("Field Count is less than or equal to 0");
throw new ValidationFieldException("Field Count is less than or equal to 0");
}
}

View File

@ -10,8 +10,9 @@ using System.Threading.Tasks;
namespace SoftwareInstallationContracts.DataModels;
public class PostDataModel(string id, string postId, string postName, PostType postType, int servicesCount, 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 PostId { get; private set; } = postId;
@ -29,25 +30,25 @@ public class PostDataModel(string id, string postId, string postName, PostType p
public void Validate()
{
if (Id.isEmpty())
throw new ValidatonException("Field Id is empty");
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidatonException("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 (PostId.isEmpty())
throw new ValidatonException("Field PostId is empty");
throw new ValidationFieldException("Field PostId is empty");
if (!PostId.isGuid())
throw new ValidatonException("The value in the field PostId is not a unique identifier");
throw new ValidationFieldException("The value in the field PostId is not a unique identifier");
if (Salary <= 0)
throw new ValidatonException("Field Salary is empty");
throw new ValidationFieldException("Field Salary is empty");
if (PostType == PostType.None)
throw new ValidatonException("Field PostType is empty");
throw new ValidationFieldException("Field PostType is empty");
if (PostName.isEmpty())
throw new ValidatonException("Field PostName is empty");
throw new ValidationFieldException("Field PostName is empty");
}
}

View File

@ -27,24 +27,24 @@ public class ProgramDataModel(string id, string programName, ProgramType program
public void Validate()
{
if (Id.isEmpty())
throw new ValidatonException("Field Id is empty");
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidatonException("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 (ProgramName.isEmpty())
throw new ValidatonException("Field ProgramName is empty");
throw new ValidationFieldException("Field ProgramName is empty");
if (ProgramType == ProgramType.None)
throw new ValidatonException("Field ProgramType is empty");
throw new ValidationFieldException("Field ProgramType is empty");
if (CompanyId.isEmpty())
throw new ValidatonException("Field CompanyId is empty");
throw new ValidationFieldException("Field CompanyId is empty");
if (!CompanyId.isGuid())
throw new ValidatonException("The value in the field CompanyId is not a unique identifier");
throw new ValidationFieldException("The value in the field CompanyId is not a unique identifier");
if (Price <= 0)
throw new ValidatonException("Field Price is less than or equal to 0");
throw new ValidationFieldException("Field Price is less than or equal to 0");
}
}

View File

@ -16,17 +16,17 @@ public class ProgramHistoryDataModel(string programId, double oldPrice) : IValid
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeUpdate { get; private set; } = DateTime.UtcNow;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public void Validate()
{
if (ProgramId.isEmpty())
throw new ValidatonException("Field ProgramId is empty");
throw new ValidationFieldException("Field ProgramId is empty");
if (!ProgramId.isGuid())
throw new ValidatonException("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 (OldPrice <= 0)
throw new ValidatonException("Field OldPrice is less than or equal to 0");
throw new ValidationFieldException("Field OldPrice is less than or equal to 0");
}
}

View File

@ -20,12 +20,12 @@ public class SalaryDataModel(string workerId, DateTime salaryDate, double worker
public void Validate()
{
if (WorkerId.isEmpty())
throw new ValidatonException("Field WorkerId is empty");
throw new ValidationFieldException("Field WorkerId is empty");
if (!WorkerId.isGuid())
throw new ValidatonException("The value in the field WorkerId is not a unique identifier");
throw new ValidationFieldException("The value in the field WorkerId is not a unique identifier");
if (Salary <= 0)
throw new ValidatonException("Field Salary is less than or equal to 0");
throw new ValidationFieldException("Field Salary is less than or equal to 0");
}
}

View File

@ -1,52 +0,0 @@
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Extensions;
using SoftwareInstallationContracts.Infrastucture;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationContracts.DataModels;
public class SaleDataModel(string id, string workerId, string buyerId, double sum, bool isCancel, List<SaleProgramDataModel> programs) : IValidation
{
public string Id { get; private set; } = id;
public string WorkerId { get; private set; } = workerId;
public string? BuyerId { get; private set; } = buyerId;
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
public double Sum { get; private set; } = sum;
public bool IsCancel { get; private set; } = isCancel;
public List<SaleProgramDataModel> Programs { get; private set; } = programs;
public void Validate()
{
if (Id.isEmpty())
throw new ValidatonException("Field Id is empty");
if (!Id.isGuid())
throw new ValidatonException("The value in the field Id is not a unique identifier");
if (WorkerId.isEmpty())
throw new ValidatonException("Field WorkerId is empty");
if (!WorkerId.isGuid())
throw new ValidatonException("The value in the field WorkerId is not a unique identifier");
if (!BuyerId?.isGuid() ?? !BuyerId?.isEmpty() ?? false)
throw new ValidatonException("The value in the field BuyerId is not a unique identifier");
if (Sum <= 0)
throw new ValidatonException("Field Sum is less than or wqual to 0");
if ((Programs?.Count() ?? 0) == 0)
throw new ValidatonException("The sale must include programs");
}
}

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace SoftwareInstallationContracts.DataModels;
@ -21,27 +22,27 @@ public class WorkerDataModel(string id, string fio, string postId, DateTime birt
public void Validate()
{
if (Id.isEmpty())
throw new ValidatonException("Field Id is empty");
throw new ValidationFieldException("Field Id is empty");
if (!Id.isGuid())
throw new ValidatonException("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())
throw new ValidatonException("Field FIO is empty");
throw new ValidationFieldException("Field FIO is empty");
if (PostId.isEmpty())
throw new ValidatonException("Field PostId is empty");
throw new ValidationFieldException("Field PostId is empty");
if (!PostId.isGuid())
throw new ValidatonException("The value in the field PostId is not a unique identifier");
throw new ValidationFieldException("The value in the field PostId is not a unique identifier");
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
throw new ValidatonException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()}");
throw new ValidationFieldException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()}");
if (EmploymentDate.Date < BirthDate.Date)
throw new ValidatonException("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)
throw new ValidatonException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()}");
throw new ValidationFieldException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()}");
}
}

View File

@ -6,6 +6,6 @@ using System.Threading.Tasks;
namespace SoftwareInstallationContracts.Exceptions;
public class ValidatonException(String message) : Exception(message)
public class ValidationFieldException(String message) : Exception(message)
{
}

View File

@ -0,0 +1,83 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationTests.DataModelsTests;
[TestFixture]
internal class ClientDataModelTests
{
private static ClientDataModel client;
[Test]
public void IdIsNullOrEmptyTest()
{
client = CreateDataModel(null, "fio", "number");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
client = CreateDataModel(string.Empty, "fio", "number");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
client = CreateDataModel("id", "fio", "number");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void FIOIsNullOrEmptyTest()
{
client = CreateDataModel(Guid.NewGuid().ToString(), null, "number");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void FIOIsIncorrectTest()
{
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "number");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PhoneNumberIsNullOrEmptyTest()
{
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", null);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PhoneNumberIsIncorrectTest()
{
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string phoneNumber = "+7-777-777-77-77";
string fio = "Василий Васильевич Васильев";
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,61 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
namespace SoftwareInstallationTests.DataModelsTests;
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,98 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationTests.DataModelsTests;
internal class InstallationServiceDataModelTests
{
private InstallationServiceDataModel sale;
[Test]
public void IdIsNullOrEmptyTest()
{
sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void WorkerIdIsNullOrEmptyTest()
{
sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
sale = CreateDataModel(Guid.NewGuid().ToString(), "workerId", Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void ClientIdIsNotGuidTest()
{
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "clientId", 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SumIsLessOrZeroTest()
{
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void programsIsNullOrEmptyTest()
{
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, null);
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, []);
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string saleId = Guid.NewGuid().ToString();
string workerId = Guid.NewGuid().ToString();
string clientId = Guid.NewGuid().ToString();
double sum = 10;
bool isCancel = true;
List<InstallationServiceProgramDataModel> programs = CreateSubDataModel();
sale = CreateDataModel(saleId, workerId, clientId, sum, isCancel, programs);
Assert.That(() => sale.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(sale.Id, Is.EqualTo(saleId));
Assert.That(sale.WorkerId, Is.EqualTo(workerId));
Assert.That(sale.ClientId, Is.EqualTo(clientId));
Assert.That(sale.Sum, Is.EqualTo(sum));
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
Assert.That(sale.Programs, Is.EquivalentTo(programs));
});
}
private static InstallationServiceDataModel CreateDataModel(string? id, string? workerId, string? clientId, double sum, bool isCancel, List<InstallationServiceProgramDataModel>? programs) =>
new(id, workerId, clientId, sum, isCancel, programs);
private static List<InstallationServiceProgramDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

View File

@ -0,0 +1,75 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationTests.DataModelsTests;
internal class InstallationServiceProgramDataModelTests
{
private InstallationServiceProgramDataModel saleProgram;
[Test]
public void SaleIdIsNullOrEmptyTest()
{
saleProgram = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
Assert.That(() => saleProgram.Validate(), Throws.TypeOf<ValidationFieldException>());
saleProgram = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => saleProgram.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SaleIdIsNotGuidTest()
{
saleProgram = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10);
Assert.That(() => saleProgram.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void ProgramIdIsNullOrEmptyTest()
{
saleProgram = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
Assert.That(() => saleProgram.Validate(), Throws.TypeOf<ValidationFieldException>());
saleProgram = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => saleProgram.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void ProgramIdIsNotGuidTest()
{
saleProgram = CreateDataModel(Guid.NewGuid().ToString(), "programId", 10);
Assert.That(() => saleProgram.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
saleProgram = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => saleProgram.Validate(), Throws.TypeOf<ValidationFieldException>());
saleProgram = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
Assert.That(() => saleProgram.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string saleId = Guid.NewGuid().ToString();
string programId = Guid.NewGuid().ToString();
int count = 10;
saleProgram = CreateDataModel(saleId, programId, count);
Assert.That(() => saleProgram.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(saleProgram.SaleId, Is.EqualTo(saleId));
Assert.That(saleProgram.ProgramId, Is.EqualTo(programId));
Assert.That(saleProgram.Count, Is.EqualTo(count));
});
}
private static InstallationServiceProgramDataModel CreateDataModel(string? saleId, string? programId, int count) =>
new(saleId, programId, count);
}

View File

@ -0,0 +1,100 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationTests.DataModelsTests;
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,99 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Enums;
using SoftwareInstallationContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static NUnit.Framework.Internal.OSPlatform;
namespace SoftwareInstallationTests.DataModelsTests;
internal class ProgramDataModelTests
{
private ProgramDataModel program;
[Test]
public void IdIsNullOrEmptyTest()
{
program = CreateDataModel(null, "name", ProgramType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
program = CreateDataModel(string.Empty, "name", ProgramType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
program = CreateDataModel("id", "name", ProgramType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void ProgramNameIsEmptyTest()
{
program = CreateDataModel(Guid.NewGuid().ToString(), null, ProgramType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
program = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProgramType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void ProgramTypeIsNoneTest()
{
program = CreateDataModel(Guid.NewGuid().ToString(), "name", ProgramType.None, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CompanyIdIsNullOrEmptyTest()
{
program = CreateDataModel(Guid.NewGuid().ToString(), "name", ProgramType.ApplicationSoftware, null, 10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
program = CreateDataModel(Guid.NewGuid().ToString(), "name", ProgramType.ApplicationSoftware, string.Empty, 10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void CompanyIdIsNotGuidTest()
{
program = CreateDataModel(Guid.NewGuid().ToString(), "name", ProgramType.ApplicationSoftware, "companyId", 10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
program = CreateDataModel(Guid.NewGuid().ToString(), "name", ProgramType.ApplicationSoftware, Guid.NewGuid().ToString(), 0, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
program = CreateDataModel(Guid.NewGuid().ToString(), "name", ProgramType.ApplicationSoftware, Guid.NewGuid().ToString(), -10, false);
Assert.That(() => program.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string programId = Guid.NewGuid().ToString();
string programName = "name";
ProgramType programType = ProgramType.ApplicationSoftware;
string programManufacturerId = Guid.NewGuid().ToString();
double programPrice = 10;
bool programIsDelete = false;
ProgramDataModel program = CreateDataModel(programId, programName, programType, programManufacturerId, programPrice, programIsDelete);
Assert.That(() => program.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(program.Id, Is.EqualTo(programId));
Assert.That(program.ProgramName, Is.EqualTo(programName));
Assert.That(program.ProgramType, Is.EqualTo(programType));
Assert.That(program.CompanyId, Is.EqualTo(programManufacturerId));
Assert.That(program.Price, Is.EqualTo(programPrice));
Assert.That(program.IsDeleted, Is.EqualTo(programIsDelete));
});
}
private static ProgramDataModel CreateDataModel(string? id, string? programName, ProgramType programType,
string? companyId, double price, bool isDeleted) =>
new(id, programName, programType, companyId, price, isDeleted);
}

View File

@ -0,0 +1,60 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
using SoftwareInstallationContracts.Enums;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationTests.DataModelsTests;
internal class ProgramHistoryDataModelTests
{
private ProgramHistoryDataModel 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.ProgramId, 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 ProgramHistoryDataModel CreateDataModel(string? programHistoryId, double oldPrice) =>
new(programHistoryId, oldPrice);
}

View File

@ -0,0 +1,59 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationTests.DataModelsTests;
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);
}

View File

@ -0,0 +1,99 @@
using SoftwareInstallationContracts.DataModels;
using SoftwareInstallationContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SoftwareInstallationTests.DataModelsTests;
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>