Compare commits
7 Commits
main
...
Task_1_Mod
Author | SHA1 | Date | |
---|---|---|---|
e6a053624b | |||
5e0e5f147e | |||
29964e0c13 | |||
9a29a70019 | |||
7040f4e256 | |||
f5def02564 | |||
4542a76661 |
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.11.35327.3
|
VisualStudioVersion = 17.11.35327.3
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PipingHot", "PipingHot\PipingHot.csproj", "{B07A5A92-372D-45A5-81AB-AE7A222928B4}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PipingHotContrast", "PipingHot\PipingHotContrast.csproj", "{B07A5A92-372D-45A5-81AB-AE7A222928B4}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PipingHotTests", "PipingHotTests\PipingHotTests.csproj", "{2269D181-1994-4BB3-A024-611BB25239AE}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -15,6 +17,10 @@ Global
|
|||||||
{B07A5A92-372D-45A5-81AB-AE7A222928B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{B07A5A92-372D-45A5-81AB-AE7A222928B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{B07A5A92-372D-45A5-81AB-AE7A222928B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{B07A5A92-372D-45A5-81AB-AE7A222928B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{B07A5A92-372D-45A5-81AB-AE7A222928B4}.Release|Any CPU.Build.0 = Release|Any CPU
|
{B07A5A92-372D-45A5-81AB-AE7A222928B4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{2269D181-1994-4BB3-A024-611BB25239AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{2269D181-1994-4BB3-A024-611BB25239AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{2269D181-1994-4BB3-A024-611BB25239AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{2269D181-1994-4BB3-A024-611BB25239AE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
44
PipingHot/PipingHot/DataModels/OrderDataModel.cs
Normal file
44
PipingHot/PipingHot/DataModels/OrderDataModel.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using PipingHotContrast.Extensions;
|
||||||
|
using PipingHotContrast.Infrastructure;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.DataModels;
|
||||||
|
|
||||||
|
public class OrderDataModel(string id, string workerId, string? restaurantId, double sum, List<OrderProductDataModel> products):IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string WorkerId { get; private set; } = workerId;
|
||||||
|
public string? RestaurantId { get; private set; } = restaurantId;
|
||||||
|
public DateTime OrderDate { get; private set; } = DateTime.UtcNow;
|
||||||
|
public double Sum { get; private set; } = sum;
|
||||||
|
public List<OrderProductDataModel> Products { get; private set; } = products;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||||
|
|
||||||
|
if (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 (!RestaurantId?.IsGuid() ?? !RestaurantId?.IsEmpty() ?? false)
|
||||||
|
throw new ValidationException("The value in the field RestaurantId 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");
|
||||||
|
}
|
||||||
|
}
|
32
PipingHot/PipingHot/DataModels/OrderProductDataModel.cs
Normal file
32
PipingHot/PipingHot/DataModels/OrderProductDataModel.cs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using PipingHotContrast.Extensions;
|
||||||
|
using PipingHotContrast.Infrastructure;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.DataModels;
|
||||||
|
|
||||||
|
|
||||||
|
public class OrderProductDataModel(string saleId, string productId, int count):IValidation
|
||||||
|
{
|
||||||
|
public string OrderId { get; private set; } = saleId;
|
||||||
|
public string ProductId { get; private set; } = productId;
|
||||||
|
public int Count { get; private set; } = count;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (OrderId.IsEmpty())
|
||||||
|
throw new ValidationException("Field SaleId is empty");
|
||||||
|
if (!OrderId.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");
|
||||||
|
}
|
||||||
|
}
|
41
PipingHot/PipingHot/DataModels/PostDataModel.cs
Normal file
41
PipingHot/PipingHot/DataModels/PostDataModel.cs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
using PipingHotContrast.Enums;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using PipingHotContrast.Extensions;
|
||||||
|
using PipingHotContrast.Infrastructure;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.DataModels;
|
||||||
|
|
||||||
|
public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate): IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string PostId { get; private set; } = postId;
|
||||||
|
public string PostName { get; private set; } = postName;
|
||||||
|
public PostType PostType { get; private set; } = postType;
|
||||||
|
public double Salary { get; private set; } = salary;
|
||||||
|
public bool IsActual { get; private set; } = isActual;
|
||||||
|
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||||
|
if (PostId.IsEmpty())
|
||||||
|
throw new ValidationException("Field PostId is empty");
|
||||||
|
if (!PostId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||||
|
if (PostName.IsEmpty())
|
||||||
|
throw new ValidationException("Field PostName is empty");
|
||||||
|
if (PostType==PostType.None)
|
||||||
|
throw new ValidationException("Field PostName is empty");
|
||||||
|
if (Salary <= 0)
|
||||||
|
throw new ValidationException("Field Salary is empty");
|
||||||
|
}
|
||||||
|
}
|
40
PipingHot/PipingHot/DataModels/ProductDataModel.cs
Normal file
40
PipingHot/PipingHot/DataModels/ProductDataModel.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using PipingHotContrast.Enums;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using PipingHotContrast.Extensions;
|
||||||
|
using PipingHotContrast.Infrastructure;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.DataModels;
|
||||||
|
|
||||||
|
public class ProductDataModel(string id, string productName, ProductType productType,string restaurantId, double price, bool isDeleted): IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string ProductName { get; private set; } = productName;
|
||||||
|
public ProductType ProductType { get; private set; } = productType;
|
||||||
|
public string RestaurantId { get; private set; } = restaurantId;
|
||||||
|
public double Price { get; private set; } = price;
|
||||||
|
public bool IsDeleted { get; private set; } = isDeleted;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||||
|
if (ProductName.IsEmpty())
|
||||||
|
throw new ValidationException("Field ProductName is empty");
|
||||||
|
if (ProductType == ProductType.None)
|
||||||
|
throw new ValidationException("Field ProductType is empty");
|
||||||
|
if (RestaurantId.IsEmpty())
|
||||||
|
throw new ValidationException("Field RestaurantId is empty");
|
||||||
|
if (!RestaurantId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field RestaurantId is not a unique identifier");
|
||||||
|
if(Price <= 0)
|
||||||
|
throw new ValidationException("Field Price is empty");
|
||||||
|
}
|
||||||
|
}
|
28
PipingHot/PipingHot/DataModels/ProductHistoryDataModel.cs
Normal file
28
PipingHot/PipingHot/DataModels/ProductHistoryDataModel.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using PipingHotContrast.Extensions;
|
||||||
|
using PipingHotContrast.Infrastructure;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.DataModels;
|
||||||
|
|
||||||
|
public class ProductHistoryDataModel(string productId, double oldPrice): IValidation
|
||||||
|
{
|
||||||
|
public string ProductId { get; private set; } = productId;
|
||||||
|
public double OldPrice { get; private set; } = oldPrice;
|
||||||
|
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (ProductId.IsEmpty())
|
||||||
|
throw new ValidationException("Field ProductId is empty");
|
||||||
|
if (!ProductId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||||
|
if (OldPrice <= 0)
|
||||||
|
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||||
|
}
|
||||||
|
}
|
33
PipingHot/PipingHot/DataModels/RestaurantDataModel.cs
Normal file
33
PipingHot/PipingHot/DataModels/RestaurantDataModel.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using PipingHotContrast.Extensions;
|
||||||
|
using PipingHotContrast.Infrastructure;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.DataModels;
|
||||||
|
|
||||||
|
public class RestaurantDataModel(string id, string restaurantName, string? prevRestaurantName, string? prevPrevRestaurantName) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
public string RestaurantName { get; private set; } = restaurantName;
|
||||||
|
|
||||||
|
public string? PrevRestaurantName { get; private set; } = prevRestaurantName;
|
||||||
|
|
||||||
|
public string? PrevPrevRestaurantName { get; private set; } = prevPrevRestaurantName;
|
||||||
|
|
||||||
|
|
||||||
|
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 (RestaurantName.IsEmpty())
|
||||||
|
throw new ValidationException("Field RestaurantName is empty");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
27
PipingHot/PipingHot/DataModels/SalaryDataModel.cs
Normal file
27
PipingHot/PipingHot/DataModels/SalaryDataModel.cs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using PipingHotContrast.Extensions;
|
||||||
|
using PipingHotContrast.Infrastructure;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.DataModels;
|
||||||
|
|
||||||
|
public class SalaryDataModel(string workerId, DateTime salaryDate, double salary) : IValidation
|
||||||
|
{
|
||||||
|
public string WorkerId { get; private set; } = workerId;
|
||||||
|
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||||
|
public double Salary { get; private set; } = salary;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (WorkerId.IsEmpty())
|
||||||
|
throw new ValidationException("Field WorkerId is empty");
|
||||||
|
if (!WorkerId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||||
|
if (Salary <= 0)
|
||||||
|
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||||
|
}
|
||||||
|
}
|
49
PipingHot/PipingHot/DataModels/WorkerDataModel.cs
Normal file
49
PipingHot/PipingHot/DataModels/WorkerDataModel.cs
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using PipingHotContrast.Extensions;
|
||||||
|
using PipingHotContrast.Infrastructure;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.DataModels;
|
||||||
|
|
||||||
|
public class WorkerDataModel(string id, string fio, string email,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 Email { get; private set; } = email;
|
||||||
|
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 (Email.IsEmpty())
|
||||||
|
throw new ValidationException("Field Email is empty");
|
||||||
|
if (!Regex.IsMatch(Email,@"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
||||||
|
throw new ValidationException("Field Email is not a valid email address");
|
||||||
|
if (PostId.IsEmpty())
|
||||||
|
throw new ValidationException("Field PostId is empty");
|
||||||
|
if (!PostId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||||
|
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
|
||||||
|
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||||
|
|
||||||
|
if (EmploymentDate.Date < BirthDate.Date)
|
||||||
|
throw new ValidationException("The date of employment cannot be less than the date of birth");
|
||||||
|
|
||||||
|
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16) // EmploymentDate.Year - BirthDate.Year
|
||||||
|
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
16
PipingHot/PipingHot/Enums/PostType.cs
Normal file
16
PipingHot/PipingHot/Enums/PostType.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.Enums;
|
||||||
|
|
||||||
|
public enum PostType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Operator = 1,
|
||||||
|
Aggregator = 2,
|
||||||
|
Deliveryman = 3
|
||||||
|
|
||||||
|
}
|
16
PipingHot/PipingHot/Enums/ProductType.cs
Normal file
16
PipingHot/PipingHot/Enums/ProductType.cs
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.Enums
|
||||||
|
{
|
||||||
|
public enum ProductType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Pizza = 1,
|
||||||
|
Sushi = 2,
|
||||||
|
Сocktail = 3
|
||||||
|
}
|
||||||
|
}
|
11
PipingHot/PipingHot/Exceptions/ValidationException.cs
Normal file
11
PipingHot/PipingHot/Exceptions/ValidationException.cs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.Exceptions;
|
||||||
|
|
||||||
|
public class ValidationException(string message) : Exception(message)
|
||||||
|
{
|
||||||
|
}
|
19
PipingHot/PipingHot/Extensions/StringExtensions.cs
Normal file
19
PipingHot/PipingHot/Extensions/StringExtensions.cs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.Extensions;
|
||||||
|
|
||||||
|
public static class StringExtensions
|
||||||
|
{
|
||||||
|
public static bool IsEmpty(this string str)
|
||||||
|
{
|
||||||
|
return string.IsNullOrEmpty(str);
|
||||||
|
}
|
||||||
|
public static bool IsGuid(this string str)
|
||||||
|
{
|
||||||
|
return Guid.TryParse(str, out _);
|
||||||
|
}
|
||||||
|
}
|
12
PipingHot/PipingHot/Infrastructure/IValidation.cs
Normal file
12
PipingHot/PipingHot/Infrastructure/IValidation.cs
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotContrast.Infrastructure;
|
||||||
|
|
||||||
|
public interface IValidation
|
||||||
|
{
|
||||||
|
void Validate();
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
<TargetFramework>net9.0-windows</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<UseWPF>true</UseWPF>
|
<UseWPF>true</UseWPF>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
@ -0,0 +1,97 @@
|
|||||||
|
using PipingHotContrast.DataModels;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class OrderDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, CreateSubDataModel());
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
order = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, CreateSubDataModel());
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, CreateSubDataModel());
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, CreateSubDataModel());
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
order = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, CreateSubDataModel());
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(), 10, CreateSubDataModel());
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void RestaurantIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "restaurantId", 10, CreateSubDataModel());
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SumIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, CreateSubDataModel());
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, CreateSubDataModel());
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductsIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, null);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, []);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var orderId = Guid.NewGuid().ToString();
|
||||||
|
var workerId = Guid.NewGuid().ToString();
|
||||||
|
var restaurantId = Guid.NewGuid().ToString();
|
||||||
|
var sum = 10;
|
||||||
|
var products = CreateSubDataModel();
|
||||||
|
var order = CreateDataModel(orderId, workerId, restaurantId, sum, products);
|
||||||
|
Assert.That(() => order.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(order.Id, Is.EqualTo(orderId));
|
||||||
|
Assert.That(order.WorkerId, Is.EqualTo(workerId));
|
||||||
|
Assert.That(order.RestaurantId, Is.EqualTo(restaurantId));
|
||||||
|
Assert.That(order.Sum, Is.EqualTo(sum));
|
||||||
|
Assert.That(order.Products, Is.EquivalentTo(products));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OrderDataModel CreateDataModel(string? id, string? workerId, string? restaurantId, double sum, List<OrderProductDataModel>? products) =>
|
||||||
|
new(id, workerId, restaurantId, sum, products);
|
||||||
|
|
||||||
|
private static List<OrderProductDataModel> CreateSubDataModel()
|
||||||
|
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,73 @@
|
|||||||
|
using PipingHotContrast.DataModels;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class OrderProductDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void SaleIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SaleIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var saleId = Guid.NewGuid().ToString();
|
||||||
|
var productId = Guid.NewGuid().ToString();
|
||||||
|
var count = 10;
|
||||||
|
var saleProduct = CreateDataModel(saleId, productId, count);
|
||||||
|
Assert.That(() => saleProduct.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(saleProduct.OrderId, Is.EqualTo(saleId));
|
||||||
|
Assert.That(saleProduct.ProductId, Is.EqualTo(productId));
|
||||||
|
Assert.That(saleProduct.Count, Is.EqualTo(count));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OrderProductDataModel CreateDataModel(string? saleId, string? productId, int count) =>
|
||||||
|
new(saleId, productId, count);
|
||||||
|
}
|
102
PipingHot/PipingHotTests/DataModelsTests/PostDataModelTests.cs
Normal file
102
PipingHot/PipingHotTests/DataModelsTests/PostDataModelTests.cs
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
using PipingHotContrast.DataModels;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using PipingHotContrast.Enums;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using System.Data;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class PostDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Operator, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Operator, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Operator, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNullEmptyTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Operator, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Operator, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Operator, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostNameIsEmptyTest()//?
|
||||||
|
{
|
||||||
|
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Operator, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Operator, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SalaryIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Operator, 0, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Operator, -10, true, DateTime.UtcNow);
|
||||||
|
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var postId = Guid.NewGuid().ToString();
|
||||||
|
var postPostId = Guid.NewGuid().ToString();
|
||||||
|
var postName = "name";
|
||||||
|
var postType = PostType.Operator;
|
||||||
|
var salary = 10;
|
||||||
|
var isActual = false;
|
||||||
|
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||||
|
var post = CreateDataModel(postId, postPostId, postName, postType, salary, isActual, changeDate);
|
||||||
|
Assert.That(() => post.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(post.Id, Is.EqualTo(postId));
|
||||||
|
Assert.That(post.PostId, Is.EqualTo(postPostId));
|
||||||
|
Assert.That(post.PostName, Is.EqualTo(postName));
|
||||||
|
Assert.That(post.PostType, Is.EqualTo(postType));
|
||||||
|
Assert.That(post.Salary, Is.EqualTo(salary));
|
||||||
|
Assert.That(post.IsActual, Is.EqualTo(isActual));
|
||||||
|
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
|
||||||
|
new(id, postId, postName, postType, salary, isActual, changeDate);
|
||||||
|
}
|
@ -0,0 +1,102 @@
|
|||||||
|
using PipingHotContrast.DataModels;
|
||||||
|
using PipingHotContrast.Enums;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class ProductDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(null, "name", ProductType.Pizza, Guid.NewGuid().ToString(),500, false);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(string.Empty, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel("id", "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductNameIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, Guid.NewGuid().ToString(), 500, false);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ReastaurantIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||||
|
ProductType.Pizza, null, 500, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||||
|
ProductType.Pizza, string.Empty, 500, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void ReastaurantIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||||
|
ProductType.Pizza, "restaurantId", 500, false);
|
||||||
|
Assert.That(() => product.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PriceIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 0, false);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), - 500, false);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var productId = Guid.NewGuid().ToString();
|
||||||
|
var productName = "name";
|
||||||
|
var productType = ProductType.Pizza;
|
||||||
|
var productRestaurantId = Guid.NewGuid().ToString();
|
||||||
|
var productPrice = 500;
|
||||||
|
var productIsDeleted = false;
|
||||||
|
var product = CreateDataModel(productId, productName, productType, productRestaurantId,productPrice, productIsDeleted);
|
||||||
|
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(product.Id, Is.EqualTo(productId));
|
||||||
|
Assert.That(product.ProductName, Is.EqualTo(productName));
|
||||||
|
Assert.That(product.ProductType, Is.EqualTo(productType));
|
||||||
|
Assert.That(product.RestaurantId, Is.EqualTo(productRestaurantId));
|
||||||
|
Assert.That(product.Price, Is.EqualTo(productPrice));
|
||||||
|
Assert.That(product.IsDeleted, Is.EqualTo(productIsDeleted));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? productRestaurantId,double price, bool isDeleted) =>
|
||||||
|
new(id, productName, productType, productRestaurantId, price, isDeleted);
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
using PipingHotContrast.DataModels;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class ProductHistoryDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(null, 500);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(string.Empty, 500);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel("id", 500);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void OldPriceIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
product = CreateDataModel(Guid.NewGuid().ToString(), -500);
|
||||||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var productId = Guid.NewGuid().ToString();
|
||||||
|
var oldPrice = 500;
|
||||||
|
var productHistory = CreateDataModel(productId, oldPrice);
|
||||||
|
Assert.That(() => productHistory.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(productHistory.ProductId, Is.EqualTo(productId));
|
||||||
|
Assert.That(productHistory.OldPrice, Is.EqualTo(oldPrice));
|
||||||
|
Assert.That(productHistory.ChangeDate, Is.LessThan(DateTime.UtcNow));
|
||||||
|
Assert.That(productHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ProductHistoryDataModel CreateDataModel(string? productId, double oldPrice) =>
|
||||||
|
new(productId, oldPrice);
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
using PipingHotContrast.DataModels;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class RestaurantDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var restaurant = CreateDataModel(null, "name");
|
||||||
|
Assert.That(() => restaurant.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
restaurant = CreateDataModel(string.Empty, "name");
|
||||||
|
Assert.That(() => restaurant.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void RestaurantIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var restaurant = CreateDataModel("id", "name");
|
||||||
|
Assert.That(() => restaurant.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void RestaurantNameIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var restaurant = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||||
|
Assert.That(() => restaurant.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
restaurant = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||||
|
Assert.That(() => restaurant.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var restaurantId = Guid.NewGuid().ToString();
|
||||||
|
var restaurantName = "name";
|
||||||
|
var prevRestaurantName = "prevRestaurantName";
|
||||||
|
var prevPrevRestaurantName = "prevPrevRestaurantName";
|
||||||
|
var restaurant = CreateDataModel(restaurantId, restaurantName, prevRestaurantName, prevPrevRestaurantName);
|
||||||
|
Assert.That(() => restaurant.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(restaurant.Id, Is.EqualTo(restaurantId));
|
||||||
|
Assert.That(restaurant.RestaurantName, Is.EqualTo(restaurantName));
|
||||||
|
Assert.That(restaurant.PrevRestaurantName, Is.EqualTo(prevRestaurantName));
|
||||||
|
Assert.That(restaurant.PrevPrevRestaurantName, Is.EqualTo(prevPrevRestaurantName));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static RestaurantDataModel CreateDataModel(string? Id, string? restaurantName, string? prevRestaurantName = null, string? prevPrevRestaurantName = null) =>
|
||||||
|
new(Id, restaurantName, prevRestaurantName, prevPrevRestaurantName);
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
using PipingHotContrast.DataModels;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class SalaryDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsEmptyTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel(null, DateTime.Now, 10);
|
||||||
|
Assert.That(() => salary.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
|
||||||
|
Assert.That(() => salary.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel("workerId", DateTime.Now, 10);
|
||||||
|
Assert.That(() => salary.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PriceIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now,
|
||||||
|
0);
|
||||||
|
Assert.That(() => salary.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -
|
||||||
|
10);
|
||||||
|
Assert.That(() => salary.Validate(),
|
||||||
|
Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var workerId = Guid.NewGuid().ToString();
|
||||||
|
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||||
|
var workerSalary = 10;
|
||||||
|
var salary = CreateDataModel(workerId, salaryDate, workerSalary);
|
||||||
|
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(salary.WorkerId, Is.EqualTo(workerId));
|
||||||
|
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
|
||||||
|
Assert.That(salary.Salary, Is.EqualTo(workerSalary));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private static SalaryDataModel CreateDataModel(string? workerId, DateTime
|
||||||
|
salaryDate, double workerSalary) =>
|
||||||
|
new(workerId, salaryDate, workerSalary);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
113
PipingHot/PipingHotTests/DataModelsTests/WorkerDataModelTests.cs
Normal file
113
PipingHot/PipingHotTests/DataModelsTests/WorkerDataModelTests.cs
Normal file
@ -0,0 +1,113 @@
|
|||||||
|
using PipingHotContrast.DataModels;
|
||||||
|
using PipingHotContrast.Exceptions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PipingHotTests.DataModelsTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class WorkerDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(null, "fio", "user@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(string.Empty, "fio","user@example.com", 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", "user@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void FIOIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), null, "user@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "user@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmailIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmailIsIncorrectTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "user-email", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "user@example.com", null, DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "user@example.com", string.Empty, DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PostIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "user@example.com", "postId", DateTime.Now.AddYears(-16), DateTime.Now, false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void BirthDateIsNotCorrectTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "user@example.com", 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", "user@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16), DateTime.Now.AddYears(-16).AddDays(-1), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "user@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16), DateTime.Now.AddYears(-14), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsIsCorrectTest()
|
||||||
|
{
|
||||||
|
var workerId = Guid.NewGuid().ToString();
|
||||||
|
var fio = "fio";
|
||||||
|
var email = "user@example.com";
|
||||||
|
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, email, 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.Email, Is.EqualTo(email));
|
||||||
|
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? email,string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||||
|
new(id, fio, email,postId, birthDate, employmentDate, isDeleted);
|
||||||
|
}
|
27
PipingHot/PipingHotTests/PipingHotTests.csproj
Normal file
27
PipingHot/PipingHotTests/PipingHotTests.csproj
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0-windows</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="..\PipingHot\PipingHotContrast.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="NUnit.Framework" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
Loading…
x
Reference in New Issue
Block a user