4-hard
This commit is contained in:
6
.idea/.idea.PIBD24_BoikoM.S._Candyhouse.dir/.idea/vcs.xml
generated
Normal file
6
.idea/.idea.PIBD24_BoikoM.S._Candyhouse.dir/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
6
CandyHouseSolution/.idea/.idea.CandyHouseSolution/.idea/vcs.xml
generated
Normal file
6
CandyHouseSolution/.idea/.idea.CandyHouseSolution/.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -1,20 +1,21 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="CandyHouseTests" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="CandyHouseTests" />
|
||||
<InternalsVisibleTo Include="CandyHouseWebApi" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CandyHouseContracts\CandyHouseContracts.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CandyHouseContracts\CandyHouseContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
internal class ClientBusinessLogicContract(IClientStorageContract clientStorageContract, ILogger logger) : IClientBusinessLogicContract
|
||||
public class ClientBusinessLogicContract(IClientStorageContract clientStorageContract, ILogger logger) : IClientBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IClientStorageContract _clientStorageContract = clientStorageContract;
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
internal class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStorageContract, ILogger logger) : IEmployeeBusinessLogicContract
|
||||
public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStorageContract, ILogger logger) : IEmployeeBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IEmployeeStorageContract _employeeStorageContract = employeeStorageContract;
|
||||
|
||||
@@ -12,14 +12,14 @@ using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
internal class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
public class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
public List<PostDataModel> GetAllPosts(bool onlyActive = true)
|
||||
public List<PostDataModel> GetAllPosts()
|
||||
{
|
||||
_logger.LogInformation("GetAllPosts params: {onlyActive}", onlyActive);
|
||||
return _postStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
||||
_logger.LogInformation("GetAllPosts");
|
||||
return _postStorageContract.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetAllDataOfPost(string postId)
|
||||
|
||||
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
internal class ProductBusinessLogicContract(IProductStorageContract productStorageContract, ILogger logger) : IProductBusinessLogicContract
|
||||
public class ProductBusinessLogicContract(IProductStorageContract productStorageContract, ILogger logger) : IProductBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IProductStorageContract _productStorageContract = productStorageContract;
|
||||
|
||||
@@ -11,7 +11,7 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,ISaleStorageContract saleStorageContract,
|
||||
public class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,ISaleStorageContract saleStorageContract,
|
||||
IPostStorageContract postStorageContract, IEmployeeStorageContract employeeStorageContract, ILogger logger) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
@@ -61,7 +61,7 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
||||
throw new NullListException();
|
||||
var salary = post.Salary + sales * 0.1;
|
||||
_logger.LogDebug("The employee {employeeId} was paid a salary of {salary}", employee.Id, salary);
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(employee.Id, finishDate, salary));
|
||||
_salaryStorageContract.AddElement(new SalaryDataModel(employee.Id, DateTime.SpecifyKind(finishDate, DateTimeKind.Utc), salary));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseBusinessLogic.Implementations;
|
||||
|
||||
internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, IStorageStorageContract storageStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,IStorageStorageContract storageStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IClientAdapter
|
||||
{
|
||||
ClientOperationResponse GetList();
|
||||
|
||||
ClientOperationResponse GetElement(string data);
|
||||
|
||||
ClientOperationResponse RegisterClient(ClientBindingModel clientModel);
|
||||
|
||||
ClientOperationResponse ChangeClientInfo(ClientBindingModel clientModel);
|
||||
|
||||
ClientOperationResponse RemoveClient(string id);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IEmployeeAdapter
|
||||
{
|
||||
EmployeeOperationResponse GetList(bool includeDeleted);
|
||||
|
||||
EmployeeOperationResponse GetPostList(string id, bool includeDeleted);
|
||||
|
||||
EmployeeOperationResponse GetListByBirthDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
|
||||
|
||||
EmployeeOperationResponse GetListByEmploymentDate(DateTime fromDate, DateTime toDate, bool includeDeleted);
|
||||
|
||||
EmployeeOperationResponse GetElement(string data);
|
||||
|
||||
EmployeeOperationResponse RegisterEmployee(EmployeeBindingModel employeeModel);
|
||||
|
||||
EmployeeOperationResponse ChangeEmployeeInfo(EmployeeBindingModel employeeModel);
|
||||
|
||||
EmployeeOperationResponse RemoveEmployee(string id);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IPostAdapter
|
||||
{
|
||||
PostOperationResponse GetList();
|
||||
|
||||
PostOperationResponse GetHistory(string id);
|
||||
|
||||
PostOperationResponse GetElement(string data);
|
||||
|
||||
PostOperationResponse RegisterPost(PostBindingModel postModel);
|
||||
|
||||
PostOperationResponse ChangePostInfo(PostBindingModel postModel);
|
||||
|
||||
PostOperationResponse RemovePost(string id);
|
||||
|
||||
PostOperationResponse RestorePost(string id);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IProductAdapter
|
||||
{
|
||||
ProductOperationResponse GetList(bool includeDeleted);
|
||||
|
||||
ProductOperationResponse GetHistory(string id);
|
||||
|
||||
ProductOperationResponse GetElement(string data);
|
||||
|
||||
ProductOperationResponse RegisterProduct(ProductBindingModel productModel);
|
||||
|
||||
ProductOperationResponse ChangeProductInfo(ProductBindingModel productModel);
|
||||
|
||||
ProductOperationResponse RemoveProduct(string id);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface ISalaryAdapter
|
||||
{
|
||||
SalaryOperationResponse GetListByPeriod(DateTime fromDate, DateTime toDate);
|
||||
SalaryOperationResponse GetListByPeriodByEmployee(DateTime fromDate, DateTime toDate, string employeeId);
|
||||
SalaryOperationResponse CalculateSalary(DateTime date);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface ISaleAdapter
|
||||
{
|
||||
SaleOperationResponse GetList(DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleOperationResponse GetEmployeeList(string id, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleOperationResponse GetClientList(string id, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleOperationResponse GetProductList(string id, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SaleOperationResponse GetElement(string id);
|
||||
|
||||
SaleOperationResponse MakeSale(SaleBindingModel saleModel);
|
||||
|
||||
SaleOperationResponse CancelSale(string id);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface IStorageAdapter
|
||||
{
|
||||
StorageOperationResponse GetAllComponents();
|
||||
StorageOperationResponse GetComponentByData(string data);
|
||||
StorageOperationResponse InsertComponent(StorageBindingModel warehouseDataModel);
|
||||
StorageOperationResponse UpdateComponent(StorageBindingModel warehouseDataModel);
|
||||
StorageOperationResponse DeleteComponent(string id);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
using CandyHouseContracts.BindingModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts;
|
||||
|
||||
public interface ISuppliesAdapter
|
||||
{
|
||||
SuppliesOperationResponse GetAllComponents();
|
||||
SuppliesOperationResponse GetComponentByData(string data);
|
||||
SuppliesOperationResponse InsertComponent(SuppliesBindingModel componentDataModel);
|
||||
SuppliesOperationResponse UpdateComponent(SuppliesBindingModel componentDataModel);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ClientOperationResponse : OperationResponse
|
||||
{
|
||||
public static ClientOperationResponse OK(List<ClientViewModel> data) => OK<ClientOperationResponse, List<ClientViewModel>>(data);
|
||||
|
||||
public static ClientOperationResponse OK(ClientViewModel data) => OK<ClientOperationResponse, ClientViewModel>(data);
|
||||
|
||||
public static ClientOperationResponse NoContent() => NoContent<ClientOperationResponse>();
|
||||
|
||||
public static ClientOperationResponse BadRequest(string message) => BadRequest<ClientOperationResponse>(message);
|
||||
|
||||
public static ClientOperationResponse NotFound(string message) => NotFound<ClientOperationResponse>(message);
|
||||
|
||||
public static ClientOperationResponse InternalServerError(string message) => InternalServerError<ClientOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class EmployeeOperationResponse : OperationResponse
|
||||
{
|
||||
public static EmployeeOperationResponse OK(List<EmployeeViewModel> data) => OK<EmployeeOperationResponse, List<EmployeeViewModel>>(data);
|
||||
|
||||
public static EmployeeOperationResponse OK(EmployeeViewModel data) => OK<EmployeeOperationResponse, EmployeeViewModel>(data);
|
||||
|
||||
public static EmployeeOperationResponse NoContent() => NoContent<EmployeeOperationResponse>();
|
||||
|
||||
public static EmployeeOperationResponse NotFound(string message) => NotFound<EmployeeOperationResponse>(message);
|
||||
|
||||
public static EmployeeOperationResponse BadRequest(string message) => BadRequest<EmployeeOperationResponse>(message);
|
||||
|
||||
public static EmployeeOperationResponse InternalServerError(string message) => InternalServerError<EmployeeOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class PostOperationResponse : OperationResponse
|
||||
{
|
||||
public static PostOperationResponse OK(List<PostViewModel> data) => OK<PostOperationResponse, List<PostViewModel>>(data);
|
||||
|
||||
public static PostOperationResponse OK(PostViewModel data) => OK<PostOperationResponse, PostViewModel>(data);
|
||||
|
||||
public static PostOperationResponse NoContent() => NoContent<PostOperationResponse>();
|
||||
|
||||
public static PostOperationResponse NotFound(string message) => NotFound<PostOperationResponse>(message);
|
||||
|
||||
public static PostOperationResponse BadRequest(string message) => BadRequest<PostOperationResponse>(message);
|
||||
|
||||
public static PostOperationResponse InternalServerError(string message) => InternalServerError<PostOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class ProductOperationResponse : OperationResponse
|
||||
{
|
||||
public static ProductOperationResponse OK(List<ProductViewModel> data) => OK<ProductOperationResponse, List<ProductViewModel>>(data);
|
||||
|
||||
public static ProductOperationResponse OK(List<ProductHistoryViewModel> data) => OK<ProductOperationResponse, List<ProductHistoryViewModel>>(data);
|
||||
|
||||
public static ProductOperationResponse OK(ProductViewModel data) => OK<ProductOperationResponse, ProductViewModel>(data);
|
||||
|
||||
public static ProductOperationResponse NoContent() => NoContent<ProductOperationResponse>();
|
||||
|
||||
public static ProductOperationResponse NotFound(string message) => NotFound<ProductOperationResponse>(message);
|
||||
|
||||
public static ProductOperationResponse BadRequest(string message) => BadRequest<ProductOperationResponse>(message);
|
||||
|
||||
public static ProductOperationResponse InternalServerError(string message) => InternalServerError<ProductOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class SalaryOperationResponse : OperationResponse
|
||||
{
|
||||
public static SalaryOperationResponse OK(List<SalaryViewModel> data) => OK<SalaryOperationResponse, List<SalaryViewModel>>(data);
|
||||
public static SalaryOperationResponse NoContent() => NoContent<SalaryOperationResponse>();
|
||||
public static SalaryOperationResponse NotFound(string message) => NotFound<SalaryOperationResponse>(message);
|
||||
public static SalaryOperationResponse BadRequest(string message) => BadRequest<SalaryOperationResponse>(message);
|
||||
public static SalaryOperationResponse InternalServerError(string message) => InternalServerError<SalaryOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class SaleOperationResponse : OperationResponse
|
||||
{
|
||||
public static SaleOperationResponse OK(List<SaleViewModel> data) => OK<SaleOperationResponse, List<SaleViewModel>>(data);
|
||||
|
||||
public static SaleOperationResponse OK(SaleViewModel data) => OK<SaleOperationResponse, SaleViewModel>(data);
|
||||
|
||||
public static SaleOperationResponse NoContent() => NoContent<SaleOperationResponse>();
|
||||
|
||||
public static SaleOperationResponse NotFound(string message) => NotFound<SaleOperationResponse>(message);
|
||||
|
||||
public static SaleOperationResponse BadRequest(string message) => BadRequest<SaleOperationResponse>(message);
|
||||
|
||||
public static SaleOperationResponse InternalServerError(string message) => InternalServerError<SaleOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class StorageOperationResponse : OperationResponse
|
||||
{
|
||||
public static StorageOperationResponse OK(List<StorageViewModel> data) => OK<StorageOperationResponse, List<StorageViewModel>>(data);
|
||||
|
||||
public static StorageOperationResponse OK(StorageViewModel data) => OK<StorageOperationResponse, StorageViewModel>(data);
|
||||
|
||||
public static StorageOperationResponse NoContent() => NoContent<StorageOperationResponse>();
|
||||
|
||||
public static StorageOperationResponse NotFound(string message) => NotFound<StorageOperationResponse>(message);
|
||||
|
||||
public static StorageOperationResponse BadRequest(string message) => BadRequest<StorageOperationResponse>(message);
|
||||
|
||||
public static StorageOperationResponse InternalServerError(string message) => InternalServerError<StorageOperationResponse>(message);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using CandyHouseContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.AdapterContracts.OperationResponses;
|
||||
|
||||
public class SuppliesOperationResponse : OperationResponse
|
||||
{
|
||||
public static SuppliesOperationResponse OK(List<SuppliesViewModel> data) => OK<SuppliesOperationResponse, List<SuppliesViewModel>>(data);
|
||||
|
||||
public static SuppliesOperationResponse OK(SuppliesViewModel data) => OK<SuppliesOperationResponse, SuppliesViewModel>(data);
|
||||
|
||||
public static SuppliesOperationResponse NoContent() => NoContent<SuppliesOperationResponse>();
|
||||
|
||||
public static SuppliesOperationResponse NotFound(string message) => NotFound<SuppliesOperationResponse>(message);
|
||||
|
||||
public static SuppliesOperationResponse BadRequest(string message) => BadRequest<SuppliesOperationResponse>(message);
|
||||
|
||||
public static SuppliesOperationResponse InternalServerError(string message) => InternalServerError<SuppliesOperationResponse>(message);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ClientBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? FIO { get; set; }
|
||||
|
||||
public string? PhoneNumber { get; set; }
|
||||
|
||||
public double DiscountSize { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class EmployeeBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? FIO { get; set; }
|
||||
|
||||
public string? Email { get; set; }
|
||||
|
||||
public string? PostId { get; set; }
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class PostBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? PostId => Id;
|
||||
|
||||
public string? PostName { get; set; }
|
||||
|
||||
public string? PostType { get; set; }
|
||||
|
||||
public double Salary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ProductBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
public string? ProductDescription { get; set; }
|
||||
public double Price { get; set; }
|
||||
public string? ProductType { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ProductStorageBindingModel
|
||||
{
|
||||
public string? StorageId { get; set; }
|
||||
public string? ProductId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class ProductSuppliesBindingModel
|
||||
{
|
||||
public string? SuppliesId { get; set; }
|
||||
public string? ProductId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class SaleBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
|
||||
public string? EmployeeId { get; set; }
|
||||
|
||||
public string? ClientId { get; set; }
|
||||
|
||||
public int DiscountType { get; set; }
|
||||
|
||||
public List<SaleProductBindingModel>? Products { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class SaleProductBindingModel
|
||||
{
|
||||
public string? SaleId { get; set; }
|
||||
|
||||
public string? ProductId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class StorageBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public ProductType? ProductType { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<ProductStorageBindingModel>? Products { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.BindingModels;
|
||||
|
||||
public class SuppliesBindingModel
|
||||
{
|
||||
public string? Id { get; set; }
|
||||
public ProductType? ProductType { get; set; }
|
||||
public DateTime ProductuionDate { get; set; }
|
||||
public int Count { get; set; }
|
||||
public List<ProductSuppliesBindingModel>? Products { get; set; }
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace CandyHouseContracts.BuisnessLogicContracts;
|
||||
|
||||
public interface IPostBusinessLogicContract
|
||||
{
|
||||
List<PostDataModel> GetAllPosts(bool onlyActive);
|
||||
List<PostDataModel> GetAllPosts();
|
||||
|
||||
List<PostDataModel> GetAllDataOfPost(string postId);
|
||||
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -12,6 +13,8 @@ namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class EmployeeDataModel(string id, string fio, string email, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
private readonly PostDataModel? _post;
|
||||
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
@@ -26,6 +29,17 @@ public class EmployeeDataModel(string id, string fio, string email, string postI
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
public string PostName => _post?.PostName ?? string.Empty;
|
||||
|
||||
public EmployeeDataModel(string id, string fio, string email, string postId, DateTime birthDate, DateTime employmentDate,
|
||||
bool isDeleted, PostDataModel post) : this(id, fio, email, postId, birthDate, employmentDate, isDeleted)
|
||||
{
|
||||
_post = post;
|
||||
}
|
||||
|
||||
public EmployeeDataModel(string id, string fio, string email, string postId, DateTime birthDate,
|
||||
DateTime employmentDate) : this(id, fio, email, postId, birthDate, employmentDate, false) { }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
||||
@@ -10,14 +10,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
public class PostDataModel(string postId, string postName, PostType postType, double salary) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string Id { get; private set; } = postId;
|
||||
public string PostName { get; private set; } = postName;
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
public double Salary { get; private set; } = salary;
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
public double Salary { get; private set; } = salary;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
|
||||
@@ -11,12 +11,22 @@ namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class ProductHistoryDataModel(string productId, double oldPrice) : IValidation
|
||||
{
|
||||
private readonly ProductDataModel? _product;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public string ProductName => _product?.ProductName ?? string.Empty;
|
||||
|
||||
public ProductHistoryDataModel(string productId, double oldPrice, DateTime changeDate, ProductDataModel product) : this(productId, oldPrice)
|
||||
{
|
||||
ChangeDate = changeDate;
|
||||
_product = product;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ProductId.IsEmpty())
|
||||
|
||||
@@ -11,12 +11,20 @@ namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary) : IValidation
|
||||
{
|
||||
private readonly EmployeeDataModel? _employee;
|
||||
public string EmployeeId { get; private set; } = employeeId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = employeeSalary;
|
||||
|
||||
public string EmployeeFIO => _employee?.FIO ?? string.Empty;
|
||||
|
||||
public SalaryDataModel(string employeeId, DateTime salaryDate, double employeeSalary, EmployeeDataModel employee) : this(employeeId, salaryDate, employeeSalary)
|
||||
{
|
||||
_employee = employee;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (EmployeeId.IsEmpty())
|
||||
|
||||
@@ -10,25 +10,78 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SaleDataModel(string id, string employeeId, string? clientId, double sum, DiscountType discountType,
|
||||
double discount, bool isCancel, List<SaleProductDataModel> saleProducts) : IValidation
|
||||
public class SaleDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
private readonly ClientDataModel? _client;
|
||||
|
||||
public string EmployeeId { get; private set; } = employeeId;
|
||||
private readonly EmployeeDataModel? _employee;
|
||||
|
||||
public string? ClientId { get; private set; } = clientId;
|
||||
public string Id { get; private set; }
|
||||
|
||||
public string EmployeeId { get; private set; }
|
||||
|
||||
public string? ClientId { get; private set; }
|
||||
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
public double Sum { get; private set; } = sum;
|
||||
|
||||
public DiscountType DiscountType { get; private set; } = discountType;
|
||||
public double Sum { get; private set; }
|
||||
|
||||
public double Discount { get; private set; } = discount;
|
||||
public DiscountType DiscountType { get; private set; }
|
||||
|
||||
public bool IsCancel { get; private set; } = isCancel;
|
||||
public double Discount { get; private set; }
|
||||
|
||||
public List<SaleProductDataModel> Products { get; private set; } = saleProducts;
|
||||
public bool IsCancel { get; private set; }
|
||||
|
||||
public List<SaleProductDataModel>? Products { get; private set; }
|
||||
|
||||
public string ClientFIO => _client?.FIO ?? string.Empty;
|
||||
|
||||
public string EmployeeFIO => _employee?.FIO ?? string.Empty;
|
||||
|
||||
public SaleDataModel(string id, string employeeId, string? clientId, DiscountType discountType, bool isCancel, List<SaleProductDataModel> saleProducts)
|
||||
{
|
||||
Id = id;
|
||||
EmployeeId = employeeId;
|
||||
ClientId = clientId;
|
||||
DiscountType = discountType;
|
||||
IsCancel = isCancel;
|
||||
Products = saleProducts;
|
||||
var percent = 0.0;
|
||||
foreach (DiscountType elem in Enum.GetValues<DiscountType>())
|
||||
{
|
||||
if ((elem & discountType) != 0)
|
||||
{
|
||||
switch (elem)
|
||||
{
|
||||
case DiscountType.None:
|
||||
break;
|
||||
case DiscountType.OnSale:
|
||||
percent += 0.1;
|
||||
break;
|
||||
case DiscountType.RegularCustomer:
|
||||
percent += 0.5;
|
||||
break;
|
||||
case DiscountType.Certificate:
|
||||
percent += 0.3;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
Sum = Products?.Sum(x => x.Price * x.Count) ?? 0;
|
||||
Discount = Sum * percent;
|
||||
}
|
||||
|
||||
public SaleDataModel(string id, string employeeId, string? clientId, double sum, DiscountType discountType, double discount, bool isCancel,
|
||||
List<SaleProductDataModel> saleProducts, EmployeeDataModel employee, ClientDataModel? client) : this(id, employeeId, clientId, discountType, isCancel, saleProducts)
|
||||
{
|
||||
Sum = sum;
|
||||
Discount = discount;
|
||||
_employee = employee;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
public SaleDataModel(string id, string employeeId, string? clientId, int discountType,
|
||||
List<SaleProductDataModel> products) : this(id, employeeId, clientId, (DiscountType)discountType, false, products) { }
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
|
||||
@@ -3,20 +3,32 @@ using CandyHouseContracts.Extensions;
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SaleProductDataModel(string saleId, string productId, int count) : IValidation
|
||||
public class SaleProductDataModel(string saleId, string productId, int count, double price) : IValidation
|
||||
{
|
||||
private readonly ProductDataModel? _product;
|
||||
|
||||
public string SaleId { get; private set; } = saleId;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public string ProductName => _product?.ProductName ?? string.Empty;
|
||||
|
||||
public SaleProductDataModel(string saleId, string productId, int count, double price, ProductDataModel product) : this(saleId, productId, count, price)
|
||||
{
|
||||
_product = product;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SaleId.IsEmpty())
|
||||
@@ -33,5 +45,8 @@ public class SaleProductDataModel(string saleId, string productId, int count) :
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace CandyHouseContracts.DataModels;
|
||||
public class StorageDataModel(string id, ProductType productType, int count, List<ProductStorageDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public ProductType Type { get; private set; } = productType;
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
public int Count { get; private set; } = count;
|
||||
public List<ProductStorageDataModel> Products { get; private set; } = products;
|
||||
|
||||
@@ -23,7 +23,7 @@ public class StorageDataModel(string id, ProductType productType, int count, Lis
|
||||
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 (Type == ProductType.None)
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
|
||||
@@ -11,11 +11,11 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace CandyHouseContracts.DataModels;
|
||||
|
||||
public class SuppliesDataModel(string id, ProductType productType, DateTime date, int count, List<ProductSuppliesDataModel> products) : IValidation
|
||||
public class SuppliesDataModel(string id, ProductType productType, DateTime productuionDate, int count, List<ProductSuppliesDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public ProductType Type { get; private set; } = productType;
|
||||
public DateTime OrderDate { get; private set; } = date;
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
public DateTime ProductuionDate { get; private set; } = productuionDate;
|
||||
public int Count { get; private set; } = count;
|
||||
public List<ProductSuppliesDataModel> Products { get; private set; } = products;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class SuppliesDataModel(string id, ProductType productType, DateTime date
|
||||
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 (Type == ProductType.None)
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
|
||||
@@ -6,11 +6,10 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.Enums;
|
||||
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Manager = 1,
|
||||
SuperManager = 2,
|
||||
Baker = 3,
|
||||
}
|
||||
TravelAgent = 2,
|
||||
Сhief = 3,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.Infrastructure;
|
||||
|
||||
public class OperationResponse
|
||||
{
|
||||
public HttpStatusCode StatusCode { get; set; }
|
||||
|
||||
public object? Result { get; set; }
|
||||
|
||||
public IActionResult GetResponse(HttpRequest request, HttpResponse response)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(request);
|
||||
ArgumentNullException.ThrowIfNull(response);
|
||||
|
||||
response.StatusCode = (int)StatusCode;
|
||||
|
||||
if (Result is null)
|
||||
{
|
||||
return new StatusCodeResult((int)StatusCode);
|
||||
}
|
||||
|
||||
return new ObjectResult(Result);
|
||||
}
|
||||
|
||||
protected static TResult OK<TResult, TData>(TData data) where TResult : OperationResponse,
|
||||
new() => new() { StatusCode = HttpStatusCode.OK, Result = data };
|
||||
|
||||
protected static TResult NoContent<TResult>() where TResult : OperationResponse,
|
||||
new() => new() { StatusCode = HttpStatusCode.NoContent };
|
||||
|
||||
protected static TResult BadRequest<TResult>(string? errorMessage = null) where TResult : OperationResponse,
|
||||
new() => new() { StatusCode = HttpStatusCode.BadRequest, Result = errorMessage };
|
||||
|
||||
protected static TResult NotFound<TResult>(string? errorMessage = null) where TResult : OperationResponse,
|
||||
new() => new() { StatusCode = HttpStatusCode.NotFound, Result = errorMessage };
|
||||
|
||||
protected static TResult InternalServerError<TResult>(string? errorMessage = null) where TResult : OperationResponse,
|
||||
new() => new() { StatusCode = HttpStatusCode.InternalServerError, Result = errorMessage };
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace CandyHouseContracts.StoragesContracts;
|
||||
|
||||
public interface IPostStorageContract
|
||||
{
|
||||
List<PostDataModel> GetList(bool onlyActual = true);
|
||||
List<PostDataModel> GetList();
|
||||
List<PostDataModel> GetPostWithHistory(string postId);
|
||||
PostDataModel? GetElementById(string id);
|
||||
PostDataModel? GetElementByName(string name);
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace CandyHouseContracts.StoragesContracts;
|
||||
|
||||
public interface ISalaryStorageContract
|
||||
{
|
||||
List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? employeeId = null);
|
||||
List<SalaryDataModel> GetList(DateTime? startDate, DateTime? endDate, string? employeeId = null);
|
||||
|
||||
void AddElement(SalaryDataModel salaryDataModel);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class ClientViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string FIO { get; set; }
|
||||
|
||||
public required string PhoneNumber { get; set; }
|
||||
|
||||
public double DiscountSize { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class EmployeeViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string FIO { get; set; }
|
||||
|
||||
public string Email { get; set; }
|
||||
|
||||
public required string PostId { get; set; }
|
||||
|
||||
public required string PostName { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class PostViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string PostName { get; set; }
|
||||
|
||||
public required string PostType { get; set; }
|
||||
|
||||
public double Salary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class ProductHistoryViewModel
|
||||
{
|
||||
public required string ProductName { get; set; }
|
||||
|
||||
public double OldPrice { get; set; }
|
||||
|
||||
public DateTime ChangeDate { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class ProductStorageViewModel
|
||||
{
|
||||
public required string StorageId { get; set; }
|
||||
public required string ProductId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class ProductSuppliesViewModel
|
||||
{
|
||||
public required string SuppliesId { get; set; }
|
||||
public required string ProductId { get; set; }
|
||||
public int Count { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class ProductViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string ProductName { get; set; }
|
||||
|
||||
public required string ProductType { get; set; }
|
||||
|
||||
public string? ProductDescription { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class SalaryViewModel
|
||||
{
|
||||
public required string EmployeeId { get; set; }
|
||||
public required string EmployeeFIO { get; set; }
|
||||
public DateTime SalaryDate { get; set; }
|
||||
public double Salary { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class SaleProductViewModel
|
||||
{
|
||||
public required string ProductId { get; set; }
|
||||
|
||||
public required string ProductName { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class SaleViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
public required string EmployeeId { get; set; }
|
||||
|
||||
public required string EmployeeFIO { get; set; }
|
||||
|
||||
public string? ClientId { get; set; }
|
||||
|
||||
public string? ClientFIO { get; set; }
|
||||
|
||||
public DateTime SaleDate { get; set; }
|
||||
|
||||
public double Sum { get; set; }
|
||||
|
||||
public required string DiscountType { get; set; }
|
||||
|
||||
public double Discount { get; set; }
|
||||
|
||||
public bool IsCancel { get; set; }
|
||||
|
||||
public required List<SaleProductViewModel> Products { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class StorageViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required ProductType ProductType { get; set; }
|
||||
public required int Count { get; set; }
|
||||
public required List<ProductStorageViewModel> Products { get; set; }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseContracts.ViewModels;
|
||||
|
||||
public class SuppliesViewModel
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required ProductType ProductType { get; set; }
|
||||
public DateTime ProductuionDate { get; set; }
|
||||
public int Count { get; set; }
|
||||
public required List<ProductSuppliesViewModel> Products { get; set; }
|
||||
}
|
||||
@@ -1,23 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CandyHouseContracts\CandyHouseContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CandyHouseContracts\CandyHouseContracts.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="CandyHouseTests" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -25,6 +25,11 @@ public class CandyHouseDbContext(IConfigurationDatabase configurationDatabase) :
|
||||
|
||||
modelBuilder.Entity<Client>().HasIndex(x => x.PhoneNumber).IsUnique();
|
||||
|
||||
modelBuilder.Entity<Sale>()
|
||||
.HasOne(e => e.Client)
|
||||
.WithMany(e => e.Sales)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
modelBuilder.Entity<Product>().HasIndex(x => x.ProductName).IsUnique();
|
||||
|
||||
modelBuilder.Entity<Post>()
|
||||
@@ -60,7 +65,7 @@ public class CandyHouseDbContext(IConfigurationDatabase configurationDatabase) :
|
||||
|
||||
public DbSet<Employee> Employees { get; set; }
|
||||
public DbSet<Supplies> Supplieses { get; set; }
|
||||
public DbSet<Storage> Agencies { get; set; }
|
||||
public DbSet<Storage> Storages { get; set; }
|
||||
public DbSet<ProductSupplies> ProductSupplieses { get; set; }
|
||||
public DbSet<ProductStorage> ProductAgensies { get; set; }
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseDatabase.Implementations;
|
||||
|
||||
internal class ClientStorageContarct : IClientStorageContract
|
||||
public class ClientStorageContract : IClientStorageContract
|
||||
{
|
||||
private readonly CandyHouseDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public ClientStorageContarct(CandyHouseDbContext magicCarpetDbContext)
|
||||
public ClientStorageContract(CandyHouseDbContext magicCarpetDbContext)
|
||||
{
|
||||
_dbContext = magicCarpetDbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -11,7 +11,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseDatabase.Implementations;
|
||||
|
||||
internal class EmployeeStorageContract : IEmployeeStorageContract
|
||||
public class EmployeeStorageContract : IEmployeeStorageContract
|
||||
{
|
||||
private readonly CandyHouseDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
@@ -21,10 +21,14 @@ internal class EmployeeStorageContract : IEmployeeStorageContract
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.AddMaps(typeof(CandyHouseDbContext).Assembly);
|
||||
cfg.CreateMap<Post, PostDataModel>()
|
||||
.ForMember(x => x.Id, x => x.MapFrom(src => src.PostId));
|
||||
cfg.CreateMap<Employee, EmployeeDataModel>();
|
||||
cfg.CreateMap<EmployeeDataModel, Employee>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<EmployeeDataModel> GetList(bool onlyActive = true, string? postId = null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime? fromEmploymentDate = null, DateTime? toEmploymentDate = null)
|
||||
{
|
||||
try
|
||||
@@ -40,13 +44,13 @@ internal class EmployeeStorageContract : IEmployeeStorageContract
|
||||
}
|
||||
if (fromBirthDate is not null && toBirthDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.BirthDate >= fromBirthDate && x.BirthDate <= toBirthDate);
|
||||
query = query.Where(x => x.BirthDate >= DateTime.SpecifyKind(fromBirthDate ?? DateTime.UtcNow, DateTimeKind.Utc) && x.BirthDate <= DateTime.SpecifyKind(toBirthDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
}
|
||||
if (fromEmploymentDate is not null && toEmploymentDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.EmploymentDate >= fromEmploymentDate && x.EmploymentDate <= toEmploymentDate);
|
||||
query = query.Where(x => x.EmploymentDate >= DateTime.SpecifyKind(fromEmploymentDate ?? DateTime.UtcNow, DateTimeKind.Utc) && x.EmploymentDate <= DateTime.SpecifyKind(toEmploymentDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<EmployeeDataModel>(x))];
|
||||
return [.. JoinPost(query).Select(x => _mapper.Map<EmployeeDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -72,7 +76,7 @@ internal class EmployeeStorageContract : IEmployeeStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<EmployeeDataModel>(_dbContext.Employees.FirstOrDefault(x => x.FIO == fio));
|
||||
return _mapper.Map<EmployeeDataModel>(AddPost(_dbContext.Employees.FirstOrDefault(x => x.FIO == fio && !x.IsDeleted)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -80,11 +84,12 @@ internal class EmployeeStorageContract : IEmployeeStorageContract
|
||||
throw new StorageException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public EmployeeDataModel? GetElementByEmail(string email)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mapper.Map<EmployeeDataModel>(_dbContext.Employees.FirstOrDefault(x => x.Email == email));
|
||||
return _mapper.Map<EmployeeDataModel>(AddPost(_dbContext.Employees.FirstOrDefault(x => x.Email == email && !x.IsDeleted)));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -152,5 +157,12 @@ internal class EmployeeStorageContract : IEmployeeStorageContract
|
||||
}
|
||||
}
|
||||
|
||||
private Employee? GetEmployeeById(string id) => _dbContext.Employees.FirstOrDefault(x => x.Id == id && !x.IsDeleted);
|
||||
private Employee? GetEmployeeById(string id) => AddPost(_dbContext.Employees.FirstOrDefault(x => x.Id == id && !x.IsDeleted));
|
||||
|
||||
private IQueryable<Employee> JoinPost(IQueryable<Employee> query)
|
||||
=> query.GroupJoin(_dbContext.Posts.Where(x => x.IsActual), x => x.PostId, y => y.PostId, (x, y) => new { Employee = x, Post = y })
|
||||
.SelectMany(xy => xy.Post.DefaultIfEmpty(), (x, y) => x.Employee.AddPost(y));
|
||||
|
||||
private Employee? AddPost(Employee? employee)
|
||||
=> employee?.AddPost(_dbContext.Posts.FirstOrDefault(x => x.PostId == employee.PostId && x.IsActual));
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseDatabase.Implementations;
|
||||
|
||||
internal class PostStorageContract : IPostStorageContract
|
||||
public class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
private readonly CandyHouseDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
@@ -34,16 +34,11 @@ internal class PostStorageContract : IPostStorageContract
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetList(bool onlyActual = true)
|
||||
public List<PostDataModel> GetList()
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Posts.AsQueryable();
|
||||
if (onlyActual)
|
||||
{
|
||||
query = query.Where(x => x.IsActual);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<PostDataModel>(x))];
|
||||
return [.. _dbContext.Posts.Select(x => _mapper.Map<PostDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseDatabase.Implementations;
|
||||
|
||||
internal class ProductStorageContract : IProductStorageContract
|
||||
public class ProductStorageContract : IProductStorageContract
|
||||
{
|
||||
private readonly CandyHouseDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
@@ -30,6 +30,7 @@ internal class ProductStorageContract : IProductStorageContract
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<ProductDataModel> GetList()
|
||||
{
|
||||
try
|
||||
@@ -47,7 +48,7 @@ internal class ProductStorageContract : IProductStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.ProductHistories.Where(x => x.ProductId == productId).OrderByDescending(x => x.ChangeDate).Select(x => _mapper.Map<ProductHistoryDataModel>(x))];
|
||||
return [.. _dbContext.ProductHistories.Include(x => x.Product).Where(x => x.ProductId == productId).OrderByDescending(x => x.ChangeDate).Select(x => _mapper.Map<ProductHistoryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -110,20 +111,35 @@ internal class ProductStorageContract : IProductStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetProductById(productDataModel.Id) ?? throw new ElementNotFoundException(productDataModel.Id);
|
||||
_dbContext.Products.Update(_mapper.Map(productDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var element = GetProductById(productDataModel.Id) ?? throw new ElementNotFoundException(productDataModel.Id);
|
||||
if (element.Price != productDataModel.Price)
|
||||
{
|
||||
_dbContext.ProductHistories.Add(new ProductHistory() { ProductId = element.Id, OldPrice = element.Price });
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
_dbContext.Products.Update(_mapper.Map(productDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Products_ProductName" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("ProductName", productDataModel.ProductName);
|
||||
}
|
||||
catch (Exception ex) when (ex is ElementDeletedException || ex is ElementNotFoundException)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
|
||||
@@ -3,6 +3,7 @@ using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using CandyHouseDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -11,7 +12,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseDatabase.Implementations;
|
||||
|
||||
internal class SalaryStorageContract : ISalaryStorageContract
|
||||
public class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
private readonly CandyHouseDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
@@ -21,6 +22,7 @@ internal class SalaryStorageContract : ISalaryStorageContract
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Employee, EmployeeDataModel>();
|
||||
cfg.CreateMap<Salary, SalaryDataModel>();
|
||||
cfg.CreateMap<SalaryDataModel, Salary>()
|
||||
.ForMember(dest => dest.EmployeeSalary, opt => opt.MapFrom(src => src.Salary));
|
||||
@@ -28,15 +30,17 @@ internal class SalaryStorageContract : ISalaryStorageContract
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? employeeId = null)
|
||||
public List<SalaryDataModel> GetList(DateTime? startDate, DateTime? endDate, string? employeeId = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Salaries.Where(x => x.SalaryDate >= startDate && x.SalaryDate <= endDate);
|
||||
if (employeeId is not null)
|
||||
{
|
||||
var query = _dbContext.Salaries.Include(d => d.Employee).AsQueryable();
|
||||
if (startDate.HasValue)
|
||||
query = query.Where(x => x.SalaryDate >= DateTime.SpecifyKind(startDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (endDate.HasValue)
|
||||
query = query.Where(x => x.SalaryDate <= DateTime.SpecifyKind(endDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (employeeId != null)
|
||||
query = query.Where(x => x.EmployeeId == employeeId);
|
||||
}
|
||||
return [.. query.Select(x => _mapper.Map<SalaryDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -12,7 +12,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseDatabase.Implementations;
|
||||
|
||||
internal class SaleStorageContract : ISaleStorageContract
|
||||
public class SaleStorageContract : ISaleStorageContract
|
||||
{
|
||||
private readonly CandyHouseDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
@@ -22,12 +22,18 @@ internal class SaleStorageContract : ISaleStorageContract
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Client, ClientDataModel>();
|
||||
cfg.CreateMap<Product, ProductDataModel>();
|
||||
cfg.CreateMap<Employee, EmployeeDataModel>();
|
||||
cfg.CreateMap<SaleProduct, SaleProductDataModel>();
|
||||
cfg.CreateMap<SaleProductDataModel, SaleProduct>();
|
||||
cfg.CreateMap<SaleProductDataModel, SaleProduct>()
|
||||
.ForMember(x => x.Product, x => x.Ignore());
|
||||
cfg.CreateMap<Sale, SaleDataModel>();
|
||||
cfg.CreateMap<SaleDataModel, Sale>()
|
||||
.ForMember(x => x.IsCancel, x => x.MapFrom(src => false))
|
||||
.ForMember(x => x.SaleProducts, x => x.MapFrom(src => src.Products));
|
||||
.ForMember(x => x.SaleProducts, x => x.MapFrom(src => src.Products))
|
||||
.ForMember(x => x.Employee, x => x.Ignore())
|
||||
.ForMember(x => x.Client, x => x.Ignore());
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
@@ -36,23 +42,23 @@ internal class SaleStorageContract : ISaleStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var query = _dbContext.Sales.Include(x => x.SaleProducts).AsQueryable();
|
||||
if (startDate is not null && endDate is not null)
|
||||
{
|
||||
query = query.Where(x => x.SaleDate >= startDate && x.SaleDate < endDate);
|
||||
}
|
||||
if (employeeId is not null)
|
||||
{
|
||||
var query = _dbContext.Sales
|
||||
.Include(r => r.Employee)
|
||||
.Include(r => r.Client)
|
||||
.Include(r => r.SaleProducts)!
|
||||
.ThenInclude(d => d.Product)
|
||||
.AsQueryable();
|
||||
if (startDate.HasValue)
|
||||
query = query.Where(x => x.SaleDate >= DateTime.SpecifyKind(startDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (endDate.HasValue)
|
||||
query = query.Where(x => x.SaleDate <= DateTime.SpecifyKind(endDate ?? DateTime.UtcNow, DateTimeKind.Utc));
|
||||
if (employeeId != null)
|
||||
query = query.Where(x => x.EmployeeId == employeeId);
|
||||
}
|
||||
if (clientId is not null)
|
||||
{
|
||||
if (clientId != null)
|
||||
query = query.Where(x => x.ClientId == clientId);
|
||||
}
|
||||
if (productId is not null)
|
||||
{
|
||||
if (productId != null)
|
||||
query = query.Where(x => x.SaleProducts!.Any(y => y.ProductId == productId));
|
||||
}
|
||||
var s = query.ToList();
|
||||
return [.. query.Select(x => _mapper.Map<SaleDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -113,5 +119,5 @@ internal class SaleStorageContract : ISaleStorageContract
|
||||
}
|
||||
}
|
||||
|
||||
private Sale? GetSaleById(string id) => _dbContext.Sales.FirstOrDefault(x => x.Id == id);
|
||||
private Sale? GetSaleById(string id) => _dbContext.Sales.Include(x => x.Client).Include(x => x.Employee).Include(x => x.SaleProducts)!.ThenInclude(x => x.Product).FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
|
||||
@@ -21,16 +21,8 @@ public class StorageStorageContract : IStorageStorageContract
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<Storage, StorageDataModel>()
|
||||
.ConstructUsing(src => new StorageDataModel(
|
||||
src.Id,
|
||||
src.Type,
|
||||
src.Count,
|
||||
_mapper.Map<List<ProductStorageDataModel>>(src.Products)
|
||||
));
|
||||
|
||||
cfg.CreateMap<StorageDataModel, Storage>();
|
||||
cfg.CreateMap<ProductStorageDataModel, ProductStorage>().ReverseMap();
|
||||
cfg.AddMaps(typeof(ProductStorage));
|
||||
cfg.AddMaps(typeof(Storage));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
}
|
||||
@@ -39,7 +31,7 @@ public class StorageStorageContract : IStorageStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
return [.. _dbContext.Agencies.Select(x => _mapper.Map<StorageDataModel>(x))];
|
||||
return [.. _dbContext.Storages.Select(x => _mapper.Map<StorageDataModel>(x))];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -65,7 +57,7 @@ public class StorageStorageContract : IStorageStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
_dbContext.Agencies.Add(_mapper.Map<Storage>(storageDataModel));
|
||||
_dbContext.Storages.Add(_mapper.Map<Storage>(storageDataModel));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -80,7 +72,7 @@ public class StorageStorageContract : IStorageStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetStorageById(storageDataModel.Id) ?? throw new ElementNotFoundException(storageDataModel.Id);
|
||||
_dbContext.Agencies.Update(_mapper.Map(storageDataModel, element));
|
||||
_dbContext.Storages.Update(_mapper.Map(storageDataModel, element));
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
@@ -100,7 +92,7 @@ public class StorageStorageContract : IStorageStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetStorageById(id) ?? throw new ElementNotFoundException(id);
|
||||
_dbContext.Agencies.Remove(element);
|
||||
_dbContext.Storages.Remove(element);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch (ElementNotFoundException)
|
||||
@@ -122,7 +114,7 @@ public class StorageStorageContract : IStorageStorageContract
|
||||
foreach (SaleProductDataModel sale_product in saleDataModel.Products)
|
||||
{
|
||||
var product = _dbContext.Products.FirstOrDefault(x => x.Id == sale_product.ProductId);
|
||||
var storage = _dbContext.Agencies.FirstOrDefault(x => x.Type == product.ProductType && x.Count >= sale_product.Count);
|
||||
var storage = _dbContext.Storages.FirstOrDefault(x => x.ProductType == product.ProductType && x.Count >= sale_product.Count);
|
||||
|
||||
if (storage == null)
|
||||
{
|
||||
@@ -144,5 +136,5 @@ public class StorageStorageContract : IStorageStorageContract
|
||||
}
|
||||
}
|
||||
|
||||
private Storage? GetStorageById(string id) => _dbContext.Agencies.FirstOrDefault(x => x.Id == id);
|
||||
private Storage? GetStorageById(string id) => _dbContext.Storages.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ public class SuppliesStorageContract : ISuppliesStorageContract
|
||||
cfg.CreateMap<Supplies, SuppliesDataModel>()
|
||||
.ConstructUsing(src => new SuppliesDataModel(
|
||||
src.Id,
|
||||
src.Type,
|
||||
src.OrderDate,
|
||||
src.ProductType,
|
||||
src.ProductuionDate,
|
||||
src.Count,
|
||||
_mapper.Map<List<ProductSuppliesDataModel>>(src.Products)
|
||||
));
|
||||
|
||||
@@ -22,11 +22,18 @@ public class Employee
|
||||
|
||||
public DateTime BirthDate { get; set; }
|
||||
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
public DateTime EmploymentDate { get; set; }
|
||||
|
||||
public bool IsDeleted { get; set; }
|
||||
public bool IsDeleted { get; set; }
|
||||
[NotMapped]
|
||||
public Post? Post { get; set; }
|
||||
[ForeignKey("EmployeeId")]
|
||||
public List<Salary>? Salaries { get; set; }
|
||||
[ForeignKey("EmployeeId")]
|
||||
public List<Sale>? Sales { get; set; }
|
||||
public Employee AddPost(Post? post)
|
||||
{
|
||||
Post = post;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@ public class Product
|
||||
public List<ProductHistory>? ProductHistories { get; set; }
|
||||
[ForeignKey("SuppliesesId")]
|
||||
public List<ProductSupplies>? ProductSupplies { get; set; }
|
||||
[ForeignKey("AgenciesId")]
|
||||
[ForeignKey("StoragesId")]
|
||||
public List<ProductStorage>? ProductStorage { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
@@ -6,11 +8,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseDatabase.Models;
|
||||
|
||||
[AutoMap(typeof(ProductStorageDataModel), ReverseMap = true)]
|
||||
public class ProductStorage
|
||||
{
|
||||
public required string StorageId { get; set; }
|
||||
public required string ProductId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public Storage? Agencies { get; set; }
|
||||
public Storage? Storages { get; set; }
|
||||
public Product? Products { get; set; }
|
||||
}
|
||||
|
||||
@@ -13,4 +13,10 @@ public class SaleProduct
|
||||
public required string ProductId { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
|
||||
public double Price { get; set; }
|
||||
|
||||
public Sale? Sale { get; set; }
|
||||
|
||||
public Product? Product { get; set; }
|
||||
}
|
||||
|
||||
@@ -10,10 +10,11 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseDatabase.Models;
|
||||
|
||||
[AutoMap(typeof(StorageDataModel), ReverseMap = true)]
|
||||
public class Storage
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required ProductType Type { get; set; }
|
||||
public required ProductType ProductType { get; set; }
|
||||
public required int Count { get; set; }
|
||||
|
||||
[ForeignKey("StorageId")]
|
||||
|
||||
@@ -13,8 +13,8 @@ namespace CandyHouseDatabase.Models;
|
||||
public class Supplies
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required ProductType Type { get; set; }
|
||||
public DateTime OrderDate { get; set; }
|
||||
public required ProductType ProductType { get; set; }
|
||||
public DateTime ProductuionDate { get; set; }
|
||||
public required int Count { get; set; }
|
||||
|
||||
[ForeignKey("SuppliesId")]
|
||||
|
||||
@@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CandyHouseBusinessLogic", "
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CandyHouseDatabase", "CandyHouseDatabase\CandyHouseDatabase.csproj", "{928DD22D-F304-4767-B950-990BEE31CFF5}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CandyHouseWebApi", "CandyHouseWebApi\CandyHouseWebApi.csproj", "{AB65B02B-ED41-471D-8C4E-475051B7ECB6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -30,5 +32,9 @@ Global
|
||||
{928DD22D-F304-4767-B950-990BEE31CFF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{928DD22D-F304-4767-B950-990BEE31CFF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{928DD22D-F304-4767-B950-990BEE31CFF5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{AB65B02B-ED41-471D-8C4E-475051B7ECB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{AB65B02B-ED41-471D-8C4E-475051B7ECB6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AB65B02B-ED41-471D-8C4E-475051B7ECB6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AB65B02B-ED41-471D-8C4E-475051B7ECB6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -38,61 +38,53 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
var listOriginal = new List<PostDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(),"name 1", PostType.Manager, 10, true, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), "name 2", PostType.Manager, 10, false, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(), "name 3", PostType.Manager, 10, true, DateTime.UtcNow),
|
||||
new(Guid.NewGuid().ToString(),"name 1", PostType.Manager, 10),
|
||||
new(Guid.NewGuid().ToString(), "name 2", PostType.Manager, 10),
|
||||
new(Guid.NewGuid().ToString(), "name 3", PostType.Manager, 10),
|
||||
};
|
||||
_postStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Returns(listOriginal);
|
||||
_postStorageContract.Setup(x => x.GetList()).Returns(listOriginal);
|
||||
//Act
|
||||
var listOnlyActive = _postBusinessLogicContract.GetAllPosts(true);
|
||||
var listAll = _postBusinessLogicContract.GetAllPosts(false);
|
||||
var list = _postBusinessLogicContract.GetAllPosts();
|
||||
//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));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
});
|
||||
_postStorageContract.Verify(x => x.GetList(true), Times.Once);
|
||||
_postStorageContract.Verify(x => x.GetList(false), Times.Once);
|
||||
_postStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Returns([]);
|
||||
_postStorageContract.Setup(x => x.GetList()).Returns([]);
|
||||
//Act
|
||||
var listOnlyActive = _postBusinessLogicContract.GetAllPosts(true);
|
||||
var listAll = _postBusinessLogicContract.GetAllPosts(false);
|
||||
var list = _postBusinessLogicContract.GetAllPosts();
|
||||
//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));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, 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);
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(), Throws.TypeOf<NullListException>());
|
||||
_postStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.GetList()).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);
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -102,8 +94,8 @@ internal class PostBusinessLogicContractTests
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<PostDataModel>()
|
||||
{
|
||||
new(postId, "name 1", PostType.Manager, 10, true, DateTime.UtcNow),
|
||||
new(postId, "name 2", PostType.Manager, 10, false, DateTime.UtcNow)
|
||||
new(postId, "name 1", PostType.Manager, 10),
|
||||
new(postId, "name 2", PostType.Manager, 10)
|
||||
};
|
||||
_postStorageContract.Setup(x => x.GetPostWithHistory(It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -167,7 +159,7 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new PostDataModel(id, "name", PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var record = new PostDataModel(id, "name", PostType.Manager, 10);
|
||||
_postStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _postBusinessLogicContract.GetPostByData(id);
|
||||
@@ -182,7 +174,7 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var postName = "name";
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), postName, PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), postName, PostType.Manager, 10);
|
||||
_postStorageContract.Setup(x => x.GetElementByName(postName)).Returns(record);
|
||||
//Act
|
||||
var element = _postBusinessLogicContract.GetPostByData(postName);
|
||||
@@ -238,12 +230,11 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 10, true, DateTime.UtcNow.AddDays(-1));
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 10);
|
||||
_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.Salary == record.Salary &&
|
||||
x.ChangeDate == record.ChangeDate;
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.Salary == record.Salary;
|
||||
});
|
||||
//Act
|
||||
_postBusinessLogicContract.InsertPost(record);
|
||||
@@ -258,7 +249,7 @@ internal class PostBusinessLogicContractTests
|
||||
//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.Manager, 10, true, DateTime.UtcNow)), Throws.TypeOf<ElementExistsException>());
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Manager, 10)), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -274,7 +265,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void InsertPost_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new PostDataModel("id", "name", PostType.Manager, 10, true, DateTime.UtcNow)), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new PostDataModel("id", "name", PostType.Manager, 10)), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -284,7 +275,7 @@ internal class PostBusinessLogicContractTests
|
||||
//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.Manager, 10, true, DateTime.UtcNow)), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.Manager, 10)), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -293,12 +284,11 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 10, true, DateTime.UtcNow.AddDays(-1));
|
||||
var record = new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 10);
|
||||
_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.Salary == record.Salary &&
|
||||
x.ChangeDate == record.ChangeDate;
|
||||
flag = x.Id == record.Id && x.PostName == record.PostName && x.PostType == record.PostType && x.Salary == record.Salary;
|
||||
});
|
||||
//Act
|
||||
_postBusinessLogicContract.UpdatePost(record);
|
||||
@@ -313,7 +303,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Manager, 10, true, DateTime.UtcNow)), Throws.TypeOf<ElementNotFoundException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Manager, 10)), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -323,7 +313,7 @@ internal class PostBusinessLogicContractTests
|
||||
//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.Manager, 10, true, DateTime.UtcNow)), Throws.TypeOf<ElementExistsException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.Manager, 10)), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -339,7 +329,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void UpdatePost_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new PostDataModel("id", "name", PostType.Manager, 10, true, DateTime.UtcNow)), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new PostDataModel("id", "name", PostType.Manager, 10)), Throws.TypeOf<ValidationException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -349,7 +339,7 @@ internal class PostBusinessLogicContractTests
|
||||
//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.Manager, 10, true, DateTime.UtcNow)), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.Manager, 10)), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,9 @@ internal class ProductBusinessLogicContractTests
|
||||
//Arrange
|
||||
var listOriginal = new List<ProductDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), "name 1", "description1", 15.5, ProductType.Chocolate),
|
||||
new(Guid.NewGuid().ToString(), "name 2", "description2", 10.1, ProductType.Candy),
|
||||
new(Guid.NewGuid().ToString(), "name 3", "description3", 13.9, ProductType.Cake),
|
||||
new(Guid.NewGuid().ToString(), "name 1", "description1", 15.5, ProductType.Cake),
|
||||
new(Guid.NewGuid().ToString(), "name 2", "description2", 10.1, ProductType.Chocolate),
|
||||
new(Guid.NewGuid().ToString(), "name 3", "description3", 13.9, ProductType.Candy),
|
||||
};
|
||||
_productStorageContract.Setup(x => x.GetList()).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -155,7 +155,7 @@ internal class ProductBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new ProductDataModel(id, "name", "description", 10, ProductType.Chocolate);
|
||||
var record = new ProductDataModel(id, "name", "description", 10, ProductType.Cake);
|
||||
_productStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _productBusinessLogicContract.GetProductByData(id);
|
||||
@@ -170,7 +170,7 @@ internal class ProductBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var name = "name";
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), name, "description", 10, ProductType.Chocolate);
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), name, "description", 10, ProductType.Cake);
|
||||
_productStorageContract.Setup(x => x.GetElementByName(name)).Returns(record);
|
||||
//Act
|
||||
var element = _productBusinessLogicContract.GetProductByData(name);
|
||||
@@ -184,7 +184,7 @@ internal class ProductBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var description = "description";
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), "name", description, 10, ProductType.Chocolate);
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), "name", description, 10, ProductType.Cake);
|
||||
_productStorageContract.Setup(x => x.GetElementByName(description)).Returns(record);
|
||||
//Act
|
||||
var element = _productBusinessLogicContract.GetProductByData(description);
|
||||
@@ -245,11 +245,11 @@ internal class ProductBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), "name","description",10, ProductType.Chocolate);
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), "name","description",10, ProductType.Cake);
|
||||
_productStorageContract.Setup(x => x.AddElement(It.IsAny<ProductDataModel>()))
|
||||
.Callback((ProductDataModel x) =>
|
||||
{
|
||||
flag = x.Id == record.Id && x.ProductName == record.ProductName && x.ProductDescription == record.ProductDescription
|
||||
flag = x.Id == record.Id && x.ProductName == record.ProductName && x.ProductDescription == record.ProductDescription
|
||||
&& x.Price == record.Price && x.ProductType == record.ProductType;
|
||||
});
|
||||
//Act
|
||||
@@ -265,7 +265,7 @@ internal class ProductBusinessLogicContractTests
|
||||
//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","description",10, ProductType.Chocolate)), Throws.TypeOf<ElementExistsException>());
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(new(Guid.NewGuid().ToString(), "name","description",10, ProductType.Cake)), Throws.TypeOf<ElementExistsException>());
|
||||
_productStorageContract.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ internal class ProductBusinessLogicContractTests
|
||||
public void InsertProduct_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(new ProductDataModel("id", "name", "description", 10, ProductType.Chocolate)), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(new ProductDataModel("id", "name", "description", 10, ProductType.Cake)), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContract.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -290,7 +290,7 @@ internal class ProductBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), "name", "description", 10, ProductType.Chocolate);
|
||||
var record = new ProductDataModel(Guid.NewGuid().ToString(), "name", "description", 10, ProductType.Cake);
|
||||
_productStorageContract.Setup(x => x.UpdElement(It.IsAny<ProductDataModel>()))
|
||||
.Callback((ProductDataModel x) =>
|
||||
{
|
||||
@@ -310,7 +310,7 @@ internal class ProductBusinessLogicContractTests
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.UpdElement(It.IsAny<ProductDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new(Guid.NewGuid().ToString(), "name", "description", 10, ProductType.Chocolate)), Throws.TypeOf<ElementNotFoundException>());
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new(Guid.NewGuid().ToString(), "name", "description", 10, ProductType.Cake)), Throws.TypeOf<ElementNotFoundException>());
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ internal class ProductBusinessLogicContractTests
|
||||
//Arrange
|
||||
_productStorageContract.Setup(x => x.UpdElement(It.IsAny<ProductDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new(Guid.NewGuid().ToString(), "name", "description", 10, ProductType.Chocolate)), Throws.TypeOf <ElementExistsException>());
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new(Guid.NewGuid().ToString(), "name", "description", 10, ProductType.Cake)), Throws.TypeOf <ElementExistsException>());
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ internal class ProductBusinessLogicContractTests
|
||||
public void UpdateProduct_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new ProductDataModel("id", "name", "description", 10, ProductType.Chocolate)), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new ProductDataModel("id", "name", "description", 10, ProductType.Cake)), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -346,7 +346,7 @@ internal class ProductBusinessLogicContractTests
|
||||
//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", "description", 10, ProductType.Chocolate)), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new(Guid.NewGuid().ToString(), "name", "description", 10, ProductType.Cake)), Throws.TypeOf<StorageException>());
|
||||
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
public void GetAllSalariesByEmployee_EmployeeIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByEmployee(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), "workerId"), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByEmployee(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), "employeeId"), Throws.TypeOf<ValidationException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -191,12 +191,12 @@ internal class SalaryBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var saleSum = 200.0;
|
||||
var saleSum = 1.2 * 5;
|
||||
var postSalary = 2000.0;
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, saleSum, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, postSalary, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, postSalary));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
var sum = 0.0;
|
||||
@@ -213,7 +213,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WithSeveralWorkers_Test()
|
||||
public void CalculateSalaryByMounth_WithSeveralEmployees_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employee1Id = Guid.NewGuid().ToString();
|
||||
@@ -225,13 +225,13 @@ internal class SalaryBusinessLogicContractTests
|
||||
new(employee3Id, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employee1Id, null, 1, DiscountType.None, 0, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee1Id, null, 1, DiscountType.None, 0, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee2Id, null, 1, DiscountType.None, 0, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, 1, DiscountType.None, 0, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, 1, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employee1Id, null, DiscountType.None, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee1Id, null, DiscountType.None, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee2Id, null, DiscountType.None, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, DiscountType.None, false, []),
|
||||
new SaleDataModel(Guid.NewGuid().ToString(), employee3Id, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000));
|
||||
_employeeStorageContract.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
|
||||
@@ -241,7 +241,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WithoutSalesByWorker_Test()
|
||||
public void CalculateSalaryByMounth_WithoutSalesByEmployee_Test()
|
||||
{
|
||||
//Arrange
|
||||
var postSalary = 2000.0;
|
||||
@@ -249,7 +249,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, postSalary, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, postSalary));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
var sum = 0.0;
|
||||
@@ -271,7 +271,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
@@ -284,22 +284,22 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, 200, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WorkerStorageReturnNull_ThrowException_Test()
|
||||
public void CalculateSalaryByMounth_EmployeeStorageReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, 200, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
@@ -312,7 +312,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
@@ -325,7 +325,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, 200, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
@@ -335,14 +335,14 @@ internal class SalaryBusinessLogicContractTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_WorkerStorageThrowException_ThrowException_Test()
|
||||
public void CalculateSalaryByMounth_EmployeeStorageThrowException_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, 200, DiscountType.None, 0, false, [])]);
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000, true, DateTime.UtcNow));
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 2000));
|
||||
_employeeStorageContract.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
|
||||
|
||||
@@ -43,10 +43,10 @@ internal class SaleBusinessLogicContractTests
|
||||
var date = DateTime.UtcNow;
|
||||
var listOriginal = new List<SaleDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -107,10 +107,10 @@ internal class SaleBusinessLogicContractTests
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SaleDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -188,10 +188,10 @@ internal class SaleBusinessLogicContractTests
|
||||
var clientId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SaleDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -269,10 +269,10 @@ internal class SaleBusinessLogicContractTests
|
||||
var cocktailId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SaleDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, DiscountType.None, false, []),
|
||||
};
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
@@ -347,8 +347,8 @@ internal class SaleBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new SaleDataModel(id, Guid.NewGuid().ToString(), null, 10, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
var record = new SaleDataModel(id, Guid.NewGuid().ToString(), null, DiscountType.None, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]);
|
||||
_saleStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
//Act
|
||||
var element = _saleBusinessLogicContract.GetSaleByData(id);
|
||||
@@ -398,8 +398,8 @@ internal class SaleBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var flag = false;
|
||||
var record = new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 10,
|
||||
false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
var record = new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.None,
|
||||
false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]);
|
||||
_storageStorageContract.Setup(x => x.CheckComponents(It.IsAny<SaleDataModel>())).Returns(true);
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>()))
|
||||
.Callback((SaleDataModel x) =>
|
||||
@@ -427,7 +427,7 @@ internal class SaleBusinessLogicContractTests
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
Guid.NewGuid().ToString(), DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])), Throws.TypeOf<ElementExistsException>());
|
||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
_storageStorageContract.Verify(x => x.CheckComponents(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -444,7 +444,7 @@ internal class SaleBusinessLogicContractTests
|
||||
public void InsertSale_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new SaleDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [])), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new SaleDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.None, false, [])), Throws.TypeOf<ValidationException>());
|
||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ internal class SaleBusinessLogicContractTests
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
Guid.NewGuid().ToString(), DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])), Throws.TypeOf<StorageException>());
|
||||
_storageStorageContract.Verify(x => x.CheckComponents(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -466,9 +466,8 @@ internal class SaleBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
_storageStorageContract.Setup(x => x.CheckComponents(It.IsAny<SaleDataModel>())).Returns(false);
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<InsufficientException>());
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])), Throws.TypeOf<InsufficientException>());
|
||||
//Act&Assert
|
||||
_storageStorageContract.Verify(x => x.CheckComponents(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ internal class StorageBusinessLogicContractTests
|
||||
// Arrange
|
||||
var listOriginal = new List<StorageDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), ProductType.Cake, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Cake, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Cake, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Candy, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Candy, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Candy, 1, []),
|
||||
};
|
||||
_warehouseStorageContract.Setup(x => x.GetList()).Returns(listOriginal);
|
||||
// Act
|
||||
@@ -88,7 +88,7 @@ internal class StorageBusinessLogicContractTests
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new StorageDataModel(id, ProductType.Cake, 1, []);
|
||||
var record = new StorageDataModel(id, ProductType.Candy, 1, []);
|
||||
_warehouseStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
// Act
|
||||
var element = _warehouseBusinessLogicContract.GetComponentByData(id);
|
||||
@@ -131,7 +131,7 @@ internal class StorageBusinessLogicContractTests
|
||||
public void InsertSupplies_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var record = new StorageDataModel(Guid.NewGuid().ToString(), ProductType.Cake, 1,
|
||||
var record = new StorageDataModel(Guid.NewGuid().ToString(), ProductType.Candy, 1,
|
||||
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_warehouseStorageContract.Setup(x => x.AddElement(It.IsAny<StorageDataModel>()));
|
||||
// Act
|
||||
@@ -146,7 +146,7 @@ internal class StorageBusinessLogicContractTests
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.AddElement(It.IsAny<StorageDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, 1,
|
||||
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<StorageDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ internal class StorageBusinessLogicContractTests
|
||||
public void InsertComponents_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(new StorageDataModel("id", ProductType.Cake, 1, [])), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(new StorageDataModel("id", ProductType.Candy, 1, [])), Throws.TypeOf<ValidationException>());
|
||||
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<StorageDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ internal class StorageBusinessLogicContractTests
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.AddElement(It.IsAny<StorageDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, 1,
|
||||
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<StorageDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ internal class StorageBusinessLogicContractTests
|
||||
public void UpdateSupplies_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var record = new StorageDataModel(Guid.NewGuid().ToString(), ProductType.Cake, 1,
|
||||
var record = new StorageDataModel(Guid.NewGuid().ToString(), ProductType.Candy, 1,
|
||||
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<StorageDataModel>()));
|
||||
// Act
|
||||
@@ -197,7 +197,7 @@ internal class StorageBusinessLogicContractTests
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<StorageDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, 1,
|
||||
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementNotFoundException>());
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -208,7 +208,7 @@ internal class StorageBusinessLogicContractTests
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<StorageDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, 1,
|
||||
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -225,7 +225,7 @@ internal class StorageBusinessLogicContractTests
|
||||
public void UpdateComponents_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new StorageDataModel(Guid.NewGuid().ToString(), ProductType.Cake, 1, [])), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new StorageDataModel(Guid.NewGuid().ToString(), ProductType.Candy, 1, [])), Throws.TypeOf<ValidationException>());
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ internal class StorageBusinessLogicContractTests
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<StorageDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, 1,
|
||||
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ internal class SuppliesBusinessLogicContractTests
|
||||
// Arrange
|
||||
var listOriginal = new List<SuppliesDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1, []),
|
||||
new(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1, []),
|
||||
};
|
||||
_suppliesStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>())).Returns(listOriginal);
|
||||
// Act
|
||||
@@ -88,7 +88,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new SuppliesDataModel(id,ProductType.Cake, DateTime.Now, 1, []);
|
||||
var record = new SuppliesDataModel(id,ProductType.Candy, DateTime.Now, 1, []);
|
||||
_suppliesStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
// Act
|
||||
var element = _suppliesBusinessLogicContract.GetComponentByData(id);
|
||||
@@ -131,7 +131,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
public void InsertSupplies_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var record = new SuppliesDataModel(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1,
|
||||
var record = new SuppliesDataModel(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1,
|
||||
[new ProductSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_suppliesStorageContract.Setup(x => x.AddElement(It.IsAny<SuppliesDataModel>()));
|
||||
// Act
|
||||
@@ -146,7 +146,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
// Arrange
|
||||
_suppliesStorageContract.Setup(x => x.AddElement(It.IsAny<SuppliesDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
// Act & Assert
|
||||
Assert.That(() => _suppliesBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1,
|
||||
Assert.That(() => _suppliesBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1,
|
||||
[new ProductSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_suppliesStorageContract.Verify(x => x.AddElement(It.IsAny<SuppliesDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -163,7 +163,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
public void InsertComponents_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _suppliesBusinessLogicContract.InsertComponent(new SuppliesDataModel("id", ProductType.Cake, DateTime.UtcNow, 1, [])), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _suppliesBusinessLogicContract.InsertComponent(new SuppliesDataModel("id", ProductType.Candy, DateTime.UtcNow, 1, [])), Throws.TypeOf<ValidationException>());
|
||||
_suppliesStorageContract.Verify(x => x.AddElement(It.IsAny<SuppliesDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -173,7 +173,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
// Arrange
|
||||
_suppliesStorageContract.Setup(x => x.AddElement(It.IsAny<SuppliesDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _suppliesBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1,
|
||||
Assert.That(() => _suppliesBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1,
|
||||
[new ProductSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_suppliesStorageContract.Verify(x => x.AddElement(It.IsAny<SuppliesDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -182,7 +182,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
public void UpdateSupplies_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var record = new SuppliesDataModel(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1,
|
||||
var record = new SuppliesDataModel(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1,
|
||||
[new ProductSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_suppliesStorageContract.Setup(x => x.UpdElement(It.IsAny<SuppliesDataModel>()));
|
||||
// Act
|
||||
@@ -197,7 +197,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
// Arrange
|
||||
_suppliesStorageContract.Setup(x => x.UpdElement(It.IsAny<SuppliesDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
// Act & Assert
|
||||
Assert.That(() => _suppliesBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1,
|
||||
Assert.That(() => _suppliesBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1,
|
||||
[new ProductSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementNotFoundException>());
|
||||
_suppliesStorageContract.Verify(x => x.UpdElement(It.IsAny<SuppliesDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -208,7 +208,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
// Arrange
|
||||
_suppliesStorageContract.Setup(x => x.UpdElement(It.IsAny<SuppliesDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
// Act & Assert
|
||||
Assert.That(() => _suppliesBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1,
|
||||
Assert.That(() => _suppliesBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1,
|
||||
[new ProductSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_suppliesStorageContract.Verify(x => x.UpdElement(It.IsAny<SuppliesDataModel>()), Times.Once);
|
||||
}
|
||||
@@ -225,7 +225,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
public void UpdateComponents_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _suppliesBusinessLogicContract.UpdateComponent(new SuppliesDataModel(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1, [])), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => _suppliesBusinessLogicContract.UpdateComponent(new SuppliesDataModel(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1, [])), Throws.TypeOf<ValidationException>());
|
||||
_suppliesStorageContract.Verify(x => x.UpdElement(It.IsAny<SuppliesDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ internal class SuppliesBusinessLogicContractTests
|
||||
// Arrange
|
||||
_suppliesStorageContract.Setup(x => x.UpdElement(It.IsAny<SuppliesDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _suppliesBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1,
|
||||
Assert.That(() => _suppliesBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1,
|
||||
[new ProductSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_suppliesStorageContract.Verify(x => x.UpdElement(It.IsAny<SuppliesDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
@@ -1,32 +1,42 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="NUnit" Version="3.14.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CandyHouseBusinessLogic\CandyHouseBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\CandyHouseContracts\CandyHouseContracts.csproj" />
|
||||
<ProjectReference Include="..\CandyHouseDatabase\CandyHouseDatabase.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.3" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="Moq" Version="4.20.72" />
|
||||
<PackageReference Include="NUnit" Version="3.14.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
<PackageReference Include="Serilog" Version="4.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CandyHouseBusinessLogic\CandyHouseBusinessLogic.csproj" />
|
||||
<ProjectReference Include="..\CandyHouseContracts\CandyHouseContracts.csproj" />
|
||||
<ProjectReference Include="..\CandyHouseDatabase\CandyHouseDatabase.csproj" />
|
||||
<ProjectReference Include="..\CandyHouseWebApi\CandyHouseWebApi.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -14,41 +14,41 @@ internal class PostDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, "name", PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel(null, "name", PostType.Manager, 10);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, "name", PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
post = CreateDataModel(string.Empty, "name", PostType.Manager, 10);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", "name", PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel("id", "name", PostType.Manager, 10);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.Manager, 10);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Manager, 10, true, DateTime.UtcNow);
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.Manager, 10);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, 10);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SalaryIsLessOrZeroTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 0, true, DateTime.UtcNow);
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, 0);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, -10, true, DateTime.UtcNow);
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.Manager, -10);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -56,13 +56,10 @@ internal class PostDataModelTests
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var postPostId = Guid.NewGuid().ToString();
|
||||
var postName = "name";
|
||||
var postType = PostType.Manager;
|
||||
var salary = 10;
|
||||
var isActual = false;
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var post = CreateDataModel(postId, postName, postType, salary, isActual, changeDate);
|
||||
var post = CreateDataModel(postId, postName, postType, salary);
|
||||
Assert.That(() => post.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -70,11 +67,9 @@ internal class PostDataModelTests
|
||||
Assert.That(post.PostName, Is.EqualTo(postName));
|
||||
Assert.That(post.PostType, Is.EqualTo(postType));
|
||||
Assert.That(post.Salary, Is.EqualTo(salary));
|
||||
Assert.That(post.IsActual, Is.EqualTo(isActual));
|
||||
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
||||
});
|
||||
}
|
||||
|
||||
private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
|
||||
new(id, postName, postType, salary, isActual, changeDate);
|
||||
private static PostDataModel CreateDataModel(string? id, string? postName, PostType postType, double salary) =>
|
||||
new(id, postName, postType, salary);
|
||||
}
|
||||
|
||||
@@ -15,48 +15,48 @@ internal class ProductDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "name", "description", 10.5, ProductType.Cake);
|
||||
var product = CreateDataModel(null, "name", "description", 10.5, ProductType.Candy);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, "name", "description", 10.5, ProductType.Cake);
|
||||
product = CreateDataModel(string.Empty, "name", "description", 10.5, ProductType.Candy);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", "name", "description", 10.5, ProductType.Cake);
|
||||
var product = CreateDataModel("id", "name", "description", 10.5, ProductType.Candy);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsNullOrEmptyTest()
|
||||
{
|
||||
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, "description", 10.5, ProductType.Cake);
|
||||
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, "description", 10.5, ProductType.Candy);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "description", 10.5, ProductType.Cake);
|
||||
cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "description", 10.5, ProductType.Candy);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
public void ProductDescriptionIsNullOrEmptyTest()
|
||||
{
|
||||
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", null, 10.5, ProductType.Cake);
|
||||
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", null, 10.5, ProductType.Candy);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", string.Empty, 10.5, ProductType.Cake);
|
||||
cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", string.Empty, 10.5, ProductType.Candy);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, ProductType.Cake);
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, ProductType.Candy);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, string.Empty, -10.5, ProductType.Cake);
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, string.Empty, -10.5, ProductType.Candy);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductTypeIsNoneTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, ProductType.Cake);
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, ProductType.Candy);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ internal class ProductDataModelTests
|
||||
var productName = "name";
|
||||
var productDescription = "description";
|
||||
var price = 10.5;
|
||||
var productType = ProductType.Chocolate;
|
||||
var productType = ProductType.Cake;
|
||||
var supplies = CreateSuppliesDataModel();
|
||||
var storage = CreateStorageDataModel();
|
||||
var product = CreateDataModel(productId, productName, productDescription, price, productType);
|
||||
|
||||
@@ -15,89 +15,120 @@ internal class SaleDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void EmployeeIdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmployeeIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ClientIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "clientId", 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "clientId", DiscountType.OnSale, 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(), 10, DiscountType.OnSale, 10, false, null);
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, null);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, []);
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalcSumAndDiscountTest()
|
||||
{
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var clientId = Guid.NewGuid().ToString();
|
||||
var products = new List<SaleProductDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 2, 1.1),
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 1.3)
|
||||
};
|
||||
var isCancel = false;
|
||||
var totalSum = products.Sum(x => x.Price * x.Count);
|
||||
var saleNone = CreateDataModel(saleId, employeeId, clientId, DiscountType.None, isCancel, products);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleNone.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleNone.Discount, Is.EqualTo(0));
|
||||
});
|
||||
var saleOnSale = CreateDataModel(saleId, employeeId, clientId, DiscountType.OnSale, isCancel, products);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleOnSale.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleOnSale.Discount, Is.EqualTo(totalSum * 0.1));
|
||||
});
|
||||
var saleRegularCustomer = CreateDataModel(saleId, employeeId, clientId, DiscountType.RegularCustomer, isCancel, products);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleRegularCustomer.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleRegularCustomer.Discount, Is.EqualTo(totalSum * 0.5));
|
||||
});
|
||||
var saleCertificate = CreateDataModel(saleId, employeeId, clientId, DiscountType.Certificate, isCancel, products);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleCertificate.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleCertificate.Discount, Is.EqualTo(totalSum * 0.3));
|
||||
});
|
||||
var saleMulty = CreateDataModel(saleId, employeeId, clientId, DiscountType.Certificate | DiscountType.RegularCustomer, isCancel, products);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleMulty.Sum, Is.EqualTo(totalSum));
|
||||
Assert.That(saleMulty.Discount, Is.EqualTo(totalSum * 0.8));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var clientId = Guid.NewGuid().ToString();
|
||||
var sum = 10;
|
||||
var discountType = DiscountType.Certificate;
|
||||
var discount = 1;
|
||||
var isCancel = true;
|
||||
var products = CreateSubDataModel();
|
||||
var sale = CreateDataModel(saleId, employeeId, clientId, sum, discountType, discount, isCancel, products);
|
||||
var sale = CreateDataModel(saleId, employeeId, clientId, discountType, isCancel, products);
|
||||
Assert.That(() => sale.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(sale.Id, Is.EqualTo(saleId));
|
||||
Assert.That(sale.EmployeeId, Is.EqualTo(employeeId));
|
||||
Assert.That(sale.ClientId, Is.EqualTo(clientId));
|
||||
Assert.That(sale.Sum, Is.EqualTo(sum));
|
||||
Assert.That(sale.DiscountType, Is.EqualTo(discountType));
|
||||
Assert.That(sale.Discount, Is.EqualTo(discount));
|
||||
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
||||
Assert.That(sale.Products, Is.EquivalentTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static SaleDataModel CreateDataModel(string? id, string? employeeId, string? clientId, double sum, DiscountType discountType,
|
||||
double discount, bool isCancel, List<SaleProductDataModel>? products) =>
|
||||
new(id, employeeId, clientId, sum, discountType, discount, isCancel, products);
|
||||
private static SaleDataModel CreateDataModel(string? id, string? employeeId, string? clientId, DiscountType discountType, bool isCancel, List<SaleProductDataModel>? products) =>
|
||||
new(id, employeeId, clientId, discountType, isCancel, products);
|
||||
|
||||
private static List<SaleProductDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 1.1)];
|
||||
}
|
||||
|
||||
@@ -14,41 +14,50 @@ internal class SaleProductDataModelTests
|
||||
[Test]
|
||||
public void SaleIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SaleIdIsNotGuidTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10);
|
||||
var saleProduct = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNullOrEmptyTest()
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10, 1.1);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10);
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10, 1.1);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, 1.1);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, 1.1);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 0);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, -10);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -58,16 +67,18 @@ internal class SaleProductDataModelTests
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var saleCocktail = CreateDataModel(saleId, productId, count);
|
||||
Assert.That(() => saleCocktail.Validate(), Throws.Nothing);
|
||||
var price = 1.2;
|
||||
var saleProduct = CreateDataModel(saleId, productId, count, price);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleCocktail.SaleId, Is.EqualTo(saleId));
|
||||
Assert.That(saleCocktail.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(saleCocktail.Count, Is.EqualTo(count));
|
||||
Assert.That(saleProduct.SaleId, Is.EqualTo(saleId));
|
||||
Assert.That(saleProduct.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(saleProduct.Count, Is.EqualTo(count));
|
||||
Assert.That(saleProduct.Price, Is.EqualTo(price));
|
||||
});
|
||||
}
|
||||
|
||||
private static SaleProductDataModel CreateDataModel(string? saleId, string? productId, int count) =>
|
||||
new(saleId, productId, count);
|
||||
private static SaleProductDataModel CreateDataModel(string? saleId, string? productId, int count, double price) =>
|
||||
new(saleId, productId, count, price);
|
||||
}
|
||||
|
||||
@@ -15,16 +15,16 @@ internal class StorageDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, ProductType.Cake, 1, CreateSubDataModel());
|
||||
var model = CreateDataModel(null, ProductType.Candy, 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
model = CreateDataModel(string.Empty, ProductType.Cake, 1, CreateSubDataModel());
|
||||
model = CreateDataModel(string.Empty, ProductType.Candy, 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel("id", ProductType.Cake, 1, CreateSubDataModel());
|
||||
var model = CreateDataModel("id", ProductType.Candy, 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -47,10 +47,10 @@ internal class StorageDataModelTests
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Cake, 1, null);
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Candy, 1, null);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Cake, 1, []);
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Candy, 1, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ internal class StorageDataModelTests
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var type = ProductType.Cake;
|
||||
var type = ProductType.Candy;
|
||||
var count = 1;
|
||||
var products = CreateSubDataModel();
|
||||
var model = CreateDataModel(id, type, count, products);
|
||||
@@ -66,7 +66,7 @@ internal class StorageDataModelTests
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.Id, Is.EqualTo(id));
|
||||
Assert.That(model.Type, Is.EqualTo(type));
|
||||
Assert.That(model.ProductType, Is.EqualTo(type));
|
||||
Assert.That(model.Count, Is.EqualTo(count));
|
||||
Assert.That(model.Products, Is.EqualTo(products));
|
||||
});
|
||||
|
||||
@@ -15,16 +15,16 @@ internal class SuppliesDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, ProductType.Cake, DateTime.Now, 1, CreateSubDataModel());
|
||||
var model = CreateDataModel(null, ProductType.Candy, DateTime.Now, 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
model = CreateDataModel(string.Empty, ProductType.Cake, DateTime.Now, 1, CreateSubDataModel());
|
||||
model = CreateDataModel(string.Empty, ProductType.Candy, DateTime.Now, 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel("id", ProductType.Cake, DateTime.Now, 1, CreateSubDataModel());
|
||||
var model = CreateDataModel("id", ProductType.Candy, DateTime.Now, 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -47,9 +47,9 @@ internal class SuppliesDataModelTests
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1, null);
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1, null);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Cake, DateTime.Now, 1, []);
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Candy, DateTime.Now, 1, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ internal class SuppliesDataModelTests
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var type = ProductType.Cake;
|
||||
var type = ProductType.Candy;
|
||||
var date = DateTime.Now;
|
||||
var count = 1;
|
||||
var products = CreateSubDataModel();
|
||||
@@ -66,8 +66,8 @@ internal class SuppliesDataModelTests
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.Id, Is.EqualTo(id));
|
||||
Assert.That(model.Type, Is.EqualTo(type));
|
||||
Assert.That(model.OrderDate, Is.EqualTo(date));
|
||||
Assert.That(model.ProductType, Is.EqualTo(type));
|
||||
Assert.That(model.ProductuionDate, Is.EqualTo(date));
|
||||
Assert.That(model.Count, Is.EqualTo(count));
|
||||
Assert.That(model.Products, Is.EqualTo(products));
|
||||
});
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseDatabase;
|
||||
using CandyHouseDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseTests.Infrastructure;
|
||||
|
||||
internal static class CandyHouseDbContextExtensions
|
||||
{
|
||||
public static Client InsertClientToDatabaseAndReturn(this CandyHouseDbContext dbContext, string? id = null, string fio = "test", string phoneNumber = "+7-777-777-77-77", double discountSize = 10)
|
||||
{
|
||||
var client = new Client() { Id = id ?? Guid.NewGuid().ToString(), FIO = fio, PhoneNumber = phoneNumber, DiscountSize = discountSize };
|
||||
dbContext.Clients.Add(client);
|
||||
dbContext.SaveChanges();
|
||||
return client;
|
||||
}
|
||||
|
||||
public static Post InsertPostToDatabaseAndReturn(this CandyHouseDbContext dbContext, string? id = null, string postName = "test", PostType postType = PostType.Manager, double salary = 10, bool isActual = true, DateTime? changeDate = null)
|
||||
{
|
||||
var post = new Post() { Id = Guid.NewGuid().ToString(), PostId = id ?? Guid.NewGuid().ToString(), PostName = postName, PostType = postType, Salary = salary, IsActual = isActual, ChangeDate = changeDate ?? DateTime.UtcNow };
|
||||
dbContext.Posts.Add(post);
|
||||
dbContext.SaveChanges();
|
||||
return post;
|
||||
}
|
||||
|
||||
public static Product InsertProductToDatabaseAndReturn(this CandyHouseDbContext dbContext, string? id = null, string productName = "test", string productDescription = "description", ProductType productType = ProductType.Candy, double price = 1)
|
||||
{
|
||||
var product = new Product() { Id = id ?? Guid.NewGuid().ToString(), ProductName = productName, ProductDescription = productDescription, ProductType = productType, Price = price };
|
||||
dbContext.Products.Add(product);
|
||||
dbContext.SaveChanges();
|
||||
return product;
|
||||
}
|
||||
|
||||
public static ProductHistory InsertProductHistoryToDatabaseAndReturn(this CandyHouseDbContext dbContext, string productId, double price = 10, DateTime? changeDate = null)
|
||||
{
|
||||
var productHistory = new ProductHistory() { Id = Guid.NewGuid().ToString(), ProductId = productId, OldPrice = price, ChangeDate = changeDate ?? DateTime.UtcNow };
|
||||
dbContext.ProductHistories.Add(productHistory);
|
||||
dbContext.SaveChanges();
|
||||
return productHistory;
|
||||
}
|
||||
|
||||
public static Salary InsertSalaryToDatabaseAndReturn(this CandyHouseDbContext dbContext, string employeeId, double employeeSalary = 1, DateTime? salaryDate = null)
|
||||
{
|
||||
var salary = new Salary() { EmployeeId = employeeId, EmployeeSalary = employeeSalary, SalaryDate = salaryDate ?? DateTime.UtcNow };
|
||||
dbContext.Salaries.Add(salary);
|
||||
dbContext.SaveChanges();
|
||||
return salary;
|
||||
}
|
||||
|
||||
public static Sale InsertSaleToDatabaseAndReturn(this CandyHouseDbContext dbContext, string employeeId, string? clientId = null, DateTime? saleDate = null, double sum = 1, DiscountType discountType = DiscountType.None, double discount = 0, bool isCancel = false, List<(string, int, double)>? products = null)
|
||||
{
|
||||
var sale = new Sale() { EmployeeId = employeeId, ClientId = clientId, SaleDate = saleDate ?? DateTime.UtcNow, Sum = sum, DiscountType = discountType, Discount = discount, IsCancel = isCancel, SaleProducts = [] };
|
||||
if (products is not null)
|
||||
{
|
||||
foreach (var elem in products)
|
||||
{
|
||||
sale.SaleProducts.Add(new SaleProduct { ProductId = elem.Item1, SaleId = sale.Id, Count = elem.Item2, Price = elem.Item3 });
|
||||
}
|
||||
}
|
||||
dbContext.Sales.Add(sale);
|
||||
dbContext.SaveChanges();
|
||||
return sale;
|
||||
}
|
||||
|
||||
public static Employee InsertEmployeeToDatabaseAndReturn(this CandyHouseDbContext dbContext, string? id = null, string fio = "test", string email = "abc@gmail.com", string? postId = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false)
|
||||
{
|
||||
var employee = new Employee() { Id = id ?? Guid.NewGuid().ToString(), FIO = fio, Email = email, PostId = postId ?? Guid.NewGuid().ToString(), BirthDate = birthDate ?? DateTime.UtcNow.AddYears(-20), EmploymentDate = employmentDate ?? DateTime.UtcNow, IsDeleted = isDeleted };
|
||||
dbContext.Employees.Add(employee);
|
||||
dbContext.SaveChanges();
|
||||
return employee;
|
||||
}
|
||||
|
||||
public static Storage InsertStorageToDatabaseAndReturn(this CandyHouseDbContext dbContext, string? id = null, ProductType productType = ProductType.Candy, int count = 20, List<(string, int)>? products = null)
|
||||
{
|
||||
var storage = new Storage() { Id = id ?? Guid.NewGuid().ToString(), ProductType = productType, Count = count, Products = [] };
|
||||
if (products is not null)
|
||||
{
|
||||
foreach (var elem in products)
|
||||
{
|
||||
storage.Products.Add(new ProductStorage { StorageId = storage.Id, ProductId = elem.Item1, Count = elem.Item2 });
|
||||
}
|
||||
}
|
||||
dbContext.Storages.Add(storage);
|
||||
dbContext.SaveChanges();
|
||||
return storage;
|
||||
}
|
||||
|
||||
public static Supplies InsertSuppliesToDatabaseAndReturn(this CandyHouseDbContext dbContext, string? id = null, ProductType type = ProductType.Candy, int count = 20, DateTime? date = null, List<(string, int)>? products = null)
|
||||
{
|
||||
var supply = new Supplies() { Id = id ?? Guid.NewGuid().ToString(), ProductType = type, Count = count, ProductuionDate = date ?? DateTime.UtcNow, Products = [] };
|
||||
if (products is not null)
|
||||
{
|
||||
foreach (var elem in products)
|
||||
{
|
||||
supply.Products.Add(new ProductSupplies { SuppliesId = supply.Id, ProductId = elem.Item1, Count = elem.Item2 });
|
||||
}
|
||||
}
|
||||
dbContext.Supplieses.Add(supply);
|
||||
dbContext.SaveChanges();
|
||||
return supply;
|
||||
}
|
||||
|
||||
public static Client? GetClientFromDatabase(this CandyHouseDbContext dbContext, string id) => dbContext.Clients.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static Post? GetPostFromDatabaseByPostId(this CandyHouseDbContext dbContext, string id) => dbContext.Posts.FirstOrDefault(x => x.PostId == id && x.IsActual);
|
||||
|
||||
public static Post[] GetPostsFromDatabaseByPostId(this CandyHouseDbContext dbContext, string id) => [.. dbContext.Posts.Where(x => x.PostId == id).OrderByDescending(x => x.ChangeDate)];
|
||||
|
||||
public static Product? GetProductFromDatabaseById(this CandyHouseDbContext dbContext, string id) => dbContext.Products.FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static Salary[] GetSalariesFromDatabaseByEmployeeId(this CandyHouseDbContext dbContext, string id) => [.. dbContext.Salaries.Where(x => x.EmployeeId == id)];
|
||||
|
||||
public static Sale? GetSaleFromDatabaseById(this CandyHouseDbContext dbContext, string id) => dbContext.Sales.Include(x => x.SaleProducts).FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static Sale[] GetSalesByClientId(this CandyHouseDbContext dbContext, string? clientId) => [.. dbContext.Sales.Include(x => x.SaleProducts).Where(x => x.ClientId == clientId)];
|
||||
|
||||
public static Employee? GetEmployeeFromDatabaseById(this CandyHouseDbContext dbContext, string id) => dbContext.Employees.FirstOrDefault(x => x.Id == id);
|
||||
public static Storage? GetStorageFromDatabaseById(this CandyHouseDbContext dbContext, string id) => dbContext.Storages.Include(x => x.Products).FirstOrDefault(x => x.Id == id);
|
||||
public static Supplies? GetSuppliesFromDatabaseById(this CandyHouseDbContext dbContext, string id) => dbContext.Supplieses.Include(x => x.Products).FirstOrDefault(x => x.Id == id);
|
||||
|
||||
public static void RemoveClientsFromDatabase(this CandyHouseDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Clients\" CASCADE;");
|
||||
|
||||
public static void RemovePostsFromDatabase(this CandyHouseDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Posts\" CASCADE;");
|
||||
|
||||
public static void RemoveProductsFromDatabase(this CandyHouseDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Products\" CASCADE;");
|
||||
|
||||
public static void RemoveSalariesFromDatabase(this CandyHouseDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Salaries\" CASCADE;");
|
||||
|
||||
public static void RemoveSalesFromDatabase(this CandyHouseDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Sales\" CASCADE;");
|
||||
|
||||
public static void RemoveEmployeesFromDatabase(this CandyHouseDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Employees\" CASCADE;");
|
||||
|
||||
public static void RemoveStoragesFromDatabase(this CandyHouseDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Storages\" CASCADE;");
|
||||
public static void RemoveSuppliesFromDatabase(this CandyHouseDbContext dbContext) => dbContext.ExecuteSqlRaw("TRUNCATE \"Supplieses\" CASCADE;");
|
||||
|
||||
private static void ExecuteSqlRaw(this CandyHouseDbContext dbContext, string command) => dbContext.Database.ExecuteSqlRaw(command);
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using CandyHouseContracts.Infrastructure;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CandyHouseTests.Infrastructure;
|
||||
|
||||
internal class CustomWebApplicationFactory<TProgram> : WebApplicationFactory<TProgram>
|
||||
where TProgram : class
|
||||
{
|
||||
protected override void ConfigureWebHost(IWebHostBuilder builder)
|
||||
{
|
||||
builder.ConfigureServices(services =>
|
||||
{
|
||||
var databaseConfig = services.SingleOrDefault(x => x.ServiceType == typeof(IConfigurationDatabase));
|
||||
if (databaseConfig is not null)
|
||||
services.Remove(databaseConfig);
|
||||
|
||||
var loggerFactory = services.SingleOrDefault(x => x.ServiceType == typeof(LoggerFactory));
|
||||
if (loggerFactory is not null)
|
||||
services.Remove(loggerFactory);
|
||||
|
||||
services.AddSingleton<IConfigurationDatabase, ConfigurationDatabaseTest>();
|
||||
});
|
||||
|
||||
builder.UseEnvironment("Development");
|
||||
|
||||
base.ConfigureWebHost(builder);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseContracts.StoragesContracts;
|
||||
using CandyHouseDatabase.Implementations;
|
||||
using CandyHouseDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -15,13 +16,10 @@ namespace CandyHouseTests.StoragesContractsTests;
|
||||
[TestFixture]
|
||||
internal class ClientStorageContractTests : BaseStorageContractTest
|
||||
{
|
||||
private ClientStorageContarct _clientStorageContract;
|
||||
private IClientStorageContract _clientStorageContract;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_clientStorageContract = new ClientStorageContarct(CandyHouseDbContext);
|
||||
}
|
||||
public void SetUp() => _clientStorageContract = new ClientStorageContract(CandyHouseDbContext);
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseDatabase.Implementations;
|
||||
using CandyHouseDatabase.Models;
|
||||
using CandyHouseTests.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -25,19 +26,19 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Employees\"CASCADE; ");
|
||||
CandyHouseDbContext.RemoveEmployeesFromDatabase();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetList_WhenHaveRecords_Test()
|
||||
{
|
||||
var employee = InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com");
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com");
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com");
|
||||
var employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com");
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com");
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com");
|
||||
var list = _employeeStorageContract.GetList();
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(3));
|
||||
AssertElement(list.First(), employee);
|
||||
AssertElement(list.First(x => x.Id == employee.Id), employee);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -52,9 +53,9 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
public void Try_GetList_ByPostId_Test()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com", postId);
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com", postId);
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com");
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com", postId);
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com", postId);
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com");
|
||||
var list = _employeeStorageContract.GetList(postId: postId);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
@@ -64,10 +65,10 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByBirthDate_Test()
|
||||
{
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-25));
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-21));
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-20));
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-19));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-25));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-21));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-20));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-19));
|
||||
var list = _employeeStorageContract.GetList(fromBirthDate: DateTime.UtcNow.AddYears(-21).AddMinutes(-1), toBirthDate: DateTime.UtcNow.AddYears(-20).AddMinutes(1));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
@@ -76,10 +77,10 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByEmploymentDate_Test()
|
||||
{
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com", employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com", employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com", employmentDate: DateTime.UtcNow.AddDays(1));
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", "abc@gmail.com", employmentDate: DateTime.UtcNow.AddDays(2));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com", employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com", employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com", employmentDate: DateTime.UtcNow.AddDays(1));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", "abc@gmail.com", employmentDate: DateTime.UtcNow.AddDays(2));
|
||||
var list = _employeeStorageContract.GetList(fromEmploymentDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-1), toEmploymentDate: DateTime.UtcNow.AddDays(1).AddMinutes(1));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
@@ -89,12 +90,11 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
public void Try_GetList_ByAllParameters_Test()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com", postId, birthDate: DateTime.UtcNow.AddYears(-25), employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com", postId, birthDate: DateTime.UtcNow.AddYears(-22), employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com", postId, birthDate: DateTime.UtcNow.AddYears(-21), employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-20), employmentDate: DateTime.UtcNow.AddDays(1));
|
||||
var list = _employeeStorageContract.GetList(postId: postId, fromBirthDate: DateTime.UtcNow.AddYears(-21).AddMinutes(-1), toBirthDate: DateTime.UtcNow.AddYears(-20).AddMinutes(1),
|
||||
fromEmploymentDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-1), toEmploymentDate: DateTime.UtcNow.AddDays(1).AddMinutes(1));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 1", "abc@gmail.com", postId, birthDate: DateTime.UtcNow.AddYears(-25), employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 2", "abc@gmail.com", postId, birthDate: DateTime.UtcNow.AddYears(-22), employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 3", "abc@gmail.com", postId, birthDate: DateTime.UtcNow.AddYears(-21), employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString(), "fio 4", "abc@gmail.com", birthDate: DateTime.UtcNow.AddYears(-20), employmentDate: DateTime.UtcNow.AddDays(1));
|
||||
var list = _employeeStorageContract.GetList(postId: postId, fromBirthDate: DateTime.UtcNow.AddYears(-21).AddMinutes(-1), toBirthDate: DateTime.UtcNow.AddYears(-20).AddMinutes(1), fromEmploymentDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-1), toEmploymentDate: DateTime.UtcNow.AddDays(1).AddMinutes(1));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(1));
|
||||
}
|
||||
@@ -102,7 +102,7 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetElementById_WhenHaveRecord_Test()
|
||||
{
|
||||
var employee = InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
var employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
AssertElement(_employeeStorageContract.GetElementById(employee.Id), employee);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetElementByFIO_WhenHaveRecord_Test()
|
||||
{
|
||||
var employee = InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
var employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
AssertElement(_employeeStorageContract.GetElementByFIO(employee.FIO), employee);
|
||||
}
|
||||
|
||||
@@ -130,14 +130,14 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
{
|
||||
var employee = CreateModel(Guid.NewGuid().ToString());
|
||||
_employeeStorageContract.AddElement(employee);
|
||||
AssertElement(GetEmployeeFromDatabase(employee.Id), employee);
|
||||
AssertElement(CandyHouseDbContext.GetEmployeeFromDatabaseById(employee.Id), employee);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_AddElement_WhenHaveRecordWithSameId_Test()
|
||||
{
|
||||
var employee = CreateModel(Guid.NewGuid().ToString());
|
||||
InsertEmployeeToDatabaseAndReturn(employee.Id);
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(employee.Id);
|
||||
Assert.That(() => _employeeStorageContract.AddElement(employee), Throws.TypeOf<ElementExistsException>());
|
||||
}
|
||||
|
||||
@@ -145,9 +145,9 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
public void Try_UpdElement_Test()
|
||||
{
|
||||
var employee = CreateModel(Guid.NewGuid().ToString(), "New Fio");
|
||||
InsertEmployeeToDatabaseAndReturn(employee.Id);
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(employee.Id);
|
||||
_employeeStorageContract.UpdElement(employee);
|
||||
AssertElement(GetEmployeeFromDatabase(employee.Id), employee);
|
||||
AssertElement(CandyHouseDbContext.GetEmployeeFromDatabaseById(employee.Id), employee);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -160,16 +160,16 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
public void Try_UpdElement_WhenNoRecordWasDeleted_Test()
|
||||
{
|
||||
var employee = CreateModel(Guid.NewGuid().ToString());
|
||||
InsertEmployeeToDatabaseAndReturn(employee.Id, isDeleted: true);
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(employee.Id, isDeleted: true);
|
||||
Assert.That(() => _employeeStorageContract.UpdElement(employee), Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_DelElement_Test()
|
||||
{
|
||||
var employee = InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
var employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
_employeeStorageContract.DelElement(employee.Id);
|
||||
var element = GetEmployeeFromDatabase(employee.Id);
|
||||
var element = CandyHouseDbContext.GetEmployeeFromDatabaseById(employee.Id);
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.IsDeleted);
|
||||
}
|
||||
@@ -184,18 +184,10 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
public void Try_DelElement_WhenNoRecordWasDeleted_Test()
|
||||
{
|
||||
var employee = CreateModel(Guid.NewGuid().ToString());
|
||||
InsertEmployeeToDatabaseAndReturn(employee.Id, isDeleted: true);
|
||||
CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(employee.Id, isDeleted: true);
|
||||
Assert.That(() => _employeeStorageContract.DelElement(employee.Id), Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
private Employee InsertEmployeeToDatabaseAndReturn(string id, string fio = "test", string email = "abc@mail.ru",string ? postId = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false)
|
||||
{
|
||||
var employee = new Employee() { Id = id, FIO = fio, Email = email, PostId = postId ?? Guid.NewGuid().ToString(), BirthDate = birthDate ?? DateTime.UtcNow.AddYears(-20), EmploymentDate = employmentDate ?? DateTime.UtcNow, IsDeleted = isDeleted };
|
||||
CandyHouseDbContext.Employees.Add(employee);
|
||||
CandyHouseDbContext.SaveChanges();
|
||||
return employee;
|
||||
}
|
||||
|
||||
private static void AssertElement(EmployeeDataModel? actual, Employee expected)
|
||||
{
|
||||
Assert.That(actual, Is.Not.Null);
|
||||
@@ -212,9 +204,7 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
}
|
||||
|
||||
private static EmployeeDataModel CreateModel(string id, string fio = "fio", string email = "abc@mail.ru", string? postId = null, DateTime? birthDate = null, DateTime? employmentDate = null, bool isDeleted = false) =>
|
||||
new(id, fio, email, postId ?? Guid.NewGuid().ToString(), birthDate ?? DateTime.UtcNow.AddYears(-20), employmentDate ?? DateTime.UtcNow, isDeleted);
|
||||
|
||||
private Employee? GetEmployeeFromDatabase(string id) => CandyHouseDbContext.Employees.FirstOrDefault(x => x.Id == id);
|
||||
new(id, fio, email, postId ?? Guid.NewGuid().ToString(), birthDate ?? DateTime.UtcNow.AddYears(-20), employmentDate ?? DateTime.UtcNow, isDeleted);
|
||||
|
||||
private static void AssertElement(Employee? actual, EmployeeDataModel expected)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseDatabase.Implementations;
|
||||
using CandyHouseDatabase.Models;
|
||||
using CandyHouseTests.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Moq;
|
||||
using System;
|
||||
@@ -29,15 +30,15 @@ internal class ProductStorageContractTests : BaseStorageContractTest
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Products\" CASCADE;");
|
||||
CandyHouseDbContext.RemoveProductsFromDatabase();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetList_WhenHaveRecords_Test()
|
||||
{
|
||||
var product = InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 1");
|
||||
InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 2");
|
||||
InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 3");
|
||||
var product = CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 1");
|
||||
CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 2");
|
||||
CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 3");
|
||||
var list = _productStorageContract.GetList();
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(3));
|
||||
@@ -55,10 +56,10 @@ internal class ProductStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetHistoryByProductId_WhenHaveRecords_Test()
|
||||
{
|
||||
var product = InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 1");
|
||||
InsertProductHistoryToDatabaseAndReturn(product.Id, 20, DateTime.UtcNow.AddDays(-1));
|
||||
InsertProductHistoryToDatabaseAndReturn(product.Id, 30, DateTime.UtcNow.AddMinutes(-10));
|
||||
InsertProductHistoryToDatabaseAndReturn(product.Id, 40, DateTime.UtcNow.AddDays(1));
|
||||
var product = CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 1");
|
||||
CandyHouseDbContext.InsertProductHistoryToDatabaseAndReturn(product.Id, 20, DateTime.UtcNow.AddDays(-1));
|
||||
CandyHouseDbContext.InsertProductHistoryToDatabaseAndReturn(product.Id, 30, DateTime.UtcNow.AddMinutes(-10));
|
||||
CandyHouseDbContext.InsertProductHistoryToDatabaseAndReturn(product.Id, 40, DateTime.UtcNow.AddDays(1));
|
||||
var list = _productStorageContract.GetHistoryByProductId(product.Id);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(3));
|
||||
@@ -67,10 +68,10 @@ internal class ProductStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetHistoryByProductId_WhenNoRecords_Test()
|
||||
{
|
||||
var product = InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 1");
|
||||
InsertProductHistoryToDatabaseAndReturn(product.Id, 20, DateTime.UtcNow.AddDays(-1));
|
||||
InsertProductHistoryToDatabaseAndReturn(product.Id, 30, DateTime.UtcNow.AddMinutes(-10));
|
||||
InsertProductHistoryToDatabaseAndReturn(product.Id, 40, DateTime.UtcNow.AddDays(1));
|
||||
var product = CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name 1");
|
||||
CandyHouseDbContext.InsertProductHistoryToDatabaseAndReturn(product.Id, 20, DateTime.UtcNow.AddDays(-1));
|
||||
CandyHouseDbContext.InsertProductHistoryToDatabaseAndReturn(product.Id, 30, DateTime.UtcNow.AddMinutes(-10));
|
||||
CandyHouseDbContext.InsertProductHistoryToDatabaseAndReturn(product.Id, 40, DateTime.UtcNow.AddDays(1));
|
||||
var list = _productStorageContract.GetHistoryByProductId(Guid.NewGuid().ToString());
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
@@ -79,28 +80,28 @@ internal class ProductStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetElementById_WhenHaveRecord_Test()
|
||||
{
|
||||
var product = InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
var product = CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
AssertElement(_productStorageContract.GetElementById(product.Id), product);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetElementById_WhenNoRecord_Test()
|
||||
{
|
||||
InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
Assert.That(() => _productStorageContract.GetElementById(Guid.NewGuid().ToString()), Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetElementByName_WhenHaveRecord_Test()
|
||||
{
|
||||
var product = InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
var product = CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
AssertElement(_productStorageContract.GetElementByName(product.ProductName), product);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetElementByName_WhenNoRecord_Test()
|
||||
{
|
||||
InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
Assert.That(() => _productStorageContract.GetElementByName("name"), Is.Null);
|
||||
}
|
||||
|
||||
@@ -109,14 +110,14 @@ internal class ProductStorageContractTests : BaseStorageContractTest
|
||||
{
|
||||
var product = CreateModel(Guid.NewGuid().ToString());
|
||||
_productStorageContract.AddElement(product);
|
||||
AssertElement(GetProductFromDatabaseById(product.Id), product);
|
||||
AssertElement(CandyHouseDbContext.GetProductFromDatabaseById(product.Id), product);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_AddElement_WhenHaveRecordWithSameId_Test()
|
||||
{
|
||||
var product = CreateModel(Guid.NewGuid().ToString());
|
||||
InsertProductToDatabaseAndReturn(product.Id, productName: "name unique");
|
||||
CandyHouseDbContext.InsertProductToDatabaseAndReturn(product.Id, productName: "name unique");
|
||||
Assert.That(() => _productStorageContract.AddElement(product), Throws.TypeOf<ElementExistsException>());
|
||||
}
|
||||
|
||||
@@ -124,17 +125,17 @@ internal class ProductStorageContractTests : BaseStorageContractTest
|
||||
public void Try_AddElement_WhenHaveRecordWithSameName_Test()
|
||||
{
|
||||
var product = CreateModel(Guid.NewGuid().ToString(), "name unique");
|
||||
InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), productName: product.ProductName);
|
||||
CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), productName: product.ProductName);
|
||||
Assert.That(() => _productStorageContract.AddElement(product), Throws.TypeOf<ElementExistsException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_UpdElement_Test()
|
||||
{
|
||||
var product = CreateModel(Guid.NewGuid().ToString(), "new name", "description");
|
||||
InsertProductToDatabaseAndReturn(product.Id);
|
||||
var product = CreateModel(Guid.NewGuid().ToString(), "new name", productType: ProductType.Candy);
|
||||
CandyHouseDbContext.InsertProductToDatabaseAndReturn(product.Id);
|
||||
_productStorageContract.UpdElement(product);
|
||||
AssertElement(GetProductFromDatabaseById(product.Id), product);
|
||||
AssertElement(CandyHouseDbContext.GetProductFromDatabaseById(product.Id), product);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -147,17 +148,17 @@ internal class ProductStorageContractTests : BaseStorageContractTest
|
||||
public void Try_UpdElement_WhenHaveRecordWithSameName_Test()
|
||||
{
|
||||
var product = CreateModel(Guid.NewGuid().ToString(), "name unique");
|
||||
InsertProductToDatabaseAndReturn(product.Id, productName: "name");
|
||||
InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), productName: product.ProductName);
|
||||
CandyHouseDbContext.InsertProductToDatabaseAndReturn(product.Id, productName: "name");
|
||||
CandyHouseDbContext.InsertProductToDatabaseAndReturn(productName: product.ProductName);
|
||||
Assert.That(() => _productStorageContract.UpdElement(product), Throws.TypeOf<ElementExistsException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_DelElement_Test()
|
||||
{
|
||||
var product = InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
var product = CandyHouseDbContext.InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString());
|
||||
_productStorageContract.DelElement(product.Id);
|
||||
var element = GetProductFromDatabaseById(product.Id);
|
||||
var element = CandyHouseDbContext.GetProductFromDatabaseById(product.Id);
|
||||
Assert.That(element, Is.Null);
|
||||
}
|
||||
|
||||
@@ -167,7 +168,7 @@ internal class ProductStorageContractTests : BaseStorageContractTest
|
||||
Assert.That(() => _productStorageContract.DelElement(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
private Product InsertProductToDatabaseAndReturn(string id, string productName = "test", string productDescription = "description", ProductType productType = ProductType.Cake, double price = 1)
|
||||
private Product InsertProductToDatabaseAndReturn(string id, string productName = "test", string productDescription = "description", ProductType productType = ProductType.Candy, double price = 1)
|
||||
{
|
||||
var product = new Product() { Id = id, ProductName = productName, ProductDescription = productDescription, ProductType = productType, Price = price };
|
||||
CandyHouseDbContext.Products.Add(product);
|
||||
@@ -196,10 +197,8 @@ internal class ProductStorageContractTests : BaseStorageContractTest
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductDataModel CreateModel(string id, string productName = "test", string productDescription = "description", ProductType type = ProductType.Cake, double price = 1)
|
||||
=> new(id, productName, productDescription, price, type);
|
||||
|
||||
private Product? GetProductFromDatabaseById(string id) => CandyHouseDbContext.Products.FirstOrDefault(x => x.Id == id);
|
||||
private static ProductDataModel CreateModel(string id, string productName = "test", string productDescription = "description", ProductType productType = ProductType.Cake, double price = 1)
|
||||
=> new(id, productName,productDescription, price, productType);
|
||||
|
||||
private static void AssertElement(Product? actual, ProductDataModel expected)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseDatabase.Implementations;
|
||||
using CandyHouseDatabase.Models;
|
||||
using CandyHouseTests.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -20,26 +21,26 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
|
||||
public void SetUp()
|
||||
{
|
||||
_salaryStorageContract = new SalaryStorageContract(CandyHouseDbContext);
|
||||
_employee = InsertEmployeeToDatabaseAndReturn();
|
||||
_employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Salaries\" CASCADE;");
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Employees\" CASCADE;");
|
||||
CandyHouseDbContext.RemoveSalariesFromDatabase();
|
||||
CandyHouseDbContext.RemoveEmployeesFromDatabase();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetList_WhenHaveRecords_Test()
|
||||
{
|
||||
var salary = InsertSalaryToDatabaseAndReturn(_employee.Id, employeeSalary: 100);
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id);
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id);
|
||||
var salary = CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, employeeSalary: 100);
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id);
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id);
|
||||
var list = _salaryStorageContract.GetList(DateTime.UtcNow.AddDays(-10), DateTime.UtcNow.AddDays(10));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(3));
|
||||
AssertElement(list.First(), salary);
|
||||
AssertElement(list.Single(x => x.Salary == salary.EmployeeSalary), salary);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -53,12 +54,12 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_OnlyInDatePeriod_Test()
|
||||
{
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-2));
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-5));
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-1).AddMinutes(5));
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(1).AddMinutes(-5));
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(1).AddMinutes(5));
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-2));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-2));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-5));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-1).AddMinutes(5));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(1).AddMinutes(-5));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(1).AddMinutes(5));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-2));
|
||||
var list = _salaryStorageContract.GetList(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
@@ -70,10 +71,10 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByEmployee_Test()
|
||||
{
|
||||
var employee = InsertEmployeeToDatabaseAndReturn("name 2");
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id);
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id);
|
||||
InsertSalaryToDatabaseAndReturn(employee.Id);
|
||||
var employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn("name 2");
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id);
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id);
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(employee.Id);
|
||||
var list = _salaryStorageContract.GetList(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), _employee.Id);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
@@ -86,13 +87,13 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByEmployeeOnlyInDatePeriod_Test()
|
||||
{
|
||||
var employee = InsertEmployeeToDatabaseAndReturn("name 2");
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-2));
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-1).AddMinutes(5));
|
||||
InsertSalaryToDatabaseAndReturn(employee.Id, salaryDate: DateTime.UtcNow.AddDays(-1).AddMinutes(5));
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(1).AddMinutes(-5));
|
||||
InsertSalaryToDatabaseAndReturn(employee.Id, salaryDate: DateTime.UtcNow.AddDays(1).AddMinutes(-5));
|
||||
InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-2));
|
||||
var employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(fio: "name 2");
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-2));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-1).AddMinutes(5));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(employee.Id, salaryDate: DateTime.UtcNow.AddDays(-1).AddMinutes(5));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(1).AddMinutes(-5));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(employee.Id, salaryDate: DateTime.UtcNow.AddDays(1).AddMinutes(-5));
|
||||
CandyHouseDbContext.InsertSalaryToDatabaseAndReturn(_employee.Id, salaryDate: DateTime.UtcNow.AddDays(-2));
|
||||
var list = _salaryStorageContract.GetList(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow.AddDays(1), _employee.Id);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
@@ -107,23 +108,7 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
|
||||
{
|
||||
var salary = CreateModel(_employee.Id);
|
||||
_salaryStorageContract.AddElement(salary);
|
||||
AssertElement(GetSalaryFromDatabaseByEmployeeId(_employee.Id), salary);
|
||||
}
|
||||
|
||||
private Employee InsertEmployeeToDatabaseAndReturn(string employeeFIO = "fio", string employeeEmail = "abc@mail.ru")
|
||||
{
|
||||
var employee = new Employee() { Id = Guid.NewGuid().ToString(), PostId = Guid.NewGuid().ToString(), FIO = employeeFIO, Email = employeeEmail, IsDeleted = false };
|
||||
CandyHouseDbContext.Employees.Add(employee);
|
||||
CandyHouseDbContext.SaveChanges();
|
||||
return employee;
|
||||
}
|
||||
|
||||
private Salary InsertSalaryToDatabaseAndReturn(string employeeId, double employeeSalary = 1, DateTime? salaryDate = null)
|
||||
{
|
||||
var salary = new Salary() { EmployeeId = employeeId, EmployeeSalary = employeeSalary, SalaryDate = salaryDate ?? DateTime.UtcNow };
|
||||
CandyHouseDbContext.Salaries.Add(salary);
|
||||
CandyHouseDbContext.SaveChanges();
|
||||
return salary;
|
||||
AssertElement(CandyHouseDbContext.GetSalariesFromDatabaseByEmployeeId(_employee.Id).First(), salary);
|
||||
}
|
||||
|
||||
private static void AssertElement(SalaryDataModel? actual, Salary expected)
|
||||
@@ -139,8 +124,6 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
|
||||
private static SalaryDataModel CreateModel(string employeeId, double employeeSalary = 1, DateTime? salaryDate = null)
|
||||
=> new(employeeId, salaryDate ?? DateTime.UtcNow, employeeSalary);
|
||||
|
||||
private Salary? GetSalaryFromDatabaseByEmployeeId(string id) => CandyHouseDbContext.Salaries.FirstOrDefault(x => x.EmployeeId == id);
|
||||
|
||||
private static void AssertElement(Salary? actual, SalaryDataModel expected)
|
||||
{
|
||||
Assert.That(actual, Is.Not.Null);
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.DataModels;
|
||||
using CandyHouseContracts.Enums;
|
||||
using CandyHouseContracts.Exceptions;
|
||||
using CandyHouseDatabase.Implementations;
|
||||
using CandyHouseDatabase.Models;
|
||||
using CandyHouseTests.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -26,26 +27,26 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
public void SetUp()
|
||||
{
|
||||
_saleStorageContract = new SaleStorageContract(CandyHouseDbContext);
|
||||
_client = InsertClientToDatabaseAndReturn();
|
||||
_employee = InsertEmployeeToDatabaseAndReturn();
|
||||
_product = InsertProductToDatabaseAndReturn();
|
||||
_client = CandyHouseDbContext.InsertClientToDatabaseAndReturn();
|
||||
_employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn();
|
||||
_product = CandyHouseDbContext.InsertProductToDatabaseAndReturn();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Sales\" CASCADE;");
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Clients\" CASCADE;");
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Employees\" CASCADE;");
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Products\" CASCADE;");
|
||||
CandyHouseDbContext.RemoveSalesFromDatabase();
|
||||
CandyHouseDbContext.RemoveEmployeesFromDatabase();
|
||||
CandyHouseDbContext.RemoveClientsFromDatabase();
|
||||
CandyHouseDbContext.RemoveProductsFromDatabase();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetList_WhenHaveRecords_Test()
|
||||
{
|
||||
var sale = InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 5)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, null, products: [(_product.Id, 10)]);
|
||||
var sale = CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 5, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, null, products: [(_product.Id, 10, 1.2)]);
|
||||
var list = _saleStorageContract.GetList();
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(3));
|
||||
@@ -63,10 +64,10 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByPeriod_Test()
|
||||
{
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-3), products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(3), products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, null, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(-3), products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, null, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(3), products: [(_product.Id, 1)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-3), products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(3), products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, null, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(-3), products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, null, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(3), products: [(_product.Id, 1, 1.2)]);
|
||||
var list = _saleStorageContract.GetList(startDate: DateTime.UtcNow.AddDays(-1), endDate: DateTime.UtcNow.AddDays(1));
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
@@ -75,10 +76,10 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByEmployeeId_Test()
|
||||
{
|
||||
var employee = InsertEmployeeToDatabaseAndReturn("Other employee");
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(employee.Id, null, products: [(_product.Id, 1)]);
|
||||
var employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(fio: "Other employee");
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(employee.Id, null, products: [(_product.Id, 1, 1.2)]);
|
||||
var list = _saleStorageContract.GetList(employeeId: _employee.Id);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
@@ -88,11 +89,11 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByClientId_Test()
|
||||
{
|
||||
var client = InsertClientToDatabaseAndReturn("Other fio", "+8-888-888-88-88");
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, client.Id, products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, null, products: [(_product.Id, 1)]);
|
||||
var client = CandyHouseDbContext.InsertClientToDatabaseAndReturn(fio: "Other fio", phoneNumber: "+8-888-888-88-88");
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, client.Id, products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, null, products: [(_product.Id, 1, 1.2)]);
|
||||
var list = _saleStorageContract.GetList(clientId: _client.Id);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(2));
|
||||
@@ -102,30 +103,30 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_ByProductId_Test()
|
||||
{
|
||||
var product = InsertProductToDatabaseAndReturn("Other name");
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 5)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1), (product.Id, 4)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, null, products: [(product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, null, products: [(product.Id, 1), (_product.Id, 1)]);
|
||||
var product = CandyHouseDbContext.InsertProductToDatabaseAndReturn(productName: "Other name");
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 5, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2), (product.Id, 4, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, null, products: [(product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, null, products: [(product.Id, 1, 1.2), (_product.Id, 1, 1.2)]);
|
||||
var list = _saleStorageContract.GetList(productId: _product.Id);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(3));
|
||||
Assert.That(list.All(x => x.Products.Any(y => y.ProductId == _product.Id)));
|
||||
Assert.That(list.All(x => x.Products!.Any(y => y.ProductId == _product.Id)));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetList_ByAllParameters_Test()
|
||||
{
|
||||
var employee = InsertEmployeeToDatabaseAndReturn("Other employee");
|
||||
var client = InsertClientToDatabaseAndReturn("Other fio", "+8-888-888-88-88");
|
||||
var product = InsertProductToDatabaseAndReturn("Other name");
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-3), products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(employee.Id, null, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(3), products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(3), products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(3), products: [(product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, client.Id, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(-3), products: [(_product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(-3), products: [(product.Id, 1)]);
|
||||
InsertSaleToDatabaseAndReturn(employee.Id, null, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(-3), products: [(_product.Id, 1)]);
|
||||
var employee = CandyHouseDbContext.InsertEmployeeToDatabaseAndReturn(fio: "Other employee");
|
||||
var client = CandyHouseDbContext.InsertClientToDatabaseAndReturn(fio: "Other fio", phoneNumber: "+8-888-888-88-88");
|
||||
var product = CandyHouseDbContext.InsertProductToDatabaseAndReturn(productName: "Other name");
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(-3), products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(employee.Id, null, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(3), products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(3), products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(-1).AddMinutes(3), products: [(product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, client.Id, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(-3), products: [(_product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(-3), products: [(product.Id, 1, 1.2)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(employee.Id, null, saleDate: DateTime.UtcNow.AddDays(1).AddMinutes(-3), products: [(_product.Id, 1, 1.2)]);
|
||||
var list = _saleStorageContract.GetList(startDate: DateTime.UtcNow.AddDays(-1), endDate: DateTime.UtcNow.AddDays(1), employeeId: _employee.Id, clientId: _client.Id, productId: product.Id);
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(1));
|
||||
@@ -134,46 +135,46 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetElementById_WhenHaveRecord_Test()
|
||||
{
|
||||
var sale = InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1)]);
|
||||
var sale = CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2)]);
|
||||
AssertElement(_saleStorageContract.GetElementById(sale.Id), sale);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetElementById_WhenNoRecord_Test()
|
||||
{
|
||||
InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1)]);
|
||||
CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2)]);
|
||||
Assert.That(() => _saleStorageContract.GetElementById(Guid.NewGuid().ToString()), Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetElementById_WhenRecordHasCanceled_Test()
|
||||
{
|
||||
var sale = InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1)], isCancel: true);
|
||||
var sale = CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2)], isCancel: true);
|
||||
AssertElement(_saleStorageContract.GetElementById(sale.Id), sale);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_AddElement_Test()
|
||||
{
|
||||
var sale = CreateModel(Guid.NewGuid().ToString(), _employee.Id, _client.Id, 1, DiscountType.RegularCustomer, 1, false, [_product.Id]);
|
||||
var sale = CreateModel(Guid.NewGuid().ToString(), _employee.Id, _client.Id, DiscountType.RegularCustomer, false, [_product.Id]);
|
||||
_saleStorageContract.AddElement(sale);
|
||||
AssertElement(GetSaleFromDatabaseById(sale.Id), sale);
|
||||
AssertElement(CandyHouseDbContext.GetSaleFromDatabaseById(sale.Id), sale);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_AddElement_WhenIsDeletedIsTrue_Test()
|
||||
{
|
||||
var sale = CreateModel(Guid.NewGuid().ToString(), _employee.Id, _client.Id, 1, DiscountType.RegularCustomer, 1, true, [_product.Id]);
|
||||
var sale = CreateModel(Guid.NewGuid().ToString(), _employee.Id, _client.Id, DiscountType.RegularCustomer, true, [_product.Id]);
|
||||
Assert.That(() => _saleStorageContract.AddElement(sale), Throws.Nothing);
|
||||
AssertElement(GetSaleFromDatabaseById(sale.Id), CreateModel(sale.Id, _employee.Id, _client.Id, 1, DiscountType.RegularCustomer, 1, false, [_product.Id]));
|
||||
AssertElement(CandyHouseDbContext.GetSaleFromDatabaseById(sale.Id), CreateModel(sale.Id, _employee.Id, _client.Id, DiscountType.RegularCustomer, false, [_product.Id]));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_DelElement_Test()
|
||||
{
|
||||
var sale = InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1)], isCancel: false);
|
||||
var sale = CandyHouseDbContext.InsertSaleToDatabaseAndReturn(_employee.Id, _client.Id, products: [(_product.Id, 1, 1.2)], isCancel: false);
|
||||
_saleStorageContract.DelElement(sale.Id);
|
||||
var element = GetSaleFromDatabaseById(sale.Id);
|
||||
var element = CandyHouseDbContext.GetSaleFromDatabaseById(sale.Id);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(element, Is.Not.Null);
|
||||
@@ -210,7 +211,7 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
return employee;
|
||||
}
|
||||
|
||||
private Product InsertProductToDatabaseAndReturn(string productName = "test", ProductType productType = ProductType.Candy, double price = 1)
|
||||
private Product InsertProductToDatabaseAndReturn(string productName = "test", ProductType productType = ProductType.Chocolate, double price = 1)
|
||||
{
|
||||
var product = new Product() { Id = Guid.NewGuid().ToString(), ProductName = productName, ProductType = productType, Price = price };
|
||||
CandyHouseDbContext.Products.Add(product);
|
||||
@@ -265,14 +266,12 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
}
|
||||
}
|
||||
|
||||
private static SaleDataModel CreateModel(string id, string employeeId, string? clientId, double sum, DiscountType discountType, double discount, bool isCancel, List<string> productIds)
|
||||
private static SaleDataModel CreateModel(string id, string employeeId, string? clientId, DiscountType discountType, bool isCancel, List<string> productIds)
|
||||
{
|
||||
var products = productIds.Select(x => new SaleProductDataModel(id, x, 1)).ToList();
|
||||
return new(id, employeeId, clientId, sum, discountType, discount, isCancel, products);
|
||||
var products = productIds.Select(x => new SaleProductDataModel(id, x, 1, 1.1)).ToList();
|
||||
return new(id, employeeId, clientId, discountType, isCancel, products);
|
||||
}
|
||||
|
||||
private Sale? GetSaleFromDatabaseById(string id) => CandyHouseDbContext.Sales.Include(x => x.SaleProducts).FirstOrDefault(x => x.Id == id);
|
||||
|
||||
private static void AssertElement(Sale? actual, SaleDataModel expected)
|
||||
{
|
||||
Assert.That(actual, Is.Not.Null);
|
||||
@@ -296,6 +295,7 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
{
|
||||
Assert.That(actual.SaleProducts[i].ProductId, Is.EqualTo(expected.Products[i].ProductId));
|
||||
Assert.That(actual.SaleProducts[i].Count, Is.EqualTo(expected.Products[i].Count));
|
||||
Assert.That(actual.SaleProducts[i].Price, Is.EqualTo(expected.Products[i].Price));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,22 +22,22 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
public void SetUp()
|
||||
{
|
||||
_storageStorageContract = new StorageStorageContract(CandyHouseDbContext);
|
||||
_product = InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name", ProductType.Candy);
|
||||
_product = InsertProductToDatabaseAndReturn(Guid.NewGuid().ToString(), "name", ProductType.Chocolate);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Agencies\" CASCADE;");
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Storages\" CASCADE;");
|
||||
CandyHouseDbContext.Database.ExecuteSqlRaw("TRUNCATE \"Products\" CASCADE;");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_GetList_WhenHaveRecords_Test()
|
||||
{
|
||||
var storage = InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Candy, 5);
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Candy, 5);
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Candy, 5);
|
||||
var storage = InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 5);
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 5);
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 5);
|
||||
var list = _storageStorageContract.GetList();
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(3));
|
||||
@@ -55,7 +55,7 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetElementById_WhenHaveRecord_Test()
|
||||
{
|
||||
var storage = InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Candy, 5);
|
||||
var storage = InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 5);
|
||||
var result = _storageStorageContract.GetElementById(storage.Id);
|
||||
AssertElement(result, storage);
|
||||
}
|
||||
@@ -69,7 +69,7 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_AddElement_WhenValidData_Test()
|
||||
{
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Candy, 5, [_product.Id]);
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Chocolate, 5, [_product.Id]);
|
||||
_storageStorageContract.AddElement(storage);
|
||||
var result = GetStorageFromDatabaseById(storage.Id);
|
||||
AssertElement(result, storage);
|
||||
@@ -78,24 +78,24 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_AddElement_WhenHaveRecordWithSameId_Test()
|
||||
{
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Candy, 5, [_product.Id]);
|
||||
InsertStorageToDatabaseAndReturn(storage.Id, ProductType.Candy, 5, [(_product.Id, 3)]);
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Chocolate, 5, [_product.Id]);
|
||||
InsertStorageToDatabaseAndReturn(storage.Id, ProductType.Chocolate, 5, [(_product.Id, 3)]);
|
||||
Assert.That(() => _storageStorageContract.AddElement(storage), Throws.TypeOf<StorageException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_AddElement_WhenNoHaveProduct_Test()
|
||||
{
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Candy, 0, [_product.Id]);
|
||||
InsertStorageToDatabaseAndReturn(storage.Id, ProductType.Candy, 5, [(_product.Id, 3)]);
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Chocolate, 0, [_product.Id]);
|
||||
InsertStorageToDatabaseAndReturn(storage.Id, ProductType.Chocolate, 5, [(_product.Id, 3)]);
|
||||
Assert.That(() => _storageStorageContract.AddElement(storage), Throws.TypeOf<StorageException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_UpdElement_WhenValidData_Test()
|
||||
{
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Candy, 5, [_product.Id]);
|
||||
InsertStorageToDatabaseAndReturn(storage.Id, ProductType.Chocolate, 10, null);
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Chocolate, 5, [_product.Id]);
|
||||
InsertStorageToDatabaseAndReturn(storage.Id, ProductType.Cake, 10, null);
|
||||
_storageStorageContract.UpdElement(storage);
|
||||
var result = GetStorageFromDatabaseById(storage.Id);
|
||||
AssertElement(result, storage);
|
||||
@@ -104,14 +104,14 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_UpdElement_WhenNoRecordWithThisId_Test()
|
||||
{
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Candy, 5, [_product.Id]);
|
||||
var storage = CreateModel(Guid.NewGuid().ToString(), ProductType.Chocolate, 5, [_product.Id]);
|
||||
Assert.That(() => _storageStorageContract.UpdElement(storage), Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_DelElement_WhenRecordExists_Test()
|
||||
{
|
||||
var storage = InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Candy, 5);
|
||||
var storage = InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 5);
|
||||
_storageStorageContract.DelElement(storage.Id);
|
||||
var result = GetStorageFromDatabaseById(storage.Id);
|
||||
Assert.That(result, Is.Null);
|
||||
@@ -120,63 +120,7 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_DelElement_WhenRecordDoesNotExist_ThrowsElementNotFoundException()
|
||||
{
|
||||
Assert.That(() => _storageStorageContract.DelElement(Guid.NewGuid().ToString()),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_CheckComponents_WhenEnoughInOneStorage_ReturnsTrue()
|
||||
{
|
||||
var storage =
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), _product.ProductType, 10, [(_product.Id, 10)]);
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 5)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.True);
|
||||
var updated = GetStorageFromDatabaseById(storage.Id);
|
||||
Assert.That(updated!.Count, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_CheckComponents_WhenExactlyEnough_RemovesStorage_ReturnsTrue()
|
||||
{
|
||||
var storage =
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), _product.ProductType, 5, [(_product.Id, 5)]);
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 5)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.True);
|
||||
var deleted = GetStorageFromDatabaseById(storage.Id);
|
||||
Assert.That(deleted, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_CheckComponents_WhenNotEnoughInStorage_ReturnsFalse()
|
||||
{
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), _product.ProductType, 2, [(_product.Id, 2)]);
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 5)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_CheckComponents_WhenNoMatchingStorage_ReturnsFalse()
|
||||
{
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 10); // другой тип
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 1)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
[Test]
|
||||
public void Try_CheckComponents_InCorrectProductTypeStorage_ReturnsFalse()
|
||||
{
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Cake, 10);
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 1)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.False);
|
||||
Assert.That(() => _storageStorageContract.DelElement(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
private Product InsertProductToDatabaseAndReturn(string id, string name, ProductType type)
|
||||
@@ -187,20 +131,17 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
return product;
|
||||
}
|
||||
|
||||
private Storage InsertStorageToDatabaseAndReturn(string id, ProductType type, int count,
|
||||
List<(string, int)>? products = null)
|
||||
private Storage InsertStorageToDatabaseAndReturn(string id, ProductType type, int count, List<(string, int)>? products = null)
|
||||
{
|
||||
var storage = new Storage { Id = id, Type = type, Count = count, Products = [] };
|
||||
var storage = new Storage { Id = id, ProductType = type, Count = count, Products = [] };
|
||||
if (products is not null)
|
||||
{
|
||||
foreach (var elem in products)
|
||||
{
|
||||
storage.Products.Add(new ProductStorage
|
||||
{ StorageId = storage.Id, ProductId = elem.Item1, Count = elem.Item2 });
|
||||
storage.Products.Add(new ProductStorage { StorageId = storage.Id, ProductId = elem.Item1, Count = elem.Item2 });
|
||||
}
|
||||
}
|
||||
|
||||
CandyHouseDbContext.Agencies.Add(storage);
|
||||
CandyHouseDbContext.Storages.Add(storage);
|
||||
CandyHouseDbContext.SaveChanges();
|
||||
return storage;
|
||||
}
|
||||
@@ -211,7 +152,7 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(actual.Id, Is.EqualTo(expected.Id));
|
||||
Assert.That(actual.Type, Is.EqualTo(expected.Type));
|
||||
Assert.That(actual.ProductType, Is.EqualTo(expected.ProductType));
|
||||
Assert.That(actual.Count, Is.EqualTo(expected.Count));
|
||||
});
|
||||
if (expected.Products is not null)
|
||||
@@ -239,7 +180,7 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(actual.Id, Is.EqualTo(expected.Id));
|
||||
Assert.That(actual.Type, Is.EqualTo(expected.Type));
|
||||
Assert.That(actual.ProductType, Is.EqualTo(expected.ProductType));
|
||||
Assert.That(actual.Count, Is.EqualTo(expected.Count));
|
||||
});
|
||||
if (expected.Products is not null)
|
||||
@@ -269,6 +210,6 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
|
||||
private Storage? GetStorageFromDatabaseById(string id)
|
||||
{
|
||||
return CandyHouseDbContext.Agencies.FirstOrDefault(x => x.Id == id);
|
||||
return CandyHouseDbContext.Storages.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ internal class SuppliesStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetList_WhenHaveRecords_Test()
|
||||
{
|
||||
var supply = InsertSupplyToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 5);
|
||||
InsertSupplyToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 5);
|
||||
InsertSupplyToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 5);
|
||||
var supply = InsertSupplyToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Cake, 5);
|
||||
InsertSupplyToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Cake, 5);
|
||||
InsertSupplyToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Cake, 5);
|
||||
var list = _suppliesStorageContract.GetList();
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(3));
|
||||
@@ -55,7 +55,7 @@ internal class SuppliesStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_GetElementById_WhenHaveRecord_Test()
|
||||
{
|
||||
var supply = InsertSupplyToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 5);
|
||||
var supply = InsertSupplyToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Cake, 5);
|
||||
AssertElement(_suppliesStorageContract.GetElementById(supply.Id), supply);
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ internal class SuppliesStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_AddElement_Test()
|
||||
{
|
||||
var supply = CreateModel(Guid.NewGuid().ToString(), ProductType.Chocolate, 5, [_product.Id]);
|
||||
var supply = CreateModel(Guid.NewGuid().ToString(), ProductType.Cake, 5, [_product.Id]);
|
||||
_suppliesStorageContract.AddElement(supply);
|
||||
AssertElement(GetSupplyFromDatabaseById(supply.Id), supply);
|
||||
}
|
||||
@@ -76,16 +76,16 @@ internal class SuppliesStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_AddElement_WhenHaveRecordWithSameId_Test()
|
||||
{
|
||||
var supply = CreateModel(Guid.NewGuid().ToString(), ProductType.Chocolate, 5, [_product.Id]);
|
||||
InsertSupplyToDatabaseAndReturn(supply.Id, ProductType.Chocolate, 5, [(_product.Id, 3)]);
|
||||
var supply = CreateModel(Guid.NewGuid().ToString(), ProductType.Cake, 5, [_product.Id]);
|
||||
InsertSupplyToDatabaseAndReturn(supply.Id, ProductType.Cake, 5, [(_product.Id, 3)]);
|
||||
Assert.That(() => _suppliesStorageContract.AddElement(supply), Throws.TypeOf<StorageException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_UpdElement_Test()
|
||||
{
|
||||
var supply = CreateModel(Guid.NewGuid().ToString(), ProductType.Chocolate, 5, [_product.Id]);
|
||||
InsertSupplyToDatabaseAndReturn(supply.Id, ProductType.Chocolate, 5, null);
|
||||
var supply = CreateModel(Guid.NewGuid().ToString(), ProductType.Cake, 5, [_product.Id]);
|
||||
InsertSupplyToDatabaseAndReturn(supply.Id, ProductType.Cake, 5, null);
|
||||
_suppliesStorageContract.UpdElement(supply);
|
||||
AssertElement(GetSupplyFromDatabaseById(supply.Id), supply);
|
||||
}
|
||||
@@ -93,12 +93,12 @@ internal class SuppliesStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_UpdElement_WhenNoRecordWithThisId_Test()
|
||||
{
|
||||
Assert.That(() => _suppliesStorageContract.UpdElement(CreateModel(Guid.NewGuid().ToString(), ProductType.Chocolate, 5, [_product.Id])), Throws.TypeOf<ElementNotFoundException>());
|
||||
Assert.That(() => _suppliesStorageContract.UpdElement(CreateModel(Guid.NewGuid().ToString(), ProductType.Cake, 5, [_product.Id])), Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
private Product InsertProductToDatabaseAndReturn()
|
||||
{
|
||||
var product = new Product { Id = Guid.NewGuid().ToString(), ProductName = "Test Product", ProductType = ProductType.Chocolate };
|
||||
var product = new Product { Id = Guid.NewGuid().ToString(), ProductName = "Test Product", ProductType = ProductType.Cake };
|
||||
CandyHouseDbContext.Products.Add(product);
|
||||
CandyHouseDbContext.SaveChanges();
|
||||
return product;
|
||||
@@ -106,7 +106,7 @@ internal class SuppliesStorageContractTests : BaseStorageContractTest
|
||||
|
||||
private Supplies InsertSupplyToDatabaseAndReturn(string id, ProductType type, int count, List<(string, int)>? products = null)
|
||||
{
|
||||
var supply = new Supplies { Id = id, Type = type, OrderDate = DateTime.UtcNow, Count = count, Products = [] };
|
||||
var supply = new Supplies { Id = id, ProductType = type, ProductuionDate = DateTime.UtcNow, Count = count, Products = [] };
|
||||
if (products is not null)
|
||||
{
|
||||
foreach (var elem in products)
|
||||
@@ -125,8 +125,8 @@ internal class SuppliesStorageContractTests : BaseStorageContractTest
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(actual.Id, Is.EqualTo(expected.Id));
|
||||
Assert.That(actual.Type, Is.EqualTo(expected.Type));
|
||||
Assert.That(actual.OrderDate, Is.EqualTo(expected.OrderDate));
|
||||
Assert.That(actual.ProductType, Is.EqualTo(expected.ProductType));
|
||||
Assert.That(actual.ProductuionDate, Is.EqualTo(expected.ProductuionDate));
|
||||
Assert.That(actual.Count, Is.EqualTo(expected.Count));
|
||||
});
|
||||
if (expected.Products is not null)
|
||||
@@ -154,8 +154,8 @@ internal class SuppliesStorageContractTests : BaseStorageContractTest
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(actual.Id, Is.EqualTo(expected.Id));
|
||||
Assert.That(actual.Type, Is.EqualTo(expected.Type));
|
||||
Assert.That(actual.OrderDate, Is.EqualTo(expected.OrderDate));
|
||||
Assert.That(actual.ProductType, Is.EqualTo(expected.ProductType));
|
||||
Assert.That(actual.ProductuionDate, Is.EqualTo(expected.ProductuionDate));
|
||||
Assert.That(actual.Count, Is.EqualTo(expected.Count));
|
||||
});
|
||||
if (expected.Products is not null)
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user