Compare commits

...

4 Commits

Author SHA1 Message Date
Anitonchik
9177ab1014 иииууууу 2025-02-18 14:19:03 +04:00
Anitonchik
094c7f18f6 базовая 2025-02-13 16:45:43 +04:00
Anitonchik
cc66aa935e ииииууууу 2025-02-13 12:34:39 +04:00
Anitonchik
a642c1f2b9 ыбыб 2025-02-11 15:38:49 +04:00
29 changed files with 1317 additions and 1 deletions

View File

@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35707.178 d17.12
VisualStudioVersion = 17.12.35707.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WildPlum", "WildPlum\WildPlum.csproj", "{07BA0D97-C05C-4E48-9661-A5F7FD5EAC46}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WildPlumTests", "WildPlumTests\WildPlumTests.csproj", "{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{07BA0D97-C05C-4E48-9661-A5F7FD5EAC46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07BA0D97-C05C-4E48-9661-A5F7FD5EAC46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07BA0D97-C05C-4E48-9661-A5F7FD5EAC46}.Release|Any CPU.Build.0 = Release|Any CPU
{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Xml;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace WildPlum.DataModels;
public class BuyerDataModel(string id, string fio, string phoneNumber) : IValidation
{
public string Id { get; private set; } = id;
public string FIO { get; private set; } = fio;
public string PhoneNumber { get; private set; } = phoneNumber;
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 (PhoneNumber.IsEmpty())
throw new ValidationException("Field PhoneNumber is empty");
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\-]?)?[\d\- ]{7,10}$"))
throw new ValidationException("Field PhoneNumber is not a phone number");
}
}

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using WildPlum.Enums;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
namespace WildPlum.DataModels;
public class JobTitleDataModel(string id, string postId, string postName, JobTitleType jobTitleType, 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 JobTitleType JobTitleType { get; private set; } = jobTitleType;
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 (JobTitleType == JobTitleType.None)
throw new ValidationException("Field PostType is empty");
if (Salary <= 0)
throw new ValidationException("Field Salary is empty");
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
namespace WildPlum.DataModels;
public class OrderDataModel (string id, string buyerId, string workerId, int price, DateTime dateStart, DateTime dateEnd, List<OrderProductDataModel> products) : IValidation
{
public string Id { get; private set; } = id;
public string BuyerId { get; private set; } = buyerId;
public string WorkerId { get; private set; } = workerId;
public int Price { get; private set; } = price;
public DateTime DateStart { get; private set; } = dateStart;
public DateTime DateEnd { get; private set; } = dateEnd;
public List<OrderProductDataModel> 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 (BuyerId.IsEmpty())
throw new ValidationException("Field BuyerId is empty");
if (!BuyerId.IsGuid())
throw new ValidationException("The value in the field BuyerId 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 (DateEnd < DateStart)
throw new ValidationException("The end date of the order cannot be less than the start date");
if ((Products?.Count ?? 0) == 0)
throw new ValidationException("The sale must include products");
}
}

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
namespace WildPlum.DataModels;
public class OrderProductDataModel (string orderId, string productId, int count) : IValidation
{
public string OrderId { get; private set; } = orderId;
public string ProductId { get; private set; } = productId;
public int Count { get; private set; } = count;
public void Validate()
{
if (OrderId.IsEmpty())
throw new ValidationException("Field OrderId is empty");
if (!OrderId.IsGuid())
throw new ValidationException("The value in the field OrderId 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 Id 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,34 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using WildPlum.Enums;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
namespace WildPlum.DataModels;
public class ProductDataModel (string id, string productName, ProductType productType, 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 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 (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
namespace WildPlum.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 System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
namespace WildPlum.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,32 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
namespace WildPlum.DataModels;
public class SupplyDataModel(string id, string warehouseId, DateTime date, List<SupplyProductDataModel> products) : IValidation
{
public string Id { get; private set; } = id;
public string WarehouseId { get; private set; } = warehouseId;
public DateTime Date { get; private set; } = date;
public List<SupplyProductDataModel> 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 (WarehouseId.IsEmpty())
throw new ValidationException("Field WarehouseId is empty");
if (!WarehouseId.IsGuid())
throw new ValidationException("The value in the field WarehouseId is not a unique identifier");
if ((Products?.Count ?? 0) == 0)
throw new ValidationException("The sale must include products");
}
}

View File

@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
namespace WildPlum.DataModels;
public class SupplyProductDataModel(string supplyId, string productId, int count) : IValidation
{
public string SupplyId { get; private set; } = supplyId;
public string ProductId { get; private set; } = productId;
public int Count { get; private set; } = count;
public void Validate()
{
if (SupplyId.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!SupplyId.IsGuid())
throw new ValidationException("The value in the field Id 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,30 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
namespace WildPlum.DataModels;
public class WarehouseDataModel(string id, string name, string address) : IValidation
{
public string Id { get; private set; } = id;
public string Name { get; private set; } = name;
public string Address { get; private set; } = address;
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 (Name.IsEmpty())
throw new ValidationException("Field Name is empty");
if (Address.IsEmpty())
throw new ValidationException("Field Adress is empty");
}
}

View File

@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using WildPlum.Extensions;
using WildPlum.Infrastructure;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace WildPlum.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,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WildPlum.Enums;
public enum JobTitleType
{
None = 0,
Operator = 1,
Delivaryman = 2,
Loader = 3
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WildPlum.Enums;
public enum ProductType
{
None = 0,
Cloth = 1,
Shoes = 2,
Toy = 3,
Office = 4
}

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WildPlum.Exceptions;
public class ValidationException(string message) : Exception(message)
{
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WildPlum.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 WildPlum.Infrastructure;
public interface IValidation
{
void Validate();
}

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
public class BuyerDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var buyer = CreateDataModel(null, "fio", "number");
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
buyer = CreateDataModel(string.Empty, "fio", "number");
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var buyer = CreateDataModel("id", "fio", "number");
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void FIOIsNullOrEmptyTest()
{
var buyer = CreateDataModel(Guid.NewGuid().ToString(), null, "number");
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
buyer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number");
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PhoneNumberIsNullOrEmptyTest()
{
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", null);
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty);
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PhoneNumberIsIncorrectTest()
{
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777");
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var buyerId = Guid.NewGuid().ToString();
var fio = "Fio";
var phoneNumber = "+7-777-777-77-77";
var buyer = CreateDataModel(buyerId, fio, phoneNumber);
Assert.That(() => buyer.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(buyer.Id, Is.EqualTo(buyerId));
Assert.That(buyer.FIO, Is.EqualTo(fio));
Assert.That(buyer.PhoneNumber, Is.EqualTo(phoneNumber));
});
}
private static BuyerDataModel CreateDataModel(string? id, string? fio, string? phoneNumber) => new(id, fio, phoneNumber);
}

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
using WildPlum.Enums;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
public class JobTitleDateModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", JobTitleType.Delivaryman, 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, JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, JobTitleType.Delivaryman, 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", JobTitleType.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", JobTitleType.Delivaryman, 0, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", JobTitleType.Delivaryman, -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 = JobTitleType.Delivaryman;
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.JobTitleType, 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 JobTitleDataModel CreateDataModel(string? id, string? postId, string? postName, JobTitleType jobTitleType, double salary, bool isActual, DateTime
changeDate) => new(id, postId, postName, jobTitleType, salary, isActual, changeDate);
}

View File

@ -0,0 +1,107 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
using WildPlum.Enums;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
public class OrderDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var order = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("1", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BuyerIdIsNullOrEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BuyerIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "1", Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNullOrEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(),Guid.NewGuid().ToString(), "1", 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StartDateAndEndDateIsNotCorrect()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow.AddDays(2), DateTime.UtcNow, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductsIsNullOrEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(2), null);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(2), []);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var id = Guid.NewGuid().ToString();
var buyerId = Guid.NewGuid().ToString();
var workerId = Guid.NewGuid().ToString();
var price = 10;
var dateStart = DateTime.UtcNow;
var dateEnd = DateTime.UtcNow.AddDays(2);
var products = CreateSubDataModel();
var order = CreateDataModel(id, buyerId, workerId, price, dateStart, dateEnd, products);
Assert.That(() => order.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(order.Id, Is.EqualTo(id));
Assert.That(order.BuyerId, Is.EqualTo(buyerId));
Assert.That(order.WorkerId, Is.EqualTo(workerId));
Assert.That(order.Price, Is.EqualTo(price));
Assert.That(order.DateStart, Is.EqualTo(dateStart));
Assert.That(order.DateEnd, Is.EqualTo(dateEnd));
Assert.That(order.Products, Is.EqualTo(products));
});
}
private static OrderDataModel CreateDataModel(string? id, string? buyerId, string? workerId, int price,
DateTime dateStart, DateTime dateEnd, List<OrderProductDataModel> products) => new(id, buyerId, workerId, price, dateStart, dateEnd, products);
private static List<OrderProductDataModel> CreateSubDataModel() => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
internal class OrderProductDataModelTests
{
[Test]
public void OrderIdIsNullOrEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel( Guid.NewGuid().ToString(), string.Empty, 1);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void OrderIdIsNotGuidTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNullOrEmptyTest()
{
var product = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNotGuidTest()
{
var product = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountNotCorrectTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var orderId = Guid.NewGuid().ToString();
var productId = Guid.NewGuid().ToString();
var count = 10;
var orderProduct = CreateDataModel(orderId, productId, count);
Assert.That(() => orderProduct.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(orderProduct.OrderId, Is.EqualTo(orderId));
Assert.That(orderProduct.ProductId, Is.EqualTo(productId));
Assert.That(orderProduct.Count, Is.EqualTo(count));
});
}
private static OrderProductDataModel CreateDataModel(string? orderId, string? productId, int count) =>
new(orderId, productId, count);
}

View File

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
using WildPlum.Enums;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
internal class ProductDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var product = CreateDataModel(null, "name", ProductType.Cloth, 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(string.Empty, "name", ProductType.Cloth, 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var product = CreateDataModel("id", "name", ProductType.Cloth, 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductNameIsEmptyTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Cloth, 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Cloth, 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductTypeIsNoneTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Cloth, 0, false);
Assert.That(() => product.Validate(),
Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Cloth, -10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var productId = Guid.NewGuid().ToString();
var productName = "name";
var productType = ProductType.Cloth;
var productPrice = 10;
var productIsDelete = false;
var product = CreateDataModel(productId, productName, productType, productPrice, productIsDelete);
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.Price, Is.EqualTo(productPrice));
Assert.That(product.IsDeleted, Is.EqualTo(productIsDelete));
});
}
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType,
double price, bool isDeleted) => new(id, productName, productType, price, isDeleted);
}

View File

@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
public 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);
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
public 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,78 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
internal class SupplyDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var supply = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.UtcNow, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.UtcNow, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var supply = CreateDataModel("id", Guid.NewGuid().ToString(), DateTime.UtcNow, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WarehouseIdIsNullOrEmptyTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.UtcNow, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.UtcNow, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WarehouseIdIsNotGuidTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), "warehouseId", DateTime.UtcNow, CreateSubDataModel());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductsIsNullOrEmptyTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, null);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, []);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var id = Guid.NewGuid().ToString();
var warehouseId = Guid.NewGuid().ToString();
var date = DateTime.UtcNow;
var products = CreateSubDataModel();
var supply = CreateDataModel(id, warehouseId, date, products);
Assert.That(() => supply.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(supply.Id, Is.EqualTo(id));
Assert.That(supply.WarehouseId, Is.EqualTo(warehouseId));
Assert.That(supply.Date, Is.EqualTo(date));
Assert.That(supply.Products, Is.EqualTo(products));
});
}
private static SupplyDataModel CreateDataModel(string? id, string? warehouseId, DateTime date, List<SupplyProductDataModel> products) =>
new (id, warehouseId, date, products);
private static List<SupplyProductDataModel> CreateSubDataModel() => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

View File

@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
internal class SupplyProductDataModelTests
{
[Test]
public void SupplyIdIsNullOrEmptyTest()
{
var supply = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SupplyIdIsNotGuidTest()
{
var supply = CreateDataModel("supplyId", Guid.NewGuid().ToString(), 10);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNullOrEmptyTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNotGuidTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountNotCorrectTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var supplyId = Guid.NewGuid().ToString();
var productId = Guid.NewGuid().ToString();
var count = 10;
var supplyProduct = CreateDataModel(supplyId, productId, count);
Assert.That(() => supplyProduct.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(supplyProduct.SupplyId, Is.EqualTo(supplyId));
Assert.That(supplyProduct.ProductId, Is.EqualTo(productId));
Assert.That(supplyProduct.Count, Is.EqualTo(count));
});
}
private static SupplyProductDataModel CreateDataModel(string? id, string? productId, int count) =>
new(id, productId, count);
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
namespace WildPlumTests.DataModelsTests;
[TestFixture]
internal class WarehouseDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var warehouse = CreateDataModel(null, "name", "address");
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
warehouse = CreateDataModel(string.Empty, "name", "address");
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var warehouse = CreateDataModel("id", "name", "address");
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void NameIsNullOrEmptyTest()
{
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), null, "address");
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
warehouse = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "address");
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AddressIsNullOrEmptyTest()
{
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), "name", null);
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
warehouse = CreateDataModel(Guid.NewGuid().ToString(), "name", string.Empty);
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
}
private static WarehouseDataModel CreateDataModel(string? id, string? name, string? adress) =>
new(id, name, adress);
}

View File

@ -0,0 +1,99 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WildPlum.DataModels;
namespace WildPlumTests.DataModelsTests;
public 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);
}

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.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="..\WildPlum\WildPlum.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>