fix: change folders

This commit is contained in:
I1nur 2025-02-10 20:47:17 +04:00
parent e1f0e39b29
commit 351975ba2b
13 changed files with 781 additions and 12 deletions

2
.gitignore vendored
View File

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

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 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 Vasilievich Vasiliev";
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,62 @@
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;
[TestFixture]
internal class CompanyDataModelTests
{
private CompanyDataModel company;
[Test]
public void IdIsNullEmptyTest()
{
company = CreateDataModel(null, "name");
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
company = CreateDataModel(string.Empty, "name");
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
company = CreateDataModel("id", "name");
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void companyNameIsNullOrEmptyTest()
{
company = CreateDataModel(Guid.NewGuid().ToString(), null);
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
company = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string companyId = Guid.NewGuid().ToString();
string companyName = "name";
string prevcompanyName = "prevcompanyName";
string prevPrevcompanyName = "prevPrevcompanyName";
company = CreateDataModel(companyId, companyName, prevcompanyName, prevPrevcompanyName);
Assert.That(() => company.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(company.Id, Is.EqualTo(companyId));
Assert.That(company.CompanyName, Is.EqualTo(companyName));
Assert.That(company.PrevCompanyName, Is.EqualTo(prevcompanyName));
Assert.That(company.PrevPrevCompanyName, Is.EqualTo(prevPrevcompanyName));
});
}
private static CompanyDataModel CreateDataModel(string? id, string? companyName, string? prevcompanyName = null, string? prevPrevcompanyName = null) =>
new(id, companyName, prevcompanyName, prevPrevcompanyName);
}

View File

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

View File

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

View File

@ -0,0 +1,101 @@
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;
[TestFixture]
internal class PostDataModelTests
{
private PostDataModel post;
[Test]
public void idIsNotNullOrEmpty()
{
post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void IdIsNotGuidTest()
{
post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostIdIsNullEmptyTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void SalaryIsLessOrZeroTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Stuff, 0, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Stuff, -10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostTypeIsNoneTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void PostNameIsEmptyTest()
{
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Stuff, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
string postId = Guid.NewGuid().ToString();
string postPostId = Guid.NewGuid().ToString();
string postName = "name";
PostType postType = PostType.Stuff;
double salary = 10;
bool isActual = false;
DateTime changeDate = DateTime.UtcNow.AddDays(-1);
post = CreateDataModel(postId, postPostId, postName, postType, salary, isActual, changeDate);
Assert.That(() => post.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(post.Id, Is.EqualTo(postId));
Assert.That(post.PostId, Is.EqualTo(postPostId));
Assert.That(post.PostName, Is.EqualTo(postName));
Assert.That(post.PostType, Is.EqualTo(postType));
Assert.That(post.Salary, Is.EqualTo(salary));
Assert.That(post.IsActual, Is.EqualTo(isActual));
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
});
}
private static PostDataModel CreateDataModel(string? id, string? postId, string? postName,
PostType postType, double salary, bool isActual, DateTime changeDate) =>
new(id, postId, postName, postType, salary, isActual, changeDate);
}

View File

@ -0,0 +1,60 @@
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;
[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);
}

View File

@ -0,0 +1,100 @@
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;
[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);
}

View File

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

View File

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

View File

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

View File

@ -16,48 +16,48 @@ internal class ClientDataModelTests
[Test]
public void IdIsNullOrEmptyTest()
{
client = CreateDataModel(null, "fio", "number");
client = CreateDataModel(null, "fio", "+7-777-777-77-77");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
client = CreateDataModel(string.Empty, "fio", "number");
client = CreateDataModel(string.Empty, "fio", "+7-777-777-77-77");
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
}
[Test]
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>());
}
[Test]
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>());
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>());
}
[Test]
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>());
}
[Test]
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>());
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>());
}
[Test]
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>());
}
@ -65,7 +65,7 @@ internal class ClientDataModelTests
public void AllFieldsIsCorrectTest()
{
string phoneNumber = "+7-777-777-77-77";
string fio = "Василий Васильевич Васильев";
string fio = "Vasiliy Vasiliev Vasilievich";
string id = Guid.NewGuid().ToString();
client = CreateDataModel(id, fio, phoneNumber);
Assert.That(() => client.Validate(), Throws.Nothing);

View File

@ -64,7 +64,7 @@ internal class InstallationSoftwareDataModelTests
Assert.That(() => installSoftware.Validate(), Throws.Nothing);
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.Count, Is.EqualTo(count));
});