From f249261d7317f325a07bf88231d25d2f0b406492 Mon Sep 17 00:00:00 2001 From: DelphyAlmond Date: Thu, 27 Feb 2025 17:13:36 +0400 Subject: [PATCH] 2(0).IntermediateResult --- BusinessLogic/BusinessLogic.csproj | 22 + .../Implementations/ManufactureBLC.cs | 34 ++ BusinessLogic/Implementations/PostBLC.cs | 44 ++ BusinessLogic/Implementations/ProductBLC.cs | 44 ++ BusinessLogic/Implementations/SalaryBLC.cs | 25 + BusinessLogic/Implementations/SaleBLC.cs | 40 ++ BusinessLogic/Implementations/WorkerBLC.cs | 48 ++ .../BusinessLogicContracts/IManufactureBLC.cs | 16 + .../BusinessLogicContracts/IPostBLC.cs | 20 + .../BusinessLogicContracts/IProductBLC.cs | 20 + .../BusinessLogicContracts/ISalaryBLC.cs | 12 + .../BusinessLogicContracts/ISaleBLC.cs | 18 + .../BusinessLogicContracts/IWorkerBLC.cs | 23 + .../DataModels/ManufacturerDataModel.cs | 28 ++ IcecreamVan/DataModels/PostDataModel.cs | 39 ++ IcecreamVan/DataModels/ProductDataModel.cs | 40 ++ .../DataModels/ProductHistoryDataModel.cs | 26 + IcecreamVan/DataModels/SalaryDataModel.cs | 26 + IcecreamVan/DataModels/SaleDataModel.cs | 48 ++ .../DataModels/SaleProductDataModel.cs | 34 ++ IcecreamVan/DataModels/WorkerDataModel.cs | 59 +++ IcecreamVan/Enums/DiscountType.cs | 9 + IcecreamVan/Enums/PostType.cs | 9 + IcecreamVan/Enums/ProductType.cs | 9 + .../Exceptions/ValidationException.cs | 41 +- IcecreamVan/Extensions/StringExtensions.cs | 14 + IcecreamVan/IcecreamVan.csproj | 5 + .../Infrastructure/IValidation.cs | 2 +- .../DataModels/ManufacturerDataModel.cs | 28 -- .../DataModels/PostDataModel.cs | 47 -- .../DataModels/ProductDataModel.cs | 40 -- .../DataModels/ProductHistoryDataModel.cs | 26 - .../DataModels/SalaryDataModel.cs | 26 - .../DataModels/SaleDataModel.cs | 48 -- .../DataModels/SaleProductDataModel.cs | 34 -- .../DataModels/WorkerDataModel.cs | 59 --- .../SnowMaidenContracts/Enums/DiscountType.cs | 9 - .../SnowMaidenContracts/Enums/PostType.cs | 9 - .../SnowMaidenContracts/Enums/ProductType.cs | 9 - .../Extensions/StringExtensions.cs | 14 - .../IManufacturerContract.cs | 20 + .../StoragesContracts/IPostContract.cs | 22 + .../StoragesContracts/IProductContract.cs | 20 + .../StoragesContracts/ISalaryContract.cs | 10 + .../StoragesContracts/ISaleContract.cs | 14 + .../StoragesContracts/IWorkerContract.cs | 18 + IcecreamVanSnowMaiden.sln | 10 +- Tests/BLCTests/ManufactureBLCTest.cs | 353 ++++++++++++++ Tests/BLCTests/PostBLCTest.cs | 453 ++++++++++++++++++ Tests/BLCTests/SalaryBLCTest.cs | 5 + Tests/BLCTests/SaleBLCTest.cs | 5 + Tests/SnowMaidenDMTests/ManufacturerDMTest.cs | 6 +- Tests/SnowMaidenDMTests/PostDMTest.cs | 46 +- Tests/SnowMaidenDMTests/ProductDMTest.cs | 6 +- .../SnowMaidenDMTests/ProductHistoryDMTest.cs | 6 +- Tests/SnowMaidenDMTests/SalaryDMTest.cs | 6 +- Tests/SnowMaidenDMTests/SaleDMTest.cs | 6 +- Tests/SnowMaidenDMTests/SaleProductDMTest.cs | 6 +- Tests/SnowMaidenDMTests/WorkerDMTest.cs | 4 +- Tests/Tests.csproj | 3 + 60 files changed, 1718 insertions(+), 405 deletions(-) create mode 100644 BusinessLogic/BusinessLogic.csproj create mode 100644 BusinessLogic/Implementations/ManufactureBLC.cs create mode 100644 BusinessLogic/Implementations/PostBLC.cs create mode 100644 BusinessLogic/Implementations/ProductBLC.cs create mode 100644 BusinessLogic/Implementations/SalaryBLC.cs create mode 100644 BusinessLogic/Implementations/SaleBLC.cs create mode 100644 BusinessLogic/Implementations/WorkerBLC.cs create mode 100644 IcecreamVan/BusinessLogicContracts/IManufactureBLC.cs create mode 100644 IcecreamVan/BusinessLogicContracts/IPostBLC.cs create mode 100644 IcecreamVan/BusinessLogicContracts/IProductBLC.cs create mode 100644 IcecreamVan/BusinessLogicContracts/ISalaryBLC.cs create mode 100644 IcecreamVan/BusinessLogicContracts/ISaleBLC.cs create mode 100644 IcecreamVan/BusinessLogicContracts/IWorkerBLC.cs create mode 100644 IcecreamVan/DataModels/ManufacturerDataModel.cs create mode 100644 IcecreamVan/DataModels/PostDataModel.cs create mode 100644 IcecreamVan/DataModels/ProductDataModel.cs create mode 100644 IcecreamVan/DataModels/ProductHistoryDataModel.cs create mode 100644 IcecreamVan/DataModels/SalaryDataModel.cs create mode 100644 IcecreamVan/DataModels/SaleDataModel.cs create mode 100644 IcecreamVan/DataModels/SaleProductDataModel.cs create mode 100644 IcecreamVan/DataModels/WorkerDataModel.cs create mode 100644 IcecreamVan/Enums/DiscountType.cs create mode 100644 IcecreamVan/Enums/PostType.cs create mode 100644 IcecreamVan/Enums/ProductType.cs rename IcecreamVan/{SnowMaidenContracts => }/Exceptions/ValidationException.cs (75%) create mode 100644 IcecreamVan/Extensions/StringExtensions.cs rename IcecreamVan/{SnowMaidenContracts => }/Infrastructure/IValidation.cs (52%) delete mode 100644 IcecreamVan/SnowMaidenContracts/DataModels/ManufacturerDataModel.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/DataModels/PostDataModel.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/DataModels/ProductDataModel.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/DataModels/ProductHistoryDataModel.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/DataModels/SalaryDataModel.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/DataModels/SaleDataModel.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/DataModels/SaleProductDataModel.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/DataModels/WorkerDataModel.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/Enums/DiscountType.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/Enums/PostType.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/Enums/ProductType.cs delete mode 100644 IcecreamVan/SnowMaidenContracts/Extensions/StringExtensions.cs create mode 100644 IcecreamVan/StoragesContracts/IManufacturerContract.cs create mode 100644 IcecreamVan/StoragesContracts/IPostContract.cs create mode 100644 IcecreamVan/StoragesContracts/IProductContract.cs create mode 100644 IcecreamVan/StoragesContracts/ISalaryContract.cs create mode 100644 IcecreamVan/StoragesContracts/ISaleContract.cs create mode 100644 IcecreamVan/StoragesContracts/IWorkerContract.cs create mode 100644 Tests/BLCTests/ManufactureBLCTest.cs create mode 100644 Tests/BLCTests/PostBLCTest.cs create mode 100644 Tests/BLCTests/SalaryBLCTest.cs create mode 100644 Tests/BLCTests/SaleBLCTest.cs diff --git a/BusinessLogic/BusinessLogic.csproj b/BusinessLogic/BusinessLogic.csproj new file mode 100644 index 0000000..f9719e9 --- /dev/null +++ b/BusinessLogic/BusinessLogic.csproj @@ -0,0 +1,22 @@ + + + + net8.0 + enable + enable + + + + + + + + + + + + + + + + diff --git a/BusinessLogic/Implementations/ManufactureBLC.cs b/BusinessLogic/Implementations/ManufactureBLC.cs new file mode 100644 index 0000000..5d2d8a6 --- /dev/null +++ b/BusinessLogic/Implementations/ManufactureBLC.cs @@ -0,0 +1,34 @@ +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 GetAllManufacturers() + { + return []; + } + + public ManufacturerDataModel GetManufacturerByData(string data) + { + return new("", "", "", ""); + } + + public void InsertManufacturer(ManufacturerDataModel manufacturerDataModel) + { + } + + public void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel) + { + } + + public void DeleteManufacturer(string id) + { + } +} diff --git a/BusinessLogic/Implementations/PostBLC.cs b/BusinessLogic/Implementations/PostBLC.cs new file mode 100644 index 0000000..c6773c8 --- /dev/null +++ b/BusinessLogic/Implementations/PostBLC.cs @@ -0,0 +1,44 @@ +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 GetAllDataOfPost(string postId) + { + return []; + } + + public List 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) + { + } +} diff --git a/BusinessLogic/Implementations/ProductBLC.cs b/BusinessLogic/Implementations/ProductBLC.cs new file mode 100644 index 0000000..29712e6 --- /dev/null +++ b/BusinessLogic/Implementations/ProductBLC.cs @@ -0,0 +1,44 @@ +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 GetAllProducts(bool onlyActive = true) + { + return []; + } + + public List GetAllProductsByManufacturer(string manufacturerId, bool onlyActive = true) + { + return []; + } + + public List 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) + { + } +} diff --git a/BusinessLogic/Implementations/SalaryBLC.cs b/BusinessLogic/Implementations/SalaryBLC.cs new file mode 100644 index 0000000..3bdfce5 --- /dev/null +++ b/BusinessLogic/Implementations/SalaryBLC.cs @@ -0,0 +1,25 @@ +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 GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate) + { + return []; + } + + public List GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId) + { + return []; + } +} diff --git a/BusinessLogic/Implementations/SaleBLC.cs b/BusinessLogic/Implementations/SaleBLC.cs new file mode 100644 index 0000000..7b659b4 --- /dev/null +++ b/BusinessLogic/Implementations/SaleBLC.cs @@ -0,0 +1,40 @@ +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 GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate) + { + return []; + } + + public List GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate) + { + return []; + } + + public List 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) + { + } +} diff --git a/BusinessLogic/Implementations/WorkerBLC.cs b/BusinessLogic/Implementations/WorkerBLC.cs new file mode 100644 index 0000000..e685ab2 --- /dev/null +++ b/BusinessLogic/Implementations/WorkerBLC.cs @@ -0,0 +1,48 @@ +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 GetAllWorkers(bool onlyActive = true) + { + return []; + } + + public List GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true) + { + return []; + } + + public List GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true) + { + return []; + } + + public List 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) + { + } +} diff --git a/IcecreamVan/BusinessLogicContracts/IManufactureBLC.cs b/IcecreamVan/BusinessLogicContracts/IManufactureBLC.cs new file mode 100644 index 0000000..9b09b88 --- /dev/null +++ b/IcecreamVan/BusinessLogicContracts/IManufactureBLC.cs @@ -0,0 +1,16 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.BusinessLogicContracts; + +public interface IManufactureBLC +{ + List GetAllManufacturers(); + + ManufacturerDataModel GetManufacturerByData(string data); + + void InsertManufacturer(ManufacturerDataModel manufacturerDataModel); + + void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel); + + void DeleteManufacturer(string id); +} diff --git a/IcecreamVan/BusinessLogicContracts/IPostBLC.cs b/IcecreamVan/BusinessLogicContracts/IPostBLC.cs new file mode 100644 index 0000000..679511a --- /dev/null +++ b/IcecreamVan/BusinessLogicContracts/IPostBLC.cs @@ -0,0 +1,20 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.BusinessLogicContracts; + +public interface IPostBLC +{ + List GetAllPosts(bool onlyActive); + + List GetAllDataOfPost(string postId); + + PostDataModel GetPostByData(string data); + + void InsertPost(PostDataModel postDataModel); + + void UpdatePost(PostDataModel postDataModel); + + void DeletePost(string id); + + void RestorePost(string id); +} diff --git a/IcecreamVan/BusinessLogicContracts/IProductBLC.cs b/IcecreamVan/BusinessLogicContracts/IProductBLC.cs new file mode 100644 index 0000000..342acac --- /dev/null +++ b/IcecreamVan/BusinessLogicContracts/IProductBLC.cs @@ -0,0 +1,20 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.BusinessLogicContracts; + +public interface IProductBLC +{ + List GetAllProducts(bool onlyActive = true); + + List GetAllProductsByManufacturer(string manufacturerId, bool onlyActive = true); + + List GetProductHistoryByProduct(string productId); + + ProductDataModel GetProductByData(string data); + + void InsertProduct(ProductDataModel productDataModel); + + void UpdateProduct(ProductDataModel productDataModel); + + void DeleteProduct(string id); +} diff --git a/IcecreamVan/BusinessLogicContracts/ISalaryBLC.cs b/IcecreamVan/BusinessLogicContracts/ISalaryBLC.cs new file mode 100644 index 0000000..c6c53ed --- /dev/null +++ b/IcecreamVan/BusinessLogicContracts/ISalaryBLC.cs @@ -0,0 +1,12 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.BusinessLogicContracts; + +public interface ISalaryBLC +{ + List GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate); + + List GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId); + + void CalculateSalaryByMounth(DateTime date); +} diff --git a/IcecreamVan/BusinessLogicContracts/ISaleBLC.cs b/IcecreamVan/BusinessLogicContracts/ISaleBLC.cs new file mode 100644 index 0000000..c5b548b --- /dev/null +++ b/IcecreamVan/BusinessLogicContracts/ISaleBLC.cs @@ -0,0 +1,18 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.BusinessLogicContracts; + +public interface ISaleBLC +{ + List GetAllSalesByPeriod(DateTime fromDate, DateTime toDate); + + List GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate); + + List GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate); + + SaleDataModel GetSaleByData(string data); + + void InsertSale(SaleDataModel saleDataModel); + + void CancelSale(string id); +} diff --git a/IcecreamVan/BusinessLogicContracts/IWorkerBLC.cs b/IcecreamVan/BusinessLogicContracts/IWorkerBLC.cs new file mode 100644 index 0000000..d1ca397 --- /dev/null +++ b/IcecreamVan/BusinessLogicContracts/IWorkerBLC.cs @@ -0,0 +1,23 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.BusinessLogicContracts; + +public interface IWorkerBLC +{ + List GetAllWorkers(bool onlyActive = true); + + List GetAllWorkersByPost(string postId, bool onlyActive = + true); + + List GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true); + + List GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true); + + WorkerDataModel GetWorkerByData(string data); + + void InsertWorker(WorkerDataModel workerDataModel); + + void UpdateWorker(WorkerDataModel workerDataModel); + + void DeleteWorker(string id); +} diff --git a/IcecreamVan/DataModels/ManufacturerDataModel.cs b/IcecreamVan/DataModels/ManufacturerDataModel.cs new file mode 100644 index 0000000..c674a0a --- /dev/null +++ b/IcecreamVan/DataModels/ManufacturerDataModel.cs @@ -0,0 +1,28 @@ +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"); + } +} \ No newline at end of file diff --git a/IcecreamVan/DataModels/PostDataModel.cs b/IcecreamVan/DataModels/PostDataModel.cs new file mode 100644 index 0000000..69d104c --- /dev/null +++ b/IcecreamVan/DataModels/PostDataModel.cs @@ -0,0 +1,39 @@ +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"); + } +} \ No newline at end of file diff --git a/IcecreamVan/DataModels/ProductDataModel.cs b/IcecreamVan/DataModels/ProductDataModel.cs new file mode 100644 index 0000000..c47e3ac --- /dev/null +++ b/IcecreamVan/DataModels/ProductDataModel.cs @@ -0,0 +1,40 @@ +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"); + } +} \ No newline at end of file diff --git a/IcecreamVan/DataModels/ProductHistoryDataModel.cs b/IcecreamVan/DataModels/ProductHistoryDataModel.cs new file mode 100644 index 0000000..fa6b705 --- /dev/null +++ b/IcecreamVan/DataModels/ProductHistoryDataModel.cs @@ -0,0 +1,26 @@ +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"); + } +} \ No newline at end of file diff --git a/IcecreamVan/DataModels/SalaryDataModel.cs b/IcecreamVan/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..d1aa899 --- /dev/null +++ b/IcecreamVan/DataModels/SalaryDataModel.cs @@ -0,0 +1,26 @@ +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"); + } +} \ No newline at end of file diff --git a/IcecreamVan/DataModels/SaleDataModel.cs b/IcecreamVan/DataModels/SaleDataModel.cs new file mode 100644 index 0000000..060f37e --- /dev/null +++ b/IcecreamVan/DataModels/SaleDataModel.cs @@ -0,0 +1,48 @@ +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 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 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"); + } +} \ No newline at end of file diff --git a/IcecreamVan/DataModels/SaleProductDataModel.cs b/IcecreamVan/DataModels/SaleProductDataModel.cs new file mode 100644 index 0000000..c84d863 --- /dev/null +++ b/IcecreamVan/DataModels/SaleProductDataModel.cs @@ -0,0 +1,34 @@ +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"); + } +} \ No newline at end of file diff --git a/IcecreamVan/DataModels/WorkerDataModel.cs b/IcecreamVan/DataModels/WorkerDataModel.cs new file mode 100644 index 0000000..5ef09d5 --- /dev/null +++ b/IcecreamVan/DataModels/WorkerDataModel.cs @@ -0,0 +1,59 @@ +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"); + } +} \ No newline at end of file diff --git a/IcecreamVan/Enums/DiscountType.cs b/IcecreamVan/Enums/DiscountType.cs new file mode 100644 index 0000000..d5b8720 --- /dev/null +++ b/IcecreamVan/Enums/DiscountType.cs @@ -0,0 +1,9 @@ +namespace IcecreamVan.Enums; + +[Flags] +public enum DiscountType +{ + None = 0, + OnSale = 1, + Certificate = 2 +} \ No newline at end of file diff --git a/IcecreamVan/Enums/PostType.cs b/IcecreamVan/Enums/PostType.cs new file mode 100644 index 0000000..6e3e827 --- /dev/null +++ b/IcecreamVan/Enums/PostType.cs @@ -0,0 +1,9 @@ +namespace IcecreamVan.Enums; + +public enum PostType +{ + None = 0, + Chef = 1, + Cashier = 2, + Assistant = 3 +} \ No newline at end of file diff --git a/IcecreamVan/Enums/ProductType.cs b/IcecreamVan/Enums/ProductType.cs new file mode 100644 index 0000000..fbbf631 --- /dev/null +++ b/IcecreamVan/Enums/ProductType.cs @@ -0,0 +1,9 @@ +namespace IcecreamVan.Enums; + +public enum ProductType +{ + None = 0, + Icecream = 1, + Milkshake = 2, + Souvenir = 3 +} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/Exceptions/ValidationException.cs b/IcecreamVan/Exceptions/ValidationException.cs similarity index 75% rename from IcecreamVan/SnowMaidenContracts/Exceptions/ValidationException.cs rename to IcecreamVan/Exceptions/ValidationException.cs index 821e6e0..a3566d2 100644 --- a/IcecreamVan/SnowMaidenContracts/Exceptions/ValidationException.cs +++ b/IcecreamVan/Exceptions/ValidationException.cs @@ -1,4 +1,6 @@ -namespace SnowMaidenContracts.Exceptions; +using static System.Runtime.InteropServices.JavaScript.JSType; + +namespace IcecreamVan.Exceptions; /* @@ -15,6 +17,43 @@ 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; + } +} diff --git a/IcecreamVan/Extensions/StringExtensions.cs b/IcecreamVan/Extensions/StringExtensions.cs new file mode 100644 index 0000000..1a54916 --- /dev/null +++ b/IcecreamVan/Extensions/StringExtensions.cs @@ -0,0 +1,14 @@ +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 _); + } +} \ No newline at end of file diff --git a/IcecreamVan/IcecreamVan.csproj b/IcecreamVan/IcecreamVan.csproj index fa71b7a..06eac23 100644 --- a/IcecreamVan/IcecreamVan.csproj +++ b/IcecreamVan/IcecreamVan.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/IcecreamVan/SnowMaidenContracts/Infrastructure/IValidation.cs b/IcecreamVan/Infrastructure/IValidation.cs similarity index 52% rename from IcecreamVan/SnowMaidenContracts/Infrastructure/IValidation.cs rename to IcecreamVan/Infrastructure/IValidation.cs index c539578..e5a2a11 100644 --- a/IcecreamVan/SnowMaidenContracts/Infrastructure/IValidation.cs +++ b/IcecreamVan/Infrastructure/IValidation.cs @@ -1,4 +1,4 @@ -namespace SnowMaidenContracts.Infrastructure; +namespace IcecreamVan.Infrastructure; public interface IValidation { diff --git a/IcecreamVan/SnowMaidenContracts/DataModels/ManufacturerDataModel.cs b/IcecreamVan/SnowMaidenContracts/DataModels/ManufacturerDataModel.cs deleted file mode 100644 index d03e161..0000000 --- a/IcecreamVan/SnowMaidenContracts/DataModels/ManufacturerDataModel.cs +++ /dev/null @@ -1,28 +0,0 @@ -using SnowMaidenContracts.Exceptions; -using SnowMaidenContracts.Extensions; -using SnowMaidenContracts.Infrastructure; - -namespace SnowMaidenContracts.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"); - } -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/DataModels/PostDataModel.cs b/IcecreamVan/SnowMaidenContracts/DataModels/PostDataModel.cs deleted file mode 100644 index 4c686a8..0000000 --- a/IcecreamVan/SnowMaidenContracts/DataModels/PostDataModel.cs +++ /dev/null @@ -1,47 +0,0 @@ -using SnowMaidenContracts.Enums; -using SnowMaidenContracts.Exceptions; -using SnowMaidenContracts.Extensions; -using SnowMaidenContracts.Infrastructure; - -namespace SnowMaidenContracts.DataModels; - -public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation -{ - public string Id { get; private set; } = id; - - public string PostId { get; private set; } = postId; - - public string PostName { get; private set; } = postName; - - public PostType PostType { get; private set; } = postType; - - public double Salary { get; private set; } = salary; - - public bool IsActual { get; private set; } = isActual; - - public DateTime ChangeDate { get; private set; } = changeDate; - - public void Validate() - { - if (Id.IsEmpty()) - throw new ValidationException("Field ID is empty"); - - if (!Id.IsGuid()) - throw new ValidationException("The ID value is NOT a unique identifier"); - - 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 (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"); - } -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/DataModels/ProductDataModel.cs b/IcecreamVan/SnowMaidenContracts/DataModels/ProductDataModel.cs deleted file mode 100644 index 284b726..0000000 --- a/IcecreamVan/SnowMaidenContracts/DataModels/ProductDataModel.cs +++ /dev/null @@ -1,40 +0,0 @@ -using SnowMaidenContracts.Enums; -using SnowMaidenContracts.Exceptions; -using SnowMaidenContracts.Extensions; -using SnowMaidenContracts.Infrastructure; - -namespace SnowMaidenContracts.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"); - } -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/DataModels/ProductHistoryDataModel.cs b/IcecreamVan/SnowMaidenContracts/DataModels/ProductHistoryDataModel.cs deleted file mode 100644 index 5cf1455..0000000 --- a/IcecreamVan/SnowMaidenContracts/DataModels/ProductHistoryDataModel.cs +++ /dev/null @@ -1,26 +0,0 @@ -using SnowMaidenContracts.Exceptions; -using SnowMaidenContracts.Extensions; -using SnowMaidenContracts.Infrastructure; - -namespace SnowMaidenContracts.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"); - } -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/DataModels/SalaryDataModel.cs b/IcecreamVan/SnowMaidenContracts/DataModels/SalaryDataModel.cs deleted file mode 100644 index 013e6bf..0000000 --- a/IcecreamVan/SnowMaidenContracts/DataModels/SalaryDataModel.cs +++ /dev/null @@ -1,26 +0,0 @@ -using SnowMaidenContracts.Exceptions; -using SnowMaidenContracts.Extensions; -using SnowMaidenContracts.Infrastructure; - -namespace SnowMaidenContracts.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"); - } -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/DataModels/SaleDataModel.cs b/IcecreamVan/SnowMaidenContracts/DataModels/SaleDataModel.cs deleted file mode 100644 index f49753e..0000000 --- a/IcecreamVan/SnowMaidenContracts/DataModels/SaleDataModel.cs +++ /dev/null @@ -1,48 +0,0 @@ -using SnowMaidenContracts.Enums; -using SnowMaidenContracts.Exceptions; -using SnowMaidenContracts.Extensions; -using SnowMaidenContracts.Infrastructure; - -namespace SnowMaidenContracts.DataModels; - -// 2. Продажа, помимо работника, содержит клиента/покупателя (Buyer -> Sale) и СПИСОК ПРОДУКТОВ (3. SaleProduct -> Sale) - -public class SaleDataModel(string id, string workerId, double sum, DiscountType discountType, double discount, bool isCancel, List 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 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"); - } -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/DataModels/SaleProductDataModel.cs b/IcecreamVan/SnowMaidenContracts/DataModels/SaleProductDataModel.cs deleted file mode 100644 index a2e6c6d..0000000 --- a/IcecreamVan/SnowMaidenContracts/DataModels/SaleProductDataModel.cs +++ /dev/null @@ -1,34 +0,0 @@ -using SnowMaidenContracts.Exceptions; -using SnowMaidenContracts.Extensions; -using SnowMaidenContracts.Infrastructure; - -namespace SnowMaidenContracts.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"); - } -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/DataModels/WorkerDataModel.cs b/IcecreamVan/SnowMaidenContracts/DataModels/WorkerDataModel.cs deleted file mode 100644 index b588b8d..0000000 --- a/IcecreamVan/SnowMaidenContracts/DataModels/WorkerDataModel.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Text.RegularExpressions; -using SnowMaidenContracts.Exceptions; -using SnowMaidenContracts.Extensions; -using SnowMaidenContracts.Infrastructure; - -namespace SnowMaidenContracts.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"); - } -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/Enums/DiscountType.cs b/IcecreamVan/SnowMaidenContracts/Enums/DiscountType.cs deleted file mode 100644 index 0cb56f6..0000000 --- a/IcecreamVan/SnowMaidenContracts/Enums/DiscountType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace SnowMaidenContracts.Enums; - -[Flags] -public enum DiscountType -{ - None = 0, - OnSale = 1, - Certificate = 2 -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/Enums/PostType.cs b/IcecreamVan/SnowMaidenContracts/Enums/PostType.cs deleted file mode 100644 index 66cf477..0000000 --- a/IcecreamVan/SnowMaidenContracts/Enums/PostType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace SnowMaidenContracts.Enums; - -public enum PostType -{ - None = 0, - Chef = 1, - Cashier = 2, - Assistant = 3 -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/Enums/ProductType.cs b/IcecreamVan/SnowMaidenContracts/Enums/ProductType.cs deleted file mode 100644 index fc0cd29..0000000 --- a/IcecreamVan/SnowMaidenContracts/Enums/ProductType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace SnowMaidenContracts.Enums; - -public enum ProductType -{ - None = 0, - Icecream = 1, - Milkshake = 2, - Souvenir = 3 -} \ No newline at end of file diff --git a/IcecreamVan/SnowMaidenContracts/Extensions/StringExtensions.cs b/IcecreamVan/SnowMaidenContracts/Extensions/StringExtensions.cs deleted file mode 100644 index f376e19..0000000 --- a/IcecreamVan/SnowMaidenContracts/Extensions/StringExtensions.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace SnowMaidenContracts.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 _); - } -} \ No newline at end of file diff --git a/IcecreamVan/StoragesContracts/IManufacturerContract.cs b/IcecreamVan/StoragesContracts/IManufacturerContract.cs new file mode 100644 index 0000000..8e6b383 --- /dev/null +++ b/IcecreamVan/StoragesContracts/IManufacturerContract.cs @@ -0,0 +1,20 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.StoragesContracts; + +public interface IManufacturerContract +{ + List 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); +} diff --git a/IcecreamVan/StoragesContracts/IPostContract.cs b/IcecreamVan/StoragesContracts/IPostContract.cs new file mode 100644 index 0000000..376a235 --- /dev/null +++ b/IcecreamVan/StoragesContracts/IPostContract.cs @@ -0,0 +1,22 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.StoragesContracts; + +public interface IPostContract +{ + List GetList(bool onlyActual = true); + + List 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); +} diff --git a/IcecreamVan/StoragesContracts/IProductContract.cs b/IcecreamVan/StoragesContracts/IProductContract.cs new file mode 100644 index 0000000..d2aa122 --- /dev/null +++ b/IcecreamVan/StoragesContracts/IProductContract.cs @@ -0,0 +1,20 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.StoragesContracts; + +public interface IProductContract +{ + List GetList(bool onlyActive = true, string? manufacturerID = null); + + List GetProductHistoryById(string productId); + + ProductDataModel? GetElementById(string id); + + ProductDataModel? GetElementByName(string name); + + void AddElement(ProductDataModel prodDataModel); + + void UpdElement(ProductDataModel prodDataModel); + + void DelElement(string id); +} diff --git a/IcecreamVan/StoragesContracts/ISalaryContract.cs b/IcecreamVan/StoragesContracts/ISalaryContract.cs new file mode 100644 index 0000000..a31e68c --- /dev/null +++ b/IcecreamVan/StoragesContracts/ISalaryContract.cs @@ -0,0 +1,10 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.StoragesContracts; + +public interface ISalaryContract +{ + List GetList(DateTime startD, DateTime endD, string? workerID = null); + + void AddElement(SalaryDataModel salary); +} diff --git a/IcecreamVan/StoragesContracts/ISaleContract.cs b/IcecreamVan/StoragesContracts/ISaleContract.cs new file mode 100644 index 0000000..13f7daf --- /dev/null +++ b/IcecreamVan/StoragesContracts/ISaleContract.cs @@ -0,0 +1,14 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.StoragesContracts; + +public interface ISaleContract +{ + List 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); +} diff --git a/IcecreamVan/StoragesContracts/IWorkerContract.cs b/IcecreamVan/StoragesContracts/IWorkerContract.cs new file mode 100644 index 0000000..200947d --- /dev/null +++ b/IcecreamVan/StoragesContracts/IWorkerContract.cs @@ -0,0 +1,18 @@ +using IcecreamVan.DataModels; + +namespace IcecreamVan.StoragesContracts; + +public interface IWorkerContract +{ + List 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); +} diff --git a/IcecreamVanSnowMaiden.sln b/IcecreamVanSnowMaiden.sln index 51855ab..1c475d3 100644 --- a/IcecreamVanSnowMaiden.sln +++ b/IcecreamVanSnowMaiden.sln @@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.8.34525.116 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IcecreamVan", "IcecreamVan\IcecreamVan.csproj", "{A0730374-6964-4D45-A425-049EAE498DEC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IcecreamVan", "IcecreamVan\IcecreamVan.csproj", "{A0730374-6964-4D45-A425-049EAE498DEC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "Tests\Tests.csproj", "{FC61899B-2BD9-43C9-AA66-6BF1A6FE2F48}" +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 @@ -21,6 +23,10 @@ Global {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 diff --git a/Tests/BLCTests/ManufactureBLCTest.cs b/Tests/BLCTests/ManufactureBLCTest.cs new file mode 100644 index 0000000..681d486 --- /dev/null +++ b/Tests/BLCTests/ManufactureBLCTest.cs @@ -0,0 +1,353 @@ +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 _Msc; + + [OneTimeSetUp] + public void OneTimeSetUp() + { + _Msc = new Mock(); + _Mblc = new ManufactureBLC(_Msc.Object, new Mock().Object); + } + + [SetUp] + public void SetUp() + { + _Msc.Reset(); + } + + [Test] + public void GetAllManufacturers_ReturnListOfRecords_Test() + { + //Arrange + var listOriginal = new List() { + 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()); + _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()); + _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()), 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()), 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()), Times.Once); + _Msc.Verify(x => x.GetElementByOldName(It.IsAny()), Times.Once); + } + + [Test] + public void GetManufacturerByData_EmptyData_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Mblc.GetManufacturerByData(null), Throws.TypeOf()); + Assert.That(() => _Mblc.GetManufacturerByData(string.Empty), Throws.TypeOf()); + _Msc.Verify(x => x.GetElementById(It.IsAny()), Times.Never); + _Msc.Verify(x => x.GetElementByName(It.IsAny()), Times.Never); + _Msc.Verify(x => x.GetElementByOldName(It.IsAny()), Times.Never); + } + + [Test] + public void GetManufacturerByData__GetById_NotFoundRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Mblc.GetManufacturerByData(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Msc.Verify(x => x.GetElementById(It.IsAny()), Times.Once); + _Msc.Verify(x => x.GetElementByName(It.IsAny()), Times.Never); + _Msc.Verify(x => x.GetElementByOldName(It.IsAny()), Times.Never); + } + + [Test] + public void + GetManufacturerByData_GetByNameOrOldName_NotFoundRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Mblc.GetManufacturerByData("name"), Throws.TypeOf()); + _Msc.Verify(x => x.GetElementById(It.IsAny()), Times.Never); + _Msc.Verify(x => x.GetElementByName(It.IsAny()), Times.Once); + _Msc.Verify(x => x.GetElementByOldName(It.IsAny()), Times.Once); + } + + [Test] + public void GetManufacturerByData_StorageThrowError_ThrowException_Test() + { + //Arrange + _Msc.Setup(x => x.GetElementById(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + _Msc.Setup(x => x.GetElementByName(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Mblc.GetManufacturerByData(Guid.NewGuid().ToString()), Throws.TypeOf()); + Assert.That(() => _Mblc.GetManufacturerByData("name"), Throws.TypeOf()); + _Msc.Verify(x => x.GetElementById(It.IsAny()), Times.Once); + _Msc.Verify(x => x.GetElementByName(It.IsAny()), Times.Once); + _Msc.Verify(x => x.GetElementByOldName(It.IsAny()), Times.Never); + } + + [Test] + public void GetManufacturerByData_GetByOldName_StorageThrowError_ThrowException_Test() + { + //Arrange + _Msc.Setup(x => x.GetElementByOldName(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Mblc.GetManufacturerByData("name"), Throws.TypeOf()); + _Msc.Verify(x => x.GetElementByName(It.IsAny()), Times.Once); + _Msc.Verify(x => x.GetElementByOldName(It.IsAny()), 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())).Callback((ManufacturerDataModel x) => + { + flag = x.Id == record.Id && x.ManufacturerName == record.ManufacturerName; + }); + //Act + _Mblc.InsertManufacturer(record); + //Assert + _Msc.Verify(x => x.AddElement(It.IsAny()), Times.Once); + Assert.That(flag); + } + + [Test] + public void InsertManufacturer_RecordWithExistsData_ThrowException_Test() + { + //Arrange + _Msc.Setup(x => x.AddElement(It.IsAny())).Throws(new ElementExistsException("Data", "Data")); + //Act&Assert + Assert.That(() => _Mblc.InsertManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf()); + _Msc.Verify(x => x.AddElement(It.IsAny()), Times.Once); + } + + [Test] + public void InsertManufacturer_NullRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Mblc.InsertManufacturer(null), Throws.TypeOf()); + _Msc.Verify(x => x.AddElement(It.IsAny()), Times.Never); + } + + [Test] + public void InsertManufacturer_InvalidRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Mblc.InsertManufacturer(new ManufacturerDataModel("id", "name", null, null)), Throws.TypeOf()); + _Msc.Verify(x => x.AddElement(It.IsAny()), Times.Never); + } + + [Test] + public void InsertManufacturer_StorageThrowError_ThrowException_Test() + { + //Arrange + _Msc.Setup(x => x.AddElement(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Mblc.InsertManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf()); + _Msc.Verify(x => x.AddElement(It.IsAny()), 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())).Callback((ManufacturerDataModel x) => + { + flag = x.Id == record.Id && x.ManufacturerName == record.ManufacturerName; + }); + //Act + _Mblc.UpdateManufacturer(record); + //Assert + _Msc.Verify(x => x.UpdElement(It.IsAny()), Times.Once); + Assert.That(flag); + } + + [Test] + public void + UpdateManufacturer_RecordWithIncorrectData_ThrowException_Test() + { + //Arrange + _Msc.Setup(x => x.UpdElement(It.IsAny())).Throws(new ElementNotFoundException("")); + //Act&Assert + Assert.That(() => _Mblc.UpdateManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf()); + _Msc.Verify(x => x.UpdElement(It.IsAny()), Times.Once); + } + + [Test] + public void UpdateManufacturer_RecordWithExistsData_ThrowException_Test() + { + //Arrange + _Msc.Setup(x => x.UpdElement(It.IsAny())).Throws(new ElementExistsException("Data", "Data")); + //Act&Assert + Assert.That(() => _Mblc.UpdateManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf()); + _Msc.Verify(x => x.UpdElement(It.IsAny()), Times.Once); + } + + [Test] + public void UpdateManufacturer_NullRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Mblc.UpdateManufacturer(null), Throws.TypeOf()); + _Msc.Verify(x => x.UpdElement(It.IsAny()), Times.Never); + } + + [Test] + public void UpdateManufacturer_InvalidRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Mblc.UpdateManufacturer(new ManufacturerDataModel("id", "name", null, null)), Throws.TypeOf()); + _Msc.Verify(x => x.UpdElement(It.IsAny()), Times.Never); + } + + [Test] + public void UpdateManufacturer_StorageThrowError_ThrowException_Test() + { + //Arrange + _Msc.Setup(x => x.UpdElement(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Mblc.UpdateManufacturer(new(Guid.NewGuid().ToString(), "name", null, null)), Throws.TypeOf()); + _Msc.Verify(x => x.UpdElement(It.IsAny()), 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()), 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())).Throws(new ElementNotFoundException(id)); + //Act&Assert + Assert.That(() => _Mblc.DeleteManufacturer(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Msc.Verify(x => x.DelElement(It.IsAny()), Times.Once); + } + + [Test] + public void DeleteManufacturer_IdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Mblc.DeleteManufacturer(null), Throws.TypeOf()); + Assert.That(() => _Mblc.DeleteManufacturer(string.Empty), Throws.TypeOf()); + _Msc.Verify(x => x.DelElement(It.IsAny()), Times.Never); + } + + [Test] + public void DeleteManufacturer_IdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Mblc.DeleteManufacturer("id"), Throws.TypeOf()); + _Msc.Verify(x => x.DelElement(It.IsAny()), Times.Never); + } + + [Test] + public void DeleteManufacturer_StorageThrowError_ThrowException_Test() + { + //Arrange + _Msc.Setup(x => x.DelElement(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Mblc.DeleteManufacturer(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Msc.Verify(x => x.DelElement(It.IsAny()), Times.Once); + } +} \ No newline at end of file diff --git a/Tests/BLCTests/PostBLCTest.cs b/Tests/BLCTests/PostBLCTest.cs new file mode 100644 index 0000000..99cc824 --- /dev/null +++ b/Tests/BLCTests/PostBLCTest.cs @@ -0,0 +1,453 @@ +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 _Psc; + + [OneTimeSetUp] + public void OneTimeSetUp() + { + _Psc = new Mock(); + _Pblc = new PostBLC(_Psc.Object, new Mock().Object); + } + + [SetUp] + public void SetUp() + { + _Psc.Reset(); + } + + [Test] + public void GetAllPosts_ReturnListOfRecords_Test() + { + //Arrange + var listOriginal = new List() + { + 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())).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())).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()), Times.Exactly(2)); + } + + [Test] + public void GetAllPosts_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.GetAllPosts(It.IsAny()), Throws.TypeOf()); + _Psc.Verify(x => x.GetList(It.IsAny()), Times.Once); + } + + [Test] + public void GetAllPosts_StorageThrowError_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.GetList(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Pblc.GetAllPosts(It.IsAny()), Throws.TypeOf()); + _Psc.Verify(x => x.GetList(It.IsAny()), Times.Once); + } + + [Test] + public void GetAllDataOfPost_ReturnListOfRecords_Test() + { + //Arrange + var postId = Guid.NewGuid().ToString(); + var listOriginal = new List() + { + 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())).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())).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()), Times.Once); + } + + [Test] + public void GetAllDataOfPost_PostIdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.GetAllDataOfPost(null), Throws.TypeOf()); + Assert.That(() => _Pblc.GetAllDataOfPost(string.Empty), Throws.TypeOf()); + _Psc.Verify(x => x.GetPostHistory(It.IsAny()), Times.Never); + } + + [Test] + public void GetAllDataOfPost_PostIdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.GetAllDataOfPost("id"), Throws.TypeOf()); + _Psc.Verify(x => x.GetPostHistory(It.IsAny()), Times.Never); + } + + [Test] + public void GetAllDataOfPost_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.GetAllDataOfPost(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Psc.Verify(x => x.GetPostHistory(It.IsAny()), Times.Once); + } + + [Test] + public void GetAllDataOfPost_StorageThrowError_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.GetPostHistory(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Pblc.GetAllDataOfPost(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Psc.Verify(x => x.GetPostHistory(It.IsAny()), 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()), 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()), Times.Once); + } + + [Test] + public void GetPostByData_EmptyData_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.GetPostByData(null), Throws.TypeOf()); + Assert.That(() => _Pblc.GetPostByData(string.Empty), Throws.TypeOf()); + _Psc.Verify(x => x.GetElementById(It.IsAny()), Times.Never); + _Psc.Verify(x => x.GetElementByName(It.IsAny()), Times.Never); + } + + [Test] + public void GetPostByData_GetById_NotFoundRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.GetPostByData(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Psc.Verify(x => x.GetElementById(It.IsAny()), Times.Once); + _Psc.Verify(x => x.GetElementByName(It.IsAny()), Times.Never); + } + + [Test] + public void GetPostByData_GetByName_NotFoundRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.GetPostByData("name"), Throws.TypeOf()); + _Psc.Verify(x => x.GetElementById(It.IsAny()), Times.Never); + _Psc.Verify(x => x.GetElementByName(It.IsAny()), Times.Once); + } + + [Test] + public void GetPostByData_StorageThrowError_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.GetElementById(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + _Psc.Setup(x => x.GetElementByName(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Pblc.GetPostByData(Guid.NewGuid().ToString()), Throws.TypeOf()); + Assert.That(() => _Pblc.GetPostByData("name"), Throws.TypeOf()); + _Psc.Verify(x => x.GetElementById(It.IsAny()), Times.Once); + _Psc.Verify(x => x.GetElementByName(It.IsAny()), 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())) + .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()), Times.Once); + Assert.That(flag); + } + + [Test] + public void InsertPost_RecordWithExistsData_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.AddElement(It.IsAny())).Throws(new ElementExistsException("Data", "Data")); + //Act&Assert + Assert.That(() => _Pblc.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf()); + _Psc.Verify(x => x.AddElement(It.IsAny()), Times.Once); + } + + [Test] + public void InsertPost_NullRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.InsertPost(null), Throws.TypeOf()); + _Psc.Verify(x => x.AddElement(It.IsAny()), 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()); + _Psc.Verify(x => x.AddElement(It.IsAny()), Times.Never); + } + + [Test] + public void InsertPost_StorageThrowError_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.AddElement(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Pblc.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf()); + _Psc.Verify(x => x.AddElement(It.IsAny()), 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())).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()), Times.Once); + Assert.That(flag); + } + + [Test] + public void UpdatePost_RecordWithIncorrectData_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.UpdElement(It.IsAny())).Throws(new ElementNotFoundException("")); + //Act&Assert + Assert.That(() => _Pblc.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf()); + _Psc.Verify(x => x.UpdElement(It.IsAny()), Times.Once); + } + + [Test] + public void UpdatePost_RecordWithExistsData_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.UpdElement(It.IsAny())).Throws(new ElementExistsException("Data", "Data")); + //Act&Assert + Assert.That(() => _Pblc.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf()); + _Psc.Verify(x => x.UpdElement(It.IsAny()), Times.Once); + } + + [Test] + public void UpdatePost_NullRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.UpdatePost(null), Throws.TypeOf()); + _Psc.Verify(x => x.UpdElement(It.IsAny()), 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()); + _Psc.Verify(x => x.UpdElement(It.IsAny()), Times.Never); + } + + [Test] + public void UpdatePost_StorageThrowError_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.UpdElement(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Pblc.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow)), Throws.TypeOf()); + _Psc.Verify(x => x.UpdElement(It.IsAny()), 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()), 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())).Throws(new ElementNotFoundException(id)); + //Act&Assert + Assert.That(() => _Pblc.DeletePost(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Psc.Verify(x => x.DelElement(It.IsAny()), Times.Once); + } + + [Test] + public void DeletePost_IdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.DeletePost(null), Throws.TypeOf()); + Assert.That(() => _Pblc.DeletePost(string.Empty), Throws.TypeOf()); + _Psc.Verify(x => x.DelElement(It.IsAny()), Times.Never); + } + + [Test] + public void DeletePost_IdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.DeletePost("id"), Throws.TypeOf()); + _Psc.Verify(x => x.DelElement(It.IsAny()), Times.Never); + } + + [Test] + public void DeletePost_StorageThrowError_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.DelElement(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Pblc.DeletePost(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Psc.Verify(x => x.DelElement(It.IsAny()), 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()), 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())).Throws(new ElementNotFoundException(id)); + //Act&Assert + Assert.That(() => _Pblc.RestorePost(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Psc.Verify(x => x.ResElement(It.IsAny()), Times.Once); + } + + [Test] + public void RestorePost_IdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.RestorePost(null), Throws.TypeOf()); + Assert.That(() => _Pblc.RestorePost(string.Empty), Throws.TypeOf()); + _Psc.Verify(x => x.ResElement(It.IsAny()), Times.Never); + } + + [Test] + public void RestorePost_IdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _Pblc.RestorePost("id"), Throws.TypeOf()); + _Psc.Verify(x => x.ResElement(It.IsAny()), Times.Never); + } + + [Test] + public void RestorePost_StorageThrowError_ThrowException_Test() + { + //Arrange + _Psc.Setup(x => x.ResElement(It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + //Act&Assert + Assert.That(() => _Pblc.RestorePost(Guid.NewGuid().ToString()), Throws.TypeOf()); + _Psc.Verify(x => x.ResElement(It.IsAny()), Times.Once); + } +} \ No newline at end of file diff --git a/Tests/BLCTests/SalaryBLCTest.cs b/Tests/BLCTests/SalaryBLCTest.cs new file mode 100644 index 0000000..3a07027 --- /dev/null +++ b/Tests/BLCTests/SalaryBLCTest.cs @@ -0,0 +1,5 @@ +namespace Tests.BLCTests; + +internal class SalaryBLCTest +{ +} diff --git a/Tests/BLCTests/SaleBLCTest.cs b/Tests/BLCTests/SaleBLCTest.cs new file mode 100644 index 0000000..f8eb3d8 --- /dev/null +++ b/Tests/BLCTests/SaleBLCTest.cs @@ -0,0 +1,5 @@ +namespace Tests.BLCTests; + +internal class SaleBLCTest +{ +} diff --git a/Tests/SnowMaidenDMTests/ManufacturerDMTest.cs b/Tests/SnowMaidenDMTests/ManufacturerDMTest.cs index 40f8d03..27d76e7 100644 --- a/Tests/SnowMaidenDMTests/ManufacturerDMTest.cs +++ b/Tests/SnowMaidenDMTests/ManufacturerDMTest.cs @@ -1,6 +1,6 @@ -using NUnit.Framework; -using SnowMaidenContracts.DataModels; -using SnowMaidenContracts.Exceptions; +using IcecreamVan.DataModels; +using IcecreamVan.Exceptions; +using NUnit.Framework; namespace SnowMaidenTests.DataModelsTest; diff --git a/Tests/SnowMaidenDMTests/PostDMTest.cs b/Tests/SnowMaidenDMTests/PostDMTest.cs index b4ae9ee..f97fe3b 100644 --- a/Tests/SnowMaidenDMTests/PostDMTest.cs +++ b/Tests/SnowMaidenDMTests/PostDMTest.cs @@ -1,7 +1,7 @@ using NUnit.Framework; -using SnowMaidenContracts.Enums; -using SnowMaidenContracts.DataModels; -using SnowMaidenContracts.Exceptions; +using IcecreamVan.DataModels; +using IcecreamVan.Enums; +using IcecreamVan.Exceptions; namespace SnowMaidenTests.DataModelsTest; @@ -11,57 +11,41 @@ internal class PostDMTest [Test] public void IdIsNullOrEmptyTest() { - var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow); + var post = CreateDataModel(null, "name", PostType.Assistant, 10, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); - post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow); + post = CreateDataModel(string.Empty, "name", PostType.Assistant, 10, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); } [Test] public void IdIsNotGuidTest() { - var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), Throws.TypeOf()); - } - - [Test] - public void PostIdIsNullEmptyTest() - { - var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Assistant, 10, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), Throws.TypeOf()); - post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Assistant, 10, true, DateTime.UtcNow); - Assert.That(() => post.Validate(), Throws.TypeOf()); - } - - [Test] - public void PostIdIsNotGuidTest() - { - var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Assistant, 10, true, DateTime.UtcNow); + var post = CreateDataModel("id", "name", PostType.Assistant, 10, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); } [Test] public void PostNameIsEmptyTest() { - var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Assistant, 10, true, DateTime.UtcNow); + var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Assistant, 10, true, DateTime.UtcNow); Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); - manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Assistant, 10, true, DateTime.UtcNow); + manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Assistant, 10, true, DateTime.UtcNow); Assert.That(() => manufacturer.Validate(), Throws.TypeOf()); } [Test] public void PostTypeIsNoneTest() { - var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow); + var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); } [Test] public void SalaryIsLessOrZeroTest() { - var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Assistant, 0, true, DateTime.UtcNow); + var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 0, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); - post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Assistant, -10, true, DateTime.UtcNow); + post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, -10, true, DateTime.UtcNow); Assert.That(() => post.Validate(), Throws.TypeOf()); } @@ -69,18 +53,16 @@ internal class PostDMTest public void AllFieldsIsCorrectTest() { var postId = Guid.NewGuid().ToString(); - var postPostId = Guid.NewGuid().ToString(); var postName = "name"; var postType = PostType.Assistant; var salary = 10; var isActual = false; var changeDate = DateTime.UtcNow.AddDays(-1); - var post = CreateDataModel(postId, postPostId, postName, postType, salary, isActual, changeDate); + 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.PostId, Is.EqualTo(postPostId)); Assert.That(post.PostName, Is.EqualTo(postName)); Assert.That(post.PostType, Is.EqualTo(postType)); Assert.That(post.Salary, Is.EqualTo(salary)); @@ -89,6 +71,6 @@ internal class PostDMTest }); } - private static PostDataModel CreateDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) => - new(id, postId, postName, postType, salary, isActual, changeDate); + private static PostDataModel CreateDataModel(string id, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) => + new(id, postName, postType, salary, isActual, changeDate); } diff --git a/Tests/SnowMaidenDMTests/ProductDMTest.cs b/Tests/SnowMaidenDMTests/ProductDMTest.cs index 26592d8..860c94c 100644 --- a/Tests/SnowMaidenDMTests/ProductDMTest.cs +++ b/Tests/SnowMaidenDMTests/ProductDMTest.cs @@ -1,7 +1,7 @@ using NUnit.Framework; -using SnowMaidenContracts.Enums; -using SnowMaidenContracts.DataModels; -using SnowMaidenContracts.Exceptions; +using IcecreamVan.DataModels; +using IcecreamVan.Enums; +using IcecreamVan.Exceptions; namespace SnowMaidenTests.DataModelsTest; diff --git a/Tests/SnowMaidenDMTests/ProductHistoryDMTest.cs b/Tests/SnowMaidenDMTests/ProductHistoryDMTest.cs index 3455a8c..ed7ac6f 100644 --- a/Tests/SnowMaidenDMTests/ProductHistoryDMTest.cs +++ b/Tests/SnowMaidenDMTests/ProductHistoryDMTest.cs @@ -1,6 +1,6 @@ -using NUnit.Framework; -using SnowMaidenContracts.DataModels; -using SnowMaidenContracts.Exceptions; +using IcecreamVan.DataModels; +using IcecreamVan.Exceptions; +using NUnit.Framework; namespace SnowMaidenTests.DataModelsTest; diff --git a/Tests/SnowMaidenDMTests/SalaryDMTest.cs b/Tests/SnowMaidenDMTests/SalaryDMTest.cs index ffd5f25..8b4f42a 100644 --- a/Tests/SnowMaidenDMTests/SalaryDMTest.cs +++ b/Tests/SnowMaidenDMTests/SalaryDMTest.cs @@ -1,6 +1,6 @@ -using NUnit.Framework; -using SnowMaidenContracts.DataModels; -using SnowMaidenContracts.Exceptions; +using IcecreamVan.DataModels; +using IcecreamVan.Exceptions; +using NUnit.Framework; namespace SnowMaidenTests.DataModelsTest; diff --git a/Tests/SnowMaidenDMTests/SaleDMTest.cs b/Tests/SnowMaidenDMTests/SaleDMTest.cs index 33572b9..81c787d 100644 --- a/Tests/SnowMaidenDMTests/SaleDMTest.cs +++ b/Tests/SnowMaidenDMTests/SaleDMTest.cs @@ -1,7 +1,7 @@ using NUnit.Framework; -using SnowMaidenContracts.Enums; -using SnowMaidenContracts.DataModels; -using SnowMaidenContracts.Exceptions; +using IcecreamVan.DataModels; +using IcecreamVan.Enums; +using IcecreamVan.Exceptions; [TestFixture] internal class SaleDMTest diff --git a/Tests/SnowMaidenDMTests/SaleProductDMTest.cs b/Tests/SnowMaidenDMTests/SaleProductDMTest.cs index 6c4af6c..5a561ce 100644 --- a/Tests/SnowMaidenDMTests/SaleProductDMTest.cs +++ b/Tests/SnowMaidenDMTests/SaleProductDMTest.cs @@ -1,6 +1,6 @@ -using NUnit.Framework; -using SnowMaidenContracts.DataModels; -using SnowMaidenContracts.Exceptions; +using IcecreamVan.DataModels; +using IcecreamVan.Exceptions; +using NUnit.Framework; namespace SnowMaidenTests.DataModelsTest; diff --git a/Tests/SnowMaidenDMTests/WorkerDMTest.cs b/Tests/SnowMaidenDMTests/WorkerDMTest.cs index 9d9cf11..3ff622c 100644 --- a/Tests/SnowMaidenDMTests/WorkerDMTest.cs +++ b/Tests/SnowMaidenDMTests/WorkerDMTest.cs @@ -1,7 +1,7 @@ using System; +using IcecreamVan.DataModels; +using IcecreamVan.Exceptions; using NUnit.Framework; -using SnowMaidenContracts.DataModels; -using SnowMaidenContracts.Exceptions; namespace SnowMaidenTests.DataModelsTest; diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index 322753a..a029f5c 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -10,7 +10,9 @@ + + @@ -18,6 +20,7 @@ +