Тесты

This commit is contained in:
Timur_Sharafutdinov 2025-02-18 16:31:10 +04:00
parent 848bfb2232
commit b96a5e32ca
28 changed files with 1091 additions and 0 deletions

View File

@ -0,0 +1,45 @@
using Carpentry.Extensions;
using Carpentry.Enums;
using Carpentry.Exceptions;
using Carpentry.Infrastructure;
namespace Carpentry.DataModels;
public class BlankDataModel(string id, string blankName, MaterialType materialType, string supplierId, double price, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string BlankName { get; private set; } = blankName;
public MaterialType MaterialType { get; private set; } = materialType;
public string SupplierId { get; private set; } = supplierId;
public double Price { get; private set; } = price;
public bool IsDeleted { get; private set; } = isDeleted;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (BlankName.IsEmpty())
throw new ValidationException("Field BlankName is empty");
if (MaterialType == MaterialType.None)
throw new ValidationException("Field MaterialType is empty");
if (SupplierId.IsEmpty())
throw new ValidationException("Field SupplierId is empty");
if (!SupplierId.IsGuid())
throw new ValidationException("The value in the field SupplierId is not a unique identifier");
if (Price <= 0)
throw new ValidationException("Field Price must be greater than 0");
}
}

View File

@ -0,0 +1,26 @@
using Carpentry.Extensions;
using Carpentry.Exceptions;
using Carpentry.Infrastructure;
namespace Carpentry.DataModels;
public class BlankHistoryDataModel(string blankId, double oldPrice) : IValidation
{
public string BlankId { get; private set; } = blankId;
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public void Validate()
{
if (BlankId.IsEmpty())
throw new ValidationException("Field BlankId is empty");
if (!BlankId.IsGuid())
throw new ValidationException("The value in the field BlankId is not a unique identifier");
if (OldPrice <= 0)
throw new ValidationException("Field OldPrice must be greater than 0");
}
}

View File

@ -0,0 +1,32 @@
using Carpentry.Extensions;
using Carpentry.Exceptions;
using Carpentry.Infrastructure;
namespace Carpentry.DataModels;
public class CutBlankDataModel(string cuttingId, string blankId, int count) : IValidation
{
public string CuttingId { get; private set; } = cuttingId;
public string BlankId { get; private set; } = blankId;
public int Count { get; private set; } = count;
public void Validate()
{
if (CuttingId.IsEmpty())
throw new ValidationException("Field CuttingId is empty");
if (!CuttingId.IsGuid())
throw new ValidationException("The value in the field CuttingId is not a unique identifier");
if (BlankId.IsEmpty())
throw new ValidationException("Field BlankId is empty");
if (!BlankId.IsGuid())
throw new ValidationException("The value in the field BlankId is not a unique identifier");
if (Count <= 0)
throw new ValidationException("Field Count must be greater than 0");
}
}

View File

@ -0,0 +1,42 @@
using Carpentry.Extensions;
using Carpentry.Enums;
using Carpentry.Exceptions;
using Carpentry.Infrastructure;
namespace Carpentry.DataModels;
public class CuttingDataModel(string id, string workerId, double totalVolume, bool isCancel, List<CutBlankDataModel> blanks) : IValidation
{
public string Id { get; private set; } = id;
public string WorkerId { get; private set; } = workerId;
public DateTime CuttingDate { get; private set; } = DateTime.UtcNow;
public double TotalVolume { get; private set; } = totalVolume; // Например, объем в кубометрах
public bool IsCancel { get; private set; } = isCancel;
public List<CutBlankDataModel> Blanks { get; private set; } = blanks; // Заготовки, участвующие в резке
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (WorkerId.IsEmpty())
throw new ValidationException("Field WorkerId is empty");
if (!WorkerId.IsGuid())
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
if (TotalVolume <= 0)
throw new ValidationException("Field TotalVolume must be greater than 0");
if ((Blanks?.Count ?? 0) == 0)
throw new ValidationException("The cutting process must include blanks");
}
}

View File

@ -0,0 +1,28 @@
using Carpentry.Extensions;
using Carpentry.Exceptions;
using Carpentry.Infrastructure;
namespace Carpentry.DataModels;
public class ManufacturerDataModel(string id, string manufacturerName, string? prevManufacturerName, string? prevPrevManufacturerName) : IValidation
{
public string Id { get; private set; } = id;
public string ManufacturerName { get; private set; } = manufacturerName;
public string? PrevManufacturerName { get; private set; } = prevManufacturerName;
public string? PrevPrevManufacturerName { get; private set; } = prevPrevManufacturerName;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (ManufacturerName.IsEmpty())
throw new ValidationException("Field ManufacturerName is empty");
}
}

View File

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

View File

@ -0,0 +1,45 @@
using Carpentry.Extensions;
using Carpentry.Enums;
using Carpentry.Exceptions;
using Carpentry.Infrastructure;
namespace Carpentry.DataModels;
public class ProductDataModel(string id, string productName, ProductType productType, string manufacturerId, double price, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string ProductName { get; private set; } = productName;
public ProductType ProductType { get; private set; } = productType;
public string ManufacturerId { get; private set; } = manufacturerId;
public double Price { get; private set; } = price;
public bool IsDeleted { get; private set; } = isDeleted;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (ProductName.IsEmpty())
throw new ValidationException("Field ProductName is empty");
if (ProductType == ProductType.None)
throw new ValidationException("Field ProductType is empty");
if (ManufacturerId.IsEmpty())
throw new ValidationException("Field ManufacturerId is empty");
if (!ManufacturerId.IsGuid())
throw new ValidationException("The value in the field ManufacturerId is not a unique identifier");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}

View File

@ -0,0 +1,26 @@
using Carpentry.Extensions;
using Carpentry.Exceptions;
using Carpentry.Infrastructure;
namespace Carpentry.DataModels;
public class ProductHistoryDataModel(string productId, double oldPrice) : IValidation
{
public string ProductId { get; private set; } = productId;
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public void Validate()
{
if (ProductId.IsEmpty())
throw new ValidationException("Field ProductId is empty");
if (!ProductId.IsGuid())
throw new ValidationException("The value in the field ProductId is not a unique identifier");
if (OldPrice <= 0)
throw new ValidationException("Field OldPrice is less than or equal to 0");
}
}

View File

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

View File

@ -0,0 +1,51 @@
using Carpentry.Extensions;
using Carpentry.Enums;
using Carpentry.Exceptions;
using Carpentry.Infrastructure;
namespace Carpentry.DataModels;
public class SaleDataModel(string id, string workerId, string? buyerId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleProductDataModel> products) : 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 DiscountType DiscountType { get; private set; } = discountType;
public double Discount { get; private set; } = discount;
public bool IsCancel { get; private set; } = isCancel;
public List<SaleProductDataModel> Products { get; private set; } = products;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (WorkerId.IsEmpty())
throw new ValidationException("Field WorkerId is empty");
if (!WorkerId.IsGuid())
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
if (!BuyerId?.IsGuid() ?? !BuyerId?.IsEmpty() ?? false)
throw new ValidationException("The value in the field BuyerId is not a unique identifier");
if (Sum <= 0)
throw new ValidationException("Field Sum is less than or equal to 0");
if ((Products?.Count ?? 0) == 0)
throw new ValidationException("The sale must include products");
}
}

View File

@ -0,0 +1,32 @@
using Carpentry.Extensions;
using Carpentry.Exceptions;
using Carpentry.Infrastructure;
namespace Carpentry.DataModels;
public class SaleProductDataModel(string saleId, string productId, int count) : IValidation
{
public string SaleId { get; private set; } = saleId;
public string ProductId { get; private set; } = productId;
public int Count { get; private set; } = count;
public void Validate()
{
if (SaleId.IsEmpty())
throw new ValidationException("Field SaleId is empty");
if (!SaleId.IsGuid())
throw new ValidationException("The value in the field SaleId is not a unique identifier");
if (ProductId.IsEmpty())
throw new ValidationException("Field ProductId is empty");
if (!ProductId.IsGuid())
throw new ValidationException("The value in the field ProductId is not a unique identifier");
if (Count <= 0)
throw new ValidationException("Field Count is less than or equal to 0");
}
}

View File

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

View File

@ -0,0 +1,10 @@
namespace Carpentry.Enums;
[Flags]
public enum DiscountType
{
None = 0,
OnSale = 1,
RegularCustomer = 2,
Certificate = 4
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Carpentry.Enums;
[Flags]
public enum MaterialType
{
None = 0,
SolidWood = 1, // Дерево
Plywood = 2, // Фанера
MDF = 4, // МДФ
Chipboard = 8, // ДСП
}

View File

@ -0,0 +1,9 @@
namespace Carpentry.Enums;
public enum PostType
{
None = 0,
OrderManager = 1, // Сотрудник, оформляющий заказы
BlankPreparator = 2, // Сотрудник, ответственный за подготовку заготовок
Cutter = 3 // Сотрудник, выполняющий резку изделий
}

View File

@ -0,0 +1,9 @@
namespace Carpentry.Enums;
public enum ProductType
{
None = 0,
Furniture = 1, // Мебель (столы, стулья, шкафы и т.д.)
Door = 2, // Двери
Window = 3 // Оконные конструкции
}

View File

@ -0,0 +1,5 @@
namespace Carpentry.Exceptions;
public class ValidationException(string message) : Exception(message)
{
}

View File

@ -0,0 +1,14 @@
namespace Carpentry.Extensions;
public static class StringExtensions
{
public static bool IsEmpty(this string str)
{
return string.IsNullOrWhiteSpace(str);
}
public static bool IsGuid(this string str)
{
return Guid.TryParse(str, out _);
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Carpentry.Infrastructure;
public interface IValidation
{
void Validate();
}

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 17.8.34525.116
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Carpentry", "Carpentry\Carpentry.csproj", "{C217EBD0-76D8-49CF-A820-9572AC6A9DC9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CarpentryWorkshopTest", "CarpentryWorkshopTest\CarpentryWorkshopTest.csproj", "{06A43B9A-4BBA-4C30-A0B7-4145755D8A0A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{C217EBD0-76D8-49CF-A820-9572AC6A9DC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C217EBD0-76D8-49CF-A820-9572AC6A9DC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C217EBD0-76D8-49CF-A820-9572AC6A9DC9}.Release|Any CPU.Build.0 = Release|Any CPU
{06A43B9A-4BBA-4C30-A0B7-4145755D8A0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{06A43B9A-4BBA-4C30-A0B7-4145755D8A0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{06A43B9A-4BBA-4C30-A0B7-4145755D8A0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06A43B9A-4BBA-4C30-A0B7-4145755D8A0A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NUnit" Version="3.14.0" />
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Carpentry\Carpentry.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,91 @@
using Carpentry.DataModels;
using Carpentry.Enums;
using Carpentry.Exceptions;
namespace CarpentryWorkshopTests.DataModelsTests;
[TestFixture]
internal class BlankDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var blank = CreateDataModel(null, "name", MaterialType.SolidWood, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
blank = CreateDataModel(string.Empty, "name", MaterialType.SolidWood, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var blank = CreateDataModel("id", "name", MaterialType.SolidWood, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BlankNameIsEmptyTest()
{
var blank = CreateDataModel(Guid.NewGuid().ToString(), null, MaterialType.SolidWood, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
blank = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, MaterialType.SolidWood, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void MaterialTypeIsNoneTest()
{
var blank = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.None, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SupplierIdIsNullOrEmptyTest()
{
var blank = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.SolidWood, null, 10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
blank = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.SolidWood, string.Empty, 10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SupplierIdIsNotGuidTest()
{
var blank = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.SolidWood, "supplierId", 10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var blank = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.SolidWood, Guid.NewGuid().ToString(), 0, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
blank = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.SolidWood, Guid.NewGuid().ToString(), -10, false);
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var blankId = Guid.NewGuid().ToString();
var blankName = "name";
var materialType = MaterialType.SolidWood;
var supplierId = Guid.NewGuid().ToString();
var blankPrice = 10;
var blankIsDeleted = false;
var blank = CreateDataModel(blankId, blankName, materialType, supplierId, blankPrice, blankIsDeleted);
Assert.That(() => blank.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(blank.Id, Is.EqualTo(blankId));
Assert.That(blank.BlankName, Is.EqualTo(blankName));
Assert.That(blank.MaterialType, Is.EqualTo(materialType));
Assert.That(blank.SupplierId, Is.EqualTo(supplierId));
Assert.That(blank.Price, Is.EqualTo(blankPrice));
Assert.That(blank.IsDeleted, Is.EqualTo(blankIsDeleted));
});
}
private static BlankDataModel CreateDataModel(string? id, string? blankName, MaterialType materialType, string? supplierId, double price, bool isDeleted) =>
new(id, blankName, materialType, supplierId, price, isDeleted);
}

View File

@ -0,0 +1,54 @@
using Carpentry.DataModels;
using Carpentry.Exceptions;
namespace CarpentryWorkshopTests.DataModelsTests;
[TestFixture]
internal class BlankHistoryDataModelTests
{
[Test]
public void BlankIdIsNullOrEmptyTest()
{
var blankHistory = CreateDataModel(null, 10);
Assert.That(() => blankHistory.Validate(), Throws.TypeOf<ValidationException>());
blankHistory = CreateDataModel(string.Empty, 10);
Assert.That(() => blankHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BlankIdIsNotGuidTest()
{
var blankHistory = CreateDataModel("id", 10);
Assert.That(() => blankHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void OldPriceIsLessOrZeroTest()
{
var blankHistory = CreateDataModel(Guid.NewGuid().ToString(), 0);
Assert.That(() => blankHistory.Validate(), Throws.TypeOf<ValidationException>());
blankHistory = CreateDataModel(Guid.NewGuid().ToString(), -10);
Assert.That(() => blankHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var blankId = Guid.NewGuid().ToString();
var oldPrice = 10;
var blankHistory = CreateDataModel(blankId, oldPrice);
Assert.That(() => blankHistory.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(blankHistory.BlankId, Is.EqualTo(blankId));
Assert.That(blankHistory.OldPrice, Is.EqualTo(oldPrice));
Assert.That(blankHistory.ChangeDate, Is.LessThan(DateTime.UtcNow));
Assert.That(blankHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
});
}
private static BlankHistoryDataModel CreateDataModel(string? blankId, double oldPrice) =>
new(blankId, oldPrice);
}

View File

@ -0,0 +1,69 @@
using Carpentry.DataModels;
using Carpentry.Exceptions;
namespace CarpentryWorkshopTests.DataModelsTests;
[TestFixture]
internal class CutBlankDataModelTests
{
[Test]
public void CuttingIdIsNullOrEmptyTest()
{
var cutBlank = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
Assert.That(() => cutBlank.Validate(), Throws.TypeOf<ValidationException>());
cutBlank = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => cutBlank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CuttingIdIsNotGuidTest()
{
var cutBlank = CreateDataModel("invalidCuttingId", Guid.NewGuid().ToString(), 10);
Assert.That(() => cutBlank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BlankIdIsNullOrEmptyTest()
{
var cutBlank = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
Assert.That(() => cutBlank.Validate(), Throws.TypeOf<ValidationException>());
cutBlank = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
Assert.That(() => cutBlank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BlankIdIsNotGuidTest()
{
var cutBlank = CreateDataModel(Guid.NewGuid().ToString(), "invalidBlankId", 10);
Assert.That(() => cutBlank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
var cutBlank = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => cutBlank.Validate(), Throws.TypeOf<ValidationException>());
cutBlank = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -5);
Assert.That(() => cutBlank.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var cuttingId = Guid.NewGuid().ToString();
var blankId = Guid.NewGuid().ToString();
var count = 10;
var cutBlank = CreateDataModel(cuttingId, blankId, count);
Assert.That(() => cutBlank.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(cutBlank.CuttingId, Is.EqualTo(cuttingId));
Assert.That(cutBlank.BlankId, Is.EqualTo(blankId));
Assert.That(cutBlank.Count, Is.EqualTo(count));
});
}
private static CutBlankDataModel CreateDataModel(string? cuttingId, string? blankId, int count) =>
new(cuttingId, blankId, count);
}

View File

@ -0,0 +1,86 @@
using Carpentry.DataModels;
using Carpentry.Enums;
using Carpentry.Exceptions;
namespace CarpentryWorkshopTests.DataModelsTests;
[TestFixture]
internal class CuttingDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var cutting = CreateDataModel(null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
cutting = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var cutting = CreateDataModel("invalidId", Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNullOrEmptyTest()
{
var cutting = CreateDataModel(Guid.NewGuid().ToString(), null, 10, false, CreateSubDataModel());
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
cutting = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10, false, CreateSubDataModel());
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
var cutting = CreateDataModel(Guid.NewGuid().ToString(), "invalidWorkerId", 10, false, CreateSubDataModel());
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void TotalVolumeIsLessOrZeroTest()
{
var cutting = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false, CreateSubDataModel());
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
cutting = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -5, false, CreateSubDataModel());
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BlanksIsNullOrEmptyTest()
{
var cutting = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, null);
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
cutting = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, []);
Assert.That(() => cutting.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var cuttingId = Guid.NewGuid().ToString();
var workerId = Guid.NewGuid().ToString();
var totalVolume = 10;
var isCancel = true;
var blanks = CreateSubDataModel();
var cutting = CreateDataModel(cuttingId, workerId, totalVolume, isCancel, blanks);
Assert.That(() => cutting.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(cutting.Id, Is.EqualTo(cuttingId));
Assert.That(cutting.WorkerId, Is.EqualTo(workerId));
Assert.That(cutting.TotalVolume, Is.EqualTo(totalVolume));
Assert.That(cutting.IsCancel, Is.EqualTo(isCancel));
Assert.That(cutting.Blanks, Is.EquivalentTo(blanks));
});
}
private static CuttingDataModel CreateDataModel(string? id, string? workerId, double totalVolume, bool isCancel, List<CutBlankDataModel>? blanks) =>
new(id, workerId, totalVolume, isCancel, blanks);
private static List<CutBlankDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)];
}

View File

@ -0,0 +1,93 @@
using Carpentry.DataModels;
using Carpentry.Enums;
using Carpentry.Exceptions;
namespace CarpentryWorkshopTests.DataModelsTests;
[TestFixture]
internal class PostDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Cutter, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Cutter, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Cutter, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Cutter, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Cutter, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Cutter, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostNameIsEmptyTest()
{
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Cutter, 10, true, DateTime.UtcNow);
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Cutter, 10, true, DateTime.UtcNow);
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostTypeIsNoneTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SalaryIsLessOrZeroTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Cutter, 0, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Cutter, -10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var postId = Guid.NewGuid().ToString();
var postPostId = Guid.NewGuid().ToString();
var postName = "name";
var postType = PostType.Cutter;
var salary = 10;
var isActual = false;
var changeDate = DateTime.UtcNow.AddDays(-1);
var 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,52 @@
using Carpentry.DataModels;
using Carpentry.Exceptions;
namespace CarpentryWorkshopTests.DataModelsTests;
[TestFixture]
internal class SalaryDataModelTests
{
[Test]
public void WorkerIdIsEmptyTest()
{
var salary = CreateDataModel(null, DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
var salary = CreateDataModel("workerId", DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var workerId = Guid.NewGuid().ToString();
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
var workerSalary = 10;
var 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,90 @@
using Carpentry.DataModels;
using Carpentry.Exceptions;
namespace CarpentryWorkshopTests.DataModelsTests;
[TestFixture]
internal class WorkerDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
worker = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void FIOIsNullOrEmptyTest()
{
var worker = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullOrEmptyTest()
{
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BirthDateIsNotCorrectTest()
{
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BirthDateAndEmploymentDateIsNotCorrectTest()
{
var 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<ValidationException>());
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var workerId = Guid.NewGuid().ToString();
var fio = "fio";
var postId = Guid.NewGuid().ToString();
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
var employmentDate = DateTime.Now;
var isDelete = false;
var 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);
}