Compare commits
2 Commits
main
...
Task_1_Mod
Author | SHA1 | Date | |
---|---|---|---|
|
eb608f757a | ||
|
c61315f4a1 |
@ -0,0 +1,39 @@
|
||||
using NorthBridgeContracts.Enums;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.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 ComponentName is empty");
|
||||
if (ComponentType == ComponentType.None)
|
||||
throw new ValidationException("Field ComponentType 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");
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.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");
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
using System.Text.RegularExpressions;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class CustomerDataModel(string id, string fio, string phone, string email, double discountSize) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string Phone { get; private set; } = phone;
|
||||
public string Email { get; private set; } = email;
|
||||
public double DiscountSize { get; private set; } = discountSize;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty");
|
||||
if (Phone.IsEmpty()) throw new ValidationException("Field Phone is empty");
|
||||
|
||||
var phoneRegex = new Regex(@"^\+7\d{10}$");
|
||||
if (!phoneRegex.IsMatch(Phone)) throw new ValidationException("Invalid phone format");
|
||||
|
||||
if (Email.IsEmpty() || !Email.Contains("@")) throw new ValidationException("Invalid email format");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.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 isempty");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,44 @@
|
||||
using NorthBridgeContracts.Enums;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.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;
|
||||
|
||||
/// <summary>
|
||||
/// Когда эта запись была изменена
|
||||
/// </summary>
|
||||
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 PostName is empty");
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace NorthBridgeContracts.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");
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using NorthBridgeContracts.Enums;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.DataModels;
|
||||
|
||||
public class SaleDataModel(string id, string workerId, string? customerId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleProductDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
public string? CustomerId { get; private set; } = customerId;
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
public double Sum { get; private set; } = sum;
|
||||
public DiscountType DiscountType { get; private set; } = discountType;
|
||||
public double Discount { get; private set; } = discount;
|
||||
public bool IsCancel { get; private set; } = isCancel;
|
||||
public List<SaleProductDataModel> Products { get; private set; } =
|
||||
products;
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
if (!CustomerId?.IsGuid() ?? !CustomerId?.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");
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NorthBridgeContracts.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");
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using NorthBridgeContracts.Extensions;
|
||||
using NorthBridgeContracts.Infrastructure;
|
||||
|
||||
namespace NorthBridgeContracts.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 caanot be less than the date of birth");
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
namespace NorthBridgeContracts.Enums;
|
||||
|
||||
public enum ComponentType
|
||||
{
|
||||
None = 0, // Не указано
|
||||
Motherboard = 1, // Мать
|
||||
Processor = 2, // Процессор
|
||||
Ram = 3, // Оперативка
|
||||
PowerUnit = 4, // БП
|
||||
GraphicsCard = 5, // Видюха
|
||||
SVO = 6, // Система Воздушного Охлаждения (кулеры)
|
||||
SJO = 7, // Система ЖИДкостного Охлаждения
|
||||
Case = 8, // Кейс
|
||||
Storage = 9, // Накопитель (SSD и HDD)
|
||||
Monitor = 10, // Монитор
|
||||
Peripheral = 11 // Периферия (мышки клавы уши, крч I/O Devices)
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
namespace NorthBridgeContracts.Enums;
|
||||
|
||||
|
||||
[Flags]
|
||||
public enum DiscountType
|
||||
{
|
||||
None = 0, // Без скидки
|
||||
SeasonalSale = 1, // Сезонная распродажа
|
||||
LoyaltyProgram = 2, // Программа ноу лоялти ноу роялти
|
||||
BundleDiscount = 4, // Скидка за комплект
|
||||
PromoCode = 8 // Скидка по промокоду
|
||||
}
|
10
NorthBridgeProject/NorthBridgeContracts/Enums/PostType.cs
Normal file
10
NorthBridgeProject/NorthBridgeContracts/Enums/PostType.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace NorthBridgeContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0, // Не указано
|
||||
Manager = 1, // Менеджер (административная должность)
|
||||
SalesSpecialist = 2, // Специалист по продажам
|
||||
TechnicalSpecialist = 3, // Технический специалист
|
||||
StockmanDNS = 4 // Кладовщик
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
namespace NorthBridgeContracts.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
namespace NorthBridgeContracts.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static bool IsEmpty(this string str)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
public static bool IsGuid(this string str)
|
||||
{
|
||||
return Guid.TryParse(str, out _);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace NorthBridgeContracts.Infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
8
NorthBridgeProject/NorthBridgeContracts/Program.cs
Normal file
8
NorthBridgeProject/NorthBridgeContracts/Program.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace NorthBridgeContracts;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
}
|
||||
}
|
@ -1,10 +1,12 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.13.35806.99 d17.13
|
||||
VisualStudioVersion = 17.13.35806.99
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NorthBridgeContracts", "NorthBridgeContracts\NorthBridgeContracts.csproj", "{5D0CC2D9-4A29-4E1E-ACE0-45B3E79C9A84}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NorthBridgeTests", "NorthBridgeTests\NorthBridgeTests.csproj", "{D12DDAC8-166D-49A8-A926-7C7048EF98C4}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{5D0CC2D9-4A29-4E1E-ACE0-45B3E79C9A84}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{5D0CC2D9-4A29-4E1E-ACE0-45B3E79C9A84}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{5D0CC2D9-4A29-4E1E-ACE0-45B3E79C9A84}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D12DDAC8-166D-49A8-A926-7C7048EF98C4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D12DDAC8-166D-49A8-A926-7C7048EF98C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D12DDAC8-166D-49A8-A926-7C7048EF98C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D12DDAC8-166D-49A8-A926-7C7048EF98C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,97 @@
|
||||
using NorthBridgeContracts.DataModels;
|
||||
using NorthBridgeContracts.Enums;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
|
||||
namespace NorthBridgeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ComponentDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(null, "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
component = CreateDataModel(string.Empty, "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var component = CreateDataModel("not-a-guid", "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentNameIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentTypeIsNoneTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.None, Guid.NewGuid().ToString(), 100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManufacturerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, null, 100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, string.Empty, 100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManufacturerIdIsNotGuidTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, "not-a-guid", 100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrEqualToZeroTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), 0, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), -100, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var componentName = "ComponentName";
|
||||
var componentType = ComponentType.Motherboard;
|
||||
var manufacturerId = Guid.NewGuid().ToString();
|
||||
var price = 100.0;
|
||||
var isDeleted = false;
|
||||
|
||||
var component = CreateDataModel(componentId, componentName, componentType, manufacturerId, price, isDeleted);
|
||||
|
||||
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(manufacturerId));
|
||||
Assert.That(component.Price, Is.EqualTo(price));
|
||||
Assert.That(component.IsDeleted, Is.EqualTo(isDeleted));
|
||||
});
|
||||
}
|
||||
|
||||
private static ComponentDataModel CreateDataModel(string? id, string? componentName, ComponentType componentType, string? manufacturerId, double price, bool isDeleted) =>
|
||||
new(id, componentName, componentType, manufacturerId, price, isDeleted);
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
using NorthBridgeContracts.DataModels;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NorthBridgeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ComponentHistoryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void ComponentIdIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(null, 10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
component = CreateDataModel(string.Empty, 10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNotGuidTest()
|
||||
{
|
||||
var component = CreateDataModel("id", 10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OldPriceIsLessOrZeroTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var oldPrice = 10;
|
||||
var componentHistory = CreateDataModel(componentId, oldPrice);
|
||||
|
||||
Assert.That(() => componentHistory.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(componentHistory.ComponentId, Is.EqualTo(componentId));
|
||||
Assert.That(componentHistory.OldPrice, Is.EqualTo(oldPrice));
|
||||
Assert.That(componentHistory.ChangeDate, Is.LessThan(DateTime.UtcNow));
|
||||
Assert.That(componentHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||
});
|
||||
}
|
||||
|
||||
private static ComponentHistoryDataModel CreateDataModel(string? componentId, double oldPrice) =>
|
||||
new(componentId, oldPrice);
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,99 @@
|
||||
using NorthBridgeContracts.DataModels;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
namespace NorthBridgeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class CustomerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var customer = CreateDataModel(null, "FIO", "+71234567890", "test@example.com", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
customer = CreateDataModel(string.Empty, "FIO", "+71234567890", "test@example.com", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var customer = CreateDataModel("not-a-guid", "FIO", "+71234567890", "test@example.com", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var customer = CreateDataModel(Guid.NewGuid().ToString(), null, "+71234567890", "test@example.com", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
customer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "+71234567890", "test@example.com", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneIsNullOrEmptyTest()
|
||||
{
|
||||
var customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", null, "test@example.com", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", string.Empty, "test@example.com", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneIsIncorrectFormatTest()
|
||||
{
|
||||
var customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "22814881337", "test@example.com", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "+7123456789", "test@example.com", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmailIsNullOrEmptyTest()
|
||||
{
|
||||
var customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "+71234567890", null, 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "+71234567890", string.Empty, 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmailIsIncorrectFormatTest()
|
||||
{
|
||||
var customer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "+71234567890", "invalid-email", 10);
|
||||
Assert.That(() => customer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var customerId = Guid.NewGuid().ToString();
|
||||
var fio = "FIO";
|
||||
var phone = "+71234567890";
|
||||
var email = "Kotcheshir@example.com";
|
||||
var discountSize = 10;
|
||||
|
||||
var customer = CreateDataModel(customerId, fio, phone, email, discountSize);
|
||||
|
||||
Assert.That(() => customer.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(customer.Id, Is.EqualTo(customerId));
|
||||
Assert.That(customer.FIO, Is.EqualTo(fio));
|
||||
Assert.That(customer.Phone, Is.EqualTo(phone));
|
||||
Assert.That(customer.Email, Is.EqualTo(email));
|
||||
Assert.That(customer.DiscountSize, Is.EqualTo(discountSize));
|
||||
});
|
||||
}
|
||||
|
||||
private static CustomerDataModel CreateDataModel(string? id, string? fio, string? phone, string? email, double discountSize) =>
|
||||
new(id, fio, phone, email, discountSize);
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
using NorthBridgeContracts.DataModels;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
|
||||
namespace NorthBridgeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ManufacturerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(null, "ManufacturerName");
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
manufacturer = CreateDataModel(string.Empty, "ManufacturerName");
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel("not-a-guid", "ManufacturerName");
|
||||
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 AllFieldsAreCorrectTest()
|
||||
{
|
||||
var manufacturerId = Guid.NewGuid().ToString();
|
||||
var manufacturerName = "ManufacturerName";
|
||||
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);
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
using NorthBridgeContracts.DataModels;
|
||||
using NorthBridgeContracts.Enums;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NorthBridgeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "PostName", PostType.Manager, 1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "PostName", PostType.Manager, 1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("not-a-guid", Guid.NewGuid().ToString(), "PostName", PostType.Manager, 1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "PostName", PostType.Manager, 1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "PostName", PostType.Manager, 1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "not-a-guid", "PostName", PostType.Manager, 1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostNameIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Manager, 1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Manager, 1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "PostName", PostType.None, 1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SalaryIsLessOrEqualToZeroTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "PostName", PostType.Manager, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "PostName", PostType.Manager, -1000, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var postPostId = Guid.NewGuid().ToString();
|
||||
var postName = "PostName";
|
||||
var postType = PostType.Manager;
|
||||
var salary = 1000.0;
|
||||
var isActual = true;
|
||||
var changeDate = DateTime.UtcNow;
|
||||
|
||||
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);
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using NorthBridgeContracts.DataModels;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
namespace NorthBridgeTests.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 SalaryIsLessOrZeroTest()
|
||||
{
|
||||
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 AllFieldsAreCorrectTest()
|
||||
{
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||
var workerSalary = 10;
|
||||
var salary = CreateDataModel(workerId, salaryDate, workerSalary);
|
||||
|
||||
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(salary.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
|
||||
Assert.That(salary.Salary, Is.EqualTo(workerSalary));
|
||||
});
|
||||
}
|
||||
|
||||
private static SalaryDataModel CreateDataModel(string? workerId, DateTime salaryDate, double workerSalary) =>
|
||||
new(workerId, salaryDate, workerSalary);
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
using NorthBridgeContracts.DataModels;
|
||||
using NorthBridgeContracts.Enums;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NorthBridgeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class SaleDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsEmptyOrNullTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel("invalidGuid", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsEmptyOrNullTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(Guid.NewGuid().ToString(), "invalidGuid", Guid.NewGuid().ToString(), 10, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CustomerIdIsNotGuidTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "invalidGuid", 10, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 0, false, null).Validate());
|
||||
Assert.Throws<ValidationException>(() => new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 0, false, new List<SaleProductDataModel>()).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreValidTest()
|
||||
{
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 0, false,
|
||||
new List<SaleProductDataModel> { new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1) });
|
||||
Assert.DoesNotThrow(() => sale.Validate());
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
using NorthBridgeContracts.DataModels;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NorthBridgeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class SaleProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void SaleIdIsEmptyOrNullTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleProductDataModel(null, Guid.NewGuid().ToString(), 10).Validate());
|
||||
Assert.Throws<ValidationException>(() => new SaleProductDataModel("", Guid.NewGuid().ToString(), 10).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SaleIdIsNotGuidTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleProductDataModel("invalidGuid", Guid.NewGuid().ToString(), 10).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsEmptyOrNullTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleProductDataModel(Guid.NewGuid().ToString(), null, 10).Validate());
|
||||
Assert.Throws<ValidationException>(() => new SaleProductDataModel(Guid.NewGuid().ToString(), "", 10).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleProductDataModel(Guid.NewGuid().ToString(), "invalidGuid", 10).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
Assert.Throws<ValidationException>(() => new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0).Validate());
|
||||
Assert.Throws<ValidationException>(() => new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1).Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreValidTest()
|
||||
{
|
||||
var saleProduct = new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10);
|
||||
Assert.DoesNotThrow(() => saleProduct.Validate());
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
using NorthBridgeContracts.DataModels;
|
||||
using NorthBridgeContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NorthBridgeTests.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 AllFieldsAreCorrectTest()
|
||||
{
|
||||
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);
|
||||
}
|
27
NorthBridgeProject/NorthBridgeTests/NorthBridgeTests.csproj
Normal file
27
NorthBridgeProject/NorthBridgeTests/NorthBridgeTests.csproj
Normal 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="..\NorthBridgeContracts\NorthBridgeContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user