Compare commits
15 Commits
main
...
Task2_Buis
Author | SHA1 | Date | |
---|---|---|---|
86c267c9a1 | |||
437105d658 | |||
43cdd25c27 | |||
e05876924f | |||
7fd73da402 | |||
e24689ed30 | |||
f16055973e | |||
449e378d85 | |||
09e7bc69f6 | |||
e5fcdd39c1 | |||
2f340b93d5 | |||
c9359593b5 | |||
5c281157cb | |||
83a4e4cd26 | |||
8f24ade3c4 |
@ -0,0 +1,72 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PapaCarloContracts.BusinessLogicContracts;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloBusinessLogic.Implementations
|
||||
{
|
||||
internal class BlankBusinessLogicContract(IBlankStorageContract blankStorageContract, ILogger logger) : IBlankBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private IBlankStorageContract _blankStorageContract = blankStorageContract;
|
||||
|
||||
public void DeleteBlank(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_blankStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
public List<BlankDataModel> GetAllBlanks()
|
||||
{
|
||||
_logger.LogInformation("GetAllBlanks");
|
||||
return _blankStorageContract.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public BlankDataModel GetBlankByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _blankStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _blankStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertBlank(BlankDataModel blankDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data:{json}", JsonSerializer.Serialize(blankDataModel));
|
||||
ArgumentNullException.ThrowIfNull(blankDataModel);
|
||||
blankDataModel.Validate();
|
||||
_blankStorageContract.AddElement(blankDataModel);
|
||||
}
|
||||
|
||||
public void UpdateBlank(BlankDataModel blankDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(blankDataModel));
|
||||
ArgumentNullException.ThrowIfNull(blankDataModel);
|
||||
blankDataModel.Validate();
|
||||
_blankStorageContract.UpdElement(blankDataModel);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PapaCarloContracts.BusinessLogicContracts;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloBusinessLogic.Implementations;
|
||||
|
||||
internal class CuttingBusinessLogicContract(ICuttingStorageContract cuttingStorageContract, ILogger logger) : ICuttingBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ICuttingStorageContract _cuttingStorageContract = cuttingStorageContract;
|
||||
|
||||
public List<CuttingDataModel> GetAllCuttingsByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllCuttings params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _cuttingStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<CuttingDataModel> GetAllCuttingsByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllCuttings params: {workerId}, {fromDate}, {toDate}", workerId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
return _cuttingStorageContract.GetList(fromDate, toDate, workerId: workerId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public CuttingDataModel GetCuttingByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (!data.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
return _cuttingStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertCutting(CuttingDataModel cuttingDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(cuttingDataModel));
|
||||
ArgumentNullException.ThrowIfNull(cuttingDataModel);
|
||||
cuttingDataModel.Validate();
|
||||
_cuttingStorageContract.AddElement(cuttingDataModel);
|
||||
}
|
||||
|
||||
public void CancelCutting(string id)
|
||||
{
|
||||
_logger.LogInformation("Cancel by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_cuttingStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PapaCarloContracts.BuisinessLogicsContracts;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloBusinessLogic.Implementations;
|
||||
|
||||
internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
|
||||
public List<PostDataModel> GetAllPosts(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllPosts params: {onlyActive}", onlyActive);
|
||||
return _postStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetAllDataOfPost(string postId)
|
||||
{
|
||||
_logger.LogInformation("GetAllDataOfPost for {postId}", postId);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _postStorageContract.GetPostWithHistory(postId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public PostDataModel GetPostByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _postStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _postStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertPost(PostDataModel postDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
_postStorageContract.AddElement(postDataModel);
|
||||
}
|
||||
|
||||
public void UpdatePost(PostDataModel postDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
_postStorageContract.UpdElement(postDataModel);
|
||||
}
|
||||
|
||||
public void DeletePost(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_postStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
public void RestorePost(string id)
|
||||
{
|
||||
_logger.LogInformation("Restore by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_postStorageContract.ResElement(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PapaCarloContracts.BusinessLogicContracts;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloBusinessLogic.Implementations;
|
||||
|
||||
internal class ProductBusinessLogicContract(IProductStorageContract productStorageContract, ILogger logger) : IProductBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IProductStorageContract _productStorageContract = productStorageContract;
|
||||
|
||||
public List<ProductDataModel> GetAllProducts(bool onlyActive)
|
||||
{
|
||||
_logger.LogInformation("GetAllProducts params: {onlyActive}", onlyActive);
|
||||
return _productStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<ProductDataModel> GetAllProductsByBlank(string blankId, bool onlyActive = true)
|
||||
{
|
||||
if (blankId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(blankId));
|
||||
}
|
||||
if (!blankId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field blankId is not a unique identifier.");
|
||||
}
|
||||
_logger.LogInformation("GetAllProducts params: {blankId}, {onlyActive}", blankId, onlyActive);
|
||||
return _productStorageContract.GetList(onlyActive, blankId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId)
|
||||
{
|
||||
_logger.LogInformation("GetProductHistoryByProduct for {productId}", productId);
|
||||
if (productId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(productId));
|
||||
}
|
||||
if (!productId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field productId is not a unique identifier.");
|
||||
}
|
||||
return _productStorageContract.GetHistoryByProductId(productId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public ProductDataModel GetProductByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _productStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _productStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertProduct(ProductDataModel productDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(productDataModel));
|
||||
ArgumentNullException.ThrowIfNull(productDataModel);
|
||||
productDataModel.Validate();
|
||||
_productStorageContract.AddElement(productDataModel);
|
||||
}
|
||||
|
||||
public void UpdateProduct(ProductDataModel productDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(productDataModel));
|
||||
ArgumentNullException.ThrowIfNull(productDataModel);
|
||||
productDataModel.Validate();
|
||||
_productStorageContract.UpdElement(productDataModel);
|
||||
}
|
||||
|
||||
public void DeleteProduct(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_productStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PapaCarloContracts.BusinessLogicContracts;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloBusinessLogic.Implementations;
|
||||
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,
|
||||
ICuttingStorageContract cuttingStorageContract, IPostStorageContract postStorageContract, IWorkerStorageContract workerStorageContract, ILogger logger) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
private readonly ICuttingStorageContract _cuttingStorageContract = cuttingStorageContract;
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
|
||||
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _salaryStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId)
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(workerId));
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
}
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, {workerId}", fromDate, toDate, workerId);
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, workerId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public void CalculateSalaryByMounth(DateTime date)
|
||||
{
|
||||
_logger.LogInformation("CalculateSalaryByMounth: {date}", date);
|
||||
var startDate = new DateTime(date.Year, date.Month, 1);
|
||||
var finishDate = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
|
||||
var workers = _workerStorageContract.GetList() ?? throw new NullListException();
|
||||
foreach (var worker in workers)
|
||||
{
|
||||
var cuttings = _cuttingStorageContract.GetList(startDate, finishDate, workerId: worker.Id)?.Count(x => x.Id != null) ??
|
||||
throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(worker.PostId) ??
|
||||
throw new NullListException();
|
||||
var salary = cuttings * 100;
|
||||
_logger.LogDebug("The employee {workerId} was paid a salary of {salary}", worker.Id, salary);
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(worker.Id, finishDate, salary));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,104 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PapaCarloContracts.BusinessLogicContracts;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloBusinessLogic.Implementations;
|
||||
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}", onlyActive);
|
||||
return _workerStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {postId}, {onlyActive},", postId, onlyActive);
|
||||
if (postId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(postId));
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, postId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromBirthDate: fromDate, toBirthDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<WorkerDataModel> GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromEmploymentDate: fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public WorkerDataModel GetWorkerByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _workerStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _workerStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorageContract.AddElement(workerDataModel);
|
||||
}
|
||||
|
||||
public void UpdateWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
_workerStorageContract.UpdElement(workerDataModel);
|
||||
}
|
||||
|
||||
public void DeleteWorker(string id)
|
||||
{
|
||||
_logger.LogInformation("Delete by id: {id}", id);
|
||||
if (id.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
}
|
||||
_workerStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="PapaCarloTests" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PapaCarloContracts\PapaCarloContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,18 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.BusinessLogicContracts;
|
||||
|
||||
public interface IBlankBusinessLogicContract
|
||||
{
|
||||
List<BlankDataModel> GetAllBlanks();
|
||||
BlankDataModel GetBlankByData(string data);
|
||||
void InsertBlank(BlankDataModel blankDataModel);
|
||||
void UpdateBlank(BlankDataModel blankDataModel);
|
||||
void DeleteBlank(string id);
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.BusinessLogicContracts;
|
||||
|
||||
public interface ICuttingBusinessLogicContract
|
||||
{
|
||||
List<CuttingDataModel> GetAllCuttingsByPeriod(DateTime fromDate, DateTime
|
||||
toDate);
|
||||
List<CuttingDataModel> GetAllCuttingsByWorkerByPeriod(string workerId, DateTime
|
||||
fromDate, DateTime toDate);
|
||||
|
||||
CuttingDataModel GetCuttingByData(string data);
|
||||
void InsertCutting(CuttingDataModel cuttingDataModel);
|
||||
void CancelCutting(string id);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.BuisinessLogicsContracts;
|
||||
|
||||
public interface IPostBusinessLogicContract
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.BusinessLogicContracts;
|
||||
|
||||
public interface IProductBusinessLogicContract
|
||||
{
|
||||
List<ProductDataModel> GetAllProducts(bool onlyActive = true);
|
||||
List<ProductDataModel> GetAllProductsByBlank(string blankId,
|
||||
bool onlyActive = true);
|
||||
List<ProductHistoryDataModel> GetProductHistoryByProduct(string productId);
|
||||
ProductDataModel GetProductByData(string data);
|
||||
void InsertProduct(ProductDataModel productDataModel);
|
||||
void UpdateProduct(ProductDataModel productDataModel);
|
||||
void DeleteProduct(string id);
|
||||
}
|
||||
|
@ -0,0 +1,16 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.BusinessLogicContracts;
|
||||
|
||||
public interface ISalaryBusinessLogicContract
|
||||
{
|
||||
List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId);
|
||||
void CalculateSalaryByMounth(DateTime date);
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.BusinessLogicContracts;
|
||||
|
||||
public interface IWorkerBusinessLogicContract
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.DataModels;
|
||||
|
||||
public class BlankDataModel(string id, string blankName, string? prevBlankName, string? prevPrevBlankName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string BlankName { get; private set; } = blankName;
|
||||
|
||||
public string? PrevBlankName { get; private set; } = prevBlankName;
|
||||
|
||||
public string? PrevPrevBlankName { get; private set; } = prevPrevBlankName;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (BlankName.IsEmpty())
|
||||
throw new ValidationException("Field blankName is empty");
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.DataModels;
|
||||
|
||||
public class CuttingDataModel(string id, string workerId, string blankId, bool isCancel, List<CuttingProductDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public DateTime CutDate { get; private set; } = DateTime.UtcNow;
|
||||
public string BlankId { get; private set; } = blankId;
|
||||
public bool IsCancel { get; private set; } = isCancel;
|
||||
|
||||
public List<CuttingProductDataModel> Products { get; private set; } = products;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
|
||||
if (BlankId.IsEmpty())
|
||||
throw new ValidationException("Field BlankId is empty");
|
||||
|
||||
if (!BlankId.IsGuid())
|
||||
throw new ValidationException("The value in the field BlankId is not a unique identifier");
|
||||
new ValidationException("Field Sum is less than or equal to 0");
|
||||
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The cut must include blanks");
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.DataModels;
|
||||
|
||||
public class CuttingProductDataModel(string cuttingId, string productId, int count) : IValidation
|
||||
{
|
||||
public string CuttingId { get; private set; } = cuttingId;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (CuttingId.IsEmpty())
|
||||
throw new ValidationException("Field CuttingId is empty");
|
||||
|
||||
if (!CuttingId.IsGuid())
|
||||
throw new ValidationException("The value in the field SaleId is not a unique identifier");
|
||||
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
using PapaCarloContracts.Enums;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postName, PostType postType,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 bool IsActual { get; private set; } = isActual;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
|
||||
if (PostName.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
using PapaCarloContracts.Enums;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.DataModels;
|
||||
|
||||
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 value in the field Id is not a unique identifier");
|
||||
|
||||
if (ProductName.IsEmpty())
|
||||
throw new ValidationException("Field ProductName is empty");
|
||||
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.DataModels;
|
||||
|
||||
public class ProductHistoryDataModel(string productId, double oldPrice) : IValidation
|
||||
{
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
|
||||
{
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.Extensions;
|
||||
using PapaCarloContracts.infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
|
||||
public DateTime BirthDate { get; private set; } = birthDate;
|
||||
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
|
||||
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||
|
||||
if (EmploymentDate.Date < BirthDate.Date)
|
||||
throw new ValidationException("The date of employment 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()})");
|
||||
}
|
||||
}
|
15
PapaCarloProject/PapaCarloContracts/Enums/PostType.cs
Normal file
15
PapaCarloProject/PapaCarloContracts/Enums/PostType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
OrderManager = 1,
|
||||
Carpenter = 2,
|
||||
MaterialPreparer = 3
|
||||
}
|
16
PapaCarloProject/PapaCarloContracts/Enums/ProductType.cs
Normal file
16
PapaCarloProject/PapaCarloContracts/Enums/ProductType.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.Enums;
|
||||
|
||||
public enum ProductType
|
||||
{
|
||||
None = 0,
|
||||
Toy = 1,
|
||||
Furniture = 2,
|
||||
Tool = 3
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.Exceptions;
|
||||
|
||||
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 value{paramValue} of parameter {paramName}")
|
||||
{
|
||||
ParamName = paramName;
|
||||
ParamValue = paramValue;
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.Exceptions;
|
||||
|
||||
public class ElementNotFoundException : Exception
|
||||
{
|
||||
public string Value { get; private set; }
|
||||
|
||||
public ElementNotFoundException(string value) : base($"Element not found at value = {value}")
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.Exceptions;
|
||||
|
||||
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}") { }
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.Exceptions;
|
||||
|
||||
public class NullListException : Exception
|
||||
{
|
||||
public NullListException() : base("The returned list is null") { }
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.Exceptions;
|
||||
|
||||
public class StorageException : Exception
|
||||
{
|
||||
public StorageException(Exception ex) : base($"Error while working in storage: {ex.Message}", ex) { }
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace PapaCarloContracts.Extensions;
|
||||
|
||||
public static class DateTimeExtensions
|
||||
{
|
||||
public static bool IsDateNotOlder(this DateTime date, DateTime olderDate)
|
||||
{
|
||||
return date >= olderDate;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static bool IsEmpty(this string str)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
public static bool IsGuid(this string str)
|
||||
{
|
||||
return Guid.TryParse(str, out _);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.StoragesContracts;
|
||||
|
||||
public interface IBlankStorageContract
|
||||
{
|
||||
List<BlankDataModel> GetList();
|
||||
BlankDataModel? GetElementById(string id);
|
||||
BlankDataModel? GetElementByName(string name);
|
||||
BlankDataModel? GetElementByOldName(string name);
|
||||
void AddElement(BlankDataModel blankDataModel);
|
||||
void UpdElement(BlankDataModel blankDataModel);
|
||||
void DelElement(string id);
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.StoragesContracts;
|
||||
|
||||
public interface ICuttingStorageContract
|
||||
{
|
||||
List<CuttingDataModel> GetList(DateTime? startDate = null, DateTime? endDate =
|
||||
null, string? workerId = null, string? blankId = null, string? productId = null);
|
||||
CuttingDataModel? GetElementById(string id);
|
||||
void AddElement(CuttingDataModel cuttingDataModel);
|
||||
void DelElement(string id);
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.StoragesContracts;
|
||||
|
||||
public interface IPostStorageContract
|
||||
{
|
||||
List<PostDataModel> GetList(bool onlyActual = true);
|
||||
List<PostDataModel> GetPostWithHistory(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);
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.StoragesContracts;
|
||||
|
||||
public interface IProductStorageContract
|
||||
{
|
||||
List<ProductDataModel> GetList(bool onlyActive = true, string? blankId = null);
|
||||
List<ProductHistoryDataModel> GetHistoryByProductId(string productId);
|
||||
ProductDataModel? GetElementById(string id);
|
||||
ProductDataModel? GetElementByName(string name);
|
||||
void AddElement(ProductDataModel productDataModel);
|
||||
void UpdElement(ProductDataModel productDataModel);
|
||||
void DelElement(string id);
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.StoragesContracts;
|
||||
public interface ISalaryStorageContract
|
||||
{
|
||||
List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string?
|
||||
workerId = null);
|
||||
void AddElement(SalaryDataModel salaryDataModel);
|
||||
}
|
||||
|
@ -0,0 +1,21 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.StoragesContracts;
|
||||
|
||||
public interface IWorkerStorageContract
|
||||
{
|
||||
List<WorkerDataModel> GetList(bool onlyActive = true, string? postId =
|
||||
null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime?
|
||||
fromEmploymentDate = null, DateTime? toEmploymentDate = null);
|
||||
WorkerDataModel? GetElementById(string id);
|
||||
WorkerDataModel? GetElementByFIO(string fio);
|
||||
void AddElement(WorkerDataModel workerDataModel);
|
||||
void UpdElement(WorkerDataModel workerDataModel);
|
||||
void DelElement(string id);
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloContracts.infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.12.35514.174 d17.12
|
||||
VisualStudioVersion = 17.12.35514.174
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PapaCarloContracts", "PapaCarloContracts\PapaCarloContracts.csproj", "{13339D4F-E8FC-4847-8D79-966E3CC2145D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PapaCarloTests", "PapaCarloTests\PapaCarloTests.csproj", "{30C630DE-DFCA-4672-B554-56984275B0AE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PapaCarloBusinessLogic", "PapaCarloBusinessLogic\PapaCarloBusinessLogic.csproj", "{2966A76B-CF78-47C3-8F6D-F227A396B916}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +19,14 @@ Global
|
||||
{13339D4F-E8FC-4847-8D79-966E3CC2145D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{13339D4F-E8FC-4847-8D79-966E3CC2145D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{13339D4F-E8FC-4847-8D79-966E3CC2145D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{30C630DE-DFCA-4672-B554-56984275B0AE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{30C630DE-DFCA-4672-B554-56984275B0AE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{30C630DE-DFCA-4672-B554-56984275B0AE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{30C630DE-DFCA-4672-B554-56984275B0AE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2966A76B-CF78-47C3-8F6D-F227A396B916}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2966A76B-CF78-47C3-8F6D-F227A396B916}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2966A76B-CF78-47C3-8F6D-F227A396B916}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2966A76B-CF78-47C3-8F6D-F227A396B916}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,287 @@
|
||||
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using PapaCarloBusinessLogic.Implementations;
|
||||
using PapaCarloContracts.BusinessLogicContracts;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.BusinessLogicsContracts;
|
||||
|
||||
[TestFixture]
|
||||
internal class BlankBusinessLogicContractTests
|
||||
{
|
||||
private BlankBusinessLogicContract _blankBusinessLogicContract;
|
||||
private Mock<IBlankStorageContract> _blankStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_blankStorageContract = new Mock<IBlankStorageContract>();
|
||||
_blankBusinessLogicContract = new BlankBusinessLogicContract(_blankStorageContract.Object, new Mock<ILogger>().Object);
|
||||
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_blankStorageContract.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllBlanks_ReturnListOfRecords_Test()
|
||||
{
|
||||
var listOriginal = new List<BlankDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(),"Mahogany","",""),
|
||||
new(Guid.NewGuid().ToString(),"Birch","",""),
|
||||
new(Guid.NewGuid().ToString(),"Spruce","","")
|
||||
};
|
||||
|
||||
_blankStorageContract.Setup(x=> x.GetList()).Returns(listOriginal);
|
||||
|
||||
var list = _blankBusinessLogicContract.GetAllBlanks();
|
||||
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllBlanks_ReturnEmptyList_Test()
|
||||
{
|
||||
|
||||
|
||||
_blankStorageContract.Setup(x => x.GetList()).Returns([]);
|
||||
|
||||
var list = _blankBusinessLogicContract.GetAllBlanks();
|
||||
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_blankStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllBlanks_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _blankBusinessLogicContract.GetAllBlanks(), Throws.TypeOf<NullListException>());
|
||||
_blankStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllBlanks_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
_blankStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _blankBusinessLogicContract.GetAllBlanks(), Throws.TypeOf<StorageException>());
|
||||
_blankStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBlankByData_GetById_ReturnRecord_Test()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new BlankDataModel(id, "Spruce", "", "");
|
||||
_blankStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
|
||||
var element = _blankBusinessLogicContract.GetBlankByData(id);
|
||||
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
_blankStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBlankByData_GetByName_ReturnRecord_Test()
|
||||
{
|
||||
var name = "Spruce";
|
||||
var record = new BlankDataModel(Guid.NewGuid().ToString(), name, "", "");
|
||||
_blankStorageContract.Setup(x => x.GetElementByName(name)).Returns(record);
|
||||
|
||||
var element = _blankBusinessLogicContract.GetBlankByData(name);
|
||||
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.BlankName, Is.EqualTo(name));
|
||||
_blankStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
public void GetBlankByData_GetByOldName_ReturnRecord_Test()
|
||||
{
|
||||
var oldName = "Spruce";
|
||||
var record = new BlankDataModel(Guid.NewGuid().ToString(), "Birch", oldName, "");
|
||||
_blankStorageContract.Setup(x => x.GetElementByOldName(oldName)).Returns(record);
|
||||
|
||||
var element = _blankBusinessLogicContract.GetBlankByData(oldName);
|
||||
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.PrevBlankName, Is.EqualTo(oldName));
|
||||
_blankStorageContract.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBlankByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _blankBusinessLogicContract.GetBlankByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _blankBusinessLogicContract.GetBlankByData(String.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
|
||||
_blankStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
_blankStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
||||
_blankStorageContract.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBlankByData_GetById_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _blankBusinessLogicContract.GetBlankByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_blankStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_blankStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
||||
_blankStorageContract.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetBlankByData_GetByName_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _blankBusinessLogicContract.GetBlankByData("Name"), Throws.TypeOf<ElementNotFoundException>());
|
||||
_blankStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
_blankStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
_blankStorageContract.Verify(x => x.GetElementByOldName(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
[Test]
|
||||
public void GetBlankByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
_blankStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_blankStorageContract.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _blankBusinessLogicContract.GetBlankByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _blankBusinessLogicContract.GetBlankByData("Name"), Throws.TypeOf<StorageException>());
|
||||
|
||||
_blankStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_blankStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertBlank_CorrectRecord_Test()
|
||||
{
|
||||
var flag = false;
|
||||
var record = new BlankDataModel(Guid.NewGuid().ToString(), "Spruce", "", "");
|
||||
_blankStorageContract.Setup(x => x.AddElement(It.IsAny<BlankDataModel>()))
|
||||
.Callback((BlankDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.BlankName == record.BlankName;
|
||||
});
|
||||
_blankBusinessLogicContract.InsertBlank(record);
|
||||
|
||||
_blankStorageContract.Verify(x => x.AddElement(It.IsAny<BlankDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertBlank_RecordWithExistData_ThrowException_Test()
|
||||
{
|
||||
_blankStorageContract.Setup(x => x.AddElement(It.IsAny<BlankDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
|
||||
Assert.That(() => _blankBusinessLogicContract.InsertBlank(new(Guid.NewGuid().ToString(), "Spruce", "", "")), Throws.TypeOf<ElementExistsException>());
|
||||
_blankStorageContract.Verify(x => x.AddElement(It.IsAny<BlankDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertBlank_NullRecord_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _blankBusinessLogicContract.InsertBlank(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_blankStorageContract.Verify(x => x.AddElement(It.IsAny<BlankDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertBlank_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _blankBusinessLogicContract.InsertBlank(new BlankDataModel("id", "name", "", "")), Throws.TypeOf<ValidationException>());
|
||||
_blankStorageContract.Verify(x => x.AddElement(It.IsAny<BlankDataModel>()), Times.Never);
|
||||
}
|
||||
[Test]
|
||||
public void InsertBlank_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
_blankStorageContract.Setup(x => x.AddElement(It.IsAny<BlankDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _blankBusinessLogicContract.InsertBlank(new(Guid.NewGuid().ToString(), "Spruce", "", "")), Throws.TypeOf<StorageException>());
|
||||
_blankStorageContract.Verify(x => x.AddElement(It.IsAny<BlankDataModel>()), Times.Once);
|
||||
}
|
||||
[Test]
|
||||
public void UpdateBlank_RecordWithIncorrectData_ThrowException_Test()
|
||||
{
|
||||
_blankStorageContract.Setup(x => x.UpdElement(It.IsAny<BlankDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
|
||||
Assert.That(() => _blankBusinessLogicContract.UpdateBlank(new(Guid.NewGuid().ToString(), "Spruce", "", "")), Throws.TypeOf<ElementNotFoundException>());
|
||||
_blankStorageContract.Verify(x => x.UpdElement(It.IsAny<BlankDataModel>()), Times.Once);
|
||||
}
|
||||
[Test]
|
||||
public void UpdateBlank_RecordWithExistData_ThrowException_Test()
|
||||
{
|
||||
_blankStorageContract.Setup(x => x.UpdElement(It.IsAny<BlankDataModel>())).Throws(new ElementExistsException("Data","Data"));
|
||||
|
||||
Assert.That(() => _blankBusinessLogicContract.UpdateBlank(new(Guid.NewGuid().ToString(), "Spruce", "", "")), Throws.TypeOf<ElementExistsException>());
|
||||
_blankStorageContract.Verify(x => x.UpdElement(It.IsAny<BlankDataModel>()), Times.Once);
|
||||
}
|
||||
[Test]
|
||||
public void UpdateBlank_NullRecord_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _blankBusinessLogicContract.UpdateBlank(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_blankStorageContract.Verify(x => x.UpdElement(It.IsAny<BlankDataModel>()), Times.Never);
|
||||
}
|
||||
[Test]
|
||||
public void UpdateBlank_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
|
||||
Assert.That(() => _blankBusinessLogicContract.UpdateBlank(new("id", "Spruce", "", "")), Throws.TypeOf<ValidationException>());
|
||||
_blankStorageContract.Verify(x => x.UpdElement(It.IsAny<BlankDataModel>()), Times.Never);
|
||||
}
|
||||
[Test]
|
||||
public void DeleteBlank_CorrectRecord_Test()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
_blankStorageContract.Setup(x => x.DelElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
||||
|
||||
_blankBusinessLogicContract.DeleteBlank(id);
|
||||
|
||||
_blankStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
[Test]
|
||||
public void DeleteBlank_RecordWithIncorrectId_ThrowException_Test()
|
||||
{
|
||||
_blankStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(""));
|
||||
|
||||
Assert.That(() => _blankBusinessLogicContract.DeleteBlank(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_blankStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
[Test]
|
||||
public void DeleteBlank_IdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _blankBusinessLogicContract.DeleteBlank(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _blankBusinessLogicContract.DeleteBlank(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_blankStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
[Test]
|
||||
public void DeleteBlank_IdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
Assert.That(() => _blankBusinessLogicContract.DeleteBlank("id"), Throws.TypeOf<ValidationException>());
|
||||
_blankStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
[Test]
|
||||
public void DeleteBlank_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
_blankStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
Assert.That(() => _blankBusinessLogicContract.DeleteBlank(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_blankStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,338 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using PapaCarloBusinessLogic.Implementations;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.BusinessLogicsContracts;
|
||||
|
||||
[TestFixture]
|
||||
internal class CuttingBusinessLogicContractTests
|
||||
{
|
||||
private CuttingBusinessLogicContract _cuttingBusinessLogicContract;
|
||||
private Mock<ICuttingStorageContract> _cuttingStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_cuttingStorageContract = new Mock<ICuttingStorageContract>();
|
||||
_cuttingBusinessLogicContract = new CuttingBusinessLogicContract(_cuttingStorageContract.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_cuttingStorageContract.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByPeriod_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
var listOriginal = new List<CuttingDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),false,
|
||||
[new CuttingProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), false, []),
|
||||
};
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
var list = _cuttingBusinessLogicContract.GetAllCuttingsByPeriod(date, date.AddDays(1));
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
_cuttingStorageContract.Verify(x => x.GetList(date, date.AddDays(1), null, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByPeriod_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var list = _cuttingBusinessLogicContract.GetAllCuttingsByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1));
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByPeriod_IncorrectDates_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByPeriod(date, date), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByPeriod(date, date.AddSeconds(-1)), Throws.TypeOf<IncorrectDatesException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByPeriod_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByPeriod_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByWorkerByPeriod_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<CuttingDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), false,
|
||||
[new CuttingProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), false, []),
|
||||
};
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
var list = _cuttingBusinessLogicContract.GetAllCuttingsByWorkerByPeriod(workerId, date, date.AddDays(1));
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
_cuttingStorageContract.Verify(x => x.GetList(date, date.AddDays(1), workerId, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByWorkerByPeriod_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var list = _cuttingBusinessLogicContract.GetAllCuttingsByWorkerByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1));
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByWorkerByPeriod_IncorrectDates_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByWorkerByPeriod(Guid.NewGuid().ToString(), date, date), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByWorkerByPeriod(Guid.NewGuid().ToString(), date, date.AddSeconds(-1)), Throws.TypeOf<IncorrectDatesException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByWorkerByPeriod_WorkerIdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByWorkerByPeriod(null, DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByWorkerByPeriod(string.Empty, DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<ArgumentNullException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByWorkerByPeriod_WorkerIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByWorkerByPeriod("workerId", DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<ValidationException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByWorkerByPeriod_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByWorkerByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllCuttingsByWorkerByPeriod_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetAllCuttingsByWorkerByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCuttingByData_GetById_ReturnRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new CuttingDataModel(id, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), false,
|
||||
[new CuttingProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_cuttingStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _cuttingBusinessLogicContract.GetCuttingByData(id);
|
||||
//Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
_cuttingStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCuttingByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetCuttingByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetCuttingByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCuttingByData_IdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetCuttingByData("cuttingId"), Throws.TypeOf<ValidationException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCuttingByData_GetById_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetCuttingByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCuttingByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_cuttingStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.GetCuttingByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_cuttingStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertCutting_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new CuttingDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
false, [new CuttingProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_cuttingStorageContract.Setup(x => x.AddElement(It.IsAny<CuttingDataModel>()))
|
||||
.Callback((CuttingDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.WorkerId == record.WorkerId && x.BlankId == record.BlankId &&
|
||||
x.CutDate == record.CutDate && x.IsCancel == record.IsCancel;
|
||||
});
|
||||
//Act
|
||||
_cuttingBusinessLogicContract.InsertCutting(record);
|
||||
//Assert
|
||||
_cuttingStorageContract.Verify(x => x.AddElement(It.IsAny<CuttingDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertCutting_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_cuttingStorageContract.Setup(x => x.AddElement(It.IsAny<CuttingDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.InsertCutting(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),false, [new CuttingProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_cuttingStorageContract.Verify(x => x.AddElement(It.IsAny<CuttingDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertCutting_NullRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.InsertCutting(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_cuttingStorageContract.Verify(x => x.AddElement(It.IsAny<CuttingDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertCutting_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.InsertCutting(new CuttingDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),false, [])), Throws.TypeOf<ValidationException>());
|
||||
_cuttingStorageContract.Verify(x => x.AddElement(It.IsAny<CuttingDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertCutting_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_cuttingStorageContract.Setup(x => x.AddElement(It.IsAny<CuttingDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.InsertCutting(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),false, [new CuttingProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_cuttingStorageContract.Verify(x => x.AddElement(It.IsAny<CuttingDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CancelCutting_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
_cuttingStorageContract.Setup(x => x.DelElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
||||
//Act
|
||||
_cuttingBusinessLogicContract.CancelCutting(id);
|
||||
//Assert
|
||||
_cuttingStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CancelCutting_RecordWithIncorrectId_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_cuttingStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.CancelCutting(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_cuttingStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CancelCutting_IdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.CancelCutting(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _cuttingBusinessLogicContract.CancelCutting(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_cuttingStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CancelCutting_IdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.CancelCutting("id"), Throws.TypeOf<ValidationException>());
|
||||
_cuttingStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CancelCutting_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_cuttingStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _cuttingBusinessLogicContract.CancelCutting(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_cuttingStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
}
|
@ -0,0 +1,342 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using PapaCarloBusinessLogic.Implementations;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Enums;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.BusinessLogicsContracts;
|
||||
|
||||
[TestFixture]
|
||||
internal class SalaryBusinessLogicContractTests
|
||||
{
|
||||
private SalaryBusinessLogicContract _salaryBusinessLogicContract;
|
||||
private Mock<ISalaryStorageContract> _salaryStorageContract;
|
||||
private Mock<ICuttingStorageContract> _cuttingStorageContract;
|
||||
private Mock<IPostStorageContract> _postStorageContract;
|
||||
private Mock<IWorkerStorageContract> _workerStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_salaryStorageContract = new Mock<ISalaryStorageContract>();
|
||||
_cuttingStorageContract = new Mock<ICuttingStorageContract>();
|
||||
_postStorageContract = new Mock<IPostStorageContract>();
|
||||
_workerStorageContract = new Mock<IWorkerStorageContract>();
|
||||
_salaryBusinessLogicContract = new SalaryBusinessLogicContract(_salaryStorageContract.Object,
|
||||
_cuttingStorageContract.Object, _postStorageContract.Object, _workerStorageContract.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_salaryStorageContract.Reset();
|
||||
_cuttingStorageContract.Reset();
|
||||
_postStorageContract.Reset();
|
||||
_workerStorageContract.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var startDate = DateTime.UtcNow;
|
||||
var endDate = DateTime.UtcNow.AddDays(1);
|
||||
var listOriginal = new List<SalaryDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), DateTime.UtcNow, 10),
|
||||
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(1), 14),
|
||||
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(-1), 30),
|
||||
};
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
var list = _salaryBusinessLogicContract.GetAllSalariesByPeriod(startDate, endDate);
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
_salaryStorageContract.Verify(x => x.GetList(startDate, endDate, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var list = _salaryBusinessLogicContract.GetAllSalariesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1));
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_IncorrectDates_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var dateTime = DateTime.UtcNow;
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriod(dateTime, dateTime), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriod(dateTime, dateTime.AddSeconds(-1)), Throws.TypeOf<IncorrectDatesException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalariesByWorker_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var startDate = DateTime.UtcNow;
|
||||
var endDate = DateTime.UtcNow.AddDays(1);
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SalaryDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), DateTime.UtcNow, 10),
|
||||
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(1), 14),
|
||||
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(-1), 30),
|
||||
};
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
var list = _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(startDate, endDate, workerId);
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
_salaryStorageContract.Verify(x => x.GetList(startDate, endDate, workerId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalariesByWorker_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var list = _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), Guid.NewGuid().ToString());
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalariesByWorker_IncorrectDates_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var dateTime = DateTime.UtcNow;
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(dateTime, dateTime, Guid.NewGuid().ToString()), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(dateTime, dateTime.AddSeconds(-1), Guid.NewGuid().ToString()), Throws.TypeOf<IncorrectDatesException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalariesByWorker_WorkerIdIsNUllOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalariesByWorker_WorkerIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), "workerId"), Throws.TypeOf<ValidationException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalariesByWorker_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), Guid.NewGuid().ToString()), Throws.TypeOf<NullListException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalariesByWorker_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_CuttingStorageReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Carpenter,true, DateTime.UtcNow));
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WithSeveralSalesByWorker_Test()
|
||||
{
|
||||
//Arrange
|
||||
var CutSum = 100;
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
|
||||
// Создаем список вырезок(cuttings)
|
||||
var cuttings = new List<CuttingDataModel>
|
||||
{
|
||||
new CuttingDataModel(Guid.NewGuid().ToString(), workerId, Guid.NewGuid().ToString(), false, []),
|
||||
new CuttingDataModel(Guid.NewGuid().ToString(), workerId, Guid.NewGuid().ToString(), false, [])
|
||||
};
|
||||
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(cuttings);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow));
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
var sum = 0.0;
|
||||
var expectedSum = CutSum * cuttings.Count;
|
||||
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
||||
.Callback((SalaryDataModel x) =>
|
||||
{
|
||||
sum = x.Salary;
|
||||
});
|
||||
//Act
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
||||
//Assert
|
||||
Assert.That(sum, Is.EqualTo(expectedSum));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WithoitCttingsByWorker_Test()
|
||||
{
|
||||
//Arrange
|
||||
var CutSum = 100;
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
|
||||
// Создаем список вырезок(cuttings)
|
||||
var cuttings = new List<CuttingDataModel>
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns(cuttings);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow));
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
var sum = 10.0;
|
||||
var expectedSum = CutSum * cuttings.Count;
|
||||
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
||||
.Callback((SalaryDataModel x) =>
|
||||
{
|
||||
sum = x.Salary;
|
||||
});
|
||||
//Act
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
||||
//Assert
|
||||
Assert.That(sum, Is.EqualTo(expectedSum));
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WithSeveralWorkers_Test()
|
||||
{
|
||||
//Arrange
|
||||
var worker1Id = Guid.NewGuid().ToString();
|
||||
var worker2Id = Guid.NewGuid().ToString();
|
||||
var worker3Id = Guid.NewGuid().ToString();
|
||||
var list = new List<WorkerDataModel>() {
|
||||
new(worker1Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
||||
new(worker2Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
||||
new(worker3Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)
|
||||
};
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new CuttingDataModel(Guid.NewGuid().ToString(), worker1Id, Guid.NewGuid().ToString(), false, []),
|
||||
new CuttingDataModel(Guid.NewGuid().ToString(), worker1Id, Guid.NewGuid().ToString(), false, []),
|
||||
new CuttingDataModel(Guid.NewGuid().ToString(), worker2Id, Guid.NewGuid().ToString(), false, []),
|
||||
new CuttingDataModel(Guid.NewGuid().ToString(), worker3Id, Guid.NewGuid().ToString(), false, []),
|
||||
new CuttingDataModel(Guid.NewGuid().ToString(), worker3Id, Guid.NewGuid().ToString(), false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Carpenter,true, DateTime.UtcNow));
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns(list);
|
||||
//Act
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
||||
//Assert
|
||||
_salaryStorageContract.Verify(x => x.AddElement(It.IsAny<SalaryDataModel>()), Times.Exactly(list.Count));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_CalculateSalary_Test()
|
||||
{
|
||||
var cutSum = 100;
|
||||
//Arrange
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
_cuttingStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(),It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new CuttingDataModel(Guid.NewGuid().ToString(), workerId, Guid.NewGuid().ToString(), false,[])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow));
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
|
||||
var sum = 0.0;
|
||||
var expectedSum = cutSum;
|
||||
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
||||
.Callback((SalaryDataModel x) =>
|
||||
{
|
||||
sum = x.Salary;
|
||||
});
|
||||
//Act
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
||||
//Assert
|
||||
Assert.That(sum, Is.EqualTo(expectedSum));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WorkerStorageThrowException_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()))
|
||||
.Returns([new SalaryDataModel(Guid.NewGuid().ToString(), DateTime.UtcNow, 200)]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow));
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,459 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using PapaCarloBusinessLogic.Implementations;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Enums;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.BusinessLogicsContracts;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostBusinessLogicContractTests
|
||||
{
|
||||
private PostBusinessLogicContract _postBusinessLogicContract;
|
||||
private Mock<IPostStorageContract> _postStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_postStorageContract = new Mock<IPostStorageContract>();
|
||||
_postBusinessLogicContract = new PostBusinessLogicContract(_postStorageContract.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_postStorageContract.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var listOriginal = new List<PostDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(),"name 1", PostType.Carpenter, true, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), "name 2", PostType.Carpenter, false, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), "name 3", PostType.Carpenter, true, DateTime.UtcNow),
|
||||
};
|
||||
_postStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Returns(listOriginal);
|
||||
//Act
|
||||
var listOnlyActive = _postBusinessLogicContract.GetAllPosts(true);
|
||||
var listAll = _postBusinessLogicContract.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));
|
||||
});
|
||||
_postStorageContract.Verify(x => x.GetList(true), Times.Once);
|
||||
_postStorageContract.Verify(x => x.GetList(false), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Returns([]);
|
||||
//Act
|
||||
var listOnlyActive = _postBusinessLogicContract.GetAllPosts(true);
|
||||
var listAll = _postBusinessLogicContract.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));
|
||||
});
|
||||
_postStorageContract.Verify(x => x.GetList(It.IsAny<bool>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_postStorageContract.Verify(x => x.GetList(It.IsAny<bool>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.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.Carpenter, true, DateTime.UtcNow),
|
||||
new(postId, "name 2", PostType.Carpenter, false, DateTime.UtcNow)
|
||||
};
|
||||
_postStorageContract.Setup(x => x.GetPostWithHistory(It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
var list = _postBusinessLogicContract.GetAllDataOfPost(postId);
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
_postStorageContract.Verify(x => x.GetPostWithHistory(postId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPost_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetPostWithHistory(It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var list = _postBusinessLogicContract.GetAllDataOfPost(Guid.NewGuid().ToString());
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_postStorageContract.Verify(x => x.GetPostWithHistory(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPost_PostIdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllDataOfPost(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllDataOfPost(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_postStorageContract.Verify(x => x.GetPostWithHistory(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPost_PostIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllDataOfPost("id"), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.GetPostWithHistory(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPost_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllDataOfPost(Guid.NewGuid().ToString()), Throws.TypeOf<NullListException>());
|
||||
_postStorageContract.Verify(x => x.GetPostWithHistory(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetPostWithHistory(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllDataOfPost(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.GetPostWithHistory(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.Carpenter, true, DateTime.UtcNow);
|
||||
_postStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _postBusinessLogicContract.GetPostByData(id);
|
||||
//Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
_postStorageContract.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.Carpenter, true, DateTime.UtcNow);
|
||||
_postStorageContract.Setup(x => x.GetElementByName(postName)).Returns(record);
|
||||
//Act
|
||||
var element = _postBusinessLogicContract.GetPostByData(postName);
|
||||
//Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.PostName, Is.EqualTo(postName));
|
||||
_postStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPostByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetPostByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _postBusinessLogicContract.GetPostByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_postStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
_postStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPostByData_GetById_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetPostByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_postStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPostByData_GetByName_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetPostByData("name"), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
_postStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPostByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetPostByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _postBusinessLogicContract.GetPostByData("name"), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_postStorageContract.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.Carpenter, true, DateTime.UtcNow.AddDays(-1));
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>()))
|
||||
.Callback((PostDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType &&
|
||||
x.ChangeDate == record.ChangeDate;
|
||||
});
|
||||
//Act
|
||||
_postBusinessLogicContract.InsertPost(record);
|
||||
//Assert
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPost_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow)), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPost_NullRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPost_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new PostDataModel("id", "name", PostType.Carpenter, true, DateTime.UtcNow)), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow)), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.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.Carpenter, true, DateTime.UtcNow.AddDays(-1));
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>()))
|
||||
.Callback((PostDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType &&
|
||||
x.ChangeDate == record.ChangeDate;
|
||||
});
|
||||
//Act
|
||||
_postBusinessLogicContract.UpdatePost(record);
|
||||
//Assert
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePost_RecordWithIncorrectData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow)), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePost_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.Carpenter, true, DateTime.UtcNow)), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePost_NullRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePost_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new PostDataModel("id", "name", PostType.Carpenter, true, DateTime.UtcNow)), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Carpenter, true, DateTime.UtcNow)), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePost_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
_postStorageContract.Setup(x => x.DelElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
||||
//Act
|
||||
_postBusinessLogicContract.DeletePost(id);
|
||||
//Assert
|
||||
_postStorageContract.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();
|
||||
_postStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.DeletePost(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePost_IdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.DeletePost(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _postBusinessLogicContract.DeletePost(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_postStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePost_IdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.DeletePost("id"), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.DeletePost(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RestorePost_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
_postStorageContract.Setup(x => x.ResElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
||||
//Act
|
||||
_postBusinessLogicContract.RestorePost(id);
|
||||
//Assert
|
||||
_postStorageContract.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();
|
||||
_postStorageContract.Setup(x => x.ResElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.RestorePost(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.ResElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RestorePost_IdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.RestorePost(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _postBusinessLogicContract.RestorePost(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_postStorageContract.Verify(x => x.ResElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RestorePost_IdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.RestorePost("id"), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.ResElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RestorePost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.ResElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.RestorePost(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.ResElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
}
|
@ -0,0 +1,486 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using PapaCarloBusinessLogic.Implementations;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Enums;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.BusinessLogicsContracts;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductBusinessLogicContractTests
|
||||
{
|
||||
private ProductBusinessLogicContract _productBusinessLogicContract;
|
||||
private Mock<IProductStorageContract> _productStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_productStorageContract = new Mock<IProductStorageContract>();
|
||||
_productBusinessLogicContract = new ProductBusinessLogicContract(_productStorageContract.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_productStorageContract.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProducts_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var listOriginal = new List<ProductDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), "name 1", ProductType.Furniture, 10, false),
|
||||
new(Guid.NewGuid().ToString(), "name 2", ProductType.Furniture, 10, false),
|
||||
new(Guid.NewGuid().ToString(), "name 3", ProductType.Furniture, 10, false),
|
||||
};
|
||||
_productStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
var listOnlyActive = _productBusinessLogicContract.GetAllProducts(true);
|
||||
var list = _productBusinessLogicContract.GetAllProducts(false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal));
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
});
|
||||
_productStorageContract.Verify(x => x.GetList(true, null), Times.Once);
|
||||
_productStorageContract.Verify(x => x.GetList(false, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProducts_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var listOnlyActive = _productBusinessLogicContract.GetAllProducts(true);
|
||||
var list = _productBusinessLogicContract.GetAllProducts(false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Has.Count.EqualTo(0));
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
});
|
||||
_productStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), null), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProducts_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetAllProducts(It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_productStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProducts_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetAllProducts(It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_productStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProductsByBlank_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var blankId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<ProductDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), "name 1", ProductType.Furniture, 10, false),
|
||||
new(Guid.NewGuid().ToString(), "name 2", ProductType.Furniture, 10, false),
|
||||
new(Guid.NewGuid().ToString(), "name 3", ProductType.Furniture, 10, false),
|
||||
};
|
||||
_productStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
var listOnlyActive = _productBusinessLogicContract.GetAllProductsByBlank(blankId, true);
|
||||
var list = _productBusinessLogicContract.GetAllProductsByBlank(blankId, false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal));
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
});
|
||||
_productStorageContract.Verify(x => x.GetList(true, blankId), Times.Once);
|
||||
_productStorageContract.Verify(x => x.GetList(false, blankId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProductsByBlank_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
var blankId = Guid.NewGuid().ToString();
|
||||
_productStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var listOnlyActive = _productBusinessLogicContract.GetAllProductsByBlank(blankId, true);
|
||||
var list = _productBusinessLogicContract.GetAllProductsByBlank(blankId, false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Has.Count.EqualTo(0));
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
});
|
||||
_productStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), blankId), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProductsByBlank_BlankIdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetAllProductsByBlank(null, It.IsAny<bool>()), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _productBusinessLogicContract.GetAllProductsByBlank(string.Empty, It.IsAny<bool>()), Throws.TypeOf<ArgumentNullException>());
|
||||
_productStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProductsByBlank_BlankIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetAllProductsByBlank("blankId", It.IsAny<bool>()), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProductsByBlank_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetAllProductsByBlank(Guid.NewGuid().ToString(), It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_productStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProductsByBlank_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetAllProductsByBlank(Guid.NewGuid().ToString(), It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_productStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductHistoryByProduct_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<ProductHistoryDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), 10),
|
||||
new(Guid.NewGuid().ToString(), 15),
|
||||
new(Guid.NewGuid().ToString(), 10),
|
||||
};
|
||||
_productStorageContract.Setup(x => x.GetHistoryByProductId(It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
var list = _productBusinessLogicContract.GetProductHistoryByProduct(productId);
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
_productStorageContract.Verify(x => x.GetHistoryByProductId(productId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductHistoryByProduct_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.GetHistoryByProductId(It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var list = _productBusinessLogicContract.GetProductHistoryByProduct(Guid.NewGuid().ToString());
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_productStorageContract.Verify(x => x.GetHistoryByProductId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductHistoryByProduct_ProductIdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductHistoryByProduct(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductHistoryByProduct(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_productStorageContract.Verify(x => x.GetHistoryByProductId(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductHistoryByProduct_ProductIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductHistoryByProduct("productId"), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContract.Verify(x => x.GetHistoryByProductId(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductHistoryByProduct_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductHistoryByProduct(Guid.NewGuid().ToString()), Throws.TypeOf<NullListException>());
|
||||
_productStorageContract.Verify(x => x.GetHistoryByProductId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductHistoryByProduct_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.GetHistoryByProductId(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductHistoryByProduct(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_productStorageContract.Verify(x => x.GetHistoryByProductId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_GetById_ReturnRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new ProductDataModel(id, "name", ProductType.Furniture, 10, false);
|
||||
_productStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _productBusinessLogicContract.GetProductByData(id);
|
||||
//Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
_productStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_GetByName_ReturnRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var name = "name";
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), name, ProductType.Furniture, 10, false);
|
||||
_productStorageContract.Setup(x => x.GetElementByName(name)).Returns(record);
|
||||
//Act
|
||||
var element = _productBusinessLogicContract.GetProductByData(name);
|
||||
//Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.ProductName, Is.EqualTo(name));
|
||||
_productStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_productStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
||||
_productStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_GetById_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_productStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_GetByName_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData("name"), Throws.TypeOf<ElementNotFoundException>());
|
||||
_productStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_productStorageContract.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData("name"), Throws.TypeOf<StorageException>());
|
||||
_productStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_productStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertProduct_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), "name", ProductType.Furniture, 10, false);
|
||||
_productStorageContract.Setup(x => x.AddElement(It.IsAny<ProductDataModel>()))
|
||||
.Callback((ProductDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.ProductName == record.ProductName && x.ProductType == record.ProductType && x.Price == record.Price && x.IsDeleted == record.IsDeleted;
|
||||
});
|
||||
//Act
|
||||
_productBusinessLogicContract.InsertProduct(record);
|
||||
//Assert
|
||||
_productStorageContract.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertProduct_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.AddElement(It.IsAny<ProductDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(new(Guid.NewGuid().ToString(), "name", ProductType.Furniture , 10, false)), Throws.TypeOf<ElementExistsException>());
|
||||
_productStorageContract.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertProduct_NullRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_productStorageContract.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertProduct_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(new ProductDataModel("id", "name", ProductType.Furniture, 10, false)), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContract.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertProduct_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.AddElement(It.IsAny<ProductDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(new(Guid.NewGuid().ToString(), "name", ProductType.Furniture, 10, false)), Throws.TypeOf<StorageException>());
|
||||
_productStorageContract.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), "name", ProductType.Furniture, 10, false);
|
||||
_productStorageContract.Setup(x => x.UpdElement(It.IsAny<ProductDataModel>()))
|
||||
.Callback((ProductDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.ProductName == record.ProductName && x.ProductType == record.ProductType && x.Price == record.Price && x.IsDeleted == record.IsDeleted;
|
||||
});
|
||||
//Act
|
||||
_productBusinessLogicContract.UpdateProduct(record);
|
||||
//Assert
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_RecordWithIncorrectData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.UpdElement(It.IsAny<ProductDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new(Guid.NewGuid().ToString(), "name", ProductType.Furniture, 10, false)), Throws.TypeOf<ElementNotFoundException>());
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.UpdElement(It.IsAny<ProductDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new(Guid.NewGuid().ToString(), "anme", ProductType.Furniture, 10, false)), Throws.TypeOf<ElementExistsException>());
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_NullRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new ProductDataModel("id", "name", ProductType.Furniture, 10, false)), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.UpdElement(It.IsAny<ProductDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new(Guid.NewGuid().ToString(), "name", ProductType.Furniture, 10, false)), Throws.TypeOf<StorageException>());
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteProduct_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
_productStorageContract.Setup(x => x.DelElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
||||
//Act
|
||||
_productBusinessLogicContract.DeleteProduct(id);
|
||||
//Assert
|
||||
_productStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteProduct_RecordWithIncorrectId_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_productStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.DeleteProduct(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_productStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteProduct_IdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.DeleteProduct(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _productBusinessLogicContract.DeleteProduct(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_productStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteProduct_IdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.DeleteProduct("id"), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteProduct_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.DeleteProduct(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_productStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
}
|
@ -0,0 +1,562 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using PapaCarloBusinessLogic.Implementations;
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using PapaCarloContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.BusinessLogicsContracts;
|
||||
|
||||
[TestFixture]
|
||||
internal class WorkerBusinessLogicContractTests
|
||||
{
|
||||
private WorkerBusinessLogicContract _workerBusinessLogicContract;
|
||||
private Mock<IWorkerStorageContract> _workerStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_workerStorageContract = new Mock<IWorkerStorageContract>();
|
||||
_workerBusinessLogicContract = new WorkerBusinessLogicContract(_workerStorageContract.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_workerStorageContract.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkers_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var listOriginal = new List<WorkerDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), "fio 1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
|
||||
new(Guid.NewGuid().ToString(), "fio 2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true),
|
||||
new(Guid.NewGuid().ToString(), "fio 3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
|
||||
};
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
|
||||
//Act
|
||||
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkers(true);
|
||||
var list = _workerBusinessLogicContract.GetAllWorkers(false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal));
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
});
|
||||
_workerStorageContract.Verify(x => x.GetList(true, null, null, null, null, null), Times.Once);
|
||||
_workerStorageContract.Verify(x => x.GetList(false, null, null, null, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkers_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns([]);
|
||||
//Act
|
||||
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkers(true);
|
||||
var list = _workerBusinessLogicContract.GetAllWorkers(false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Has.Count.EqualTo(0));
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
});
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), null, null, null, null, null), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkers_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkers(It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkers_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkers(It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), null, null, null, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByPost_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<WorkerDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), "fio 1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
|
||||
new(Guid.NewGuid().ToString(), "fio 2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true),
|
||||
new(Guid.NewGuid().ToString(), "fio 3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
|
||||
};
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
|
||||
//Act
|
||||
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByPost(postId, true);
|
||||
var list = _workerBusinessLogicContract.GetAllWorkersByPost(postId, false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal));
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
});
|
||||
_workerStorageContract.Verify(x => x.GetList(true, postId, null, null, null, null), Times.Once);
|
||||
_workerStorageContract.Verify(x => x.GetList(false, postId, null, null, null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByPost_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns([]);
|
||||
//Act
|
||||
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(), true);
|
||||
var list = _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(), false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Has.Count.EqualTo(0));
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
});
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByPost_PostIdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByPost(null, It.IsAny<bool>()), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByPost(string.Empty, It.IsAny<bool>()), Throws.TypeOf<ArgumentNullException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByPost_PostIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByPost("postId", It.IsAny<bool>()), Throws.TypeOf<ValidationException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByPost_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(), It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByPost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(), It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByBirthDate_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
var listOriginal = new List<WorkerDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), "fio 1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
|
||||
new(Guid.NewGuid().ToString(), "fio 2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true),
|
||||
new(Guid.NewGuid().ToString(), "fio 3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
|
||||
};
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
|
||||
//Act
|
||||
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddDays(1), true);
|
||||
var list = _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddDays(1), false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal));
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
});
|
||||
_workerStorageContract.Verify(x => x.GetList(true, null, date, date.AddDays(1), null, null), Times.Once);
|
||||
_workerStorageContract.Verify(x => x.GetList(false, null, date, date.AddDays(1), null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByBirthDate_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns([]);
|
||||
//Act
|
||||
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByBirthDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), true);
|
||||
var list = _workerBusinessLogicContract.GetAllWorkers(false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Has.Count.EqualTo(0));
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
});
|
||||
_workerStorageContract.Verify(x => x.GetList(true, null, It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), null, null), Times.Once);
|
||||
_workerStorageContract.Verify(x => x.GetList(false, null, It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), null, null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByBirthDate_IncorrectDates_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date, It.IsAny<bool>()), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddSeconds(-1), It.IsAny<bool>()), Throws.TypeOf<IncorrectDatesException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByBirthDate_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByBirthDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByBirthDate_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByBirthDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByEmploymentDate_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
var listOriginal = new List<WorkerDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), "fio 1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
|
||||
new(Guid.NewGuid().ToString(), "fio 2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true),
|
||||
new(Guid.NewGuid().ToString(), "fio 3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false),
|
||||
};
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
|
||||
//Act
|
||||
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date.AddDays(1), true);
|
||||
var list = _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date.AddDays(1), false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal));
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
});
|
||||
_workerStorageContract.Verify(x => x.GetList(true, null, null, null, date, date.AddDays(1)), Times.Once);
|
||||
_workerStorageContract.Verify(x => x.GetList(false, null, null, null, date, date.AddDays(1)), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByEmploymentDate_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns([]);
|
||||
//Act
|
||||
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), true);
|
||||
var list = _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), false);
|
||||
//Assert
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(listOnlyActive, Is.Not.Null);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(listOnlyActive, Has.Count.EqualTo(0));
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
});
|
||||
_workerStorageContract.Verify(x => x.GetList(true, null, null, null, It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
_workerStorageContract.Verify(x => x.GetList(false, null, null, null, It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByEmploymentDate_IncorrectDates_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date, It.IsAny<bool>()), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date.AddSeconds(-1), It.IsAny<bool>()), Throws.TypeOf<IncorrectDatesException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByEmploymentDate_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWorkersByEmploymentDate_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_workerStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkerByData_GetById_ReturnRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new WorkerDataModel(id, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
|
||||
_workerStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _workerBusinessLogicContract.GetWorkerByData(id);
|
||||
//Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
_workerStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkerByData_GetByFio_ReturnRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var fio = "fio";
|
||||
var record = new WorkerDataModel(Guid.NewGuid().ToString(), fio, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
|
||||
_workerStorageContract.Setup(x => x.GetElementByFIO(fio)).Returns(record);
|
||||
//Act
|
||||
var element = _workerBusinessLogicContract.GetWorkerByData(fio);
|
||||
//Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.FIO, Is.EqualTo(fio));
|
||||
_workerStorageContract.Verify(x => x.GetElementByFIO(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkerByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetWorkerByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _workerBusinessLogicContract.GetWorkerByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_workerStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
_workerStorageContract.Verify(x => x.GetElementByFIO(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkerByData_GetById_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetWorkerByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_workerStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_workerStorageContract.Verify(x => x.GetElementByFIO(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkerByData_GetByFio_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetWorkerByData("fio"), Throws.TypeOf<ElementNotFoundException>());
|
||||
_workerStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
_workerStorageContract.Verify(x => x.GetElementByFIO(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWorkerByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_workerStorageContract.Setup(x => x.GetElementByFIO(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.GetWorkerByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _workerBusinessLogicContract.GetWorkerByData("fio"), Throws.TypeOf<StorageException>());
|
||||
_workerStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_workerStorageContract.Verify(x => x.GetElementByFIO(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWorker_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new WorkerDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
|
||||
_workerStorageContract.Setup(x => x.AddElement(It.IsAny<WorkerDataModel>()))
|
||||
.Callback((WorkerDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.FIO == record.FIO && x.PostId == record.PostId && x.BirthDate == record.BirthDate &&
|
||||
x.EmploymentDate == record.EmploymentDate && x.IsDeleted == record.IsDeleted;
|
||||
});
|
||||
//Act
|
||||
_workerBusinessLogicContract.InsertWorker(record);
|
||||
//Assert
|
||||
_workerStorageContract.Verify(x => x.AddElement(It.IsAny<WorkerDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWorker_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ElementExistsException>());
|
||||
_workerStorageContract.Verify(x => x.AddElement(It.IsAny<WorkerDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWorker_NullRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.InsertWorker(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_workerStorageContract.Verify(x => x.AddElement(It.IsAny<WorkerDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWorker_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new WorkerDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ValidationException>());
|
||||
_workerStorageContract.Verify(x => x.AddElement(It.IsAny<WorkerDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWorker_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<StorageException>());
|
||||
_workerStorageContract.Verify(x => x.AddElement(It.IsAny<WorkerDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWorker_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new WorkerDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false);
|
||||
_workerStorageContract.Setup(x => x.UpdElement(It.IsAny<WorkerDataModel>()))
|
||||
.Callback((WorkerDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.FIO == record.FIO && x.PostId == record.PostId && x.BirthDate == record.BirthDate &&
|
||||
x.EmploymentDate == record.EmploymentDate && x.IsDeleted == record.IsDeleted;
|
||||
});
|
||||
//Act
|
||||
_workerBusinessLogicContract.UpdateWorker(record);
|
||||
//Assert
|
||||
_workerStorageContract.Verify(x => x.UpdElement(It.IsAny<WorkerDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWorker_RecordWithIncorrectData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ElementNotFoundException>());
|
||||
_workerStorageContract.Verify(x => x.UpdElement(It.IsAny<WorkerDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWorker_NullRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_workerStorageContract.Verify(x => x.UpdElement(It.IsAny<WorkerDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWorker_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new WorkerDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ValidationException>());
|
||||
_workerStorageContract.Verify(x => x.UpdElement(It.IsAny<WorkerDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWorker_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<StorageException>());
|
||||
_workerStorageContract.Verify(x => x.UpdElement(It.IsAny<WorkerDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWorker_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
_workerStorageContract.Setup(x => x.DelElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
||||
//Act
|
||||
_workerBusinessLogicContract.DeleteWorker(id);
|
||||
//Assert
|
||||
_workerStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWorker_RecordWithIncorrectId_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_workerStorageContract.Setup(x => x.DelElement(It.Is((string x) => x != id))).Throws(new ElementNotFoundException(id));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.DeleteWorker(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_workerStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWorker_IdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.DeleteWorker(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _workerBusinessLogicContract.DeleteWorker(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_workerStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWorker_IdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.DeleteWorker("id"), Throws.TypeOf<ValidationException>());
|
||||
_workerStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWorker_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _workerBusinessLogicContract.DeleteWorker(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_workerStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class BlankDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullEmptyTest()
|
||||
{
|
||||
var blank = CreateDataModel(null, "name");
|
||||
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
blank = CreateDataModel(string.Empty, "name");
|
||||
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var blank = CreateDataModel("id", "name");
|
||||
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BlankNameIsNullOrEmptyTest()
|
||||
{
|
||||
var blank = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
blank = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||
Assert.That(() => blank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var blankId = Guid.NewGuid().ToString();
|
||||
var blankName = "name";
|
||||
var prevBlankName = "prevBlankName";
|
||||
var prevPrevBlankName = "prevPrevBlankName";
|
||||
var blank = CreateDataModel(blankId, blankName, prevBlankName, prevPrevBlankName);
|
||||
Assert.That(() => blank.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(blank.Id, Is.EqualTo(blankId));
|
||||
Assert.That(blank.BlankName, Is.EqualTo(blankName));
|
||||
Assert.That(blank.PrevBlankName, Is.EqualTo(prevBlankName));
|
||||
Assert.That(blank.PrevPrevBlankName, Is.EqualTo(prevPrevBlankName));
|
||||
});
|
||||
}
|
||||
|
||||
private static BlankDataModel CreateDataModel(string? id, string? blankName, string? prevBlankName = null, string? prevPrevBlankName = null) =>
|
||||
new(id, blankName, prevBlankName, prevPrevBlankName);
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.DataModelsTests;
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class CuttingDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "workerId", Guid.NewGuid().ToString(), false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BlankIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "blankId", false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),false, null);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),false, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var cuttingId = Guid.NewGuid().ToString();
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var blankId = Guid.NewGuid().ToString();
|
||||
var isCancel = true;
|
||||
var products = CreateSubDataModel();
|
||||
var sale = CreateDataModel(cuttingId, workerId, blankId, isCancel, products);
|
||||
Assert.That(() => sale.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(sale.Id, Is.EqualTo(cuttingId));
|
||||
Assert.That(sale.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(sale.BlankId, Is.EqualTo(blankId));
|
||||
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
||||
Assert.That(sale.Products, Is.EquivalentTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static CuttingDataModel CreateDataModel(string? id, string? workerId, string? blankId, bool isCancel, List<CuttingProductDataModel>? products) =>
|
||||
new(id, workerId, blankId, isCancel, products);
|
||||
|
||||
private static List<CuttingProductDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class CuttingProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CuttingIdIsNullOrEmptyTest()
|
||||
{
|
||||
var cuttingProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => cuttingProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
cuttingProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => cuttingProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CuttingIdIsNotGuidTest()
|
||||
{
|
||||
var cuttingProduct = CreateDataModel("cuttingId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => cuttingProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var cuttingProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => cuttingProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
cuttingProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => cuttingProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var cuttingProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10);
|
||||
Assert.That(() => cuttingProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var cuttingProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => cuttingProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
cuttingProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => cuttingProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var cuttingId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var cuttingProduct = CreateDataModel(cuttingId, productId, count);
|
||||
Assert.That(() => cuttingProduct.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(cuttingProduct.CuttingId, Is.EqualTo(cuttingId));
|
||||
Assert.That(cuttingProduct.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(cuttingProduct.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static CuttingProductDataModel CreateDataModel(string? cuttingId, string? productId, int count) =>
|
||||
new(cuttingId, productId, count);
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Enums;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, "name", PostType.Carpenter, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, "name", PostType.Carpenter, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", "name", PostType.Carpenter, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Carpenter, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Carpenter, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var postPostId = Guid.NewGuid().ToString();
|
||||
var postName = "name";
|
||||
var postType = PostType.Carpenter;
|
||||
var isActual = false;
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var post = CreateDataModel(postId, postName, postType,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.IsActual, Is.EqualTo(isActual));
|
||||
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
||||
});
|
||||
}
|
||||
|
||||
private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType, bool isActual, DateTime changeDate) =>
|
||||
new(id, postName, postType, isActual, changeDate);
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Enums;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "name", ProductType.Furniture, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, "name", ProductType.Furniture, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", "name", ProductType.Furniture, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Furniture, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Furniture, 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 PriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Furniture, 0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Furniture, -10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var productName = "name";
|
||||
var productType = ProductType.Furniture;
|
||||
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);
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SalaryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WorkerIdIsEmptyTest()
|
||||
{
|
||||
var salary = CreateDataModel(null, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var salary = CreateDataModel("workerId", DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||
var workerSalary = 10;
|
||||
var salary = CreateDataModel(workerId, salaryDate, workerSalary);
|
||||
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(salary.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
|
||||
Assert.That(salary.Salary, Is.EqualTo(workerSalary));
|
||||
});
|
||||
}
|
||||
|
||||
private static SalaryDataModel CreateDataModel(string? workerId, DateTime salaryDate, double workerSalary) =>
|
||||
new(workerId, salaryDate, workerSalary);
|
||||
}
|
@ -0,0 +1,95 @@
|
||||
using PapaCarloContracts.DataModels;
|
||||
using PapaCarloContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PapaCarloTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WorkerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var fio = "fio";
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
||||
var employmentDate = DateTime.Now;
|
||||
var isDelete = false;
|
||||
var worker = CreateDataModel(workerId, fio, postId, birthDate, employmentDate, isDelete);
|
||||
Assert.That(() => worker.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(worker.Id, Is.EqualTo(workerId));
|
||||
Assert.That(worker.FIO, Is.EqualTo(fio));
|
||||
Assert.That(worker.PostId, Is.EqualTo(postId));
|
||||
Assert.That(worker.BirthDate, Is.EqualTo(birthDate));
|
||||
Assert.That(worker.EmploymentDate, Is.EqualTo(employmentDate));
|
||||
Assert.That(worker.IsDeleted, Is.EqualTo(isDelete));
|
||||
});
|
||||
}
|
||||
|
||||
private static WorkerDataModel CreateDataModel(string? id, string? fio, string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||
new(id, fio, postId, birthDate, employmentDate, isDeleted);
|
||||
}
|
29
PapaCarloProject/PapaCarloTests/PapaCarloTests.csproj
Normal file
29
PapaCarloProject/PapaCarloTests/PapaCarloTests.csproj
Normal file
@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="NUnit" Version="4.2.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PapaCarloBusinessLogic\PapaCarloBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\PapaCarloContracts\PapaCarloContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user