Compare commits

...

4 Commits

37 changed files with 1671 additions and 1 deletions

View File

@ -3,7 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.10.35013.160
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NorthBridgeContract", "NorthBridgeContract\NorthBridgeContract.csproj", "{28744C88-4DE9-429F-83DA-CA3670CE2D70}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NorthBridgeContract", "NorthBridgeContract\NorthBridgeContract.csproj", "{28744C88-4DE9-429F-83DA-CA3670CE2D70}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NorthBridgeTest", "NorthBridgeTest\NorthBridgeTest.csproj", "{0105777C-5918-452B-9321-ECAEB1767753}"
ProjectSection(ProjectDependencies) = postProject
{28744C88-4DE9-429F-83DA-CA3670CE2D70} = {28744C88-4DE9-429F-83DA-CA3670CE2D70}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +20,10 @@ Global
{28744C88-4DE9-429F-83DA-CA3670CE2D70}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28744C88-4DE9-429F-83DA-CA3670CE2D70}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28744C88-4DE9-429F-83DA-CA3670CE2D70}.Release|Any CPU.Build.0 = Release|Any CPU
{0105777C-5918-452B-9321-ECAEB1767753}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0105777C-5918-452B-9321-ECAEB1767753}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0105777C-5918-452B-9321-ECAEB1767753}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0105777C-5918-452B-9321-ECAEB1767753}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,36 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
using System.Text.RegularExpressions;
namespace NorthBridgeContract.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");
if (!Regex.IsMatch(FIO, @"^[А-ЯЁ][а-яё]+(?:-[А-ЯЁ][а-яё]+)?\s[А-ЯЁ][а-яё]+(?:\s[А-ЯЁ][а-яё]+)?$"))
throw new ValidationException("Field FIO is not a fio");
}
}

View File

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

View File

@ -0,0 +1,26 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
namespace NorthBridgeContract.DataModels;
public class ComponentHistoryDataModel(string componentId, double oldPrice) : IValidation
{
public string ComponentId { get; private set; } = componentId;
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public void Validate()
{
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 (OldPrice <= 0)
throw new ValidationException("Field OldPrice is less than or equal to 0");
}
}

View File

@ -0,0 +1,28 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
namespace NorthBridgeContract.DataModels
{
public class ComponentInProductDataModel(string componentId, string productId) : IValidation
{
public string ComponentId { get; private set; } = componentId;
public string ProductId { get; private set;} = productId;
public void Validate()
{
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 (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");
}
}
}

View File

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

View File

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

View File

@ -0,0 +1,47 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
namespace NorthBridgeContract.DataModels;
public class ProductDataModel(string id, string productName, string workerId, bool isDeleted, List<ComponentDataModel> components) : IValidation
{
public string Id { get; private set; } = id;
public string ProductName { get; private set; } = productName;
public string WorkerId { get; private set; } = workerId;
public bool IsDeleted { get; private set; } = isDeleted;
public List<ComponentDataModel> Components { get; private set; } = components;
public double TotalPrice => Components.Sum(x => x.Price);
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 (WorkerId.IsEmpty())
throw new ValidationException("Field ManufacturerId is empty");
if (!WorkerId.IsGuid())
throw new ValidationException("The value in the field ManufacturerId is not a unique identifier");
if (TotalPrice <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
if (TotalPrice != Components.Sum(x => x.Price))
throw new ValidationException("The total price of the components does not match");
if (Components.Count == 0)
throw new ValidationException("At least 1 component is needed");
}
}

View File

@ -0,0 +1,33 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
namespace NorthBridgeContract.DataModels
{
public class ProductOnStorageDataModel(string storageId, string productId, int count) : IValidation
{
public string StorageId { get; private set; } = storageId;
public string ProductId { get; private set; } = productId;
public int Count { get; private set; } = count;
public void Validate()
{
if (StorageId.IsEmpty())
throw new ValidationException("Field StorageId is empty");
if (!StorageId.IsGuid())
throw new ValidationException("The value in the field StorageId 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,32 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
namespace NorthBridgeContract.DataModels
{
public class ProductsInSupplyDataModel(string supplyId, string productId, int count)
{
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 SupplyId is empty");
if (!SupplyId.IsGuid())
throw new ValidationException("The value in the field SupplyId 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,26 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
namespace NorthBridgeContract.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,47 @@
using NorthBridgeContract.Enums;
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
namespace NorthBridgeContract.DataModels;
public class SaleDataModel(string id, string workerId, string? buyerId, double sum, bool isCancel, List<SaleProductDataModel> products) : IValidation
{
public string Id { get; private set; } = id;
public string WorkerId { get; private set; } = workerId;
public string? BuyerId { get; private set; } = buyerId;
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
public double Sum { get; private set; } = sum;
public bool IsCancel { get; private set; } = isCancel;
public List<SaleProductDataModel> Products { get; private set; } = products;
public void Validate()
{
if (Id.IsEmpty())
throw new ValidationException("Field Id is empty");
if (!Id.IsGuid())
throw new ValidationException("The value in the field Id is not a unique identifier");
if (WorkerId.IsEmpty())
throw new ValidationException("Field WorkerId is empty");
if (!WorkerId.IsGuid())
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
if (!BuyerId?.IsGuid() ?? !BuyerId?.IsEmpty() ?? false)
throw new ValidationException("The value in the field BuyerId is not a unique identifier");
if (Sum <= 0)
throw new ValidationException("Field Sum is less than or equal to 0");
if ((Products?.Count ?? 0) == 0)
throw new ValidationException("The sale must include products");
}
}

View File

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

View File

@ -0,0 +1,24 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
namespace NorthBridgeContract.DataModels
{
public class StorageDataModel(string id, string address) : IValidation
{
public string Id { get; private set; } = id;
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 (Address.IsEmpty())
throw new ValidationException("Field Address is empty");
}
}
}

View File

@ -0,0 +1,33 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NorthBridgeContract.DataModels
{
public class SupplyDataModel(string id, string storageId, DateTime date) : IValidation
{
public string Id { get; private set; } = id;
public string StorageId { get; private set; } = storageId;
public DateTime Date { get; private set; } = date;
public void Validate()
{
if (StorageId.IsEmpty())
throw new ValidationException("Field StorageId is empty");
if (!StorageId.IsGuid())
throw new ValidationException("The value in the field StorageId is not a unique identifier");
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");
}
}
}

View File

@ -0,0 +1,47 @@
using NorthBridgeContract.Exceptions;
using NorthBridgeContract.Extensions;
using NorthBridgeContract.Infrastructure;
namespace NorthBridgeContract.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,14 @@
namespace NorthBridgeContract.Enums;
public enum ComponentType
{
None = 0,
GraphicsCard = 1,
Motherboard = 2,
RAM = 3,
Storage = 4,
PowerSupply = 5,
CoolingSystem = 6,
Case = 7,
Processor = 8
}

View File

@ -0,0 +1,9 @@
namespace NorthBridgeContract.Enums;
public enum PostType
{
None = 0,
Supervisor = 1,
CashierConsultant = 2,
Assistant = 3
}

View File

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

View File

@ -0,0 +1,14 @@
namespace NorthBridgeContract.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,8 @@
using NorthBridgeContract.Exceptions;
namespace NorthBridgeContract.Infrastructure;
public interface IValidation
{
void Validate();
}

View File

@ -0,0 +1,69 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests;
[TestFixture]
internal class BuyerDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var buyer = CreateDataModel(null, "Иванов Иван Иванович", "number");
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
buyer = CreateDataModel(string.Empty, "Иванов Иван Иванович", "number");
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var buyer = CreateDataModel("id", "Иванов Иван Иванович", "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(), "Иванов Иван Иванович", null);
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
buyer = CreateDataModel(Guid.NewGuid().ToString(), "Иванов Иван Иванович", string.Empty);
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PhoneNumberIsIncorrectTest()
{
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "Иванов Иван Иванович", "777");
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var buyerId = Guid.NewGuid().ToString();
var 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,91 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Enums;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests;
[TestFixture]
internal class ComponentDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var component = CreateDataModel(null, "name", ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
component = CreateDataModel(string.Empty, "name", ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var component = CreateDataModel("id", "name", ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ComponentNameIsEmptyTest()
{
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ComponentTypeIsNoneTest()
{
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.None, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ManufacturerIdIsNullOrEmptyTest()
{
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, null, 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, string.Empty, 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ManufacturerIdIsNotGuidTest()
{
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, "manufacturerId", 10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, Guid.NewGuid().ToString(), 0, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, Guid.NewGuid().ToString(), -10, false);
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var componentId = Guid.NewGuid().ToString();
var componentName = "name";
var componentType = ComponentType.Processor;
var componentManufacturerId = Guid.NewGuid().ToString();
var componentPrice = 10;
var componentIsDelete = false;
var component = CreateDataModel(componentId, componentName, componentType, componentManufacturerId, componentPrice, componentIsDelete);
Assert.That(() => component.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(component.Id, Is.EqualTo(componentId));
Assert.That(component.ComponentName, Is.EqualTo(componentName));
Assert.That(component.ComponentType, Is.EqualTo(componentType));
Assert.That(component.ManufacturerId, Is.EqualTo(componentManufacturerId));
Assert.That(component.Price, Is.EqualTo(componentPrice));
Assert.That(component.IsDeleted, Is.EqualTo(componentIsDelete));
});
}
private static ComponentDataModel CreateDataModel(string? id, string? componentName, ComponentType componentType, string? manufacturerId, double price, bool isDeleted) =>
new(id, componentName, componentType, manufacturerId, price, isDeleted);
}

View File

@ -0,0 +1,52 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests;
[TestFixture]
internal class ComponentHistoryDataModelTests
{
[Test]
public void ComponentIdIsNullOrEmptyTest()
{
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 ComponentIdIsNotGuidTest()
{
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 componentId = Guid.NewGuid().ToString();
var oldPrice = 10;
var productHistory = CreateDataModel(componentId, oldPrice);
Assert.That(() => productHistory.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(productHistory.ComponentId, Is.EqualTo(componentId));
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 ComponentHistoryDataModel CreateDataModel(string? componentId, double oldPrice) =>
new(componentId, oldPrice);
}

View File

@ -0,0 +1,63 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
using NUnit.Framework;
using System;
namespace NorthBridgeTest.DataModelsTests
{
[TestFixture]
internal class ComponentInProductDataModelTests
{
[Test]
public void ComponentIdIsNullOrEmptyTest()
{
var componentInProduct = CreateDataModel(null, Guid.NewGuid().ToString());
Assert.That(() => componentInProduct.Validate(), Throws.TypeOf<ValidationException>());
componentInProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString());
Assert.That(() => componentInProduct.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ComponentIdIsNotGuidTest()
{
var componentInProduct = CreateDataModel("invalid_id", Guid.NewGuid().ToString());
Assert.That(() => componentInProduct.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNullOrEmptyTest()
{
var componentInProduct = CreateDataModel(Guid.NewGuid().ToString(), null);
Assert.That(() => componentInProduct.Validate(), Throws.TypeOf<ValidationException>());
componentInProduct = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
Assert.That(() => componentInProduct.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNotGuidTest()
{
var componentInProduct = CreateDataModel(Guid.NewGuid().ToString(), "invalid_id");
Assert.That(() => componentInProduct.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var componentId = Guid.NewGuid().ToString();
var productId = Guid.NewGuid().ToString();
var componentInProduct = CreateDataModel(componentId, productId);
Assert.That(() => componentInProduct.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(componentInProduct.ComponentId, Is.EqualTo(componentId));
Assert.That(componentInProduct.ProductId, Is.EqualTo(productId));
});
}
private static ComponentInProductDataModel CreateDataModel(string? componentId, string? productId) =>
new(componentId, productId);
}
}

View File

@ -0,0 +1,54 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests;
[TestFixture]
internal class ManufacturerDataModelTests
{
[Test]
public void IdIsNullEmptyTest()
{
var manufacturer = CreateDataModel(null, "name");
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
manufacturer = CreateDataModel(string.Empty, "name");
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var manufacturer = CreateDataModel("id", "name");
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ManufacturerNameIsNullOrEmptyTest()
{
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null);
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var manufacturerId = Guid.NewGuid().ToString();
var manufacturerName = "name";
var prevManufacturerName = "prevManufacturerName";
var prevPrevManufacturerName = "prevPrevManufacturerName";
var manufacturer = CreateDataModel(manufacturerId, manufacturerName, prevManufacturerName, prevPrevManufacturerName);
Assert.That(() => manufacturer.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(manufacturer.Id, Is.EqualTo(manufacturerId));
Assert.That(manufacturer.ManufacturerName, Is.EqualTo(manufacturerName));
Assert.That(manufacturer.PrevManufacturerName, Is.EqualTo(prevManufacturerName));
Assert.That(manufacturer.PrevPrevManufacturerName, Is.EqualTo(prevPrevManufacturerName));
});
}
private static ManufacturerDataModel CreateDataModel(string? id, string? manufacturerName, string? prevManufacturerName = null, string? prevPrevManufacturerName = null) =>
new(id, manufacturerName, prevManufacturerName, prevPrevManufacturerName);
}

View File

@ -0,0 +1,93 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Enums;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests;
[TestFixture]
internal class PostDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Assistant, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Assistant, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Assistant, 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.Assistant, 10, true, DateTime.UtcNow);
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Assistant, 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.Assistant, 0, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Assistant, -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.Assistant;
var salary = 10;
var isActual = false;
var changeDate = DateTime.UtcNow.AddDays(-1);
var post = CreateDataModel(postId, postPostId, postName, postType, salary, isActual, changeDate);
Assert.That(() => post.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(post.Id, Is.EqualTo(postId));
Assert.That(post.PostId, Is.EqualTo(postPostId));
Assert.That(post.PostName, Is.EqualTo(postName));
Assert.That(post.PostType, Is.EqualTo(postType));
Assert.That(post.Salary, Is.EqualTo(salary));
Assert.That(post.IsActual, Is.EqualTo(isActual));
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
});
}
private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
new(id, postId, postName, postType, salary, isActual, changeDate);
}

View File

@ -0,0 +1,75 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Enums;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests
{
[TestFixture]
internal class ProductDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var product = CreateDataModel(null, "Processor", Guid.NewGuid().ToString(), false, new List<ComponentDataModel> { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) });
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(string.Empty, "Processor", Guid.NewGuid().ToString(), false, new List<ComponentDataModel> { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) });
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var product = CreateDataModel("id", "Processor", Guid.NewGuid().ToString(), false, new List<ComponentDataModel> { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) });
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductNameIsNullOrEmptyTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), false, new List<ComponentDataModel> { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) });
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), false, new List<ComponentDataModel> { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) });
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNullOrEmptyTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", null, false, new List<ComponentDataModel> { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) });
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", string.Empty, false, new List<ComponentDataModel> { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) });
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", "workerId", false, new List<ComponentDataModel> { new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false) });
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ComponentsAreNullOrEmptyTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", Guid.NewGuid().ToString(), false, null);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", Guid.NewGuid().ToString(), false, new List<ComponentDataModel>());
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void TotalPriceIsIncorrectTest()
{
var components = new List<ComponentDataModel>
{
new ComponentDataModel(Guid.NewGuid().ToString(), "CPU", ComponentType.Processor, Guid.NewGuid().ToString(), 200, false),
new ComponentDataModel(Guid.NewGuid().ToString(), "GPU", ComponentType.GraphicsCard, Guid.NewGuid().ToString(), 300, false)
};
var product = CreateDataModel(Guid.NewGuid().ToString(), "Processor", Guid.NewGuid().ToString(), false, components);
Assert.That(product.TotalPrice, Is.EqualTo(500));
}
private static ProductDataModel CreateDataModel(string? id, string? productName, string? workerId, bool isDeleted, List<ComponentDataModel>? components) =>
new(id, productName, workerId, isDeleted, components ?? new List<ComponentDataModel>());
}
}

View File

@ -0,0 +1,71 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NorthBridgeTest.DataModelsTests
{
[TestFixture]
internal class ProductOnStorageDataModelTests
{
[Test]
public void StorageIdIsNullOrEmptyTest()
{
var productStorage = new ProductOnStorageDataModel(null, Guid.NewGuid().ToString(), 1);
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
productStorage = new ProductOnStorageDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StorageIdIsNotGuidTest()
{
var productStorage = new ProductOnStorageDataModel("id", Guid.NewGuid().ToString(), 1);
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNullOrEmptyTest()
{
var productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), null, 1);
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNotGuidTest()
{
var productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), "id", 1);
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessThanOrEqualToZeroTest()
{
var productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
productStorage = new ProductOnStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
Assert.That(() => productStorage.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var storageId = Guid.NewGuid().ToString();
var productId = Guid.NewGuid().ToString();
var count = 5;
var productStorage = new ProductOnStorageDataModel(storageId, productId, count);
Assert.That(() => productStorage.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(productStorage.StorageId, Is.EqualTo(storageId));
Assert.That(productStorage.ProductId, Is.EqualTo(productId));
Assert.That(productStorage.Count, Is.EqualTo(count));
});
}
}
}

View File

@ -0,0 +1,70 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests
{
[TestFixture]
internal class ProductsInSupplyDataModelTests
{
[Test]
public void SupplyIdIsNullOrEmptyTest()
{
var productSupply = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
productSupply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SupplyIdIsNotGuidTest()
{
var productSupply = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNullOrEmptyTest()
{
var productSupply = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
productSupply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNotGuidTest()
{
var productSupply = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessThanOrEqualToZeroTest()
{
var productSupply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
productSupply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var supplyId = Guid.NewGuid().ToString();
var productId = Guid.NewGuid().ToString();
var count = 5;
var productSupply = CreateDataModel(supplyId, productId, count);
Assert.That(() => productSupply.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(productSupply.SupplyId, Is.EqualTo(supplyId));
Assert.That(productSupply.ProductId, Is.EqualTo(productId));
Assert.That(productSupply.Count, Is.EqualTo(count));
});
}
private static ProductsInSupplyDataModel CreateDataModel(string? supplyId, string? productId, int count) =>
new(supplyId, productId, count);
}
}

View File

@ -0,0 +1,52 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests;
[TestFixture]
internal class SalaryDataModelTests
{
[Test]
public void WorkerIdIsEmptyTest()
{
var salary = CreateDataModel(null, DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
var salary = CreateDataModel("workerId", DateTime.Now, 10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var workerId = Guid.NewGuid().ToString();
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
var workerSalary = 10;
var salary = CreateDataModel(workerId, salaryDate, workerSalary);
Assert.That(() => salary.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(salary.WorkerId, Is.EqualTo(workerId));
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
Assert.That(salary.Salary, Is.EqualTo(workerSalary));
});
}
private static SalaryDataModel CreateDataModel(string? workerId, DateTime salaryDate, double workerSalary) =>
new(workerId, salaryDate, workerSalary);
}

View File

@ -0,0 +1,93 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Enums;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests;
[TestFixture]
internal class SaleDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNullOrEmptyTest()
{
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void WorkerIdIsNotGuidTest()
{
var sale = CreateDataModel(Guid.NewGuid().ToString(), "workerId", Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BuyerIdIsNotGuidTest()
{
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", 10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SumIsLessOrZeroTest()
{
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, false, CreateSubDataModel());
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductsIsNullOrEmptyTest()
{
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, null);
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, []);
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var saleId = Guid.NewGuid().ToString();
var workerId = Guid.NewGuid().ToString();
var buyerId = Guid.NewGuid().ToString();
var sum = 10;
var isCancel = true;
var products = CreateSubDataModel();
var sale = CreateDataModel(saleId, workerId, buyerId, sum, isCancel, products);
Assert.That(() => sale.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(sale.Id, Is.EqualTo(saleId));
Assert.That(sale.WorkerId, Is.EqualTo(workerId));
Assert.That(sale.BuyerId, Is.EqualTo(buyerId));
Assert.That(sale.Sum, Is.EqualTo(sum));
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
Assert.That(sale.Products, Is.EquivalentTo(products));
});
}
private static SaleDataModel CreateDataModel(string? id, string? workerId, string? buyerId, double sum, bool isCancel, List<SaleProductDataModel>? products) =>
new(id, workerId, buyerId, sum, isCancel, products);
private static List<SaleProductDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

View File

@ -0,0 +1,68 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests;
[TestFixture]
internal class SaleProductDataModelTests
{
[Test]
public void SaleIdIsNullOrEmptyTest()
{
var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SaleIdIsNotGuidTest()
{
var saleProduct = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10);
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNullOrEmptyTest()
{
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNotGuidTest()
{
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10);
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var saleId = Guid.NewGuid().ToString();
var productId = Guid.NewGuid().ToString();
var count = 10;
var saleProduct = CreateDataModel(saleId, productId, count);
Assert.That(() => saleProduct.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(saleProduct.SaleId, Is.EqualTo(saleId));
Assert.That(saleProduct.ProductId, Is.EqualTo(productId));
Assert.That(saleProduct.Count, Is.EqualTo(count));
});
}
private static SaleProductDataModel CreateDataModel(string? saleId, string? productId, int count) =>
new(saleId, productId, count);
}

View File

@ -0,0 +1,51 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests
{
[TestFixture]
internal class StorageDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var storage = CreateDataModel(null, "ул. Ленина, д. 10");
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
storage = CreateDataModel(string.Empty, "ул. Ленина, д. 10");
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var storage = CreateDataModel("id", "ул. Ленина, д. 10");
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AddressIsNullOrEmptyTest()
{
var storage = CreateDataModel(Guid.NewGuid().ToString(), null);
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
storage = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var storageId = Guid.NewGuid().ToString();
var address = "ул. Ленина, д. 10";
var storage = CreateDataModel(storageId, address);
Assert.That(() => storage.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(storage.Id, Is.EqualTo(storageId));
Assert.That(storage.Address, Is.EqualTo(address));
});
}
private static StorageDataModel CreateDataModel(string? id, string? address) =>
new(id, address);
}
}

View File

@ -0,0 +1,60 @@
using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests
{
[TestFixture]
internal class SupplyDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var supply = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.Now);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.Now);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var supply = CreateDataModel("id", Guid.NewGuid().ToString(), DateTime.Now);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StorageIdIsNullOrEmptyTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.Now);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.Now);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StorageIdIsNotGuidTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), "id", DateTime.Now);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var supplyId = Guid.NewGuid().ToString();
var storageId = Guid.NewGuid().ToString();
var date = DateTime.Now;
var supply = CreateDataModel(supplyId, storageId, date);
Assert.That(() => supply.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(supply.Id, Is.EqualTo(supplyId));
Assert.That(supply.StorageId, Is.EqualTo(storageId));
Assert.That(supply.Date, Is.EqualTo(date));
});
}
private static SupplyDataModel CreateDataModel(string? id, string? storageId, DateTime date) =>
new(id, storageId, date);
}
}

View File

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

View File

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