PIBD-22. Denisov V.D. LabWork_1 #1
@@ -1,10 +1,12 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.13.35806.99 d17.13
|
||||
VisualStudioVersion = 17.13.35806.99
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreContracts", "JewelryStoreContracts\JewelryStoreContracts.csproj", "{14756BCC-EFF7-4643-8713-547C93AF5728}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JewelryStoreTests", "JewelryStoreTests\JewelryStoreTests.csproj", "{B2046245-F218-4137-88EC-4856046EBDDC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{14756BCC-EFF7-4643-8713-547C93AF5728}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{14756BCC-EFF7-4643-8713-547C93AF5728}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{14756BCC-EFF7-4643-8713-547C93AF5728}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B2046245-F218-4137-88EC-4856046EBDDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B2046245-F218-4137-88EC-4856046EBDDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B2046245-F218-4137-88EC-4856046EBDDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B2046245-F218-4137-88EC-4856046EBDDC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Extensions;
|
||||
|
||||
namespace JewelryStoreContracts.DataModels;
|
||||
|
||||
public class CraftDataModel(string? id, string? workerId, DateTime craftDate, double additionalPrice)
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public DateTime CraftDate { get; private set; } = craftDate;
|
||||
|
||||
public double AdditionalPrice { get; private set; } = additionalPrice;
|
||||
|
||||
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 (CraftDate.Date > DateTime.Now)
|
||||
throw new ValidationException($"It is impossible to craft things in the future");
|
||||
|
||||
if (AdditionalPrice <= 0)
|
||||
throw new ValidationException("Field AdditionalPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using JewelryStoreContracts.Enums;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Extensions;
|
||||
using JewelryStoreContracts.Infrastructure;
|
||||
|
||||
namespace JewelryStoreContracts.DataModels;
|
||||
|
||||
public class MaterialDataModel(string id, string materialName, MaterialType materialType, double weight, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string MaterialName { get; private set; } = materialName;
|
||||
|
||||
public MaterialType MaterialType { get; private set; } = materialType;
|
||||
|
||||
public double Weight { get; private set; } = weight;
|
||||
|
||||
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 (MaterialName.IsEmpty())
|
||||
throw new ValidationException("Field MaterialName is empty");
|
||||
|
||||
if (Weight <= 0)
|
||||
throw new ValidationException("Field Weight is less than or equal to 0");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
|
||||
if (MaterialType == MaterialType.None)
|
||||
throw new ValidationException("Field MaterialType is empty");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using JewelryStoreContracts.Enums;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Extensions;
|
||||
using JewelryStoreContracts.Infrastructure;
|
||||
|
||||
namespace JewelryStoreContracts.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postId, string postName, PostType postType, double pay, 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 Pay { get; private set; } = pay;
|
||||
|
||||
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 (Pay <= 0)
|
||||
throw new ValidationException("Field Pay is empty");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Extensions;
|
||||
using JewelryStoreContracts.Infrastructure;
|
||||
|
||||
namespace JewelryStoreContracts.DataModels;
|
||||
|
||||
public class ProductComponentDataModel(string? productId, string? componentId, int count) : IValidation
|
||||
{
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public string ComponentId { get; private set; } = componentId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
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 (ComponentId.IsEmpty())
|
||||
throw new ValidationException("Field ComponentId is empty");
|
||||
|
||||
if (!ComponentId.IsGuid())
|
||||
throw new ValidationException("The value in the field ComponentId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
using JewelryStoreContracts.Enums;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Extensions;
|
||||
using JewelryStoreContracts.Infrastructure;
|
||||
|
||||
namespace JewelryStoreContracts.DataModels;
|
||||
|
||||
public class ProductDataModel(string id, string productName, string craftId, ProductType productType, double price, bool isDeleted, List<ProductComponentDataModel> components) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string ProductName { get; private set; } = productName;
|
||||
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
|
||||
public string CraftId { get; private set; } = craftId;
|
||||
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
public List<ProductComponentDataModel> Components { get; private set; } = components;
|
||||
|
||||
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 (CraftId.IsEmpty())
|
||||
throw new ValidationException("Field CraftId is empty");
|
||||
|
||||
if (!CraftId.IsGuid())
|
||||
throw new ValidationException("The value in the field CraftId is not a unique identifier");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
|
||||
if ((Components?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Extensions;
|
||||
using JewelryStoreContracts.Infrastructure;
|
||||
|
||||
namespace JewelryStoreContracts.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");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Extensions;
|
||||
using JewelryStoreContracts.Infrastructure;
|
||||
|
||||
namespace JewelryStoreContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double salary) : IValidation
|
||||
{
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = salary;
|
||||
|
||||
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");
|
||||
|
||||
if (SalaryDate.Date > DateTime.Now)
|
||||
throw new ValidationException($"It is impossible to pay Salary in the future");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Extensions;
|
||||
using JewelryStoreContracts.Infrastructure;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace JewelryStoreContracts.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(-18).Date)
|
||||
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||
|
||||
if (!Regex.IsMatch(FIO, @"^([A-Za-zА-ЯЁ][a-zA-Zа-яё]+)\s+([A-Za-zА-ЯЁ][a-zA-Zа-яё]+)\s+([A-Za-zА-ЯЁ][a-zA-Zа-яё]+)$"))
|
||||
throw new ValidationException("Field FIO must contain exactly three words, each starting with a capital letter.");
|
||||
|
||||
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 < 18)
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace JewelryStoreContracts.Enums;
|
||||
|
||||
[Flags]
|
||||
public enum MaterialType
|
||||
{
|
||||
None = 0,
|
||||
Gold = 1,
|
||||
Silver = 2,
|
||||
Platinum = 4,
|
||||
Palladium = 8,
|
||||
Diamond = 16,
|
||||
Ruby = 32,
|
||||
Sapphire = 64,
|
||||
Emerald = 128,
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace JewelryStoreContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Evaluation = 1,
|
||||
Cutting = 2,
|
||||
Selling = 3,
|
||||
Administrative_work = 4
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace JewelryStoreContracts.Enums;
|
||||
|
||||
public enum ProductType
|
||||
{
|
||||
None = 0,
|
||||
Ring = 1,
|
||||
Necklace = 2,
|
||||
Earrings = 3,
|
||||
Bracelet = 4,
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace JewelryStoreContracts.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace JewelryStoreContracts.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 _);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace JewelryStoreContracts.Infrastructure;
|
||||
|
||||
internal interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
using JewelryStoreContracts.DataModels;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
|
||||
namespace JewelryStoreTests.DataModelTests;
|
||||
[TestFixture]
|
||||
public class CraftDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.Now, 10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
component = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.Now, 10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var component = CreateDataModel("id", Guid.NewGuid().ToString(), DateTime.Now, 10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.Now, 10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.Now, 10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "id", DateTime.Now, 10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AdditionalPriceIsLessOrZeroTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now, -10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now, 0);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CraftDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddDays(5), 0);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var craftId = Guid.NewGuid().ToString();
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var additionalPrice = 10;
|
||||
var date = DateTime.Now;
|
||||
var craft = CreateDataModel(craftId, workerId, date, additionalPrice);
|
||||
Assert.That(() => craft.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(craft.Id, Is.EqualTo(craftId));
|
||||
Assert.That(craft.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(craft.CraftDate, Is.EqualTo(date));
|
||||
Assert.That(craft.AdditionalPrice, Is.EqualTo(additionalPrice));
|
||||
});
|
||||
}
|
||||
|
||||
private static CraftDataModel CreateDataModel(string? id, string? workerId, DateTime craftDate, double additionalParice) =>
|
||||
new(id, workerId, craftDate, additionalParice);
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using JewelryStoreContracts.DataModels;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Enums;
|
||||
|
||||
namespace JewelryStoreTests.DataModelTests;
|
||||
|
||||
class MaterialDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(null, "name", MaterialType.Gold, 15, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
component = CreateDataModel(string.Empty, "name", MaterialType.Gold, 15, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var component = CreateDataModel("id", "name", MaterialType.Gold, 15, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentNameIsEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), null, MaterialType.Diamond, 15, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, MaterialType.Diamond, 15, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentTypeIsNoneTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.None, 15, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.Diamond, 15, -10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.Diamond, 15, 0, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WeightIsLessOrZeroTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.Diamond, -15, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), "name", MaterialType.Diamond, 0, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var componentName = "name";
|
||||
var componentType = MaterialType.Diamond;
|
||||
var componentWeight = 10;
|
||||
var componentPrice = 10;
|
||||
var componentIsDelete = false;
|
||||
var component = CreateDataModel(componentId, componentName, componentType, componentWeight, componentPrice, componentIsDelete);
|
||||
Assert.That(() => component.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(component.Id, Is.EqualTo(componentId));
|
||||
Assert.That(component.MaterialName, Is.EqualTo(componentName));
|
||||
Assert.That(component.MaterialType, Is.EqualTo(componentType));
|
||||
Assert.That(component.Weight, Is.EqualTo(componentWeight));
|
||||
Assert.That(component.Price, Is.EqualTo(componentPrice));
|
||||
Assert.That(component.IsDeleted, Is.EqualTo(componentIsDelete));
|
||||
});
|
||||
}
|
||||
|
||||
private static MaterialDataModel CreateDataModel(string? id, string? name, MaterialType materialType, double weight, double price, bool isDeleted) =>
|
||||
new(id, name, materialType, weight, price, isDeleted);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using JewelryStoreContracts.DataModels;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Enums;
|
||||
|
||||
namespace JewelryStoreTests.DataModelTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Evaluation, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Evaluation, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Evaluation, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Evaluation, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Evaluation, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Evaluation, 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.Evaluation, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Evaluation, 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.Evaluation, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Evaluation, -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.Evaluation;
|
||||
var salary = 100;
|
||||
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.Pay, Is.EqualTo(salary));
|
||||
Assert.That(post.IsActual, Is.EqualTo(isActual));
|
||||
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
||||
});
|
||||
}
|
||||
|
||||
private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
|
||||
new(id, postId, postName, postType, salary, isActual, changeDate);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using JewelryStoreContracts.DataModels;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
|
||||
namespace JewelryStoreTests.DataModelTests;
|
||||
|
||||
[TestFixture]
|
||||
public class ProductComponentDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var ComponentProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => ComponentProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
ComponentProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => ComponentProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var ComponentProduct = CreateDataModel("ProductId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => ComponentProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNullOrEmptyTest()
|
||||
{
|
||||
var ComponentProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => ComponentProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
ComponentProduct = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => ComponentProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNotGuidTest()
|
||||
{
|
||||
var ComponentProduct = CreateDataModel(Guid.NewGuid().ToString(), "ComponentId", 10);
|
||||
Assert.That(() => ComponentProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var ComponentProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => ComponentProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
ComponentProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => ComponentProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var ComponentProduct = CreateDataModel(productId, componentId, count);
|
||||
Assert.That(() => ComponentProduct.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(ComponentProduct.ComponentId, Is.EqualTo(componentId));
|
||||
Assert.That(ComponentProduct.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(ComponentProduct.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductComponentDataModel CreateDataModel(string? productId, string? componentId, int count) =>
|
||||
new(productId, componentId, count);
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using JewelryStoreContracts.DataModels;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
using JewelryStoreContracts.Enums;
|
||||
|
||||
namespace JewelryStoreTests.DataModelTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "name", Guid.NewGuid().ToString(), ProductType.Ring, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, "name", Guid.NewGuid().ToString(), ProductType.Ring, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", "name", Guid.NewGuid().ToString(), ProductType.Ring, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), ProductType.Ring, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), ProductType.Ring, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductTypeIsNoneTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), ProductType.None, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManufacturerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", null, ProductType.Ring, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", string.Empty, ProductType.Ring, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManufacturerIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", "craftId", ProductType.Ring, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", Guid.NewGuid().ToString(), ProductType.Ring, 0, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", Guid.NewGuid().ToString(), ProductType.Ring, -10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentsIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", Guid.NewGuid().ToString(), ProductType.Ring, 0, false, []);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", Guid.NewGuid().ToString(), ProductType.Ring, -10, false, null);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var productName = "name";
|
||||
var productType = ProductType.Bracelet;
|
||||
var craftId = Guid.NewGuid().ToString();
|
||||
var productPrice = 10;
|
||||
var productIsDelete = false;
|
||||
var components = CreateSubDataModel();
|
||||
var product = CreateDataModel(productId, productName, craftId, productType, productPrice, productIsDelete, components);
|
||||
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(product.Id, Is.EqualTo(productId));
|
||||
Assert.That(product.ProductName, Is.EqualTo(productName));
|
||||
Assert.That(product.ProductType, Is.EqualTo(productType));
|
||||
Assert.That(product.CraftId, Is.EqualTo(craftId));
|
||||
Assert.That(product.Price, Is.EqualTo(productPrice));
|
||||
Assert.That(product.IsDeleted, Is.EqualTo(productIsDelete));
|
||||
Assert.That(product.Components, Is.EquivalentTo(components));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductDataModel CreateDataModel(string? id, string? productName, string? craftId, ProductType productType, double price, bool isDeleted, List<ProductComponentDataModel> components) =>
|
||||
new(id, productName, craftId, productType, price, isDeleted, components);
|
||||
|
||||
private static List<ProductComponentDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using JewelryStoreContracts.DataModels;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
|
||||
namespace JewelryStoreTests.DataModelTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductHistoryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, 10);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, 10);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", 10);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OldPriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var oldPrice = 10;
|
||||
var productHistory = CreateDataModel(productId, oldPrice);
|
||||
Assert.That(() => productHistory.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(productHistory.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(productHistory.OldPrice, Is.EqualTo(oldPrice));
|
||||
Assert.That(productHistory.ChangeDate, Is.LessThan(DateTime.UtcNow));
|
||||
Assert.That(productHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductHistoryDataModel CreateDataModel(string? productId, double oldPrice) =>
|
||||
new(productId, oldPrice);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using JewelryStoreContracts.DataModels;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
|
||||
namespace JewelryStoreTests.DataModelTests;
|
||||
|
||||
[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);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
using JewelryStoreContracts.DataModels;
|
||||
using JewelryStoreContracts.Exceptions;
|
||||
|
||||
namespace JewelryStoreTests.DataModelTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WorkerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(null, "Fn Sn Tn", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(string.Empty, "Fn Sn Tn", 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", "Fn Sn Tn", 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 FIOIsIncorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", 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(), "Fn Sn Tn", null, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "Fn Sn Tn", 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(), "Fn Sn Tn", "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(), "Fn Sn Tn", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18).AddDays(1), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "Fn Sn Tn", 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(), "Fn Sn Tn", 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 = "Firstname Secondname Fathername";
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var birthDate = DateTime.Now.AddYears(-18).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);
|
||||
}
|
||||
@@ -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.12.0" />
|
||||
<PackageReference Include="NUnit" Version="4.2.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\JewelryStoreContracts\JewelryStoreContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user