Compare commits
No commits in common. "Lab2" and "start" have entirely different histories.
@ -1,22 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Moq" Version="4.20.72" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<InternalsVisibleTo Include="Tests"/>
|
|
||||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2"/>
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\IcecreamVan\IcecreamVan.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,34 +0,0 @@
|
|||||||
using IcecreamVan.BusinessLogicContracts;
|
|
||||||
using IcecreamVan.StoragesContracts;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace BusinessLogic.Implementations;
|
|
||||||
|
|
||||||
internal class ManufactureBLC(IManufacturerContract mc, ILogger logger) : IManufactureBLC
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger = logger;
|
|
||||||
private readonly IManufacturerContract _mc = mc;
|
|
||||||
|
|
||||||
public List<ManufacturerDataModel> GetAllManufacturers()
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public ManufacturerDataModel GetManufacturerByData(string data)
|
|
||||||
{
|
|
||||||
return new("", "", "", "");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertManufacturer(ManufacturerDataModel manufacturerDataModel)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteManufacturer(string id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
using IcecreamVan.BusinessLogicContracts;
|
|
||||||
using IcecreamVan.StoragesContracts;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Enums;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace BusinessLogic.Implementations;
|
|
||||||
|
|
||||||
internal class PostBLC(IPostContract pc, ILogger logger) : IPostBLC
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger = logger;
|
|
||||||
private readonly IPostContract _pc = pc;
|
|
||||||
|
|
||||||
public List<PostDataModel> GetAllDataOfPost(string postId)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<PostDataModel> GetAllPosts(bool onlyActive)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public PostDataModel GetPostByData(string data)
|
|
||||||
{
|
|
||||||
return new("", "", PostType.None, 0, true, DateTime.Now);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertPost(PostDataModel postDataModel)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void RestorePost(string id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdatePost(PostDataModel postDataModel)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeletePost(string id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
using IcecreamVan.BusinessLogicContracts;
|
|
||||||
using IcecreamVan.StoragesContracts;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Enums;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace BusinessLogic.Implementations;
|
|
||||||
|
|
||||||
internal class ProductBLC(IProductContract prc, ILogger logger) : IProductBLC
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger = logger;
|
|
||||||
private readonly IProductContract _prc = prc;
|
|
||||||
public List<ProductDataModel> GetAllProducts(bool onlyActive = true)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ProductDataModel> GetAllProductsByManufacturer(string manufacturerId, bool onlyActive = true)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public ProductDataModel GetProductByData(string data)
|
|
||||||
{
|
|
||||||
return new("", "", ProductType.None, 0, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertProduct(ProductDataModel productDataModel)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateProduct(ProductDataModel productDataModel)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteProduct(string id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
using IcecreamVan.BusinessLogicContracts;
|
|
||||||
using IcecreamVan.StoragesContracts;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace BusinessLogic.Implementations;
|
|
||||||
|
|
||||||
internal class SalaryBLC(ISalaryContract salc, ILogger logger) : ISalaryBLC
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger = logger;
|
|
||||||
private readonly ISalaryContract _salc = salc;
|
|
||||||
public void CalculateSalaryByMounth(DateTime date)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
using IcecreamVan.BusinessLogicContracts;
|
|
||||||
using IcecreamVan.StoragesContracts;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Enums;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace BusinessLogic.Implementations;
|
|
||||||
|
|
||||||
internal class SaleBLC(ISaleContract sc, ILogger logger) : ISaleBLC
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger = logger;
|
|
||||||
private readonly ISaleContract _sc = sc;
|
|
||||||
public List<SaleDataModel> GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SaleDataModel> GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public SaleDataModel GetSaleByData(string data)
|
|
||||||
{
|
|
||||||
return new("", "", 0, DiscountType.None, 0, true, []);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertSale(SaleDataModel saleDataModel)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void CancelSale(string id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
using IcecreamVan.BusinessLogicContracts;
|
|
||||||
using IcecreamVan.StoragesContracts;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace BusinessLogic.Implementations;
|
|
||||||
|
|
||||||
internal class WorkerBLC(IWorkerContract wc, ILogger logger) : IWorkerBLC
|
|
||||||
{
|
|
||||||
private readonly ILogger _logger = logger;
|
|
||||||
private readonly IWorkerContract _wc = wc;
|
|
||||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true)
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorkerDataModel GetWorkerByData(string data)
|
|
||||||
{
|
|
||||||
return new("", "", "", "", DateTime.Now, DateTime.Now, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void UpdateWorker(WorkerDataModel workerDataModel)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteWorker(string id)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.BusinessLogicContracts;
|
|
||||||
|
|
||||||
public interface IManufactureBLC
|
|
||||||
{
|
|
||||||
List<ManufacturerDataModel> GetAllManufacturers();
|
|
||||||
|
|
||||||
ManufacturerDataModel GetManufacturerByData(string data);
|
|
||||||
|
|
||||||
void InsertManufacturer(ManufacturerDataModel manufacturerDataModel);
|
|
||||||
|
|
||||||
void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel);
|
|
||||||
|
|
||||||
void DeleteManufacturer(string id);
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.BusinessLogicContracts;
|
|
||||||
|
|
||||||
public interface IPostBLC
|
|
||||||
{
|
|
||||||
List<PostDataModel> GetAllPosts(bool onlyActive);
|
|
||||||
|
|
||||||
List<PostDataModel> GetAllDataOfPost(string postId);
|
|
||||||
|
|
||||||
PostDataModel GetPostByData(string data);
|
|
||||||
|
|
||||||
void InsertPost(PostDataModel postDataModel);
|
|
||||||
|
|
||||||
void UpdatePost(PostDataModel postDataModel);
|
|
||||||
|
|
||||||
void DeletePost(string id);
|
|
||||||
|
|
||||||
void RestorePost(string id);
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.BusinessLogicContracts;
|
|
||||||
|
|
||||||
public interface IProductBLC
|
|
||||||
{
|
|
||||||
List<ProductDataModel> GetAllProducts(bool onlyActive = true);
|
|
||||||
|
|
||||||
List<ProductDataModel> GetAllProductsByManufacturer(string manufacturerId, bool onlyActive = true);
|
|
||||||
|
|
||||||
List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId);
|
|
||||||
|
|
||||||
ProductDataModel GetProductByData(string data);
|
|
||||||
|
|
||||||
void InsertProduct(ProductDataModel productDataModel);
|
|
||||||
|
|
||||||
void UpdateProduct(ProductDataModel productDataModel);
|
|
||||||
|
|
||||||
void DeleteProduct(string id);
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.BusinessLogicContracts;
|
|
||||||
|
|
||||||
public interface ISalaryBLC
|
|
||||||
{
|
|
||||||
List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate);
|
|
||||||
|
|
||||||
List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId);
|
|
||||||
|
|
||||||
void CalculateSalaryByMounth(DateTime date);
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.BusinessLogicContracts;
|
|
||||||
|
|
||||||
public interface ISaleBLC
|
|
||||||
{
|
|
||||||
List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate);
|
|
||||||
|
|
||||||
List<SaleDataModel> GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate);
|
|
||||||
|
|
||||||
List<SaleDataModel> GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate);
|
|
||||||
|
|
||||||
SaleDataModel GetSaleByData(string data);
|
|
||||||
|
|
||||||
void InsertSale(SaleDataModel saleDataModel);
|
|
||||||
|
|
||||||
void CancelSale(string id);
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.BusinessLogicContracts;
|
|
||||||
|
|
||||||
public interface IWorkerBLC
|
|
||||||
{
|
|
||||||
List<WorkerDataModel> GetAllWorkers(bool onlyActive = true);
|
|
||||||
|
|
||||||
List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive =
|
|
||||||
true);
|
|
||||||
|
|
||||||
List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
|
||||||
|
|
||||||
List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true);
|
|
||||||
|
|
||||||
WorkerDataModel GetWorkerByData(string data);
|
|
||||||
|
|
||||||
void InsertWorker(WorkerDataModel workerDataModel);
|
|
||||||
|
|
||||||
void UpdateWorker(WorkerDataModel workerDataModel);
|
|
||||||
|
|
||||||
void DeleteWorker(string id);
|
|
||||||
}
|
|
@ -1,28 +0,0 @@
|
|||||||
using IcecreamVan.Extensions;
|
|
||||||
using IcecreamVan.Infrastructure;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
public class ManufacturerDataModel(string id, string manufacturerName, string? prevManufacturerName, string? prevPrevManufacturerName) : IValidation
|
|
||||||
{
|
|
||||||
public string Id { get; private set; } = id;
|
|
||||||
|
|
||||||
public string ManufacturerName { get; private set; } = manufacturerName;
|
|
||||||
|
|
||||||
public string? PrevManufacturerName { get; private set; } = prevManufacturerName;
|
|
||||||
|
|
||||||
public string? PrevPrevManufacturerName { get; private set; } = prevPrevManufacturerName;
|
|
||||||
|
|
||||||
public void Validate()
|
|
||||||
{
|
|
||||||
if (Id.IsEmpty())
|
|
||||||
throw new ValidationException("Field ID is empty");
|
|
||||||
|
|
||||||
if (!Id.IsGuid())
|
|
||||||
throw new ValidationException("The field ID value is NOT a unique identifier");
|
|
||||||
|
|
||||||
if (ManufacturerName.IsEmpty())
|
|
||||||
throw new ValidationException("Field ManufacturerName is empty");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
using IcecreamVan.Enums;
|
|
||||||
using IcecreamVan.Extensions;
|
|
||||||
using IcecreamVan.Infrastructure;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
public class PostDataModel(string id, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
|
||||||
{
|
|
||||||
public string Id { get; private set; } = id;
|
|
||||||
|
|
||||||
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 ID value is NOT a unique identifier");
|
|
||||||
|
|
||||||
if (PostName.IsEmpty())
|
|
||||||
throw new ValidationException("Name is empty");
|
|
||||||
|
|
||||||
if (PostType == PostType.None)
|
|
||||||
throw new ValidationException("Type is empty");
|
|
||||||
|
|
||||||
if (Salary <= 0)
|
|
||||||
throw new ValidationException("Salary is empty");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,40 +0,0 @@
|
|||||||
using IcecreamVan.Enums;
|
|
||||||
using IcecreamVan.Extensions;
|
|
||||||
using IcecreamVan.Infrastructure;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
// 4. У продукта, в свою очередь, есть производитель (Manufacturer -> Product) и тип (перечисление),
|
|
||||||
// а также информация об изменениях расценки (Product -> 5. History)
|
|
||||||
|
|
||||||
public class ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted) : IValidation
|
|
||||||
{
|
|
||||||
public string Id { get; private set; } = id;
|
|
||||||
|
|
||||||
public string ProductName { get; private set; } = productName;
|
|
||||||
|
|
||||||
public ProductType ProductType { get; private set; } = productType;
|
|
||||||
|
|
||||||
public double Price { get; private set; } = price;
|
|
||||||
|
|
||||||
public bool IsDeleted { get; private set; } = isDeleted;
|
|
||||||
|
|
||||||
public void Validate()
|
|
||||||
{
|
|
||||||
if (Id.IsEmpty())
|
|
||||||
throw new ValidationException("Field ID is empty");
|
|
||||||
|
|
||||||
if (!Id.IsGuid())
|
|
||||||
throw new ValidationException("The ID value is NOT a unique identifier");
|
|
||||||
|
|
||||||
if (ProductName.IsEmpty())
|
|
||||||
throw new ValidationException("Name is empty");
|
|
||||||
|
|
||||||
if (ProductType == ProductType.None)
|
|
||||||
throw new ValidationException("Type is empty");
|
|
||||||
|
|
||||||
if (Price <= 0)
|
|
||||||
throw new ValidationException("Field Price is less than or equal to 0");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
using IcecreamVan.Extensions;
|
|
||||||
using IcecreamVan.Infrastructure;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace IcecreamVan.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 Product ID is empty");
|
|
||||||
|
|
||||||
if (!ProductId.IsGuid())
|
|
||||||
throw new ValidationException("The value is NOT a unique identifier");
|
|
||||||
|
|
||||||
if (OldPrice <= 0)
|
|
||||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,26 +0,0 @@
|
|||||||
using IcecreamVan.Extensions;
|
|
||||||
using IcecreamVan.Infrastructure;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
|
|
||||||
{
|
|
||||||
public string WorkerId { get; private set; } = workerId;
|
|
||||||
|
|
||||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
|
||||||
|
|
||||||
public double Salary { get; private set; } = workerSalary;
|
|
||||||
|
|
||||||
public void Validate()
|
|
||||||
{
|
|
||||||
if (WorkerId.IsEmpty())
|
|
||||||
throw new ValidationException("Field Worker ID is empty");
|
|
||||||
|
|
||||||
if (!WorkerId.IsGuid())
|
|
||||||
throw new ValidationException("The Worker ID value is NOT a unique identifier");
|
|
||||||
|
|
||||||
if (Salary <= 0)
|
|
||||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
using IcecreamVan.Enums;
|
|
||||||
using IcecreamVan.Extensions;
|
|
||||||
using IcecreamVan.Infrastructure;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
// 2. Продажа, помимо работника, содержит клиента/покупателя (Buyer -> Sale) и СПИСОК ПРОДУКТОВ (3. SaleProduct -> Sale)
|
|
||||||
|
|
||||||
public class SaleDataModel(string id, string workerId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleProductDataModel> products) : IValidation
|
|
||||||
{
|
|
||||||
public string Id { get; private set; } = id;
|
|
||||||
|
|
||||||
public string WorkerId { get; private set; } = workerId;
|
|
||||||
|
|
||||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
|
||||||
|
|
||||||
public double Sum { get; private set; } = sum;
|
|
||||||
|
|
||||||
public DiscountType DiscountType { get; private set; } = discountType;
|
|
||||||
|
|
||||||
public double Discount { get; private set; } = discount;
|
|
||||||
|
|
||||||
public bool IsCancel { get; private set; } = isCancel;
|
|
||||||
|
|
||||||
public List<SaleProductDataModel> Products { get; private set; } = products;
|
|
||||||
|
|
||||||
public void Validate()
|
|
||||||
{
|
|
||||||
if (Id.IsEmpty())
|
|
||||||
throw new ValidationException("Field ID is empty");
|
|
||||||
|
|
||||||
if (!Id.IsGuid())
|
|
||||||
throw new ValidationException("The ID is not a unique identifier");
|
|
||||||
|
|
||||||
if (WorkerId.IsEmpty())
|
|
||||||
throw new ValidationException("Field Worker ID is empty");
|
|
||||||
|
|
||||||
if (!WorkerId.IsGuid())
|
|
||||||
throw new ValidationException("The Worker ID 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");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
using IcecreamVan.Extensions;
|
|
||||||
using IcecreamVan.Infrastructure;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
// 3. Каждый продукт связан с продажей промежуточной информацией о количестве данного продукта (4. Product -> SaleProduct)
|
|
||||||
|
|
||||||
public class SaleProductDataModel(string saleId, string productId, int count) : IValidation
|
|
||||||
{
|
|
||||||
public string SaleId { get; private set; } = saleId;
|
|
||||||
|
|
||||||
public string ProductId { get; private set; } = productId;
|
|
||||||
|
|
||||||
public int Count { get; private set; } = count;
|
|
||||||
|
|
||||||
public void Validate()
|
|
||||||
{
|
|
||||||
if (SaleId.IsEmpty())
|
|
||||||
throw new ValidationException("Field Sale ID is empty");
|
|
||||||
|
|
||||||
if (!SaleId.IsGuid())
|
|
||||||
throw new ValidationException("The Sale ID value is NOT a unique identifier");
|
|
||||||
|
|
||||||
if (ProductId.IsEmpty())
|
|
||||||
throw new ValidationException("Field Product ID is empty");
|
|
||||||
|
|
||||||
if (!ProductId.IsGuid())
|
|
||||||
throw new ValidationException("The Product ID value is NOT a unique identifier");
|
|
||||||
|
|
||||||
if (Count <= 0)
|
|
||||||
throw new ValidationException("Field Count is less than or equal to 0");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
using System.Text.RegularExpressions;
|
|
||||||
using IcecreamVan.Extensions;
|
|
||||||
using IcecreamVan.Infrastructure;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
// 1. Работник (Worker -> 2. Sale) фигурирует затем в продажах,
|
|
||||||
// имеет определенную должность (Post -> Worker), имеет отношение к зачислению з/п (Worker -> Salary)
|
|
||||||
|
|
||||||
public class WorkerDataModel(string id, string fio, string postId, string phoneNumber, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
|
||||||
{
|
|
||||||
public string Id { get; private set; } = id;
|
|
||||||
|
|
||||||
public string FIO { get; private set; } = fio;
|
|
||||||
|
|
||||||
public string PhoneNumber { get; private set; } = phoneNumber;
|
|
||||||
|
|
||||||
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 ID value is NOT a unique identifier");
|
|
||||||
|
|
||||||
if (FIO.IsEmpty())
|
|
||||||
throw new ValidationException("Field FIO is empty");
|
|
||||||
|
|
||||||
if (PostId.IsEmpty())
|
|
||||||
throw new ValidationException("Field Post ID is empty");
|
|
||||||
|
|
||||||
if (!PostId.IsGuid())
|
|
||||||
throw new ValidationException("The Post ID value 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()})");
|
|
||||||
|
|
||||||
if (PhoneNumber.IsEmpty())
|
|
||||||
throw new ValidationException("Field PhoneNumber is empty");
|
|
||||||
|
|
||||||
if (!Regex.IsMatch(PhoneNumber, @"^(8|\+7)\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{2}[-.\s]?\d{2}")) // *
|
|
||||||
throw new ValidationException("Field PhoneNumber is NOT a phone number");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
namespace IcecreamVan.Enums;
|
|
||||||
|
|
||||||
[Flags]
|
|
||||||
public enum DiscountType
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
OnSale = 1,
|
|
||||||
Certificate = 2
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
namespace IcecreamVan.Enums;
|
|
||||||
|
|
||||||
public enum PostType
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
Chef = 1,
|
|
||||||
Cashier = 2,
|
|
||||||
Assistant = 3
|
|
||||||
}
|
|
@ -1,9 +0,0 @@
|
|||||||
namespace IcecreamVan.Enums;
|
|
||||||
|
|
||||||
public enum ProductType
|
|
||||||
{
|
|
||||||
None = 0,
|
|
||||||
Icecream = 1,
|
|
||||||
Milkshake = 2,
|
|
||||||
Souvenir = 3
|
|
||||||
}
|
|
@ -1,117 +0,0 @@
|
|||||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
|
||||||
|
|
||||||
namespace IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Необходимо реализовать приложение для автоматизации работы
|
|
||||||
фургончика с мороженным «Снегурочка». В фургончике трудятся
|
|
||||||
работники на разных должностях, они отвечают за готовку,
|
|
||||||
продажу, перемещение. Необходимо фиксировать продажи различного
|
|
||||||
мороженного (разных типов от разных производителей). Предусмотреть
|
|
||||||
возможность начисления ежемесячной зарплаты работникам на основе выполненных продаж.
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class ValidationException(string message) : Exception(message)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public class NullListException : Exception
|
|
||||||
{
|
|
||||||
public NullListException() : base("The returned LIST is NULL") { }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class StorageException : Exception
|
|
||||||
{
|
|
||||||
public StorageException(Exception ex) : base($"Error while working in STORAGE: {ex.Message}", ex) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ElementExistsException : Exception
|
|
||||||
{
|
|
||||||
public string ParamName { get; private set; }
|
|
||||||
public string ParamValue { get; private set; }
|
|
||||||
|
|
||||||
public ElementExistsException(string paramName, string paramValue) : base($"There is already an element with SAME VALUE{paramValue} of parameter {paramName}")
|
|
||||||
{ ParamName = paramName; ParamValue = paramValue; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ElementNotFoundException : Exception
|
|
||||||
{
|
|
||||||
public string Value { get; private set; }
|
|
||||||
public ElementNotFoundException(string value) : base($"Element NOT FOUND at value = {value}") { Value = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public class IncorrectDatesException : Exception
|
|
||||||
{
|
|
||||||
public IncorrectDatesException(DateTime start, DateTime end) : base($"The END date must be LATER than the START date..StartDate: {start: dd.MM.YYYY}. EndDate: {end:dd.MM.YYYY}") { }
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class DateTimeExtensions
|
|
||||||
{
|
|
||||||
public static bool IsDateNotOlder(this DateTime date, DateTime olderDate)
|
|
||||||
{
|
|
||||||
return date >= olderDate;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
Questions :
|
|
||||||
1. Регулярные выражения (regex или regexp) -
|
|
||||||
последовательность символов, которая определяет шаблон поиска.
|
|
||||||
Используется при проверки соответствия строки определенному шаблону (например, проверка формата email-адреса).
|
|
||||||
Один из основных инструментов - Метасимволы.
|
|
||||||
Специальные символы, имеющие особое значение. Вот некоторые из наиболее распространенных:
|
|
||||||
. Соответствует любому одиночному символу(кроме новой строки, если не указано иное).
|
|
||||||
^ - началу строки.
|
|
||||||
$ - концу строки.
|
|
||||||
* - нулю или более повторениям предыдущего символа или группы.
|
|
||||||
+ - одному или более повторениям предыдущего символа или группы.
|
|
||||||
? - нулю или одному повторению предыдущего символа или группы.
|
|
||||||
([!] СМ. BuyerDataModel / WorkerDM [!])
|
|
||||||
|
|
||||||
Regex.Matches(text, pattern) - выполняет поиск всех соответствий шаблону pattern в тексте text.
|
|
||||||
MatchCollection - коллекция найденных соответствий.
|
|
||||||
match.Value - свойство объекта Match, содержащее найденную подстроку.
|
|
||||||
|
|
||||||
|
|
||||||
2. В Solution Explorer -> Выбр. роект(щёлкнув), в который вы хотите добавить ссылку, Add -> Project Reference…
|
|
||||||
(или “Добавить” -> “Ссылка на проект…”). В открывшемся окне отметить проект, который хочу подключить
|
|
||||||
ВАЖНО : Не допускать циклических зависимостей + Убедиться, что подключаемые классы и методы,
|
|
||||||
для исп. в другом проекте, имеют модификатор доступа public / internal (по умолчанию)
|
|
||||||
делает их доступными только в пределах текущей сборки.
|
|
||||||
|
|
||||||
|
|
||||||
3. В C# тестирование обычно выполняется с использованием фреймворков, таких как MSTest, NUnit или xUnit.
|
|
||||||
Независимо от фреймворка, Visual Studio предоставляет удобный интерфейс для запуска тестов.
|
|
||||||
|
|
||||||
Запуск тестов через Test Explorer: Открыть Test Explorer: Test -> Windows -> Test Explorer (или Ctrl+E, T).
|
|
||||||
Иногда может потребоваться нажать кнопку “Refresh” в Test Explorer.
|
|
||||||
Щелкните правой кнопкой мыши по имени теста в Test Explorer и выберите “Run Selected Tests”
|
|
||||||
(или “Запустить выбранные тесты”). Можно выбрать несколько тестов, удерживая Ctrl или Shift и щелкая по ним, а затем запустить их.
|
|
||||||
|
|
||||||
*/
|
|
@ -1,14 +0,0 @@
|
|||||||
namespace IcecreamVan.Extensions;
|
|
||||||
|
|
||||||
public static class StringExtensions
|
|
||||||
{
|
|
||||||
public static bool IsEmpty(this string str)
|
|
||||||
{
|
|
||||||
return string.IsNullOrWhiteSpace(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool IsGuid(this string str)
|
|
||||||
{
|
|
||||||
return Guid.TryParse(str, out _);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net8.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
|
||||||
<PackageReference Include="Moq" Version="4.20.72" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,6 +0,0 @@
|
|||||||
namespace IcecreamVan.Infrastructure;
|
|
||||||
|
|
||||||
public interface IValidation
|
|
||||||
{
|
|
||||||
void Validate();
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.StoragesContracts;
|
|
||||||
|
|
||||||
public interface IManufacturerContract
|
|
||||||
{
|
|
||||||
List<ManufacturerDataModel> GetList();
|
|
||||||
|
|
||||||
ManufacturerDataModel? GetElementById(string id);
|
|
||||||
|
|
||||||
ManufacturerDataModel? GetElementByName(string name);
|
|
||||||
|
|
||||||
ManufacturerDataModel? GetElementByOldName(string oldName);
|
|
||||||
|
|
||||||
void AddElement(ManufacturerDataModel manufDataModel);
|
|
||||||
|
|
||||||
void UpdElement(ManufacturerDataModel manufDataModel);
|
|
||||||
|
|
||||||
void DelElement(string id);
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.StoragesContracts;
|
|
||||||
|
|
||||||
public interface IPostContract
|
|
||||||
{
|
|
||||||
List<PostDataModel> GetList(bool onlyActual = true);
|
|
||||||
|
|
||||||
List<PostDataModel> GetPostHistory(string postId);
|
|
||||||
|
|
||||||
PostDataModel? GetElementById(string id);
|
|
||||||
|
|
||||||
PostDataModel? GetElementByName(string name);
|
|
||||||
|
|
||||||
void AddElement(PostDataModel postDataModel);
|
|
||||||
|
|
||||||
void UpdElement(PostDataModel postDataModel);
|
|
||||||
|
|
||||||
void DelElement(string id);
|
|
||||||
|
|
||||||
void ResElement(string id);
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.StoragesContracts;
|
|
||||||
|
|
||||||
public interface IProductContract
|
|
||||||
{
|
|
||||||
List<ProductDataModel> GetList(bool onlyActive = true, string? manufacturerID = null);
|
|
||||||
|
|
||||||
List<ProductHistoryDataModel> GetProductHistoryById(string productId);
|
|
||||||
|
|
||||||
ProductDataModel? GetElementById(string id);
|
|
||||||
|
|
||||||
ProductDataModel? GetElementByName(string name);
|
|
||||||
|
|
||||||
void AddElement(ProductDataModel prodDataModel);
|
|
||||||
|
|
||||||
void UpdElement(ProductDataModel prodDataModel);
|
|
||||||
|
|
||||||
void DelElement(string id);
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.StoragesContracts;
|
|
||||||
|
|
||||||
public interface ISalaryContract
|
|
||||||
{
|
|
||||||
List<SalaryDataModel> GetList(DateTime startD, DateTime endD, string? workerID = null);
|
|
||||||
|
|
||||||
void AddElement(SalaryDataModel salary);
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.StoragesContracts;
|
|
||||||
|
|
||||||
public interface ISaleContract
|
|
||||||
{
|
|
||||||
List<SaleDataModel> GetList(DateTime? startD = null, DateTime? endD = null, string? workerID = null, string? buyerID = null, string? productID = null);
|
|
||||||
|
|
||||||
SaleDataModel? GetElementById(string id);
|
|
||||||
|
|
||||||
void AddElement(SaleDataModel saleDataModel);
|
|
||||||
|
|
||||||
void DelElement(string id);
|
|
||||||
}
|
|
@ -1,18 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
|
|
||||||
namespace IcecreamVan.StoragesContracts;
|
|
||||||
|
|
||||||
public interface IWorkerContract
|
|
||||||
{
|
|
||||||
List<WorkerDataModel> GetList(bool onlyActive = true, string? postID = null, DateTime? fromBD = null, DateTime? toBD = null, DateTime? fromEmploymentDate = null, DateTime? toEmploymentDate = null);
|
|
||||||
|
|
||||||
WorkerDataModel? GetElementById(string id);
|
|
||||||
|
|
||||||
WorkerDataModel? GetElementByName(string fio);
|
|
||||||
|
|
||||||
void AddElement(WorkerDataModel workerDataModel);
|
|
||||||
|
|
||||||
void UpdElement(WorkerDataModel workerDataModel);
|
|
||||||
|
|
||||||
void DelElement(string id);
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
|
||||||
# Visual Studio Version 17
|
|
||||||
VisualStudioVersion = 17.8.34525.116
|
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IcecreamVan", "IcecreamVan\IcecreamVan.csproj", "{A0730374-6964-4D45-A425-049EAE498DEC}"
|
|
||||||
EndProject
|
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{FC61899B-2BD9-43C9-AA66-6BF1A6FE2F48}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BusinessLogic", "BusinessLogic\BusinessLogic.csproj", "{45D1B6A1-441D-4020-A4EB-22F21F54243C}"
|
|
||||||
EndProject
|
|
||||||
Global
|
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
|
||||||
Debug|Any CPU = Debug|Any CPU
|
|
||||||
Release|Any CPU = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
|
||||||
{A0730374-6964-4D45-A425-049EAE498DEC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{A0730374-6964-4D45-A425-049EAE498DEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{A0730374-6964-4D45-A425-049EAE498DEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{A0730374-6964-4D45-A425-049EAE498DEC}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{FC61899B-2BD9-43C9-AA66-6BF1A6FE2F48}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{FC61899B-2BD9-43C9-AA66-6BF1A6FE2F48}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{FC61899B-2BD9-43C9-AA66-6BF1A6FE2F48}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{FC61899B-2BD9-43C9-AA66-6BF1A6FE2F48}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{45D1B6A1-441D-4020-A4EB-22F21F54243C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{45D1B6A1-441D-4020-A4EB-22F21F54243C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{45D1B6A1-441D-4020-A4EB-22F21F54243C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{45D1B6A1-441D-4020-A4EB-22F21F54243C}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
|
||||||
HideSolutionNode = FALSE
|
|
||||||
EndGlobalSection
|
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
|
||||||
SolutionGuid = {9B025B6B-EB5B-42BD-ABD4-4F16CF081CD4}
|
|
||||||
EndGlobalSection
|
|
||||||
EndGlobal
|
|
@ -1,353 +0,0 @@
|
|||||||
using IcecreamVan.BusinessLogicContracts;
|
|
||||||
using BusinessLogic.Implementations;
|
|
||||||
using IcecreamVan.StoragesContracts;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
using NUnit.Framework;
|
|
||||||
using Moq;
|
|
||||||
|
|
||||||
namespace Tests.BLCTests;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class ManufactureBLCTest
|
|
||||||
{
|
|
||||||
private IManufactureBLC _Mblc;
|
|
||||||
private Mock<IManufacturerContract> _Msc;
|
|
||||||
|
|
||||||
[OneTimeSetUp]
|
|
||||||
public void OneTimeSetUp()
|
|
||||||
{
|
|
||||||
_Msc = new Mock<IManufacturerContract>();
|
|
||||||
_Mblc = new ManufactureBLC(_Msc.Object, new Mock<ILogger>().Object);
|
|
||||||
}
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void SetUp()
|
|
||||||
{
|
|
||||||
_Msc.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllManufacturers_ReturnListOfRecords_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var listOriginal = new List<ManufacturerDataModel>() {
|
|
||||||
new(Guid.NewGuid().ToString(), "name 1", null, null),
|
|
||||||
new(Guid.NewGuid().ToString(), "name 2", null, null),
|
|
||||||
new(Guid.NewGuid().ToString(), "name 3", null, null),
|
|
||||||
};
|
|
||||||
_Msc.Setup(x => x.GetList()).Returns(listOriginal);
|
|
||||||
//Act
|
|
||||||
var list = _Mblc.GetAllManufacturers();
|
|
||||||
//Assert
|
|
||||||
Assert.That(list, Is.Not.Null);
|
|
||||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllManufacturers_ReturnEmptyList_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.GetList()).Returns([]);
|
|
||||||
//Act
|
|
||||||
var list = _Mblc.GetAllManufacturers();
|
|
||||||
//Assert
|
|
||||||
Assert.That(list, Is.Not.Null);
|
|
||||||
Assert.That(list, Has.Count.EqualTo(0));
|
|
||||||
_Msc.Verify(x => x.GetList(), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllManufacturers_ReturnNull_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.GetAllManufacturers(), Throws.TypeOf<NullListException>());
|
|
||||||
_Msc.Verify(x => x.GetList(), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllManufacturers_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.GetAllManufacturers(), Throws.TypeOf<StorageException>());
|
|
||||||
_Msc.Verify(x => x.GetList(), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetManufacturerByData_GetById_ReturnRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var id = Guid.NewGuid().ToString();
|
|
||||||
var record = new ManufacturerDataModel(id, "name", null, null);
|
|
||||||
_Msc.Setup(x => x.GetElementById(id)).Returns(record);
|
|
||||||
//Act
|
|
||||||
var element =
|
|
||||||
_Mblc.GetManufacturerByData(id);
|
|
||||||
//Assert
|
|
||||||
Assert.That(element, Is.Not.Null);
|
|
||||||
Assert.That(element.Id, Is.EqualTo(id));
|
|
||||||
_Msc.Verify(x =>
|
|
||||||
x.GetElementById(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetManufacturerByData_GetByName_ReturnRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var manufacturerName = "name";
|
|
||||||
var record = new ManufacturerDataModel(Guid.NewGuid().ToString(), manufacturerName, null, null);
|
|
||||||
_Msc.Setup(x => x.GetElementByName(manufacturerName)).Returns(record);
|
|
||||||
//Act
|
|
||||||
var element = _Mblc.GetManufacturerByData(manufacturerName);
|
|
||||||
//Assert
|
|
||||||
Assert.That(element, Is.Not.Null);
|
|
||||||
Assert.That(element.ManufacturerName, Is.EqualTo(manufacturerName));
|
|
||||||
_Msc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetManufacturerByData_GetByOldName_ReturnRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var manufacturerOldName = "name before";
|
|
||||||
var record = new ManufacturerDataModel(Guid.NewGuid().ToString(), "name", manufacturerOldName, null);
|
|
||||||
_Msc.Setup(x => x.GetElementByOldName(manufacturerOldName)).Returns(record);
|
|
||||||
//Act
|
|
||||||
var element = _Mblc.GetManufacturerByData(manufacturerOldName);
|
|
||||||
//Assert
|
|
||||||
Assert.That(element, Is.Not.Null);
|
|
||||||
Assert.That(element.PrevManufacturerName, Is.EqualTo(manufacturerOldName));
|
|
||||||
_Msc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
||||||
_Msc.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetManufacturerByData_EmptyData_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.GetManufacturerByData(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
Assert.That(() => _Mblc.GetManufacturerByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Msc.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
|
||||||
_Msc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
|
||||||
_Msc.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetManufacturerByData__GetById_NotFoundRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.GetManufacturerByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
|
||||||
_Msc.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
|
||||||
_Msc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
|
||||||
_Msc.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void
|
|
||||||
GetManufacturerByData_GetByNameOrOldName_NotFoundRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.GetManufacturerByData("name"), Throws.TypeOf<ElementNotFoundException>());
|
|
||||||
_Msc.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
|
||||||
_Msc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
||||||
_Msc.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetManufacturerByData_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
_Msc.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.GetManufacturerByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
|
||||||
Assert.That(() => _Mblc.GetManufacturerByData("name"), Throws.TypeOf<StorageException>());
|
|
||||||
_Msc.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
|
||||||
_Msc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
||||||
_Msc.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetManufacturerByData_GetByOldName_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.GetElementByOldName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.GetManufacturerByData("name"), Throws.TypeOf<StorageException>());
|
|
||||||
_Msc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
||||||
_Msc.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertManufacturer_CorrectRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var flag = false;
|
|
||||||
var record = new ManufacturerDataModel(Guid.NewGuid().ToString(), "name", null, null);
|
|
||||||
_Msc.Setup(x => x.AddElement(It.IsAny<ManufacturerDataModel>())).Callback((ManufacturerDataModel x) =>
|
|
||||||
{
|
|
||||||
flag = x.Id == record.Id && x.ManufacturerName == record.ManufacturerName;
|
|
||||||
});
|
|
||||||
//Act
|
|
||||||
_Mblc.InsertManufacturer(record);
|
|
||||||
//Assert
|
|
||||||
_Msc.Verify(x => x.AddElement(It.IsAny<ManufacturerDataModel>()), Times.Once);
|
|
||||||
Assert.That(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertManufacturer_RecordWithExistsData_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.AddElement(It.IsAny<ManufacturerDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.InsertManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf<ElementExistsException>());
|
|
||||||
_Msc.Verify(x => x.AddElement(It.IsAny<ManufacturerDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertManufacturer_NullRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.InsertManufacturer(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Msc.Verify(x => x.AddElement(It.IsAny<ManufacturerDataModel>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertManufacturer_InvalidRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.InsertManufacturer(new ManufacturerDataModel("id", "name", null, null)), Throws.TypeOf<ValidationException>());
|
|
||||||
_Msc.Verify(x => x.AddElement(It.IsAny<ManufacturerDataModel>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertManufacturer_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.AddElement(It.IsAny<ManufacturerDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.InsertManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf<StorageException>());
|
|
||||||
_Msc.Verify(x => x.AddElement(It.IsAny<ManufacturerDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdateManufacturer_CorrectRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var flag = false;
|
|
||||||
var record = new ManufacturerDataModel(Guid.NewGuid().ToString(), "name", null, null);
|
|
||||||
_Msc.Setup(x => x.UpdElement(It.IsAny<ManufacturerDataModel>())).Callback((ManufacturerDataModel x) =>
|
|
||||||
{
|
|
||||||
flag = x.Id == record.Id && x.ManufacturerName == record.ManufacturerName;
|
|
||||||
});
|
|
||||||
//Act
|
|
||||||
_Mblc.UpdateManufacturer(record);
|
|
||||||
//Assert
|
|
||||||
_Msc.Verify(x => x.UpdElement(It.IsAny<ManufacturerDataModel>()), Times.Once);
|
|
||||||
Assert.That(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void
|
|
||||||
UpdateManufacturer_RecordWithIncorrectData_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.UpdElement(It.IsAny<ManufacturerDataModel>())).Throws(new ElementNotFoundException(""));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.UpdateManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf<ElementNotFoundException>());
|
|
||||||
_Msc.Verify(x => x.UpdElement(It.IsAny<ManufacturerDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdateManufacturer_RecordWithExistsData_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.UpdElement(It.IsAny<ManufacturerDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.UpdateManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf<ElementExistsException>());
|
|
||||||
_Msc.Verify(x => x.UpdElement(It.IsAny<ManufacturerDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdateManufacturer_NullRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.UpdateManufacturer(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Msc.Verify(x => x.UpdElement(It.IsAny<ManufacturerDataModel>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdateManufacturer_InvalidRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.UpdateManufacturer(new ManufacturerDataModel("id", "name", null, null)), Throws.TypeOf<ValidationException>());
|
|
||||||
_Msc.Verify(x => x.UpdElement(It.IsAny<ManufacturerDataModel>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdateManufacturer_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.UpdElement(It.IsAny<ManufacturerDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.UpdateManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf<StorageException>());
|
|
||||||
_Msc.Verify(x => x.UpdElement(It.IsAny<ManufacturerDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeleteManufacturer_CorrectRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var id = Guid.NewGuid().ToString();
|
|
||||||
var flag = false;
|
|
||||||
_Msc.Setup(x => x.DelElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
|
||||||
//Act
|
|
||||||
_Mblc.DeleteManufacturer(id);
|
|
||||||
//Assert
|
|
||||||
_Msc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
|
||||||
Assert.That(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeleteManufacturer_RecordWithIncorrectId_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var id = Guid.NewGuid().ToString();
|
|
||||||
_Msc.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.DeleteManufacturer(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
|
||||||
_Msc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeleteManufacturer_IdIsNullOrEmpty_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.DeleteManufacturer(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
Assert.That(() => _Mblc.DeleteManufacturer(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Msc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeleteManufacturer_IdIsNotGuid_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.DeleteManufacturer("id"), Throws.TypeOf<ValidationException>());
|
|
||||||
_Msc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeleteManufacturer_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Msc.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Mblc.DeleteManufacturer(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
|
||||||
_Msc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,453 +0,0 @@
|
|||||||
using IcecreamVan.BusinessLogicContracts;
|
|
||||||
using BusinessLogic.Implementations;
|
|
||||||
using IcecreamVan.StoragesContracts;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
using IcecreamVan.Enums;
|
|
||||||
using NUnit.Framework;
|
|
||||||
using Moq;
|
|
||||||
|
|
||||||
namespace Tests.BLCTests;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class PostBLCTests
|
|
||||||
{
|
|
||||||
private IPostBLC _Pblc;
|
|
||||||
private Mock<IPostContract> _Psc;
|
|
||||||
|
|
||||||
[OneTimeSetUp]
|
|
||||||
public void OneTimeSetUp()
|
|
||||||
{
|
|
||||||
_Psc = new Mock<IPostContract>();
|
|
||||||
_Pblc = new PostBLC(_Psc.Object, new Mock<ILogger>().Object);
|
|
||||||
}
|
|
||||||
|
|
||||||
[SetUp]
|
|
||||||
public void SetUp()
|
|
||||||
{
|
|
||||||
_Psc.Reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllPosts_ReturnListOfRecords_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var listOriginal = new List<PostDataModel>()
|
|
||||||
{
|
|
||||||
new(Guid.NewGuid().ToString(),"name 1", PostType.Assistant, 10, true, DateTime.UtcNow),
|
|
||||||
new(Guid.NewGuid().ToString(), "name 2", PostType.Assistant, 10, false, DateTime.UtcNow),
|
|
||||||
new(Guid.NewGuid().ToString(), "name 3", PostType.Assistant, 10, true, DateTime.UtcNow),
|
|
||||||
};
|
|
||||||
_Psc.Setup(x => x.GetList(It.IsAny<bool>())).Returns(listOriginal);
|
|
||||||
//Act
|
|
||||||
var listOnlyActive = _Pblc.GetAllPosts(true);
|
|
||||||
var listAll = _Pblc.GetAllPosts(false);
|
|
||||||
//Assert
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(listOnlyActive, Is.Not.Null);
|
|
||||||
Assert.That(listAll, Is.Not.Null);
|
|
||||||
Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal));
|
|
||||||
Assert.That(listAll, Is.EquivalentTo(listOriginal));
|
|
||||||
});
|
|
||||||
_Psc.Verify(x => x.GetList(true), Times.Once);
|
|
||||||
_Psc.Verify(x => x.GetList(false), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllPosts_ReturnEmptyList_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.GetList(It.IsAny<bool>())).Returns([]);
|
|
||||||
//Act
|
|
||||||
var listOnlyActive = _Pblc.GetAllPosts(true);
|
|
||||||
var listAll = _Pblc.GetAllPosts(false);
|
|
||||||
//Assert
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(listOnlyActive, Is.Not.Null);
|
|
||||||
Assert.That(listAll, Is.Not.Null);
|
|
||||||
Assert.That(listOnlyActive, Has.Count.EqualTo(0));
|
|
||||||
Assert.That(listAll, Has.Count.EqualTo(0));
|
|
||||||
});
|
|
||||||
_Psc.Verify(x => x.GetList(It.IsAny<bool>()), Times.Exactly(2));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllPosts_ReturnNull_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetAllPosts(It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
|
||||||
_Psc.Verify(x => x.GetList(It.IsAny<bool>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllPosts_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.GetList(It.IsAny<bool>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetAllPosts(It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
|
||||||
_Psc.Verify(x => x.GetList(It.IsAny<bool>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllDataOfPost_ReturnListOfRecords_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var postId = Guid.NewGuid().ToString();
|
|
||||||
var listOriginal = new List<PostDataModel>()
|
|
||||||
{
|
|
||||||
new(postId, "name 1", PostType.Assistant, 10, true, DateTime.UtcNow),
|
|
||||||
new(postId, "name 2", PostType.Assistant, 10, false, DateTime.UtcNow)
|
|
||||||
};
|
|
||||||
_Psc.Setup(x => x.GetPostHistory(It.IsAny<string>())).Returns(listOriginal);
|
|
||||||
//Act
|
|
||||||
var list = _Pblc.GetAllDataOfPost(postId);
|
|
||||||
//Assert
|
|
||||||
Assert.That(list, Is.Not.Null);
|
|
||||||
Assert.That(list, Has.Count.EqualTo(2));
|
|
||||||
_Psc.Verify(x => x.GetPostHistory(postId), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllDataOfPost_ReturnEmptyList_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.GetPostHistory(It.IsAny<string>())).Returns([]);
|
|
||||||
//Act
|
|
||||||
var list = _Pblc.GetAllDataOfPost(Guid.NewGuid().ToString());
|
|
||||||
//Assert
|
|
||||||
Assert.That(list, Is.Not.Null);
|
|
||||||
Assert.That(list, Has.Count.EqualTo(0));
|
|
||||||
_Psc.Verify(x => x.GetPostHistory(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllDataOfPost_PostIdIsNullOrEmpty_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetAllDataOfPost(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
Assert.That(() => _Pblc.GetAllDataOfPost(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Psc.Verify(x => x.GetPostHistory(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllDataOfPost_PostIdIsNotGuid_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetAllDataOfPost("id"), Throws.TypeOf<ValidationException>());
|
|
||||||
_Psc.Verify(x => x.GetPostHistory(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllDataOfPost_ReturnNull_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetAllDataOfPost(Guid.NewGuid().ToString()), Throws.TypeOf<NullListException>());
|
|
||||||
_Psc.Verify(x => x.GetPostHistory(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetAllDataOfPost_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.GetPostHistory(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetAllDataOfPost(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
|
||||||
_Psc.Verify(x => x.GetPostHistory(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetPostByData_GetById_ReturnRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var id = Guid.NewGuid().ToString();
|
|
||||||
var record = new PostDataModel(id, "name", PostType.Assistant, 10, true, DateTime.UtcNow);
|
|
||||||
_Psc.Setup(x => x.GetElementById(id)).Returns(record);
|
|
||||||
//Act
|
|
||||||
var element = _Pblc.GetPostByData(id);
|
|
||||||
//Assert
|
|
||||||
Assert.That(element, Is.Not.Null);
|
|
||||||
Assert.That(element.Id, Is.EqualTo(id));
|
|
||||||
_Psc.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetPostByData_GetByName_ReturnRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var postName = "name";
|
|
||||||
var record = new PostDataModel(Guid.NewGuid().ToString(), postName, PostType.Assistant, 10, true, DateTime.UtcNow);
|
|
||||||
_Psc.Setup(x => x.GetElementByName(postName)).Returns(record);
|
|
||||||
//Act
|
|
||||||
var element = _Pblc.GetPostByData(postName);
|
|
||||||
//Assert
|
|
||||||
Assert.That(element, Is.Not.Null);
|
|
||||||
Assert.That(element.PostName, Is.EqualTo(postName));
|
|
||||||
_Psc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetPostByData_EmptyData_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetPostByData(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
Assert.That(() => _Pblc.GetPostByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Psc.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
|
||||||
_Psc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetPostByData_GetById_NotFoundRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetPostByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
|
||||||
_Psc.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
|
||||||
_Psc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetPostByData_GetByName_NotFoundRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetPostByData("name"), Throws.TypeOf<ElementNotFoundException>());
|
|
||||||
_Psc.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
|
||||||
_Psc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void GetPostByData_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
_Psc.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.GetPostByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
|
||||||
Assert.That(() => _Pblc.GetPostByData("name"), Throws.TypeOf<StorageException>());
|
|
||||||
_Psc.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
|
||||||
_Psc.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertPost_CorrectRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var flag = false;
|
|
||||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow.AddDays(-1));
|
|
||||||
_Psc.Setup(x => x.AddElement(It.IsAny<PostDataModel>()))
|
|
||||||
.Callback((PostDataModel x) =>
|
|
||||||
{
|
|
||||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.Salary == record.Salary && x.ChangeDate == record.ChangeDate;
|
|
||||||
});
|
|
||||||
//Act
|
|
||||||
_Pblc.InsertPost(record);
|
|
||||||
//Assert
|
|
||||||
_Psc.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
|
||||||
Assert.That(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertPost_RecordWithExistsData_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf<ElementExistsException>());
|
|
||||||
_Psc.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertPost_NullRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.InsertPost(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Psc.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertPost_InvalidRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.InsertPost(new PostDataModel("id", "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf<ValidationException>());
|
|
||||||
_Psc.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void InsertPost_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf<StorageException>());
|
|
||||||
_Psc.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdatePost_CorrectRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var flag = false;
|
|
||||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow.AddDays(-1));
|
|
||||||
_Psc.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Callback((PostDataModel x) =>
|
|
||||||
{
|
|
||||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.Salary == record.Salary && x.ChangeDate == record.ChangeDate;
|
|
||||||
});
|
|
||||||
//Act
|
|
||||||
_Pblc.UpdatePost(record);
|
|
||||||
//Assert
|
|
||||||
_Psc.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
|
||||||
Assert.That(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdatePost_RecordWithIncorrectData_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementNotFoundException(""));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf<ElementNotFoundException>());
|
|
||||||
_Psc.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdatePost_RecordWithExistsData_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf<ElementExistsException>());
|
|
||||||
_Psc.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdatePost_NullRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.UpdatePost(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Psc.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdatePost_InvalidRecord_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.UpdatePost(new PostDataModel("id", "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf<ValidationException>());
|
|
||||||
_Psc.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdatePost_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf<StorageException>());
|
|
||||||
_Psc.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeletePost_CorrectRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var id = Guid.NewGuid().ToString();
|
|
||||||
var flag = false;
|
|
||||||
_Psc.Setup(x => x.DelElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
|
||||||
//Act
|
|
||||||
_Pblc.DeletePost(id);
|
|
||||||
//Assert
|
|
||||||
_Psc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
|
||||||
Assert.That(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeletePost_RecordWithIncorrectId_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var id = Guid.NewGuid().ToString();
|
|
||||||
_Psc.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.DeletePost(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
|
||||||
_Psc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeletePost_IdIsNullOrEmpty_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.DeletePost(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
Assert.That(() => _Pblc.DeletePost(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Psc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeletePost_IdIsNotGuid_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.DeletePost("id"), Throws.TypeOf<ValidationException>());
|
|
||||||
_Psc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void DeletePost_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.DeletePost(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
|
||||||
_Psc.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void RestorePost_CorrectRecord_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var id = Guid.NewGuid().ToString();
|
|
||||||
var flag = false;
|
|
||||||
_Psc.Setup(x => x.ResElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
|
||||||
//Act
|
|
||||||
_Pblc.RestorePost(id);
|
|
||||||
//Assert
|
|
||||||
_Psc.Verify(x => x.ResElement(It.IsAny<string>()), Times.Once);
|
|
||||||
Assert.That(flag);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void RestorePost_RecordWithIncorrectId_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
var id = Guid.NewGuid().ToString();
|
|
||||||
_Psc.Setup(x => x.ResElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.RestorePost(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
|
||||||
_Psc.Verify(x => x.ResElement(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void RestorePost_IdIsNullOrEmpty_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.RestorePost(null), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
Assert.That(() => _Pblc.RestorePost(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
|
||||||
_Psc.Verify(x => x.ResElement(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void RestorePost_IdIsNotGuid_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.RestorePost("id"), Throws.TypeOf<ValidationException>());
|
|
||||||
_Psc.Verify(x => x.ResElement(It.IsAny<string>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void RestorePost_StorageThrowError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_Psc.Setup(x => x.ResElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _Pblc.RestorePost(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
|
||||||
_Psc.Verify(x => x.ResElement(It.IsAny<string>()), Times.Once);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
namespace Tests.BLCTests;
|
|
||||||
|
|
||||||
internal class SalaryBLCTest
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
namespace Tests.BLCTests;
|
|
||||||
|
|
||||||
internal class SaleBLCTest
|
|
||||||
{
|
|
||||||
}
|
|
@ -1,55 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace SnowMaidenTests.DataModelsTest;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class ManufacturerDMTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void IdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var manufacturer = CreateDataModel(null, "name");
|
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
manufacturer = CreateDataModel(string.Empty, "name");
|
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void IdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var manufacturer = CreateDataModel("id", "name");
|
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ManufacturerNameIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null);
|
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void AllFieldsIsCorrectTest()
|
|
||||||
{
|
|
||||||
var manufacturerId = Guid.NewGuid().ToString();
|
|
||||||
var manufacturerName = "name";
|
|
||||||
var prevManufacturerName = "LastName";
|
|
||||||
var prevPrevManufacturerName = "EarlierName";
|
|
||||||
var manufacturer = CreateDataModel(manufacturerId, manufacturerName, prevManufacturerName, prevPrevManufacturerName);
|
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.Nothing);
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(manufacturer.Id, Is.EqualTo(manufacturerId));
|
|
||||||
Assert.That(manufacturer.ManufacturerName, Is.EqualTo(manufacturerName));
|
|
||||||
Assert.That(manufacturer.PrevManufacturerName, Is.EqualTo(prevManufacturerName));
|
|
||||||
Assert.That(manufacturer.PrevPrevManufacturerName, Is.EqualTo(prevPrevManufacturerName));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ManufacturerDataModel CreateDataModel(string id, string manufacturerName, string? prevManufacturerName = null, string? prevPrevManufacturerName = null) =>
|
|
||||||
new(id, manufacturerName, prevManufacturerName, prevPrevManufacturerName);
|
|
||||||
}
|
|
@ -1,76 +0,0 @@
|
|||||||
using NUnit.Framework;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Enums;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace SnowMaidenTests.DataModelsTest;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class PostDMTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void IdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var post = CreateDataModel(null, "name", PostType.Assistant, 10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
post = CreateDataModel(string.Empty, "name", PostType.Assistant, 10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void IdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var post = CreateDataModel("id", "name", PostType.Assistant, 10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PostNameIsEmptyTest()
|
|
||||||
{
|
|
||||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Assistant, 10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Assistant, 10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PostTypeIsNoneTest()
|
|
||||||
{
|
|
||||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SalaryIsLessOrZeroTest()
|
|
||||||
{
|
|
||||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 0, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, -10, true, DateTime.UtcNow);
|
|
||||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void AllFieldsIsCorrectTest()
|
|
||||||
{
|
|
||||||
var postId = Guid.NewGuid().ToString();
|
|
||||||
var postName = "name";
|
|
||||||
var postType = PostType.Assistant;
|
|
||||||
var salary = 10;
|
|
||||||
var isActual = false;
|
|
||||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
|
||||||
var post = CreateDataModel(postId, postName, postType, salary, isActual, changeDate);
|
|
||||||
Assert.That(() => post.Validate(), Throws.Nothing);
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(post.Id, Is.EqualTo(postId));
|
|
||||||
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 postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
|
|
||||||
new(id, postName, postType, salary, isActual, changeDate);
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
using NUnit.Framework;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Enums;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
namespace SnowMaidenTests.DataModelsTest;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class ProductDMTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void IdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel(null, "name", ProductType.Souvenir, 10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
product = CreateDataModel(string.Empty, "name", ProductType.Souvenir, 10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void IdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel("id", "name", ProductType.Souvenir, 10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ProductNameIsEmptyTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Souvenir, 10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Souvenir, 10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ProductTypeIsNoneTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, 10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ManufacturerIdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Souvenir, 10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Souvenir, 10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ManufacturerIdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel("Mid", "name", ProductType.Souvenir, 10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PriceIsLessOrZeroTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Souvenir, 0, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Souvenir, -10, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void AllFieldsIsCorrectTest()
|
|
||||||
{
|
|
||||||
var productId = Guid.NewGuid().ToString();
|
|
||||||
var productName = "name";
|
|
||||||
var productType = ProductType.Souvenir;
|
|
||||||
var productManufacturerId = Guid.NewGuid().ToString();
|
|
||||||
var productPrice = 10;
|
|
||||||
var productIsDelete = false;
|
|
||||||
var product = CreateDataModel(productId, productName, productType, productPrice, productIsDelete);
|
|
||||||
Assert.That(() => product.Validate(), Throws.Nothing);
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(product.Id, Is.EqualTo(productId));
|
|
||||||
Assert.That(product.ProductName, Is.EqualTo(productName));
|
|
||||||
Assert.That(product.ProductType, Is.EqualTo(productType));
|
|
||||||
Assert.That(product.Price, Is.EqualTo(productPrice));
|
|
||||||
Assert.That(product.IsDeleted, Is.EqualTo(productIsDelete));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, double price, bool isDeleted) =>
|
|
||||||
new(id, productName, productType, price, isDeleted);
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace SnowMaidenTests.DataModelsTest;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class ProductHistoryDMTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void ProductIdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel(null, 10);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
product = CreateDataModel(string.Empty, 10);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ProductIdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel("id", 10);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void OldPriceIsLessOrZeroTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void AllFieldsIsCorrectTest()
|
|
||||||
{
|
|
||||||
var productId = Guid.NewGuid().ToString();
|
|
||||||
var oldPrice = 10;
|
|
||||||
var productHistory = CreateDataModel(productId, oldPrice);
|
|
||||||
Assert.That(() => productHistory.Validate(), Throws.Nothing);
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(productHistory.ProductId, Is.EqualTo(productId));
|
|
||||||
Assert.That(productHistory.OldPrice, Is.EqualTo(oldPrice));
|
|
||||||
Assert.That(productHistory.ChangeDate, Is.LessThan(DateTime.UtcNow));
|
|
||||||
Assert.That(productHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ProductHistoryDataModel CreateDataModel(string productId, double oldPrice) =>
|
|
||||||
new(productId, oldPrice);
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace SnowMaidenTests.DataModelsTest;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class SalaryDMTest
|
|
||||||
{
|
|
||||||
[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);
|
|
||||||
}
|
|
@ -1,88 +0,0 @@
|
|||||||
using NUnit.Framework;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Enums;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class SaleDMTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void IdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void IdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
[Test]
|
|
||||||
public void WorkerIdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void WorkerIdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "workerId", 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SumIsLessOrZeroTest()
|
|
||||||
{
|
|
||||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ProductsIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, null);
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, []);
|
|
||||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void AllFieldsIsCorrectTest()
|
|
||||||
{
|
|
||||||
var saleId = Guid.NewGuid().ToString();
|
|
||||||
var workerId = Guid.NewGuid().ToString();
|
|
||||||
var buyerId = Guid.NewGuid().ToString();
|
|
||||||
var sum = 10;
|
|
||||||
var discountType = DiscountType.Certificate;
|
|
||||||
var discount = 1;
|
|
||||||
var isCancel = true;
|
|
||||||
var products = CreateSubDataModel();
|
|
||||||
var sale = CreateDataModel(saleId, workerId, sum, discountType, discount, isCancel, products);
|
|
||||||
Assert.That(() => sale.Validate(), Throws.Nothing);
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(sale.Id, Is.EqualTo(saleId));
|
|
||||||
Assert.That(sale.WorkerId, Is.EqualTo(workerId));
|
|
||||||
Assert.That(sale.Sum, Is.EqualTo(sum));
|
|
||||||
Assert.That(sale.DiscountType, Is.EqualTo(discountType));
|
|
||||||
Assert.That(sale.Discount, Is.EqualTo(discount));
|
|
||||||
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
|
||||||
Assert.That(sale.Products, Is.EquivalentTo(products));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SaleDataModel CreateDataModel(string? id, string? workerId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleProductDataModel>? products) =>
|
|
||||||
new(id, workerId, sum, discountType, discount, isCancel, products);
|
|
||||||
|
|
||||||
private static List<SaleProductDataModel> CreateSubDataModel()
|
|
||||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
|
||||||
}
|
|
@ -1,69 +0,0 @@
|
|||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace SnowMaidenTests.DataModelsTest;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class SaleProductDMTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void SaleIdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
|
||||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
|
||||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void SaleIdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var saleProduct = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10);
|
|
||||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ProductIdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
|
||||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
|
||||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ProductIdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10);
|
|
||||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void CountIsLessOrZeroTest()
|
|
||||||
{
|
|
||||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
|
||||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
|
||||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void AllFieldsIsCorrectTest()
|
|
||||||
{
|
|
||||||
var saleId = Guid.NewGuid().ToString();
|
|
||||||
var productId = Guid.NewGuid().ToString();
|
|
||||||
var count = 10;
|
|
||||||
var saleProduct = CreateDataModel(saleId, productId, count);
|
|
||||||
Assert.That(() => saleProduct.Validate(), Throws.Nothing);
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(saleProduct.SaleId, Is.EqualTo(saleId));
|
|
||||||
Assert.That(saleProduct.ProductId, Is.EqualTo(productId));
|
|
||||||
Assert.That(saleProduct.Count, Is.EqualTo(count));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SaleProductDataModel CreateDataModel(string? saleId, string? productId, int count) =>
|
|
||||||
new(saleId, productId, count);
|
|
||||||
}
|
|
@ -1,110 +0,0 @@
|
|||||||
using System;
|
|
||||||
using IcecreamVan.DataModels;
|
|
||||||
using IcecreamVan.Exceptions;
|
|
||||||
using NUnit.Framework;
|
|
||||||
|
|
||||||
namespace SnowMaidenTests.DataModelsTest;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class WorkerDMTest
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void IdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var worker = CreateDataModel(null, "FIO", Guid.NewGuid().ToString(), "number", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
worker = CreateDataModel(string.Empty, "FIO", Guid.NewGuid().ToString(), "number", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void IdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var worker = CreateDataModel("id", "FIO", Guid.NewGuid().ToString(), "number", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void FIOIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), "number", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), "number", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PostIdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "FIO", null, "number", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "FIO", string.Empty, "number", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PhoneNumberIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", Guid.NewGuid().ToString(), null, DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
|
||||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
buyer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", Guid.NewGuid().ToString(), string.Empty, DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
|
||||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PhoneNumberIsIncorrectTest()
|
|
||||||
{
|
|
||||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "FIO", Guid.NewGuid().ToString(), "777", DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
|
||||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void PostIdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "FIO", "postId", "number", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void BirthDateIsNotCorrectTest()
|
|
||||||
{
|
|
||||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "FIO", Guid.NewGuid().ToString(), "number", DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
|
||||||
{
|
|
||||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "FIO", Guid.NewGuid().ToString(), "number", DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "FIO", Guid.NewGuid().ToString(), "number", DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void AllFieldsIsCorrectTest()
|
|
||||||
{
|
|
||||||
var workerId = Guid.NewGuid().ToString();
|
|
||||||
var fio = "FIO";
|
|
||||||
var postId = Guid.NewGuid().ToString();
|
|
||||||
var phoneNumber = "+7(903)123-45-67";
|
|
||||||
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
|
||||||
var employmentDate = DateTime.Now;
|
|
||||||
var isDelete = false;
|
|
||||||
var worker = CreateDataModel(workerId, fio, postId, phoneNumber, birthDate, employmentDate, isDelete);
|
|
||||||
Assert.That(() => worker.Validate(), Throws.Nothing);
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(worker.Id, Is.EqualTo(workerId));
|
|
||||||
Assert.That(worker.FIO, Is.EqualTo(fio));
|
|
||||||
Assert.That(worker.PostId, Is.EqualTo(postId));
|
|
||||||
Assert.That(worker.PhoneNumber, Is.EqualTo(phoneNumber));
|
|
||||||
Assert.That(worker.BirthDate, Is.EqualTo(birthDate));
|
|
||||||
Assert.That(worker.EmploymentDate, Is.EqualTo(employmentDate));
|
|
||||||
Assert.That(worker.IsDeleted, Is.EqualTo(isDelete));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static WorkerDataModel CreateDataModel(string? id, string? fio, string? postId, string? number, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
|
||||||
new(id, fio, postId, number, birthDate, employmentDate, isDeleted);
|
|
||||||
}
|
|
@ -1,27 +0,0 @@
|
|||||||
<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.Extensions.Logging.Abstractions" Version="9.0.2" />
|
|
||||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
|
||||||
<PackageReference Include="Moq" Version="4.20.72" />
|
|
||||||
<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="..\BusinessLogic\BusinessLogic.csproj" />
|
|
||||||
<ProjectReference Include="..\IcecreamVan\IcecreamVan.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
Loading…
x
Reference in New Issue
Block a user