Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
c0c0d1c398 | |||
77dc500a54 |
41
WildPlumContracts/DataModels/EmployeeDataModel.cs
Normal file
41
WildPlumContracts/DataModels/EmployeeDataModel.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
using WildPlumContracts.Extensions;
|
||||||
|
using WildPlumContracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace WildPlumContracts.DataModels;
|
||||||
|
|
||||||
|
public class EmployeeDataModel(string id, string fullName, string email, string roleId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string FullName { get; private set; } = fullName;
|
||||||
|
public string Email { get; private set; } = email;
|
||||||
|
public string RoleId { get; private set; } = roleId;
|
||||||
|
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("Employee Id is empty");
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("Employee Id is not a valid GUID");
|
||||||
|
if (FullName.IsEmpty())
|
||||||
|
throw new ValidationException("Employee Full Name is empty");
|
||||||
|
if (Email.IsEmpty())
|
||||||
|
throw new ValidationException("Employee Email is empty");
|
||||||
|
if (!Regex.IsMatch(Email, @"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"))
|
||||||
|
throw new ValidationException("Field Email is not a email");
|
||||||
|
if (RoleId.IsEmpty())
|
||||||
|
throw new ValidationException("Field RoleId is empty");
|
||||||
|
if (!RoleId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field RoleId 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()})");
|
||||||
|
}
|
||||||
|
}
|
37
WildPlumContracts/DataModels/OrderDataModel.cs
Normal file
37
WildPlumContracts/DataModels/OrderDataModel.cs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
using WildPlumContracts.Enums;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
using WildPlumContracts.Extensions;
|
||||||
|
using WildPlumContracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace WildPlumContracts.DataModels;
|
||||||
|
|
||||||
|
public class OrderDataModel(string id, string warehouseId, string workerId, string customerName, OrderStatus status, DateTime orderDate, List<OrderProductDataModel> products) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string WarehouseId { get; private set; } = warehouseId;
|
||||||
|
public string WorkerId { get; private set; } = workerId;
|
||||||
|
public string CustomerName { get; private set; } = customerName;
|
||||||
|
public OrderStatus Status { get; private set; } = status;
|
||||||
|
public DateTime OrderDate { get; private set; } = orderDate;
|
||||||
|
public List<OrderProductDataModel> Products { get; private set; } = products;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Order Id is empty");
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("Order Id is not a valid GUID");
|
||||||
|
if (WarehouseId.IsEmpty())
|
||||||
|
throw new ValidationException("Warehouse Id is empty");
|
||||||
|
if (!WarehouseId.IsGuid())
|
||||||
|
throw new ValidationException("Warehouse Id is not a valid GUID");
|
||||||
|
if (WorkerId.IsEmpty())
|
||||||
|
throw new ValidationException("WorkerId Id is empty");
|
||||||
|
if (!WorkerId.IsGuid())
|
||||||
|
throw new ValidationException("WorkerId Id is not a valid GUID");
|
||||||
|
if (CustomerName.IsEmpty())
|
||||||
|
throw new ValidationException("Customer Name is empty");
|
||||||
|
if ((Products?.Count ?? 0) == 0)
|
||||||
|
throw new ValidationException("The order must include products");
|
||||||
|
}
|
||||||
|
}
|
20
WildPlumContracts/DataModels/OrderHistoryDataModel.cs
Normal file
20
WildPlumContracts/DataModels/OrderHistoryDataModel.cs
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
using WildPlumContracts.Enums;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
using WildPlumContracts.Extensions;
|
||||||
|
using WildPlumContracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace WildPlumContracts.DataModels;
|
||||||
|
|
||||||
|
public class OrderHistoryDataModel(string orderId, OrderStatus oldStatus) : IValidation
|
||||||
|
{
|
||||||
|
public string OrderId { get; private set; } = orderId;
|
||||||
|
public OrderStatus OldStatus { get; private set; } = oldStatus;
|
||||||
|
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (OrderId.IsEmpty())
|
||||||
|
throw new ValidationException("Field OrderId is empty");
|
||||||
|
if (!OrderId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field OrderId is not a unique identifier");
|
||||||
|
}
|
||||||
|
}
|
25
WildPlumContracts/DataModels/OrderProductDataModel.cs
Normal file
25
WildPlumContracts/DataModels/OrderProductDataModel.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
using WildPlumContracts.Extensions;
|
||||||
|
using WildPlumContracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace WildPlumContracts.DataModels;
|
||||||
|
|
||||||
|
public class OrderProductDataModel(string productId, string orderId, int count) : IValidation
|
||||||
|
{
|
||||||
|
public string OrderId { get; private set; } = orderId;
|
||||||
|
public string ProductId { get; private set; } = productId;
|
||||||
|
public int Count { get; private set; } = count;
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (ProductId.IsEmpty())
|
||||||
|
throw new ValidationException("ProductId is empty");
|
||||||
|
if (!ProductId.IsGuid())
|
||||||
|
throw new ValidationException("ProductId is not a valid GUID");
|
||||||
|
if (OrderId.IsEmpty())
|
||||||
|
throw new ValidationException("OrderId is empty");
|
||||||
|
if (!OrderId.IsGuid())
|
||||||
|
throw new ValidationException("OrderId is not a valid GUID");
|
||||||
|
if (Count <= 0)
|
||||||
|
throw new ValidationException("Field Count is less than or equal to 0");
|
||||||
|
}
|
||||||
|
}
|
25
WildPlumContracts/DataModels/ProductDataModel.cs
Normal file
25
WildPlumContracts/DataModels/ProductDataModel.cs
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
using WildPlumContracts.Extensions;
|
||||||
|
using WildPlumContracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace WildPlumContracts.DataModels;
|
||||||
|
|
||||||
|
public class ProductDataModel(string id, string productName, double price, bool isDeleted) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string ProductName { get; private set; } = productName;
|
||||||
|
public double Price { get; private set; } = price;
|
||||||
|
public bool IsDeleted { get; private set; } = isDeleted;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||||
|
if (ProductName.IsEmpty())
|
||||||
|
throw new ValidationException("Field ProductName is empty");
|
||||||
|
if (Price <= 0)
|
||||||
|
throw new ValidationException("Field Price is less than or equal to 0");
|
||||||
|
}
|
||||||
|
}
|
29
WildPlumContracts/DataModels/RoleDataModel.cs
Normal file
29
WildPlumContracts/DataModels/RoleDataModel.cs
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
using WildPlumContracts.Enums;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
using WildPlumContracts.Extensions;
|
||||||
|
using WildPlumContracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace WildPlumContracts.DataModels;
|
||||||
|
|
||||||
|
public class RoleDataModel(string id, string roleId, WorkerRole role, bool isActual, DateTime changeDate) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string RoleId { get; private set; } = roleId;
|
||||||
|
public WorkerRole Role { get; private set; } = role;
|
||||||
|
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 (RoleId.IsEmpty())
|
||||||
|
throw new ValidationException("Field RoleId is empty");
|
||||||
|
if (!RoleId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field RoleId is not a unique identifier");
|
||||||
|
if (Role == WorkerRole.None)
|
||||||
|
throw new ValidationException("Field Role is empty");
|
||||||
|
}
|
||||||
|
}
|
27
WildPlumContracts/DataModels/SalaryDataModel.cs
Normal file
27
WildPlumContracts/DataModels/SalaryDataModel.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
using WildPlumContracts.Extensions;
|
||||||
|
using WildPlumContracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace WildPlumContracts.DataModels;
|
||||||
|
|
||||||
|
public class SalaryDataModel(string id, string workerId, decimal amount, DateTime salaryDate) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string WorkerId { get; private set; } = workerId;
|
||||||
|
public decimal Amount { get; private set; } = amount;
|
||||||
|
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Salary Id is empty");
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("Salary Id is not a valid GUID");
|
||||||
|
if (WorkerId.IsEmpty())
|
||||||
|
throw new ValidationException("WorkerId is empty");
|
||||||
|
if (!WorkerId.IsGuid())
|
||||||
|
throw new ValidationException("WorkerId is not a valid GUID");
|
||||||
|
if (Amount <= 0)
|
||||||
|
throw new ValidationException("Salary amount must be positive");
|
||||||
|
}
|
||||||
|
}
|
24
WildPlumContracts/DataModels/WarehouseDataModel.cs
Normal file
24
WildPlumContracts/DataModels/WarehouseDataModel.cs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
using WildPlumContracts.Extensions;
|
||||||
|
using WildPlumContracts.Infrastructure;
|
||||||
|
|
||||||
|
namespace WildPlumContracts.DataModels;
|
||||||
|
|
||||||
|
public class WarehouseDataModel(string id, string name, string location) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string Name { get; private set; } = name;
|
||||||
|
public string Location { get; private set; } = location;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Warehouse Id is empty");
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("Warehouse Id is not a valid GUID");
|
||||||
|
if (Name.IsEmpty())
|
||||||
|
throw new ValidationException("Warehouse Name is empty");
|
||||||
|
if (Location.IsEmpty())
|
||||||
|
throw new ValidationException("Warehouse Location is empty");
|
||||||
|
}
|
||||||
|
}
|
9
WildPlumContracts/Enums/OrderStatus.cs
Normal file
9
WildPlumContracts/Enums/OrderStatus.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace WildPlumContracts.Enums;
|
||||||
|
|
||||||
|
public enum OrderStatus
|
||||||
|
{
|
||||||
|
Pending = 0,
|
||||||
|
InProgress = 1,
|
||||||
|
Completed = 2,
|
||||||
|
Canceled = 3
|
||||||
|
}
|
9
WildPlumContracts/Enums/WorkerRole.cs
Normal file
9
WildPlumContracts/Enums/WorkerRole.cs
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
namespace WildPlumContracts.Enums;
|
||||||
|
|
||||||
|
public enum WorkerRole
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Operator = 1,
|
||||||
|
Loader = 2,
|
||||||
|
Courier = 3
|
||||||
|
}
|
5
WildPlumContracts/Exceptions/ValidationException.cs
Normal file
5
WildPlumContracts/Exceptions/ValidationException.cs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
namespace WildPlumContracts.Exceptions;
|
||||||
|
|
||||||
|
public class ValidationException(string message) : Exception(message)
|
||||||
|
{
|
||||||
|
}
|
7
WildPlumContracts/Extensions/StringExtensions.cs
Normal file
7
WildPlumContracts/Extensions/StringExtensions.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace WildPlumContracts.Extensions;
|
||||||
|
|
||||||
|
public static class StringExtensions
|
||||||
|
{
|
||||||
|
public static bool IsEmpty(this string str) => string.IsNullOrWhiteSpace(str);
|
||||||
|
public static bool IsGuid(this string str) => Guid.TryParse(str, out _);
|
||||||
|
}
|
6
WildPlumContracts/Infrastructure/IValidation.cs
Normal file
6
WildPlumContracts/Infrastructure/IValidation.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace WildPlumContracts.Infrastructure;
|
||||||
|
|
||||||
|
public interface IValidation
|
||||||
|
{
|
||||||
|
void Validate();
|
||||||
|
}
|
9
WildPlumContracts/WildPlumContracts.csproj
Normal file
9
WildPlumContracts/WildPlumContracts.csproj
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
31
WildPlumProject.sln
Normal file
31
WildPlumProject.sln
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.8.34330.188
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WildPlumContracts", "WildPlumContracts\WildPlumContracts.csproj", "{8E51CF35-5E5B-4E26-A590-F4C5F0B3E496}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WildPlumTests", "WildPlumTests\WildPlumTests.csproj", "{B93BC3DA-0A43-439E-B759-28C5D22CF969}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{8E51CF35-5E5B-4E26-A590-F4C5F0B3E496}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8E51CF35-5E5B-4E26-A590-F4C5F0B3E496}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8E51CF35-5E5B-4E26-A590-F4C5F0B3E496}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8E51CF35-5E5B-4E26-A590-F4C5F0B3E496}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B93BC3DA-0A43-439E-B759-28C5D22CF969}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B93BC3DA-0A43-439E-B759-28C5D22CF969}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B93BC3DA-0A43-439E-B759-28C5D22CF969}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B93BC3DA-0A43-439E-B759-28C5D22CF969}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {5BA42D74-9F38-4C41-880E-6B110B64C537}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
134
WildPlumTests/DataModelTests/EmployeeDataModelTests.cs
Normal file
134
WildPlumTests/DataModelTests/EmployeeDataModelTests.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
using WildPlumContracts.DataModels;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace WildPlumTests.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class EmployeeDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(null!, "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(string.Empty, "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel("invalid-guid", "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenFullNameIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null!, "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "test@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenEmailIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Jhon Doe", null!, Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Jhon Doe", string.Empty, Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenEmailIsNotInCorrectFormat()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John doe", "test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "john doe", "test@", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "john doe", "test@gmail", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenRoleIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", null!, DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", string.Empty, DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenRoleIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", "invalid-guid", DateTime.UtcNow, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenBirthDateIsLessThan16YearsAgo()
|
||||||
|
{
|
||||||
|
var birthDate = DateTime.Now.AddYears(-15); // less than 16 years ago
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), birthDate, DateTime.UtcNow, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenEmploymentDateIsBeforeBirthDate()
|
||||||
|
{
|
||||||
|
var birthDate = DateTime.Now.AddYears(-18); // valid birth date
|
||||||
|
var employmentDate = DateTime.Now.AddYears(-19); // employment date before birth date
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com", Guid.NewGuid().ToString(), birthDate, employmentDate, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenEmploymentDateIsLessThan16YearsAfterBirthDate()
|
||||||
|
{
|
||||||
|
var birthDate = DateTime.Now.AddYears(-17); // birth date more than 16 years ago
|
||||||
|
var employmentDate = DateTime.Now.AddYears(-16); // employment date less than 16 years after birth date
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "John Doe", "test@gmail.com" , Guid.NewGuid().ToString(), birthDate, employmentDate, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var fullName = "John Doe";
|
||||||
|
var email = "bbbbb@gmail.com";
|
||||||
|
var roleId = Guid.NewGuid().ToString();
|
||||||
|
var birthDate = DateTime.Now.AddYears(-20);
|
||||||
|
var employmentDate = DateTime.Now.AddYears(-2);
|
||||||
|
|
||||||
|
var employeeData = CreateDataModel(id, fullName, email, roleId, birthDate, employmentDate, false);
|
||||||
|
|
||||||
|
Assert.That(() => employeeData.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(employeeData.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(employeeData.FullName, Is.EqualTo(fullName));
|
||||||
|
Assert.That(employeeData.Email, Is.EqualTo(email));
|
||||||
|
Assert.That(employeeData.RoleId, Is.EqualTo(roleId));
|
||||||
|
Assert.That(employeeData.BirthDate, Is.EqualTo(birthDate));
|
||||||
|
Assert.That(employeeData.EmploymentDate, Is.EqualTo(employmentDate));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static EmployeeDataModel CreateDataModel(string id, string fullName, string email, string roleId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||||
|
new(id, fullName, email, roleId, birthDate, employmentDate, isDeleted);
|
||||||
|
}
|
127
WildPlumTests/DataModelTests/OrderDataModelTests.cs
Normal file
127
WildPlumTests/DataModelTests/OrderDataModelTests.cs
Normal file
@ -0,0 +1,127 @@
|
|||||||
|
using WildPlumContracts.DataModels;
|
||||||
|
using WildPlumContracts.Enums;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace WildPlumTests.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class OrderDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "John Doe", OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "John Doe", OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "John Doe", OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenWarehouseIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), "John Doe", OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), "John Doe", OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenWarehouseIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", Guid.NewGuid().ToString(), "John Doe", OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenWorkerIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, "John Doe", OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, "John Doe", OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenWorkerIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "invalid-guid", "John Doe", OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenCustomerNameIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, OrderStatus.Pending, DateTime.Now, CreateSubDataModel()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenProductsListIsEmptyOrNull()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "John Doe", OrderStatus.Pending, DateTime.Now, null).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "John Doe", OrderStatus.Pending, DateTime.Now, new List<OrderProductDataModel>()).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var warehouseId = Guid.NewGuid().ToString();
|
||||||
|
var workerId = Guid.NewGuid().ToString();
|
||||||
|
var customerName = "John Doe";
|
||||||
|
var status = OrderStatus.Pending;
|
||||||
|
var orderDate = DateTime.Now;
|
||||||
|
var products = CreateSubDataModel();
|
||||||
|
|
||||||
|
var order = CreateDataModel(id, warehouseId, workerId, customerName, status, orderDate, products);
|
||||||
|
|
||||||
|
Assert.That(() => order.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(order.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(order.WarehouseId, Is.EqualTo(warehouseId));
|
||||||
|
Assert.That(order.WorkerId, Is.EqualTo(workerId));
|
||||||
|
Assert.That(order.CustomerName, Is.EqualTo(customerName));
|
||||||
|
Assert.That(order.Status, Is.EqualTo(status));
|
||||||
|
Assert.That(order.OrderDate, Is.EqualTo(orderDate).Within(TimeSpan.FromSeconds(1)));
|
||||||
|
Assert.That(order.Products, Is.EquivalentTo(products));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OrderDataModel CreateDataModel(string? id, string? warehouseId, string? workerId, string? customerName, OrderStatus status, DateTime orderDate, List<OrderProductDataModel>? products) =>
|
||||||
|
new(id, warehouseId, workerId, customerName, status, orderDate, products);
|
||||||
|
|
||||||
|
private static List<OrderProductDataModel> CreateSubDataModel() =>
|
||||||
|
new() { new OrderProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1) };
|
||||||
|
}
|
47
WildPlumTests/DataModelTests/OrderHistoryDataModelTests.cs
Normal file
47
WildPlumTests/DataModelTests/OrderHistoryDataModelTests.cs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
using WildPlumContracts.DataModels;
|
||||||
|
using WildPlumContracts.Enums;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace WildPlumTests.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class OrderHistoryDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void OrderIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(null, OrderStatus.InProgress);
|
||||||
|
Assert.That(() => order.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
order = CreateDataModel(string.Empty, OrderStatus.InProgress);
|
||||||
|
Assert.That(() => order.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void OrderIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel("id", OrderStatus.InProgress);
|
||||||
|
Assert.That(() => order.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var orderId = Guid.NewGuid().ToString();
|
||||||
|
var oldStatus = OrderStatus.Pending;
|
||||||
|
var orderHistory = CreateDataModel(orderId, oldStatus);
|
||||||
|
Assert.That(() => orderHistory.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(orderHistory.OrderId, Is.EqualTo(orderId));
|
||||||
|
Assert.That(orderHistory.OldStatus, Is.EqualTo(oldStatus));
|
||||||
|
Assert.That(orderHistory.ChangeDate,
|
||||||
|
Is.LessThan(DateTime.UtcNow));
|
||||||
|
Assert.That(orderHistory.ChangeDate,
|
||||||
|
Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static OrderHistoryDataModel CreateDataModel(string? productId,
|
||||||
|
OrderStatus oldStatus) =>
|
||||||
|
new(productId, oldStatus);
|
||||||
|
}
|
83
WildPlumTests/DataModelTests/OrderProductDataModelTests.cs
Normal file
83
WildPlumTests/DataModelTests/OrderProductDataModelTests.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
using WildPlumContracts.DataModels;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace WildPlumTests.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class OrderProductDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenProductIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(null, Guid.NewGuid().ToString(), 1).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenProductIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), 1).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenOrderIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null, 1).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenOrderIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", 1).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenCountIsLessThanOrEqualToZero()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var productId = Guid.NewGuid().ToString();
|
||||||
|
var orderId = Guid.NewGuid().ToString();
|
||||||
|
var count = 5;
|
||||||
|
|
||||||
|
var orderProduct = CreateDataModel(productId, orderId, count);
|
||||||
|
|
||||||
|
Assert.That(() => orderProduct.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(orderProduct.ProductId, Is.EqualTo(productId));
|
||||||
|
Assert.That(orderProduct.OrderId, Is.EqualTo(orderId));
|
||||||
|
Assert.That(orderProduct.Count, Is.EqualTo(count));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OrderProductDataModel CreateDataModel(string? productId, string? orderId, int count) =>
|
||||||
|
new(productId!, orderId!, count);
|
||||||
|
}
|
||||||
|
|
77
WildPlumTests/DataModelTests/ProductDataModelTests.cs
Normal file
77
WildPlumTests/DataModelTests/ProductDataModelTests.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using WildPlumContracts.DataModels;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace WildPlumTests.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class ProductDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(null, "Laptop", 1000, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(string.Empty, "Laptop", 1000, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel("invalid-guid", "Laptop", 1000, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenProductNameIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null, 1000, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1000, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenPriceIsLessThanOrEqualToZero()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Laptop", 0, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Laptop", -100, false).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var productName = "Laptop";
|
||||||
|
var price = 1500.5;
|
||||||
|
var isDeleted = false;
|
||||||
|
|
||||||
|
var product = CreateDataModel(id, productName, price, isDeleted);
|
||||||
|
|
||||||
|
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(product.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(product.ProductName, Is.EqualTo(productName));
|
||||||
|
Assert.That(product.Price, Is.EqualTo(price));
|
||||||
|
Assert.That(product.IsDeleted, Is.EqualTo(isDeleted));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ProductDataModel CreateDataModel(string? id, string? productName, double price, bool isDeleted) =>
|
||||||
|
new(id!, productName!, price, isDeleted);
|
||||||
|
}
|
79
WildPlumTests/DataModelTests/RoleDataModelTests.cs
Normal file
79
WildPlumTests/DataModelTests/RoleDataModelTests.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
using WildPlumContracts.DataModels;
|
||||||
|
using WildPlumContracts.Enums;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace WildPlumTests.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class RoleDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(null!, Guid.NewGuid().ToString(), WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(string.Empty, Guid.NewGuid().ToString(), WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenRoleIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null!, WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenRoleIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenRoleIsNone()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), WorkerRole.None, true, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var roleId = Guid.NewGuid().ToString();
|
||||||
|
var role = WorkerRole.Courier;
|
||||||
|
var isActual = true;
|
||||||
|
var changeDate = DateTime.UtcNow;
|
||||||
|
|
||||||
|
var roleData = CreateDataModel(id, roleId, role, isActual, changeDate);
|
||||||
|
|
||||||
|
Assert.That(() => roleData.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(roleData.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(roleData.RoleId, Is.EqualTo(roleId));
|
||||||
|
Assert.That(roleData.Role, Is.EqualTo(role));
|
||||||
|
Assert.That(roleData.IsActual, Is.EqualTo(isActual));
|
||||||
|
Assert.That(roleData.ChangeDate, Is.EqualTo(changeDate).Within(TimeSpan.FromSeconds(1)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RoleDataModel CreateDataModel(string id, string roleId, WorkerRole role, bool isActive, DateTime createdAt) =>
|
||||||
|
new(id, roleId, role, isActive, createdAt);
|
||||||
|
}
|
76
WildPlumTests/DataModelTests/SalaryDataModelTests.cs
Normal file
76
WildPlumTests/DataModelTests/SalaryDataModelTests.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using WildPlumContracts.DataModels;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace WildPlumTests.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class SalaryDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(null!, Guid.NewGuid().ToString(), 5000, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 5000, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), 5000, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenWorkerIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null!, 5000, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 5000, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenWorkerIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", 5000, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenAmountIsNonPositive()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, DateTime.UtcNow).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var workerId = Guid.NewGuid().ToString();
|
||||||
|
var amount = 5000;
|
||||||
|
var salaryDate = DateTime.UtcNow;
|
||||||
|
|
||||||
|
var salaryData = CreateDataModel(id, workerId, amount, salaryDate);
|
||||||
|
|
||||||
|
Assert.That(() => salaryData.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(salaryData.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(salaryData.WorkerId, Is.EqualTo(workerId));
|
||||||
|
Assert.That(salaryData.Amount, Is.EqualTo(amount));
|
||||||
|
Assert.That(salaryData.SalaryDate, Is.EqualTo(salaryDate).Within(TimeSpan.FromSeconds(1)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SalaryDataModel CreateDataModel(string id, string workerId, decimal amount, DateTime date) =>
|
||||||
|
new(id, workerId, amount, date);
|
||||||
|
}
|
72
WildPlumTests/DataModelTests/WarehouseDataModelTests.cs
Normal file
72
WildPlumTests/DataModelTests/WarehouseDataModelTests.cs
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
using WildPlumContracts.DataModels;
|
||||||
|
using WildPlumContracts.Exceptions;
|
||||||
|
|
||||||
|
namespace WildPlumTests.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
public class WarehouseDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(null!, "Warehouse Name", "Location").Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(string.Empty, "Warehouse Name", "Location").Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenIdIsNotGuid()
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel("invalid-guid", "Warehouse Name", "Location").Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenNameIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null!, "Location").Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "Location").Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Validate_ThrowsException_WhenLocationIsNullOrEmpty()
|
||||||
|
{
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Warehouse Name", null!).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "Warehouse Name", string.Empty).Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var name = "Warehouse Name";
|
||||||
|
var location = "Location";
|
||||||
|
|
||||||
|
var warehouseData = CreateDataModel(id, name, location);
|
||||||
|
|
||||||
|
Assert.That(() => warehouseData.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(warehouseData.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(warehouseData.Name, Is.EqualTo(name));
|
||||||
|
Assert.That(warehouseData.Location, Is.EqualTo(location));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WarehouseDataModel CreateDataModel(string id, string name, string location) =>
|
||||||
|
new(id, name, location);
|
||||||
|
}
|
1
WildPlumTests/GlobalUsings.cs
Normal file
1
WildPlumTests/GlobalUsings.cs
Normal file
@ -0,0 +1 @@
|
|||||||
|
global using NUnit.Framework;
|
24
WildPlumTests/WildPlumTests.csproj
Normal file
24
WildPlumTests/WildPlumTests.csproj
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<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="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||||
|
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||||
|
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
|
||||||
|
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\WildPlumContracts\WildPlumContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user