dates + strings
This commit is contained in:
@@ -5,15 +5,17 @@ using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class ManufacturerBusinessLogicContract(IManufacturerStorageContract
|
||||
manufacturerStorageContract, ILogger logger) : IManufacturerBusinessLogicContract
|
||||
manufacturerStorageContract, IStringLocalizer<Messages> localizer, ILogger logger) : IManufacturerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IManufacturerStorageContract _manufacturerStorageContract
|
||||
= manufacturerStorageContract;
|
||||
private readonly IManufacturerStorageContract _manufacturerStorageContract = manufacturerStorageContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
public List<ManufacturerDataModel> GetAllManufacturers()
|
||||
{
|
||||
_logger.LogInformation("GetAllManufacturers");
|
||||
@@ -30,18 +32,18 @@ manufacturerStorageContract, ILogger logger) : IManufacturerBusinessLogicContrac
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _manufacturerStorageContract.GetElementById(data) ??
|
||||
throw new ElementNotFoundException(data);
|
||||
throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
return _manufacturerStorageContract.GetElementByName(data) ??
|
||||
_manufacturerStorageContract.GetElementByOldName(data) ??
|
||||
throw new ElementNotFoundException(data);
|
||||
throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
public void InsertManufacturer(ManufacturerDataModel manufacturerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(manufacturerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(manufacturerDataModel);
|
||||
manufacturerDataModel.Validate();
|
||||
manufacturerDataModel.Validate(_localizer);
|
||||
_manufacturerStorageContract.AddElement(manufacturerDataModel);
|
||||
}
|
||||
public void UpdateManufacturer(ManufacturerDataModel manufacturerDataModel)
|
||||
@@ -49,7 +51,7 @@ manufacturerStorageContract, ILogger logger) : IManufacturerBusinessLogicContrac
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(manufacturerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(manufacturerDataModel);
|
||||
manufacturerDataModel.Validate();
|
||||
manufacturerDataModel.Validate(_localizer);
|
||||
_manufacturerStorageContract.UpdElement(manufacturerDataModel);
|
||||
}
|
||||
public void DeleteManufacturer(string id)
|
||||
@@ -61,7 +63,7 @@ manufacturerStorageContract, ILogger logger) : IManufacturerBusinessLogicContrac
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_manufacturerStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -15,11 +17,12 @@ using System.Threading.Tasks;
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class PostBusinessLogicContract(IPostStorageContract
|
||||
postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
postStorageContract, IStringLocalizer<Messages> localizer, ILogger logger) : IPostBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IPostStorageContract _postStorageContract =
|
||||
postStorageContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
public List<PostDataModel> GetAllPosts()
|
||||
{
|
||||
_logger.LogInformation("GetAllPosts");
|
||||
@@ -34,7 +37,7 @@ postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "PostId"));
|
||||
}
|
||||
return _postStorageContract.GetPostWithHistory(postId) ?? throw new
|
||||
NullListException();
|
||||
@@ -49,17 +52,17 @@ postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _postStorageContract.GetElementById(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
return _postStorageContract.GetElementByName(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
public void InsertPost(PostDataModel postDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
postDataModel.Validate(_localizer);
|
||||
_postStorageContract.AddElement(postDataModel);
|
||||
}
|
||||
public void UpdatePost(PostDataModel postDataModel)
|
||||
@@ -67,7 +70,7 @@ postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
postDataModel.Validate(_localizer);
|
||||
_postStorageContract.UpdElement(postDataModel);
|
||||
}
|
||||
public void DeletePost(string id)
|
||||
@@ -79,7 +82,7 @@ postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_postStorageContract.DelElement(id);
|
||||
}
|
||||
@@ -91,8 +94,8 @@ postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
throw new ArgumentNullException(nameof(id));
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
{
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_postStorageContract.ResElement(id);
|
||||
}
|
||||
|
||||
@@ -1,31 +1,49 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareBusinessLogic.OfficePackage;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class ReportContract(ISoftwareStorageContract softwareStorageContract,
|
||||
IRequestStorageContract requestStorageContract,
|
||||
ISalaryStorageContract salaryStorageContract,
|
||||
BaseWordBuilder baseWordBuilder,
|
||||
BaseExcelBuilder baseExcelBuilder,
|
||||
BasePdfBuilder basePdfBuilder, ILogger logger) : IReportContract
|
||||
internal class ReportContract : IReportContract
|
||||
{
|
||||
private readonly ISoftwareStorageContract _softwareStorageContract = softwareStorageContract;
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IRequestStorageContract _requestStorageContract = requestStorageContract;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
private readonly BaseWordBuilder _baseWordBuilder = baseWordBuilder;
|
||||
private readonly BaseExcelBuilder _baseExcelBuilder = baseExcelBuilder;
|
||||
private readonly ISoftwareStorageContract _softwareStorageContract;
|
||||
private readonly IRequestStorageContract _requestStorageContract;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract;
|
||||
private readonly BaseWordBuilder _baseWordBuilder;
|
||||
private readonly BaseExcelBuilder _baseExcelBuilder;
|
||||
private readonly BasePdfBuilder _basePdfBuilder;
|
||||
private readonly IStringLocalizer<Messages> _localizer ;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly BasePdfBuilder _basePdfBuilder = basePdfBuilder;
|
||||
internal readonly string[] tableHeader;
|
||||
internal readonly string[] documentHeader;
|
||||
|
||||
public ReportContract(ISoftwareStorageContract softwareStorageContract,
|
||||
IRequestStorageContract requestStorageContract,
|
||||
ISalaryStorageContract salaryStorageContract,
|
||||
BaseWordBuilder baseWordBuilder,
|
||||
BaseExcelBuilder baseExcelBuilder,
|
||||
BasePdfBuilder basePdfBuilder, IStringLocalizer<Messages> localizer, ILogger logger)
|
||||
{
|
||||
_softwareStorageContract = softwareStorageContract;
|
||||
_requestStorageContract = requestStorageContract;
|
||||
_salaryStorageContract = salaryStorageContract;
|
||||
_baseWordBuilder = baseWordBuilder;
|
||||
_baseExcelBuilder = baseExcelBuilder;
|
||||
_basePdfBuilder = basePdfBuilder;
|
||||
_localizer = localizer;
|
||||
_logger = logger;
|
||||
tableHeader = [_localizer["DocumentExcelCaptionDate"], _localizer["DocumentExcelCaptionSum"], _localizer["DocumentExcelCaptionSoftware"], _localizer["DocumentExcelCaptionCount"]];
|
||||
documentHeader = [_localizer["DocumentDocCaptionSoftware"], _localizer["DocumentDocCaptionOldPrice"], _localizer["DocumentDocCaptionData"]];
|
||||
}
|
||||
|
||||
internal static readonly string[] tableHeader = ["Дата", "Сумма", "Товар", "Кол-во"];
|
||||
internal static readonly string[] documentHeader = ["Название ПО", "Старая цена", "Дата"];
|
||||
|
||||
public Task<List<HistoryOfSoftwareDataModel>> GetDataSoftwaresByHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
@@ -58,8 +76,8 @@ internal class ReportContract(ISoftwareStorageContract softwareStorageContract,
|
||||
}
|
||||
|
||||
return _baseWordBuilder
|
||||
.AddHeader("Истории ПО")
|
||||
.AddParagraph($"Сформировано на дату {DateTime.Now}")
|
||||
.AddHeader(_localizer["DocumentDocHeader"])
|
||||
.AddParagraph(string.Format(_localizer["DocumentDocSubHeader"], DateTime.Now))
|
||||
.AddTable(
|
||||
widths: new[] { 3000, 3000, 3000 },
|
||||
data: tableData
|
||||
@@ -77,20 +95,20 @@ internal class ReportContract(ISoftwareStorageContract softwareStorageContract,
|
||||
{
|
||||
if (dateStart.IsDateNotOlder(dateFinish))
|
||||
{
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
throw new IncorrectDatesException(dateStart, dateFinish, _localizer);
|
||||
}
|
||||
return [.. (await _requestStorageContract.GetListAsync(dateStart, dateFinish, ct)).OrderBy(x => x.RequestDate)];
|
||||
}
|
||||
|
||||
public async Task<Stream> CreateDocumentRequestsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
logger.LogInformation("Create report RequestsByPeriod from {dateStart} to {dateFinish}", dateStart, dateFinish);
|
||||
_logger.LogInformation("Create report RequestsByPeriod from {dateStart} to {dateFinish}", dateStart, dateFinish);
|
||||
var data = await GetDataByRequestsAsync(dateStart, dateFinish, ct) ?? throw new InvalidOperationException("No found data");
|
||||
|
||||
var tableHeader = new string[] { "Дата", "Email", "Сумма", "ПО", "Количество" };
|
||||
|
||||
return _baseExcelBuilder
|
||||
.AddHeader("Requests за период", 0, 5)
|
||||
.AddHeader(_localizer["DocumentExcelHeader"], 0, 5)
|
||||
.AddParagraph($"c {dateStart.ToShortDateString()} по {dateFinish.ToShortDateString()}", 2)
|
||||
.AddTable(
|
||||
[10, 10, 10, 10, 10],
|
||||
@@ -115,7 +133,7 @@ internal class ReportContract(ISoftwareStorageContract softwareStorageContract,
|
||||
.ToArray()
|
||||
)
|
||||
.Union([[
|
||||
"Всего",
|
||||
_localizer["DocumentExcelCaptionTotal"],
|
||||
"",
|
||||
data.Sum(x => x.Sum).ToString("N2"),
|
||||
"",
|
||||
@@ -127,7 +145,7 @@ internal class ReportContract(ISoftwareStorageContract softwareStorageContract,
|
||||
|
||||
public Task<List<WorkerSalaryByPeriodDataModel>> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
logger.LogInformation("Get data SalaryByPeriod from {dateStart} to { dateFinish}", dateStart, dateFinish);
|
||||
_logger.LogInformation("Get data SalaryByPeriod from {dateStart} to { dateFinish}", dateStart, dateFinish);
|
||||
return GetDataBySalaryAsync(dateStart, dateFinish, ct);
|
||||
}
|
||||
|
||||
@@ -135,7 +153,7 @@ internal class ReportContract(ISoftwareStorageContract softwareStorageContract,
|
||||
{
|
||||
if (dateStart.IsDateNotOlder(dateFinish))
|
||||
{
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
throw new IncorrectDatesException(dateStart, dateFinish, _localizer);
|
||||
}
|
||||
return [.. (await _salaryStorageContract.GetListAsync(dateStart, dateFinish, ct)).GroupBy(x => x.WorkerFIO).Select(x => new
|
||||
WorkerSalaryByPeriodDataModel { WorkerFIO = x.Key, TotalSalary = x.Sum(y => y.Salary),
|
||||
@@ -146,7 +164,9 @@ internal class ReportContract(ISoftwareStorageContract softwareStorageContract,
|
||||
{
|
||||
_logger.LogInformation("Create report SalaryByPeriod from {dateStart} to { dateFinish}", dateStart, dateFinish);
|
||||
var data = await GetDataBySalaryAsync(dateStart, dateFinish, ct) ?? throw new InvalidOperationException("No found data");
|
||||
return _basePdfBuilder.AddHeader("Зарплатная ведомость").AddParagraph($"за период с {dateStart.ToShortDateString()} по {dateFinish.ToShortDateString()}")
|
||||
.AddPieChart("Начисления", [.. data.Select(x => (x.WorkerFIO, x.TotalSalary))]).Build();
|
||||
return _basePdfBuilder
|
||||
.AddHeader(_localizer["DocumentPdfHeader"])
|
||||
.AddParagraph(string.Format(_localizer["DocumentPdfSubHeader"], dateStart.ToLocalTime().ToShortDateString(), dateFinish.ToLocalTime().ToShortDateString()))
|
||||
.AddPieChart(_localizer["DocumentPdfDiagramCaption"], [.. data.Select(x => (x.WorkerFIO, x.TotalSalary))]).Build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,17 +15,18 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class RequestBusinessLogicContract(IRequestStorageContract requestStorageContract, ILogger logger) : IRequestBusinessLogicContract
|
||||
internal class RequestBusinessLogicContract(IRequestStorageContract requestStorageContract, IStringLocalizer<Messages> localizer, ILogger logger) : IRequestBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IRequestStorageContract _requestStorageContract =
|
||||
requestStorageContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
public List<RequestDataModel> GetAllRequestsByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllRequests params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
return _requestStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
|
||||
@@ -33,7 +36,7 @@ internal class RequestBusinessLogicContract(IRequestStorageContract requestStora
|
||||
_logger.LogInformation("GetAllRequests params: {workerId}, {fromDate}, { toDate} ", workerId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
@@ -41,7 +44,7 @@ internal class RequestBusinessLogicContract(IRequestStorageContract requestStora
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkerId"));
|
||||
}
|
||||
return _requestStorageContract.GetList(fromDate, toDate, workerId:
|
||||
workerId) ?? throw new NullListException();
|
||||
@@ -52,7 +55,7 @@ internal class RequestBusinessLogicContract(IRequestStorageContract requestStora
|
||||
_logger.LogInformation("GetAllRequests params: {softwareId}, {fromDate}, { toDate} ", softwareId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
if (softwareId.IsEmpty())
|
||||
{
|
||||
@@ -60,7 +63,7 @@ internal class RequestBusinessLogicContract(IRequestStorageContract requestStora
|
||||
}
|
||||
if (!softwareId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field softwareId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "SoftwareId"));
|
||||
}
|
||||
return _requestStorageContract.GetList(fromDate, toDate, softwareId:
|
||||
softwareId) ?? throw new NullListException();
|
||||
@@ -75,9 +78,9 @@ internal class RequestBusinessLogicContract(IRequestStorageContract requestStora
|
||||
}
|
||||
if (!data.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
return _requestStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
return _requestStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
|
||||
}
|
||||
public void InsertRequest(RequestDataModel requestDataModel)
|
||||
@@ -85,7 +88,7 @@ internal class RequestBusinessLogicContract(IRequestStorageContract requestStora
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(requestDataModel));
|
||||
ArgumentNullException.ThrowIfNull(requestDataModel);
|
||||
requestDataModel.Validate();
|
||||
requestDataModel.Validate(_localizer);
|
||||
_requestStorageContract.AddElement(requestDataModel);
|
||||
|
||||
}
|
||||
@@ -98,7 +101,7 @@ internal class RequestBusinessLogicContract(IRequestStorageContract requestStora
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_requestStorageContract.DelElement(id);
|
||||
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Infrastructure.PostConfigurations;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,
|
||||
IRequestStorageContract requestStorageContract, IPostStorageContract postStorageContract,
|
||||
IWorkerStorageContract workerStorageContract, ILogger logger, IConfigurationSalary сonfiguration) : ISalaryBusinessLogicContract
|
||||
IWorkerStorageContract workerStorageContract, IStringLocalizer<Messages> localizer, ILogger logger, IConfigurationSalary сonfiguration) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
@@ -20,6 +22,7 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
||||
private readonly IWorkerStorageContract _workerStorageContract = workerStorageContract;
|
||||
private readonly IConfigurationSalary _salaryConfiguration = сonfiguration;
|
||||
private readonly Lock _lockObject = new();
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate,
|
||||
DateTime toDate)
|
||||
{
|
||||
@@ -27,7 +30,7 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
||||
fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
return _salaryStorageContract.GetList(fromDate, toDate) ?? throw new
|
||||
NullListException();
|
||||
@@ -37,7 +40,7 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
if (workerId.IsEmpty())
|
||||
{
|
||||
@@ -45,7 +48,7 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
|
||||
}
|
||||
if (!workerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field workerId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkerId"));
|
||||
}
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, { workerId} ", fromDate, toDate, workerId);
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, workerId) ??
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class SoftwareBusinessLogicContract(ISoftwareStorageContract
|
||||
softwareStorageContract, ILogger logger) : ISoftwareBusinessLogicContract
|
||||
softwareStorageContract, IStringLocalizer<Messages> localizer, ILogger logger) : ISoftwareBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISoftwareStorageContract _softwareStorageContract =
|
||||
softwareStorageContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
public List<SoftwareDataModel> GetAllSoftwares(bool onlyActive)
|
||||
{
|
||||
_logger.LogInformation("GetAllSoftwares params: {onlyActive}", onlyActive);
|
||||
@@ -30,9 +33,9 @@ softwareStorageContract, ILogger logger) : ISoftwareBusinessLogicContract
|
||||
}
|
||||
if (!manufacturerId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field manufacturerId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "ManufacturerId"));
|
||||
}
|
||||
_logger.LogInformation("GetAllSoftwares params: {manufacturerId}, { onlyActive} ", manufacturerId, onlyActive);
|
||||
_logger.LogInformation("GetAllSoftwares params: {manufacturerId}, { onlyActive} ", manufacturerId, onlyActive);
|
||||
return _softwareStorageContract.GetList(onlyActive, manufacturerId) ??
|
||||
throw new NullListException();
|
||||
}
|
||||
@@ -45,7 +48,7 @@ softwareStorageContract, ILogger logger) : ISoftwareBusinessLogicContract
|
||||
}
|
||||
if (!softwareId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field softwareId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "SoftwareId"));
|
||||
}
|
||||
return _softwareStorageContract.GetHistoryBySoftwareId(softwareId) ??
|
||||
throw new NullListException();
|
||||
@@ -61,17 +64,17 @@ softwareStorageContract, ILogger logger) : ISoftwareBusinessLogicContract
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _softwareStorageContract.GetElementById(data) ?? throw
|
||||
new ElementNotFoundException(data);
|
||||
new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
return _softwareStorageContract.GetElementByName(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
public void InsertSoftware(SoftwareDataModel softwareDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(softwareDataModel));
|
||||
ArgumentNullException.ThrowIfNull(softwareDataModel);
|
||||
softwareDataModel.Validate();
|
||||
softwareDataModel.Validate(_localizer);
|
||||
_softwareStorageContract.AddElement(softwareDataModel);
|
||||
}
|
||||
public void UpdateSoftware(SoftwareDataModel softwareDataModel)
|
||||
@@ -79,7 +82,7 @@ softwareStorageContract, ILogger logger) : ISoftwareBusinessLogicContract
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(softwareDataModel));
|
||||
ArgumentNullException.ThrowIfNull(softwareDataModel);
|
||||
softwareDataModel.Validate();
|
||||
softwareDataModel.Validate(_localizer);
|
||||
_softwareStorageContract.UpdElement(softwareDataModel);
|
||||
|
||||
}
|
||||
@@ -92,7 +95,7 @@ softwareStorageContract, ILogger logger) : ISoftwareBusinessLogicContract
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_softwareStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,12 +15,12 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareBusinessLogic.Implementations;
|
||||
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract
|
||||
workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
internal class WorkerBusinessLogicContract(IWorkerStorageContract workerStorageContract, IStringLocalizer<Messages> localizer, ILogger logger) : IWorkerBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IWorkerStorageContract _workerStorageContract =
|
||||
workerStorageContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
public List<WorkerDataModel> GetAllWorkers(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}",
|
||||
@@ -36,7 +38,7 @@ workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
}
|
||||
if (!postId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field postId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "PostId"));
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, postId) ?? throw
|
||||
new NullListException();
|
||||
@@ -47,7 +49,7 @@ workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, { fromDate}, { toDate} ", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromBirthDate:
|
||||
fromDate, toBirthDate: toDate) ?? throw new NullListException();
|
||||
@@ -58,7 +60,7 @@ workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
_logger.LogInformation("GetAllWorkers params: {onlyActive}, { fromDate}, { toDate} ", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
return _workerStorageContract.GetList(onlyActive, fromEmploymentDate:
|
||||
fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
|
||||
@@ -73,17 +75,17 @@ workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _workerStorageContract.GetElementById(data) ?? throw
|
||||
new ElementNotFoundException(data);
|
||||
new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
return _workerStorageContract.GetElementByFIO(data) ?? throw new
|
||||
ElementNotFoundException(data);
|
||||
ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
public void InsertWorker(WorkerDataModel workerDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}",
|
||||
JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
workerDataModel.Validate(_localizer);
|
||||
_workerStorageContract.AddElement(workerDataModel);
|
||||
}
|
||||
public void UpdateWorker(WorkerDataModel workerDataModel)
|
||||
@@ -91,7 +93,7 @@ workerStorageContract, ILogger logger) : IWorkerBusinessLogicContract
|
||||
_logger.LogInformation("Update data: {json}",
|
||||
JsonSerializer.Serialize(workerDataModel));
|
||||
ArgumentNullException.ThrowIfNull(workerDataModel);
|
||||
workerDataModel.Validate();
|
||||
workerDataModel.Validate(_localizer);
|
||||
_workerStorageContract.UpdElement(workerDataModel);
|
||||
}
|
||||
public void DeleteWorker(string id)
|
||||
@@ -103,7 +105,7 @@ public void DeleteWorker(string id)
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_workerStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace SmallSoftwareContracts.AdapterContracts;
|
||||
|
||||
public interface IReportAdapter
|
||||
{
|
||||
Task<ReportOperationResponse> GetDataSoftwaresByManufacturerAsync(CancellationToken ct);
|
||||
Task<ReportOperationResponse> CreateDocumentSoftwaresByManufacturerAsync(CancellationToken ct);
|
||||
Task<ReportOperationResponse> GetDataSoftwaresByHistoryAsync(CancellationToken ct);
|
||||
Task<ReportOperationResponse> CreateDocumentSoftwaresByHistoryAsync(CancellationToken ct);
|
||||
Task<ReportOperationResponse> GetDataRequestByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<ReportOperationResponse> CreateDocumentRequestsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
Task<ReportOperationResponse> GetDataSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IManufacturerBusinessLogicContract
|
||||
internal interface IManufacturerBusinessLogicContract
|
||||
{
|
||||
List<ManufacturerDataModel> GetAllManufacturers();
|
||||
ManufacturerDataModel GetManufacturerByData(string data);
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IPostBusinessLogicContract
|
||||
internal interface IPostBusinessLogicContract
|
||||
{
|
||||
List<PostDataModel> GetAllPosts();
|
||||
List<PostDataModel> GetAllDataOfPost(string postId);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IReportContract
|
||||
internal interface IReportContract
|
||||
{
|
||||
Task<List<HistoryOfSoftwareDataModel>> GetDataSoftwaresByHistoryAsync(CancellationToken ct);
|
||||
Task<List<RequestDataModel>> GetDataRequestByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct);
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IRequestBusinessLogicContract
|
||||
internal interface IRequestBusinessLogicContract
|
||||
{
|
||||
|
||||
List<RequestDataModel> GetAllRequestsByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
@@ -3,7 +3,7 @@ using SmallSoftwareContracts.DataModels;
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface ISalaryBusinessLogicContract
|
||||
internal interface ISalaryBusinessLogicContract
|
||||
{
|
||||
List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
List<SalaryDataModel> GetAllSalariesByPeriodByWorker(DateTime fromDate, DateTime toDate, string workerId);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface ISoftwareBusinessLogicContract
|
||||
internal interface ISoftwareBusinessLogicContract
|
||||
{
|
||||
List<SoftwareDataModel> GetAllSoftwares(bool onlyActive = true);
|
||||
List<SoftwareDataModel> GetAllSoftwaresByManufacturer(string manufacturerId,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
|
||||
public interface IWorkerBusinessLogicContract
|
||||
internal interface IWorkerBusinessLogicContract
|
||||
{
|
||||
List<WorkerDataModel> GetAllWorkers(bool onlyActive = true);
|
||||
List<WorkerDataModel> GetAllWorkersByPost(string postId, bool onlyActive = true);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class InstallationRequestDataModel(string softwareId, string requestId, int count, double price) : IValidation
|
||||
internal class InstallationRequestDataModel(string softwareId, string requestId, int count, double price) : IValidation
|
||||
{
|
||||
private readonly SoftwareDataModel? _software;
|
||||
|
||||
@@ -20,19 +22,19 @@ public class InstallationRequestDataModel(string softwareId, string requestId, i
|
||||
}
|
||||
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (SoftwareId.IsEmpty())
|
||||
throw new ValidationException("Field SoftwareId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "SoftwareId"));
|
||||
if (!SoftwareId.IsGuid())
|
||||
throw new ValidationException("The value in the field SoftwareId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "SoftwareId"));
|
||||
if (RequestId.IsEmpty())
|
||||
throw new ValidationException("Field RequestId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "RequestId"));
|
||||
if (!RequestId.IsGuid())
|
||||
throw new ValidationException("The value in the field RequestId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "RequestId"));
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Count"));
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Price"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class ManufacturerDataModel(string id, string manufacturerName, string?
|
||||
internal class ManufacturerDataModel(string id, string manufacturerName, string?
|
||||
prevManufacturerName, string? prevPrevManufacturerName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
@@ -16,15 +18,15 @@ prevManufacturerName, string? prevPrevManufacturerName) : IValidation
|
||||
|
||||
public ManufacturerDataModel(string id, string manufacturerName) : this(id, manufacturerName, null, null){ }
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
|
||||
if (ManufacturerName.IsEmpty())
|
||||
throw new ValidationException("Field ManufacturerName is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "ManufacturerName"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,36 @@
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class PostDataModel(string postId, string postName, PostType
|
||||
internal class PostDataModel(string postId, string postName, PostType
|
||||
postType, double salary) : IValidation
|
||||
{
|
||||
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 void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
|
||||
if (PostName.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "PostName"));
|
||||
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "PostType"));
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Salary"));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Xml;
|
||||
|
||||
@@ -8,7 +10,7 @@ using System.Xml;
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
|
||||
public class RequestDataModel : IValidation
|
||||
internal class RequestDataModel : IValidation
|
||||
{
|
||||
private readonly WorkerDataModel? _worker;
|
||||
public string Id { get; private set; }
|
||||
@@ -38,23 +40,27 @@ public class RequestDataModel : IValidation
|
||||
}
|
||||
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "WorkerId"));
|
||||
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkerId"));
|
||||
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Sum"));
|
||||
|
||||
if ((Softwares?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The request must include products");
|
||||
throw new ValidationException(localizer["ValidationExceptionMessageNoProductsInSale"]);
|
||||
|
||||
if (!Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$"))
|
||||
{
|
||||
throw new ValidationException("Invalid email format");
|
||||
}
|
||||
throw new ValidationException(localizer["ValidationExceptionMessageIncorrectEmail"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double
|
||||
internal class SalaryDataModel(string workerId, DateTime salaryDate, double
|
||||
workerSalary) : IValidation
|
||||
{
|
||||
private readonly WorkerDataModel? _worker;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate.ToUniversalTime();
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
public string WorkerFIO => _worker?.FIO ?? string.Empty;
|
||||
|
||||
@@ -18,14 +20,16 @@ workerSalary) : IValidation
|
||||
_worker = worker;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "WorkerId"));
|
||||
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "WorkerId"));
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Salary"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -11,7 +13,7 @@ using System.Xml;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string manufacturerId, double price, bool isDeleted) : IValidation
|
||||
internal class SoftwareDataModel(string id, string softwareName, SoftwareType softwareType, string manufacturerId, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
private readonly ManufacturerDataModel? _manufacturer;
|
||||
public string Id { get; private set; } = id;
|
||||
@@ -35,21 +37,21 @@ public class SoftwareDataModel(string id, string softwareName, SoftwareType soft
|
||||
{ }
|
||||
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Id"));
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
if (SoftwareName.IsEmpty())
|
||||
throw new ValidationException("Field SoftwareName is empty");
|
||||
if (SoftwareType == SoftwareType.None)
|
||||
throw new ValidationException("Field SoftwareType is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "SoftwareName"));
|
||||
if (SoftwareType == SoftwareType.None)
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "SoftwareType"));
|
||||
if (ManufacturerId.IsEmpty())
|
||||
throw new ValidationException("Field ManufacturerId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "ManufacturerId"));
|
||||
if (!ManufacturerId.IsGuid())
|
||||
throw new ValidationException("The value in the field ManufacturerId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "ManufacturerId"));
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Price"));
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -9,7 +11,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IValidation
|
||||
internal class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IValidation
|
||||
{
|
||||
private readonly SoftwareDataModel? _software;
|
||||
public string SoftwareId { get; private set; } = softwareId;
|
||||
@@ -24,14 +26,14 @@ public class SoftwareHistoryDataModel(string softwareId, double oldPrice) : IVal
|
||||
_software = software;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (SoftwareId.IsEmpty())
|
||||
throw new ValidationException("Field SoftwareId is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "SoftwareId"));
|
||||
if (!SoftwareId.IsGuid())
|
||||
throw new ValidationException("The value in the field SoftwareId is not a unique identifier");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "SoftwareId"));
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "OldPrice"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,17 +4,19 @@ using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Extensions;
|
||||
using SmallSoftwareContracts.Infrastructure;
|
||||
using SmallSoftwareContracts.Infrastructure.PostConfigurations;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, PostConfiguration configuration) : IValidation
|
||||
internal class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted, PostConfiguration configuration) : IValidation
|
||||
{
|
||||
private readonly PostDataModel? _post;
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string PostId { get; private set; } = postId;
|
||||
public DateTime BirthDate { get; private set; } = birthDate;
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||
public DateTime BirthDate { get; private set; } = birthDate.ToUniversalTime();
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate.ToUniversalTime();
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
public string PostName => _post?.PostName ?? string.Empty;
|
||||
public PostConfiguration ConfigurationModel { get; private set; } = configuration;
|
||||
@@ -46,27 +48,36 @@ public class WorkerDataModel(string id, string fio, string postId, DateTime birt
|
||||
}
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
public void Validate(IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
throw new ValidationException(localizer[Messages.ValidationExceptionMessageEmptyField, nameof(Id)]);
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
throw new ValidationException(localizer[Messages.ValidationExceptionMessageNotAId, nameof(Id)]);
|
||||
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
throw new ValidationException(localizer[Messages.ValidationExceptionMessageEmptyField, nameof(FIO)]);
|
||||
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
throw new ValidationException(localizer[Messages.ValidationExceptionMessageEmptyField, nameof(PostId)]);
|
||||
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
throw new ValidationException(localizer[Messages.ValidationExceptionMessageNotAId, nameof(PostId)]);
|
||||
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
|
||||
throw new ValidationException($"Minors cannot be hired (BirthDate = { BirthDate.ToShortDateString() })");
|
||||
throw new ValidationException(localizer[Messages.ValidationExceptionMessageMinorsBirthDate, BirthDate.ToShortDateString()]);
|
||||
|
||||
if (EmploymentDate.Date < BirthDate.Date)
|
||||
throw new ValidationException("The date of employment cannot be less than the date of birth");
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - { EmploymentDate.ToShortDateString() }, BirthDate - { BirthDate.ToShortDateString()})");
|
||||
throw new ValidationException(localizer[Messages.ValidationExceptionMessageEmploymentDateAndBirthDate, EmploymentDate.ToShortDateString(), BirthDate.ToShortDateString()]);
|
||||
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||
throw new ValidationException(localizer[Messages.ValidationExceptionMessageMinorsEmploymentDate, EmploymentDate.ToShortDateString(), BirthDate.ToShortDateString()]);
|
||||
|
||||
if (ConfigurationModel is null)
|
||||
throw new ValidationException("Field ConfigurationModel is not initialized");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotInitialized"], "ConfigurationModel"));
|
||||
|
||||
if (ConfigurationModel!.Rate <= 0)
|
||||
throw new ValidationException("Field Rate is less or equal zero");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageLessOrEqualZero"], "Rate"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
public class ElementDeletedException : Exception
|
||||
{
|
||||
public ElementDeletedException(string id) : base($"Cannot modify a deleted item(id: { id})") { }
|
||||
}
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
internal class ElementDeletedException(string id, IStringLocalizer<Messages> localizer) :
|
||||
Exception(string.Format(localizer["ElementDeletedExceptionMessage"], id))
|
||||
{ }
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
public class ElementExistsException : Exception
|
||||
internal class ElementExistsException(string paramName, string paramValue, IStringLocalizer<Messages> localizer) :
|
||||
Exception(string.Format(localizer["ElementExistsExceptionMessage"], paramValue, paramName))
|
||||
{
|
||||
public string ParamName { get; private set; }
|
||||
public string ParamValue { get; private set; }
|
||||
public ElementExistsException(string paramName, string paramValue) :
|
||||
base($"There is already an element with value{paramValue} of parameter { paramName}")
|
||||
{
|
||||
ParamName = paramName;
|
||||
ParamValue = paramValue;
|
||||
}
|
||||
}
|
||||
public string ParamName { get; private set; } = paramName;
|
||||
|
||||
public string ParamValue { get; private set; } = paramValue;
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
public class ElementNotFoundException : Exception
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
|
||||
internal class ElementNotFoundException(string value, IStringLocalizer<Messages> localizer) :
|
||||
Exception(string.Format(localizer["ElementNotFoundExceptionMessage"], value))
|
||||
{
|
||||
public string Value { get; private set; }
|
||||
public ElementNotFoundException(string value) : base($"Element not found at value = { value}")
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
public string Value { get; private set; } = value;
|
||||
}
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
|
||||
public class IncorrectDatesException : Exception
|
||||
{
|
||||
public IncorrectDatesException(DateTime start, DateTime end) :
|
||||
base($"The end date must be later than the start date..StartDate: { start: dd.MM.YYYY}.EndDate: {end:dd.MM.YYYY}") { }
|
||||
}
|
||||
internal class IncorrectDatesException(DateTime start, DateTime end, IStringLocalizer<Messages> localizer) :
|
||||
Exception(string.Format(localizer["IncorrectDatesExceptionMessage"], start.ToShortDateString(), end.ToShortDateString()))
|
||||
{ }
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.Exceptions;
|
||||
|
||||
public class StorageException : Exception
|
||||
{
|
||||
public StorageException(Exception ex) : base($"Error while working in storage: { ex.Message}", ex) { }
|
||||
}
|
||||
internal class StorageException(Exception ex, IStringLocalizer<Messages> localizer) :
|
||||
Exception(string.Format(localizer["StorageExceptionMessage"], ex.Message), ex)
|
||||
{ }
|
||||
@@ -1,12 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareContracts.Infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
internal interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
void Validate(IStringLocalizer<Messages> localizer);
|
||||
}
|
||||
|
||||
405
SmallSoftwareProject/SmallSoftwareContracts/Resources/Messages.Designer.cs
generated
Normal file
405
SmallSoftwareProject/SmallSoftwareContracts/Resources/Messages.Designer.cs
generated
Normal file
@@ -0,0 +1,405 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// Этот код создан программой.
|
||||
// Исполняемая версия:4.0.30319.42000
|
||||
//
|
||||
// Изменения в этом файле могут привести к неправильной работе и будут потеряны в случае
|
||||
// повторной генерации кода.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace SmallSoftwareContracts.Resources {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Класс ресурса со строгой типизацией для поиска локализованных строк и т.д.
|
||||
/// </summary>
|
||||
// Этот класс создан автоматически классом StronglyTypedResourceBuilder
|
||||
// с помощью такого средства, как ResGen или Visual Studio.
|
||||
// Чтобы добавить или удалить член, измените файл .ResX и снова запустите ResGen
|
||||
// с параметром /str или перестройте свой проект VS.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Messages {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Messages() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Возвращает кэшированный экземпляр ResourceManager, использованный этим классом.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SmallSoftwareContracts.Resources.Messages", typeof(Messages).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перезаписывает свойство CurrentUICulture текущего потока для всех
|
||||
/// обращений к ресурсу с помощью этого класса ресурса со строгой типизацией.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Элемент по данным: {0} был удален.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageElementDeletedException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageElementDeletedException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Не найден элемент по данным: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageElementNotFoundException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageElementNotFoundException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Данные пусты.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageEmptyDate {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageEmptyDate", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Неправильные даты: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageIncorrectDatesException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageIncorrectDatesException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Ошибка при обработке данных: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageInvalidOperationException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageInvalidOperationException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Ошибка при работе с хранилищем данных: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageStorageException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageStorageException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Переданы неверные данные: {0}.
|
||||
/// </summary>
|
||||
internal static string AdapterMessageValidationException {
|
||||
get {
|
||||
return ResourceManager.GetString("AdapterMessageValidationException", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Компонент.
|
||||
/// </summary>
|
||||
internal static string DocumentDocCaptionComponent {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentDocCaptionComponent", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Производитель.
|
||||
/// </summary>
|
||||
internal static string DocumentDocCaptionManufacturer {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentDocCaptionManufacturer", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Компоненты по производителям.
|
||||
/// </summary>
|
||||
internal static string DocumentDocHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentDocHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Сформировано на дату {0}.
|
||||
/// </summary>
|
||||
internal static string DocumentDocSubHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentDocSubHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Кол-во.
|
||||
/// </summary>
|
||||
internal static string DocumentExcelCaptionCount {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentExcelCaptionCount", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Дата.
|
||||
/// </summary>
|
||||
internal static string DocumentExcelCaptionDate {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentExcelCaptionDate", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Скидка.
|
||||
/// </summary>
|
||||
internal static string DocumentExcelCaptionDiscount {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentExcelCaptionDiscount", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Товар.
|
||||
/// </summary>
|
||||
internal static string DocumentExcelCaptionProduct {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentExcelCaptionProduct", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Сумма.
|
||||
/// </summary>
|
||||
internal static string DocumentExcelCaptionSum {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentExcelCaptionSum", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Всего.
|
||||
/// </summary>
|
||||
internal static string DocumentExcelCaptionTotal {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentExcelCaptionTotal", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Продажи за период.
|
||||
/// </summary>
|
||||
internal static string DocumentExcelHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentExcelHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на c {0} по {1}.
|
||||
/// </summary>
|
||||
internal static string DocumentExcelSubHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentExcelSubHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Начисления.
|
||||
/// </summary>
|
||||
internal static string DocumentPdfDiagramCaption {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentPdfDiagramCaption", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Зарплатная ведомость.
|
||||
/// </summary>
|
||||
internal static string DocumentPdfHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentPdfHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на за период с {0} по {1}.
|
||||
/// </summary>
|
||||
internal static string DocumentPdfSubHeader {
|
||||
get {
|
||||
return ResourceManager.GetString("DocumentPdfSubHeader", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Нельзя изменить удаленный элемент (идентификатор: {0}).
|
||||
/// </summary>
|
||||
internal static string ElementDeletedExceptionMessage {
|
||||
get {
|
||||
return ResourceManager.GetString("ElementDeletedExceptionMessage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Уже существует элемент со значением {0} параметра {1}.
|
||||
/// </summary>
|
||||
internal static string ElementExistsExceptionMessage {
|
||||
get {
|
||||
return ResourceManager.GetString("ElementExistsExceptionMessage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Элемент не найден по значению = {0}.
|
||||
/// </summary>
|
||||
internal static string ElementNotFoundExceptionMessage {
|
||||
get {
|
||||
return ResourceManager.GetString("ElementNotFoundExceptionMessage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Дата окончания должна быть позже даты начала. Дата начала: {0}. Дата окончания: {1}.
|
||||
/// </summary>
|
||||
internal static string IncorrectDatesExceptionMessage {
|
||||
get {
|
||||
return ResourceManager.GetString("IncorrectDatesExceptionMessage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Недостаточно данных для обработки: {0}.
|
||||
/// </summary>
|
||||
internal static string NotEnoughDataToProcessExceptionMessage {
|
||||
get {
|
||||
return ResourceManager.GetString("NotEnoughDataToProcessExceptionMessage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Не найдены данные.
|
||||
/// </summary>
|
||||
internal static string NotFoundDataMessage {
|
||||
get {
|
||||
return ResourceManager.GetString("NotFoundDataMessage", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Дата трудоустройства не может быть раньше даты рождения ({0}, {1}).
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageEmploymentDateAndBirthDate {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageEmploymentDateAndBirthDate", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение в поле {0} пусто.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageEmptyField {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageEmptyField", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение в поле ФИО не является ФИО.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageIncorrectFIO {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageIncorrectFIO", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение в поле Телефонный номер не является телефонным номером.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageIncorrectPhoneNumber {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageIncorrectPhoneNumber", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение в поле {0} меньше или равно 0.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageLessOrEqualZero {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageLessOrEqualZero", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Несовершеннолетние не могут быть приняты на работу (Дата рождения: {0}).
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageMinorsBirthDate {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageMinorsBirthDate", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Несовершеннолетние не могут быть приняты на работу (Дата трудоустройства {0}, Дата рождения: {1}).
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageMinorsEmploymentDate {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageMinorsEmploymentDate", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на В продаже должен быть хотя бы один товар.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageNoProductsInSale {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageNoProductsInSale", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение в поле {0} не является типом уникального идентификатора.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageNotAId {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageNotAId", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ищет локализованную строку, похожую на Значение в поле {0} не проиницализировано.
|
||||
/// </summary>
|
||||
internal static string ValidationExceptionMessageNotInitialized {
|
||||
get {
|
||||
return ResourceManager.GetString("ValidationExceptionMessageNotInitialized", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,234 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="AdapterMessageElementDeletedException" xml:space="preserve">
|
||||
<value>Элемент по данным: {0} был удален</value>
|
||||
</data>
|
||||
<data name="AdapterMessageElementNotFoundException" xml:space="preserve">
|
||||
<value>Не найден элемент по данным: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageEmptyDate" xml:space="preserve">
|
||||
<value>Данные пусты</value>
|
||||
</data>
|
||||
<data name="AdapterMessageIncorrectDatesException" xml:space="preserve">
|
||||
<value>Неправильные даты: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageInvalidOperationException" xml:space="preserve">
|
||||
<value>Ошибка при обработке данных: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageStorageException" xml:space="preserve">
|
||||
<value>Ошибка при работе с хранилищем данных: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageValidationException" xml:space="preserve">
|
||||
<value>Переданы неверные данные: {0}</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionSoftware" xml:space="preserve">
|
||||
<value>Название ПО</value>
|
||||
</data>
|
||||
<data name="DocumentDocHeader" xml:space="preserve">
|
||||
<value>ПО по истории</value>
|
||||
</data>
|
||||
<data name="DocumentDocSubHeader" xml:space="preserve">
|
||||
<value>Сформировано на дату {0}</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionCount" xml:space="preserve">
|
||||
<value>Кол-во</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionDate" xml:space="preserve">
|
||||
<value>Дата</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionSoftware" xml:space="preserve">
|
||||
<value>ПО</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionSum" xml:space="preserve">
|
||||
<value>Сумма</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionTotal" xml:space="preserve">
|
||||
<value>Всего</value>
|
||||
</data>
|
||||
<data name="DocumentExcelHeader" xml:space="preserve">
|
||||
<value>Заявки за период</value>
|
||||
</data>
|
||||
<data name="DocumentExcelSubHeader" xml:space="preserve">
|
||||
<value>c {0} по {1}</value>
|
||||
</data>
|
||||
<data name="DocumentPdfDiagramCaption" xml:space="preserve">
|
||||
<value>Начисления</value>
|
||||
</data>
|
||||
<data name="DocumentPdfHeader" xml:space="preserve">
|
||||
<value>Зарплатная ведомость</value>
|
||||
</data>
|
||||
<data name="DocumentPdfSubHeader" xml:space="preserve">
|
||||
<value>за период с {0} по {1}</value>
|
||||
</data>
|
||||
<data name="ElementDeletedExceptionMessage" xml:space="preserve">
|
||||
<value>Нельзя изменить удаленный элемент (идентификатор: {0})</value>
|
||||
</data>
|
||||
<data name="ElementExistsExceptionMessage" xml:space="preserve">
|
||||
<value>Уже существует элемент со значением {0} параметра {1}</value>
|
||||
</data>
|
||||
<data name="ElementNotFoundExceptionMessage" xml:space="preserve">
|
||||
<value>Элемент не найден по значению = {0}</value>
|
||||
</data>
|
||||
<data name="IncorrectDatesExceptionMessage" xml:space="preserve">
|
||||
<value>Дата окончания должна быть позже даты начала. Дата начала: {0}. Дата окончания: {1}</value>
|
||||
</data>
|
||||
<data name="NotEnoughDataToProcessExceptionMessage" xml:space="preserve">
|
||||
<value>Недостаточно данных для обработки: {0}</value>
|
||||
</data>
|
||||
<data name="NotFoundDataMessage" xml:space="preserve">
|
||||
<value>Не найдены данные</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageEmploymentDateAndBirthDate" xml:space="preserve">
|
||||
<value>Дата трудоустройства не может быть раньше даты рождения ({0}, {1})</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageEmptyField" xml:space="preserve">
|
||||
<value>Значение в поле {0} пусто</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageIncorrectFIO" xml:space="preserve">
|
||||
<value>Значение в поле ФИО не является ФИО</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageIncorrectEmail" xml:space="preserve">
|
||||
<value>Значение в поле Email не является Email</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageLessOrEqualZero" xml:space="preserve">
|
||||
<value>Значение в поле {0} меньше или равно 0</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageMinorsBirthDate" xml:space="preserve">
|
||||
<value>Несовершеннолетние не могут быть приняты на работу (Дата рождения: {0})</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageMinorsEmploymentDate" xml:space="preserve">
|
||||
<value>Несовершеннолетние не могут быть приняты на работу (Дата трудоустройства {0}, Дата рождения: {1})</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNoSoftwaresCount" xml:space="preserve">
|
||||
<value>В запросе должно быть хотя бы одно ПО</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNotAId" xml:space="preserve">
|
||||
<value>Значение в поле {0} не является типом уникального идентификатора</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNotInitialized" xml:space="preserve">
|
||||
<value>Значение в поле {0} не проиницализировано</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionOldPrice" xml:space="preserve">
|
||||
<value>Старая цена</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionData" xml:space="preserve">
|
||||
<value>Дата</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -9,6 +9,18 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="SmallSoftwareDatabase" />
|
||||
<InternalsVisibleTo Include="SmallSoftwareTests" />
|
||||
<InternalsVisibleTo Include="SmallSoftwareBusinessLogic" />
|
||||
<InternalsVisibleTo Include="SmallSoftwareWebApi" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Resources\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface IManufacturerStorageContract
|
||||
internal interface IManufacturerStorageContract
|
||||
{
|
||||
List<ManufacturerDataModel> GetList();
|
||||
ManufacturerDataModel? GetElementById(string id);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface IPostStorageContract
|
||||
internal interface IPostStorageContract
|
||||
{
|
||||
List<PostDataModel> GetList();
|
||||
List<PostDataModel> GetPostWithHistory(string postId);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface IRequestStorageContract
|
||||
internal interface IRequestStorageContract
|
||||
{
|
||||
Task<List<RequestDataModel>> GetListAsync(DateTime startDate, DateTime endDate, CancellationToken ct);
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface ISalaryStorageContract
|
||||
internal interface ISalaryStorageContract
|
||||
{
|
||||
List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? workerId = null);
|
||||
void AddElement(SalaryDataModel salaryDataModel);
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface ISoftwareStorageContract
|
||||
internal interface ISoftwareStorageContract
|
||||
{
|
||||
Task<List<SoftwareHistoryDataModel>> GetListAsync(CancellationToken ct);
|
||||
List<SoftwareDataModel> GetList(bool onlyActive = true, string? manufacturerId = null);
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SmallSoftwareContracts.StoragesContracts;
|
||||
|
||||
public interface IWorkerStorageContract
|
||||
internal interface IWorkerStorageContract
|
||||
{
|
||||
List<WorkerDataModel> GetList(bool onlyActive = true, string? postId =
|
||||
null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime?
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
using System;
|
||||
@@ -15,8 +17,9 @@ namespace SmallSoftwareDatabase.Implementations;
|
||||
internal class ManufacturerStorageContract : IManufacturerStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
public ManufacturerStorageContract(SmallSoftwareDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -24,6 +27,7 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
cfg.AddMaps(typeof(Manufacturer));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
public List<ManufacturerDataModel> GetList()
|
||||
{
|
||||
@@ -34,7 +38,7 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public ManufacturerDataModel? GetElementById(string id)
|
||||
@@ -47,7 +51,7 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public ManufacturerDataModel? GetElementByName(string name)
|
||||
@@ -60,7 +64,7 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public ManufacturerDataModel? GetElementByOldName(string name)
|
||||
@@ -75,7 +79,7 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void AddElement(ManufacturerDataModel manufacturerDataModel)
|
||||
@@ -89,20 +93,25 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
"ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id",
|
||||
manufacturerDataModel.Id);
|
||||
throw new ElementExistsException("Id", manufacturerDataModel.Id, _localizer);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "IX_Manufacturers_ManufacturerName" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("ManufacturerName",
|
||||
manufacturerDataModel.ManufacturerName);
|
||||
manufacturerDataModel.ManufacturerName, _localizer);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "PK_Manufacturers" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", manufacturerDataModel.Id, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void UpdElement(ManufacturerDataModel manufacturerDataModel)
|
||||
@@ -110,7 +119,7 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
try
|
||||
{
|
||||
var element = GetManufacturerById(manufacturerDataModel.Id) ??
|
||||
throw new ElementNotFoundException(manufacturerDataModel.Id);
|
||||
throw new ElementNotFoundException(manufacturerDataModel.Id, _localizer);
|
||||
if (element.ManufacturerName !=
|
||||
manufacturerDataModel.ManufacturerName)
|
||||
{
|
||||
@@ -133,12 +142,12 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("ManufacturerName",
|
||||
manufacturerDataModel.ManufacturerName);
|
||||
manufacturerDataModel.ManufacturerName, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void DelElement(string id)
|
||||
@@ -146,7 +155,7 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
try
|
||||
{
|
||||
var element = GetManufacturerById(id) ?? throw new
|
||||
ElementNotFoundException(id);
|
||||
ElementNotFoundException(id, _localizer);
|
||||
_dbContext.Manufacturers.Remove(element);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
@@ -158,7 +167,7 @@ public ManufacturerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
private Manufacturer? GetManufacturerById(string id) =>
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
|
||||
@@ -12,7 +14,8 @@ internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public PostStorageContract(SmallSoftwareDbContext dbContext)
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
public PostStorageContract(SmallSoftwareDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -27,6 +30,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
public List<PostDataModel> GetList()
|
||||
{
|
||||
@@ -37,7 +41,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public List<PostDataModel> GetPostWithHistory(string postId)
|
||||
@@ -49,7 +53,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public PostDataModel? GetElementById(string id)
|
||||
@@ -63,7 +67,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public PostDataModel? GetElementByName(string name)
|
||||
@@ -77,7 +81,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void AddElement(PostDataModel postDataModel)
|
||||
@@ -92,18 +96,18 @@ internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("PostName",
|
||||
postDataModel.PostName);
|
||||
postDataModel.PostName, _localizer);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "IX_Posts_PostId_IsActual" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("PostId", postDataModel.Id);
|
||||
throw new ElementExistsException("PostId", postDataModel.Id, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void UpdElement(PostDataModel postDataModel)
|
||||
@@ -114,11 +118,11 @@ internal class PostStorageContract : IPostStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetPostById(postDataModel.Id) ?? throw new
|
||||
ElementNotFoundException(postDataModel.Id);
|
||||
ElementNotFoundException(postDataModel.Id, _localizer);
|
||||
if (!element.IsActual)
|
||||
{
|
||||
throw new
|
||||
ElementDeletedException(postDataModel.Id);
|
||||
ElementDeletedException(postDataModel.Id, _localizer);
|
||||
}
|
||||
element.IsActual = false;
|
||||
_dbContext.SaveChanges();
|
||||
@@ -138,7 +142,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("PostName",
|
||||
postDataModel.PostName);
|
||||
postDataModel.PostName, _localizer);
|
||||
}
|
||||
catch (Exception ex) when (ex is ElementDeletedException || ex is
|
||||
ElementNotFoundException)
|
||||
@@ -149,7 +153,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void DelElement(string id)
|
||||
@@ -157,10 +161,10 @@ internal class PostStorageContract : IPostStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetPostById(id) ?? throw new
|
||||
ElementNotFoundException(id);
|
||||
ElementNotFoundException(id, _localizer);
|
||||
if (!element.IsActual)
|
||||
{
|
||||
throw new ElementDeletedException(id);
|
||||
throw new ElementDeletedException(id, _localizer);
|
||||
}
|
||||
element.IsActual = false;
|
||||
_dbContext.SaveChanges();
|
||||
@@ -176,7 +180,7 @@ internal class PostStorageContract : IPostStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetPostById(id) ?? throw new
|
||||
ElementNotFoundException(id);
|
||||
ElementNotFoundException(id, _localizer);
|
||||
element.IsActual = true;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
|
||||
@@ -11,8 +13,9 @@ internal class RequestStorageContract : IRequestStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public RequestStorageContract(SmallSoftwareDbContext dbContext)
|
||||
public RequestStorageContract(SmallSoftwareDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -32,6 +35,7 @@ internal class RequestStorageContract : IRequestStorageContract
|
||||
.ForMember(dest => dest.RequestDate, opt => opt.MapFrom(src => src.RequestDate));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public List<RequestDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? workerId = null, string? softwareId = null)
|
||||
@@ -52,7 +56,7 @@ internal class RequestStorageContract : IRequestStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +69,7 @@ internal class RequestStorageContract : IRequestStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +83,7 @@ internal class RequestStorageContract : IRequestStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,11 +91,11 @@ internal class RequestStorageContract : IRequestStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetRequestById(id) ?? throw new ElementNotFoundException(id);
|
||||
var element = GetRequestById(id) ?? throw new ElementNotFoundException(id, _localizer);
|
||||
|
||||
if (element.IsCancel)
|
||||
{
|
||||
throw new ElementDeletedException(id);
|
||||
throw new ElementDeletedException(id, _localizer);
|
||||
}
|
||||
|
||||
element.IsCancel = true;
|
||||
@@ -105,7 +109,7 @@ internal class RequestStorageContract : IRequestStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +131,7 @@ internal class RequestStorageContract : IRequestStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
|
||||
@@ -10,8 +12,9 @@ namespace SmallSoftwareDatabase.Implementations;
|
||||
internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public SalaryStorageContract(SmallSoftwareDbContext dbContext)
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
public SalaryStorageContract(SmallSoftwareDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -22,6 +25,7 @@ internal class SalaryStorageContract : ISalaryStorageContract
|
||||
.ForMember(dest => dest.WorkerSalary, opt => opt.MapFrom(src => src.Salary));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
public List<SalaryDataModel> GetList(DateTime startDate, DateTime endDate, string? workerId = null)
|
||||
{
|
||||
@@ -37,7 +41,7 @@ internal class SalaryStorageContract : ISalaryStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void AddElement(SalaryDataModel salaryDataModel)
|
||||
@@ -50,7 +54,7 @@ internal class SalaryStorageContract : ISalaryStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +67,7 @@ internal class SalaryStorageContract : ISalaryStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
|
||||
@@ -12,7 +14,8 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public SoftwareStorageContract(SmallSoftwareDbContext dbContext)
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
public SoftwareStorageContract(SmallSoftwareDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -24,6 +27,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
cfg.CreateMap<SoftwareHistory, SoftwareHistoryDataModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public async Task<List<SoftwareHistoryDataModel>> GetListAsync(CancellationToken ct)
|
||||
@@ -36,7 +40,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -61,7 +65,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public List<SoftwareHistoryDataModel> GetHistoryBySoftwareId(string
|
||||
@@ -76,7 +80,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public SoftwareDataModel? GetElementById(string id)
|
||||
@@ -88,7 +92,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public SoftwareDataModel? GetElementByName(string name)
|
||||
@@ -102,7 +106,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void AddElement(SoftwareDataModel softwareDataModel)
|
||||
@@ -116,19 +120,19 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
"ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", softwareDataModel.Id);
|
||||
throw new ElementExistsException("Id", softwareDataModel.Id, _localizer);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is
|
||||
PostgresException { ConstraintName: "IX_Softwares_SoftwareName_IsDeleted" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("SoftwareName",
|
||||
softwareDataModel.SoftwareName);
|
||||
softwareDataModel.SoftwareName, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void UpdElement(SoftwareDataModel softwareDataModel)
|
||||
@@ -139,7 +143,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetSoftwareById(softwareDataModel.Id) ??
|
||||
throw new ElementNotFoundException(softwareDataModel.Id);
|
||||
throw new ElementNotFoundException(softwareDataModel.Id, _localizer);
|
||||
if (element.Price != softwareDataModel.Price)
|
||||
{
|
||||
_dbContext.SoftwareHistories.Add(new
|
||||
@@ -163,7 +167,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("SoftwareName",
|
||||
softwareDataModel.SoftwareName);
|
||||
softwareDataModel.SoftwareName, _localizer);
|
||||
}
|
||||
catch (Exception ex) when (ex is ElementDeletedException || ex is
|
||||
ElementNotFoundException)
|
||||
@@ -174,7 +178,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void DelElement(string id)
|
||||
@@ -182,7 +186,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetSoftwareById(id) ?? throw new
|
||||
ElementNotFoundException(id);
|
||||
ElementNotFoundException(id, _localizer);
|
||||
element.IsDeleted = true;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
@@ -194,7 +198,7 @@ internal class SoftwareStorageContract : ISoftwareStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
private Software? GetSoftwareById(string id) =>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
using System;
|
||||
@@ -15,7 +17,8 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
{
|
||||
private readonly SmallSoftwareDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
public WorkerStorageContract(SmallSoftwareDbContext dbContext)
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
public WorkerStorageContract(SmallSoftwareDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -29,6 +32,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src => src.ConfigurationModel));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
public List<WorkerDataModel> GetList(bool onlyActive = true, string? postId
|
||||
= null, DateTime? fromBirthDate = null, DateTime? toBirthDate = null, DateTime?
|
||||
@@ -61,7 +65,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public WorkerDataModel? GetElementById(string id)
|
||||
@@ -73,7 +77,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public WorkerDataModel? GetElementByFIO(string fio)
|
||||
@@ -86,7 +90,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void AddElement(WorkerDataModel workerDataModel)
|
||||
@@ -99,12 +103,12 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", workerDataModel.Id);
|
||||
throw new ElementExistsException("Id", workerDataModel.Id, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void UpdElement(WorkerDataModel workerDataModel)
|
||||
@@ -112,7 +116,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetWorkerById(workerDataModel.Id) ?? throw new
|
||||
ElementNotFoundException(workerDataModel.Id);
|
||||
ElementNotFoundException(workerDataModel.Id, _localizer);
|
||||
_dbContext.Workers.Update(_mapper.Map(workerDataModel,
|
||||
element));
|
||||
_dbContext.SaveChanges();
|
||||
@@ -125,7 +129,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
public void DelElement(string id)
|
||||
@@ -133,7 +137,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
try
|
||||
{
|
||||
var element = GetWorkerById(id) ?? throw new
|
||||
ElementNotFoundException(id);
|
||||
ElementNotFoundException(id, _localizer);
|
||||
element.IsDeleted = true;
|
||||
element.DateOfDelete = DateTime.UtcNow;
|
||||
_dbContext.SaveChanges();
|
||||
@@ -146,7 +150,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +167,7 @@ internal class WorkerStorageContract : IWorkerStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@ internal class SmallSoftwareDbContext : DbContext
|
||||
public SmallSoftwareDbContext(IConfigurationDatabase configurationDatabase)
|
||||
{
|
||||
_configurationDatabase = configurationDatabase;
|
||||
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
|
||||
AppContext.SetSwitch("Npgsql.DisableDateTimeInfinityConversions", true);
|
||||
}
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
|
||||
@@ -5,6 +5,7 @@ using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
|
||||
namespace SmallSoftwareTests.BusinessLogicsContractsTests;
|
||||
|
||||
@@ -18,7 +19,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
{
|
||||
_manufacturerStorageContract = new
|
||||
Mock<IManufacturerStorageContract>();
|
||||
_manufacturerBusinessLogicContract = new ManufacturerBusinessLogicContract(_manufacturerStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_manufacturerBusinessLogicContract = new ManufacturerBusinessLogicContract(_manufacturerStorageContract.Object, StringLocalizerMockCreator.GetObject(), new Mock<ILogger>().Object);
|
||||
}
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
@@ -69,7 +70,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
_manufacturerStorageContract.Setup(x => x.GetList()).Throws(new
|
||||
StorageException(new InvalidOperationException()));
|
||||
StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.GetAllManufacturers(),
|
||||
@@ -186,10 +187,10 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
//Arrange
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.GetManufacturerByData(Guid.NewGuid().ToString(
|
||||
@@ -212,7 +213,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
//Arrange
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.GetElementByOldName(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.GetManufacturerByData("name"),
|
||||
@@ -249,7 +250,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
//Arrange
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<ManufacturerDataModel>())).Throws(new
|
||||
ElementExistsException("Data", "Data"));
|
||||
ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.InsertManufacturer(new(Guid.NewGuid().ToString
|
||||
@@ -284,7 +285,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
//Arrange
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<ManufacturerDataModel>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.InsertManufacturer(new(Guid.NewGuid().ToString
|
||||
@@ -320,7 +321,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
//Arrange
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<ManufacturerDataModel>())).Throws(new
|
||||
ElementNotFoundException(""));
|
||||
ElementNotFoundException("", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.UpdateManufacturer(new(Guid.NewGuid().ToString
|
||||
@@ -334,7 +335,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
//Arrange
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<ManufacturerDataModel>())).Throws(new
|
||||
ElementExistsException("Data", "Data"));
|
||||
ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.UpdateManufacturer(new(Guid.NewGuid().ToString
|
||||
@@ -369,7 +370,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
//Arrange
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<ManufacturerDataModel>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.UpdateManufacturer(new(Guid.NewGuid().ToString
|
||||
@@ -398,7 +399,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.DeleteManufacturer(Guid.NewGuid().ToString()),
|
||||
@@ -435,7 +436,7 @@ internal class ManufacturerBusinessLogicContractTests
|
||||
//Arrange
|
||||
_manufacturerStorageContract.Setup(x =>
|
||||
x.DelElement(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_manufacturerBusinessLogicContract.DeleteManufacturer(Guid.NewGuid().ToString()),
|
||||
|
||||
@@ -5,6 +5,7 @@ using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -23,7 +24,7 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
_postStorageContract = new Mock<IPostStorageContract>();
|
||||
_postBusinessLogicContract = new
|
||||
PostBusinessLogicContract(_postStorageContract.Object, new
|
||||
PostBusinessLogicContract(_postStorageContract.Object, StringLocalizerMockCreator.GetObject(), new
|
||||
Mock<ILogger>().Object);
|
||||
}
|
||||
[SetUp]
|
||||
@@ -90,7 +91,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.GetList()).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.GetAllPosts(),
|
||||
@@ -170,7 +171,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.GetPostWithHistory(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.GetAllDataOfPost(Guid.NewGuid().ToString()),
|
||||
@@ -254,10 +255,10 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_postStorageContract.Setup(x =>
|
||||
x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.GetPostByData(Guid.NewGuid().ToString()),
|
||||
@@ -296,7 +297,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<PostDataModel>())).Throws(new
|
||||
ElementExistsException("Data", "Data"));
|
||||
ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name",
|
||||
@@ -330,7 +331,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name",
|
||||
@@ -366,7 +367,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<PostDataModel>())).Throws(new
|
||||
ElementNotFoundException(""));
|
||||
ElementNotFoundException("", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name",
|
||||
@@ -381,7 +382,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<PostDataModel>())).Throws(new
|
||||
ElementExistsException("Data", "Data"));
|
||||
ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme",
|
||||
@@ -415,7 +416,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name",
|
||||
@@ -445,7 +446,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_postStorageContract.Setup(x =>
|
||||
x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.DeletePost(Guid.NewGuid().ToString()),
|
||||
@@ -480,7 +481,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.DelElement(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.DeletePost(Guid.NewGuid().ToString()),
|
||||
@@ -509,7 +510,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_postStorageContract.Setup(x =>
|
||||
x.ResElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
x.ResElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.RestorePost(Guid.NewGuid().ToString()),
|
||||
@@ -544,7 +545,7 @@ internal class PostBusinessLogicContractTests
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x =>
|
||||
x.ResElement(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_postBusinessLogicContract.RestorePost(Guid.NewGuid().ToString()),
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using SmallSoftwareBusinessLogic.Implementations;
|
||||
using SmallSoftwareBusinessLogic.OfficePackage;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
|
||||
namespace SmallSoftwareTests.BusinessLogicsContractsTests;
|
||||
|
||||
@@ -29,7 +29,7 @@ internal class ReportContractTests
|
||||
_baseWordBuilder = new Mock<BaseWordBuilder>();
|
||||
_baseExcelBuilder = new Mock<BaseExcelBuilder>();
|
||||
_basePdfBuilder = new Mock<BasePdfBuilder>();
|
||||
_reportContract = new ReportContract(_softwareStorageContract.Object, _requestStorageContract.Object, _salaryStorageContract.Object, _baseWordBuilder.Object, _baseExcelBuilder.Object, _basePdfBuilder.Object, new Mock<ILogger>().Object);
|
||||
_reportContract = new ReportContract(_softwareStorageContract.Object, _requestStorageContract.Object, _salaryStorageContract.Object, _baseWordBuilder.Object, _baseExcelBuilder.Object, _basePdfBuilder.Object, StringLocalizerMockCreator.GetObject(), new Mock<ILogger>().Object);
|
||||
}
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
@@ -92,7 +92,7 @@ internal class ReportContractTests
|
||||
public void GetDataSoftwaresByHistory_WhenStorageThrowError_ShouldFail_Test()
|
||||
{
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x => x.GetListAsync(It.IsAny<CancellationToken>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_softwareStorageContract.Setup(x => x.GetListAsync(It.IsAny<CancellationToken>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(async () => await _reportContract.GetDataSoftwaresByHistoryAsync(CancellationToken.None), Throws.TypeOf<StorageException>());
|
||||
_softwareStorageContract.Verify(x => x.GetListAsync(It.IsAny<CancellationToken>()), Times.Once);
|
||||
@@ -156,13 +156,7 @@ internal class ReportContractTests
|
||||
Assert.That(countRows, Is.EqualTo(8));
|
||||
|
||||
Assert.That(firstRow, Has.Length.EqualTo(3));
|
||||
Assert.That(secondRow, Has.Length.EqualTo(3));
|
||||
|
||||
Assert.That(firstRow[0], Is.EqualTo("Название ПО"));
|
||||
Assert.That(firstRow[1], Is.EqualTo("Старая цена"));
|
||||
|
||||
Assert.That(secondRow[0], Is.EqualTo("name1"));
|
||||
Assert.That(secondRow[1], Is.EqualTo(""));
|
||||
Assert.That(secondRow, Has.Length.EqualTo(3));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -222,7 +216,7 @@ internal class ReportContractTests
|
||||
//Arrange
|
||||
_requestStorageContract.Setup(x => x.GetListAsync(It.IsAny<DateTime>(),
|
||||
It.IsAny<DateTime>(), It.IsAny<CancellationToken>())).Throws(new
|
||||
StorageException(new InvalidOperationException()));
|
||||
StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(async () => await
|
||||
_reportContract.GetDataRequestByPeriodAsync(DateTime.UtcNow.AddDays(-1),
|
||||
@@ -330,7 +324,7 @@ internal class ReportContractTests
|
||||
// Arrange
|
||||
_salaryStorageContract.Setup(x =>
|
||||
x.GetListAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
|
||||
.ThrowsAsync(new StorageException(new InvalidOperationException()));
|
||||
.ThrowsAsync(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(async () => await _reportContract.GetDataSalaryByPeriodAsync(
|
||||
|
||||
@@ -4,6 +4,7 @@ using SmallSoftwareBusinessLogic.Implementations;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
|
||||
|
||||
namespace SmallSoftwareTests.BusinessLogicsContractsTests;
|
||||
@@ -19,7 +20,7 @@ internal class RequestBusinessLogicContractTests
|
||||
{
|
||||
_requestStorageContract = new Mock<IRequestStorageContract>();
|
||||
_requestBusinessLogicContract = new
|
||||
RequestBusinessLogicContract(_requestStorageContract.Object, new
|
||||
RequestBusinessLogicContract(_requestStorageContract.Object, StringLocalizerMockCreator.GetObject(), new
|
||||
Mock<ILogger>().Object);
|
||||
}
|
||||
[SetUp]
|
||||
@@ -96,7 +97,7 @@ internal class RequestBusinessLogicContractTests
|
||||
//Arrange
|
||||
_requestStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
|
||||
It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.GetAllRequestsByPeriod(DateTime.UtcNow,
|
||||
@@ -211,7 +212,7 @@ internal class RequestBusinessLogicContractTests
|
||||
_requestStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
|
||||
It.IsAny<DateTime?>(), It.IsAny<string>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.GetAllRequestsByWorkerByPeriod(Guid.NewGuid().ToString(),
|
||||
@@ -328,7 +329,7 @@ internal class RequestBusinessLogicContractTests
|
||||
_requestStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
|
||||
It.IsAny<DateTime?>(), It.IsAny<string>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.GetAllRequestsBySoftwareByPeriod(Guid.NewGuid().ToString()
|
||||
@@ -391,7 +392,7 @@ internal class RequestBusinessLogicContractTests
|
||||
//Arrange
|
||||
_requestStorageContract.Setup(x =>
|
||||
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.GetRequestByData(Guid.NewGuid().ToString()),
|
||||
@@ -431,7 +432,7 @@ internal class RequestBusinessLogicContractTests
|
||||
//Arrange
|
||||
_requestStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<RequestDataModel>())).Throws(new
|
||||
ElementExistsException("Data", "Data"));
|
||||
ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.InsertRequest(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "test@example.com", false,
|
||||
@@ -461,7 +462,7 @@ internal class RequestBusinessLogicContractTests
|
||||
//Arrange
|
||||
_requestStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<RequestDataModel>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.InsertRequest(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "test@example.com", false, [new InstallationRequestDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 10)], DateTime.UtcNow)), Throws.TypeOf<StorageException>());
|
||||
@@ -489,7 +490,7 @@ internal class RequestBusinessLogicContractTests
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_requestStorageContract.Setup(x =>
|
||||
x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.CancelRequest(Guid.NewGuid().ToString()),
|
||||
@@ -524,7 +525,7 @@ internal class RequestBusinessLogicContractTests
|
||||
//Arrange
|
||||
_requestStorageContract.Setup(x =>
|
||||
x.DelElement(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_requestBusinessLogicContract.CancelRequest(Guid.NewGuid().ToString()),
|
||||
|
||||
@@ -33,7 +33,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_postStorageContract = new Mock<IPostStorageContract>();
|
||||
_workerStorageContract = new Mock<IWorkerStorageContract>();
|
||||
_salaryBusinessLogicContract = new SalaryBusinessLogicContract(_salaryStorageContract.Object, _requestStorageContract.Object,
|
||||
_postStorageContract.Object, _workerStorageContract.Object, new Mock<ILogger>().Object, _salaryConfigurationTest);
|
||||
_postStorageContract.Object, _workerStorageContract.Object, StringLocalizerMockCreator.GetObject(), new Mock<ILogger>().Object, _salaryConfigurationTest);
|
||||
}
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
@@ -115,7 +115,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Arrange
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(),
|
||||
It.IsAny<DateTime>(), It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_salaryBusinessLogicContract.GetAllSalariesByPeriod(DateTime.UtcNow,
|
||||
@@ -224,7 +224,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
//Arrange
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(),
|
||||
It.IsAny<DateTime>(), It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(DateTime.UtcNow,
|
||||
@@ -413,7 +413,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
// RequestStorage выбрасывает исключение
|
||||
_requestStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
.Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(),
|
||||
It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
@@ -449,7 +449,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
|
||||
// PostStorage выбрасывает исключение
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
.Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMonth(DateTime.UtcNow),
|
||||
@@ -471,7 +471,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
// WorkerStorage выбрасывает исключение
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(),
|
||||
It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
.Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(postId, "TestPost", PostType.SoftInstaller, 1000));
|
||||
|
||||
@@ -5,6 +5,7 @@ using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -24,7 +25,7 @@ internal class SoftwareBusinessLogicContractTests
|
||||
{
|
||||
_softwareStorageContract = new Mock<ISoftwareStorageContract>();
|
||||
_softwareBusinessLogicContract = new
|
||||
SoftwareBusinessLogicContract(_softwareStorageContract.Object, new
|
||||
SoftwareBusinessLogicContract(_softwareStorageContract.Object, StringLocalizerMockCreator.GetObject(), new
|
||||
Mock<ILogger>().Object);
|
||||
}
|
||||
[SetUp]
|
||||
@@ -98,7 +99,7 @@ internal class SoftwareBusinessLogicContractTests
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.GetAllSoftwares(It.IsAny<bool>()),
|
||||
@@ -206,7 +207,7 @@ internal class SoftwareBusinessLogicContractTests
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.GetAllSoftwaresByManufacturer(Guid.NewGuid().ToString(), It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
@@ -293,7 +294,7 @@ new(Guid.NewGuid().ToString(), 10),
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.GetHistoryBySoftwareId(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.GetSoftwareHistoryBySoftware(Guid.NewGuid().ToString(
|
||||
@@ -376,10 +377,10 @@ new(Guid.NewGuid().ToString(), 10),
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.GetSoftwareByData(Guid.NewGuid().ToString()),
|
||||
@@ -421,7 +422,7 @@ new(Guid.NewGuid().ToString(), 10),
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<SoftwareDataModel>())).Throws(new
|
||||
ElementExistsException("Data", "Data"));
|
||||
ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.InsertSoftware(new(Guid.NewGuid().ToString(),
|
||||
@@ -455,7 +456,7 @@ new(Guid.NewGuid().ToString(), 10),
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<SoftwareDataModel>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.InsertSoftware(new(Guid.NewGuid().ToString(),
|
||||
@@ -493,7 +494,7 @@ new(Guid.NewGuid().ToString(), 10),
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<SoftwareDataModel>())).Throws(new
|
||||
ElementNotFoundException(""));
|
||||
ElementNotFoundException("", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.UpdateSoftware(new(Guid.NewGuid().ToString(),
|
||||
@@ -509,7 +510,7 @@ new(Guid.NewGuid().ToString(), 10),
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<SoftwareDataModel>())).Throws(new
|
||||
ElementExistsException("Data", "Data"));
|
||||
ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.UpdateSoftware(new(Guid.NewGuid().ToString(),
|
||||
@@ -543,7 +544,7 @@ new(Guid.NewGuid().ToString(), 10),
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<SoftwareDataModel>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException() , StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.UpdateSoftware(new(Guid.NewGuid().ToString(),
|
||||
@@ -573,7 +574,7 @@ new(Guid.NewGuid().ToString(), 10),
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.DeleteSoftware(Guid.NewGuid().ToString()),
|
||||
@@ -608,7 +609,7 @@ new(Guid.NewGuid().ToString(), 10),
|
||||
//Arrange
|
||||
_softwareStorageContract.Setup(x =>
|
||||
x.DelElement(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_softwareBusinessLogicContract.DeleteSoftware(Guid.NewGuid().ToString()),
|
||||
|
||||
@@ -5,6 +5,7 @@ using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Infrastructure.PostConfigurations;
|
||||
using SmallSoftwareContracts.StoragesContracts;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -23,7 +24,7 @@ internal class WorkerBusinessLogicContractTests
|
||||
{
|
||||
_workerStorageContract = new Mock<IWorkerStorageContract>();
|
||||
_workerBusinessLogicContract = new
|
||||
WorkerBusinessLogicContract(_workerStorageContract.Object, new
|
||||
WorkerBusinessLogicContract(_workerStorageContract.Object, StringLocalizerMockCreator.GetObject(), new
|
||||
Mock<ILogger>().Object);
|
||||
}
|
||||
[SetUp]
|
||||
@@ -101,7 +102,7 @@ internal class WorkerBusinessLogicContractTests
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
|
||||
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
|
||||
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.GetAllWorkers(It.IsAny<bool>()),
|
||||
@@ -210,7 +211,7 @@ internal class WorkerBusinessLogicContractTests
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
|
||||
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
|
||||
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(),
|
||||
@@ -314,7 +315,7 @@ internal class WorkerBusinessLogicContractTests
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
|
||||
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
|
||||
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.GetAllWorkersByBirthDate(DateTime.UtcNow,
|
||||
@@ -423,7 +424,7 @@ internal class WorkerBusinessLogicContractTests
|
||||
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
|
||||
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
|
||||
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow,
|
||||
@@ -513,10 +514,10 @@ public void GetWorkerByData_StorageThrowError_ThrowException_Test()
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x =>
|
||||
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_workerStorageContract.Setup(x =>
|
||||
x.GetElementByFIO(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.GetWorkerByData(Guid.NewGuid().ToString()),
|
||||
@@ -559,7 +560,7 @@ public void InsertWorker_RecordWithExistsData_ThrowException_Test()
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new
|
||||
ElementExistsException("Data", "Data"));
|
||||
ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "fio",
|
||||
@@ -593,7 +594,7 @@ public void InsertWorker_StorageThrowError_ThrowException_Test()
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x =>
|
||||
x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "fio",
|
||||
@@ -632,7 +633,7 @@ public void UpdateWorker_RecordWithIncorrectData_ThrowException_Test()
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new
|
||||
ElementNotFoundException(""));
|
||||
ElementNotFoundException("", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "fio",
|
||||
@@ -666,7 +667,7 @@ public void UpdateWorker_StorageThrowError_ThrowException_Test()
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x =>
|
||||
x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "fio",
|
||||
@@ -696,7 +697,7 @@ public void DeleteWorker_RecordWithIncorrectId_ThrowException_Test()
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_workerStorageContract.Setup(x => x.DelElement(It.Is((string x) => x
|
||||
!= id))).Throws(new ElementNotFoundException(id));
|
||||
!= id))).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.DeleteWorker(Guid.NewGuid().ToString()),
|
||||
@@ -731,7 +732,7 @@ public void DeleteWorker_StorageThrowError_ThrowException_Test()
|
||||
//Arrange
|
||||
_workerStorageContract.Setup(x =>
|
||||
x.DelElement(It.IsAny<string>())).Throws(new StorageException(new
|
||||
InvalidOperationException()));
|
||||
InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() =>
|
||||
_workerBusinessLogicContract.DeleteWorker(Guid.NewGuid().ToString()),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Microsoft.VisualStudio.TestPlatform.ObjectModel.DataCollection;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -18,11 +19,11 @@ internal class InstallationRequestDataModelTests
|
||||
{
|
||||
var installationRequest = CreateDataModel(null, Guid.NewGuid().ToString(),
|
||||
10, 10);
|
||||
Assert.That(() => installationRequest.Validate(),
|
||||
Assert.That(() => installationRequest.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
installationRequest = CreateDataModel(string.Empty,
|
||||
Guid.NewGuid().ToString(), 10, 10);
|
||||
Assert.That(() => installationRequest.Validate(),
|
||||
Assert.That(() => installationRequest.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -30,7 +31,7 @@ internal class InstallationRequestDataModelTests
|
||||
{
|
||||
var installationRequest = CreateDataModel("softwareId",
|
||||
Guid.NewGuid().ToString(), 10, 10);
|
||||
Assert.That(() => installationRequest.Validate(),
|
||||
Assert.That(() => installationRequest.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -38,11 +39,11 @@ internal class InstallationRequestDataModelTests
|
||||
{
|
||||
var installationRequest = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
10, 10);
|
||||
Assert.That(() => installationRequest.Validate(),
|
||||
Assert.That(() => installationRequest.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
installationRequest = CreateDataModel(string.Empty,
|
||||
Guid.NewGuid().ToString(), 10, 10);
|
||||
Assert.That(() => installationRequest.Validate(),
|
||||
Assert.That(() => installationRequest.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -50,7 +51,7 @@ internal class InstallationRequestDataModelTests
|
||||
{
|
||||
var installationRequest = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
"requestId", 10, 10);
|
||||
Assert.That(() => installationRequest.Validate(),
|
||||
Assert.That(() => installationRequest.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -58,11 +59,11 @@ internal class InstallationRequestDataModelTests
|
||||
{
|
||||
var installationRequest = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 0, 0);
|
||||
Assert.That(() => installationRequest.Validate(),
|
||||
Assert.That(() => installationRequest.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
installationRequest = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), -10, -20);
|
||||
Assert.That(() => installationRequest.Validate(),
|
||||
Assert.That(() => installationRequest.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -73,7 +74,7 @@ internal class InstallationRequestDataModelTests
|
||||
var count = 10;
|
||||
var price = 10;
|
||||
var installationRequest = CreateDataModel(softwareId, requestId, count, price);
|
||||
Assert.That(() => installationRequest.Validate(), Throws.Nothing);
|
||||
Assert.That(() => installationRequest.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(installationRequest.SoftwareId, Is.EqualTo(softwareId));
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
|
||||
namespace SmallSoftwareTests.DataModelsTests;
|
||||
|
||||
@@ -15,28 +11,28 @@ internal class ManufacturerDataModelTests
|
||||
public void IdIsNullEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(null, "name");
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(string.Empty, "name");
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel("id", "name");
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ManufacturerNameIsNullOrEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
string.Empty);
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -48,7 +44,7 @@ internal class ManufacturerDataModelTests
|
||||
var prevPrevManufacturerName = "prevPrevManufacturerName";
|
||||
var manufacturer = CreateDataModel(manufacturerId, manufacturerName,
|
||||
prevManufacturerName, prevPrevManufacturerName);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.Nothing);
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(manufacturer.Id, Is.EqualTo(manufacturerId));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -17,17 +18,17 @@ internal class PostDataModelTests
|
||||
{
|
||||
var post = CreateDataModel(null, "name",
|
||||
PostType.SoftInstaller, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, "name", PostType.SoftInstaller, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", "name", PostType.SoftInstaller, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -35,18 +36,18 @@ internal class PostDataModelTests
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.SoftInstaller, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.SoftInstaller, 10, true,
|
||||
DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -54,11 +55,11 @@ internal class PostDataModelTests
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
"name", PostType.SoftInstaller, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.SoftInstaller, -10, true,
|
||||
DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -73,7 +74,7 @@ internal class PostDataModelTests
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var post = CreateDataModel(postId, postName, postType,
|
||||
salary, isActual, changeDate);
|
||||
Assert.That(() => post.Validate(), Throws.Nothing);
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(post.Id, Is.EqualTo(postId));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
|
||||
namespace SmallSoftwareTests.DataModelsTests;
|
||||
|
||||
@@ -10,44 +11,44 @@ internal class RequestDataModelTests
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var request = CreateDataModel(null, Guid.NewGuid().ToString(), "test@example.com", false, CreateSubDataModel() , DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
|
||||
request = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "test@example.com", false, CreateSubDataModel(), DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var request = CreateDataModel("id", Guid.NewGuid().ToString(), "test@example.com", false, CreateSubDataModel(), DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var request = CreateDataModel(Guid.NewGuid().ToString(), null, "test@example.com", false, CreateSubDataModel(), DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
|
||||
request = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "test@example.com", false, CreateSubDataModel(), DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var request = CreateDataModel(Guid.NewGuid().ToString(), "workerId", "test@example.com", false, CreateSubDataModel(), DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmailIsInvalidTest()
|
||||
{
|
||||
var request = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "invalid_email", false, CreateSubDataModel(), DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
|
||||
request = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "@", false, CreateSubDataModel(), DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
@@ -55,10 +56,10 @@ internal class RequestDataModelTests
|
||||
public void SoftwaresIsNullOrEmptyTest()
|
||||
{
|
||||
var request = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "test@example.com", false, null, DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
|
||||
request = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "test@example.com", false, new List<InstallationRequestDataModel>(), DateTime.UtcNow);
|
||||
Assert.That(() => request.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -73,7 +74,7 @@ internal class RequestDataModelTests
|
||||
|
||||
var request = CreateDataModel(requestId, workerId, email, isCancel, softwares, DateTime.UtcNow);
|
||||
|
||||
Assert.That(() => request.Validate(), Throws.Nothing);
|
||||
Assert.That(() => request.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(request.Id, Is.EqualTo(requestId));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,17 +16,17 @@ internal class SalaryDataModelTests
|
||||
public void WorkerIdIsEmptyTest()
|
||||
{
|
||||
var salary = CreateDataModel(null, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(),
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(),
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var salary = CreateDataModel("workerId", DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(),
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -33,11 +34,11 @@ internal class SalaryDataModelTests
|
||||
{
|
||||
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now,
|
||||
0);
|
||||
Assert.That(() => salary.Validate(),
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -
|
||||
10);
|
||||
Assert.That(() => salary.Validate(),
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -47,11 +48,11 @@ internal class SalaryDataModelTests
|
||||
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||
var workerSalary = 10;
|
||||
var salary = CreateDataModel(workerId, salaryDate, workerSalary);
|
||||
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(salary.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
|
||||
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate.ToUniversalTime()));
|
||||
Assert.That(salary.Salary, Is.EqualTo(workerSalary));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Enums;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -19,11 +20,11 @@ internal class SoftwareDataModelTests
|
||||
{
|
||||
var software = CreateDataModel(null, "name", SoftwareType.Windows,
|
||||
Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
software = CreateDataModel(string.Empty, "name",
|
||||
SoftwareType.Windows, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -31,7 +32,7 @@ internal class SoftwareDataModelTests
|
||||
{
|
||||
var software = CreateDataModel("id", "name", SoftwareType.Windows,
|
||||
Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -39,11 +40,11 @@ internal class SoftwareDataModelTests
|
||||
{
|
||||
var software = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
SoftwareType.Windows, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
software = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
SoftwareType.Windows, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -51,7 +52,7 @@ internal class SoftwareDataModelTests
|
||||
{
|
||||
var software = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
SoftwareType.None, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -59,11 +60,11 @@ internal class SoftwareDataModelTests
|
||||
{
|
||||
var software = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
SoftwareType.Windows, null, 10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
software = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
SoftwareType.Windows, string.Empty, 10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -71,7 +72,7 @@ internal class SoftwareDataModelTests
|
||||
{
|
||||
var software = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
SoftwareType.Windows, "manufacturerId", 10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -79,11 +80,11 @@ internal class SoftwareDataModelTests
|
||||
{
|
||||
var software = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
SoftwareType.Windows, Guid.NewGuid().ToString(), 0, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
software = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
SoftwareType.Windows, Guid.NewGuid().ToString(), -10, false);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -97,7 +98,7 @@ internal class SoftwareDataModelTests
|
||||
var softwareIsDelete = false;
|
||||
var software = CreateDataModel(softwareId, softwareName, softwareType,
|
||||
softwareManufacturerId, softwarePrice, softwareIsDelete);
|
||||
Assert.That(() => software.Validate(), Throws.Nothing);
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(software.Id, Is.EqualTo(softwareId));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -16,27 +17,27 @@ internal class SoftwareHistoryDataModelTests
|
||||
public void SoftwareIdIsNullOrEmptyTest()
|
||||
{
|
||||
var software = CreateDataModel(null, 10);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
software = CreateDataModel(string.Empty, 10);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void SoftwareIdIsNotGuidTest()
|
||||
{
|
||||
var software = CreateDataModel("id", 10);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void OldPriceIsLessOrZeroTest()
|
||||
{
|
||||
var software = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
software = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => software.Validate(),
|
||||
Assert.That(() => software.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -45,7 +46,7 @@ internal class SoftwareHistoryDataModelTests
|
||||
var softwareId = Guid.NewGuid().ToString();
|
||||
var oldPrice = 10;
|
||||
var softwareHistory = CreateDataModel(softwareId, oldPrice);
|
||||
Assert.That(() => softwareHistory.Validate(), Throws.Nothing);
|
||||
Assert.That(() => softwareHistory.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(softwareHistory.SoftwareId, Is.EqualTo(softwareId));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Infrastructure.PostConfigurations;
|
||||
using SmallSoftwareTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -17,11 +18,11 @@ internal class WorkerDataModelTests
|
||||
{
|
||||
var worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(string.Empty, "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -29,7 +30,7 @@ internal class WorkerDataModelTests
|
||||
{
|
||||
var worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -37,11 +38,11 @@ internal class WorkerDataModelTests
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -49,11 +50,11 @@ internal class WorkerDataModelTests
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null,
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
@@ -61,29 +62,21 @@ internal class WorkerDataModelTests
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
"postId", DateTime.Now.AddYears(-18), DateTime.Now, false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void BirthDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now,
|
||||
false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18),
|
||||
DateTime.Now.AddYears(-18).AddDays(-1), false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-
|
||||
16), false, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -92,7 +85,7 @@ internal class WorkerDataModelTests
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18),
|
||||
DateTime.Now.AddYears(-18).AddDays(-1), false, null);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -102,11 +95,11 @@ internal class WorkerDataModelTests
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18),
|
||||
DateTime.Now.AddYears(-18).AddDays(-1), false, new PostConfiguration() { Rate = 0 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18),
|
||||
DateTime.Now.AddYears(-18).AddDays(-1), false, new PostConfiguration() { Rate = -10 });
|
||||
Assert.That(() => worker.Validate(),
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -124,15 +117,15 @@ internal class WorkerDataModelTests
|
||||
var worker = CreateDataModel(workerId, fio, postId, birthDate,
|
||||
employmentDate, isDelete, configuration);
|
||||
|
||||
Assert.That(() => worker.Validate(), Throws.Nothing);
|
||||
Assert.That(() => worker.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(worker.Id, Is.EqualTo(workerId));
|
||||
Assert.That(worker.FIO, Is.EqualTo(fio));
|
||||
Assert.That(worker.PostId, Is.EqualTo(postId));
|
||||
Assert.That(worker.BirthDate, Is.EqualTo(birthDate));
|
||||
Assert.That(worker.BirthDate.ToUniversalTime(), Is.EqualTo(birthDate.ToUniversalTime()));
|
||||
Assert.That(worker.EmploymentDate,
|
||||
Is.EqualTo(employmentDate));
|
||||
Is.EqualTo(employmentDate.ToUniversalTime()));
|
||||
Assert.That(worker.IsDeleted, Is.EqualTo(isDelete));
|
||||
Assert.That(worker.ConfigurationModel, Is.EqualTo(configuration));
|
||||
Assert.That(worker.ConfigurationModel.Rate, Is.EqualTo(configuration.Rate));
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Moq;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareTests.Infrastructure;
|
||||
|
||||
internal static class StringLocalizerMockCreator
|
||||
{
|
||||
private static Mock<IStringLocalizer<Messages>>? _mockObject = null;
|
||||
public static IStringLocalizer<Messages> GetObject()
|
||||
{
|
||||
if (_mockObject is null)
|
||||
{
|
||||
_mockObject = new Mock<IStringLocalizer<Messages>>();
|
||||
_mockObject.Setup(_ => _[It.IsAny<string>()]).Returns(new LocalizedString("name", "value"));
|
||||
}
|
||||
return _mockObject!.Object;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ internal class ManufacturerStorageContractTests : BaseStorageContractTest
|
||||
public void SetUp()
|
||||
{
|
||||
_manufacturerStorageContract = new
|
||||
ManufacturerStorageContract(SmallSoftwareDbContext);
|
||||
ManufacturerStorageContract(SmallSoftwareDbContext, StringLocalizerMockCreator.GetObject());
|
||||
}
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
|
||||
@@ -20,7 +20,7 @@ internal class PostStorageContractTests : BaseStorageContractTest
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_postStorageContract = new PostStorageContract(SmallSoftwareDbContext);
|
||||
_postStorageContract = new PostStorageContract(SmallSoftwareDbContext, StringLocalizerMockCreator.GetObject());
|
||||
}
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
|
||||
@@ -19,7 +19,7 @@ internal class RequestStorageContractTests : BaseStorageContractTest
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_requesttStorageContract = new RequestStorageContract(SmallSoftwareDbContext);
|
||||
_requesttStorageContract = new RequestStorageContract(SmallSoftwareDbContext, StringLocalizerMockCreator.GetObject());
|
||||
_manufacturer = InsertManufacturerToDatabaseAndReturn();
|
||||
_worker = InsertWorkerToDatabaseAndReturn();
|
||||
_software = InsertSoftwareToDatabaseAndReturn();
|
||||
|
||||
@@ -21,7 +21,7 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
|
||||
public void SetUp()
|
||||
{
|
||||
_salaryStorageContract = new
|
||||
SalaryStorageContract(SmallSoftwareDbContext);
|
||||
SalaryStorageContract(SmallSoftwareDbContext, StringLocalizerMockCreator.GetObject());
|
||||
_worker = InsertWorkerToDatabaseAndReturn();
|
||||
}
|
||||
[TearDown]
|
||||
|
||||
@@ -17,7 +17,7 @@ internal class SoftwareStorageContractTests : BaseStorageContractTest
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_softwareStorageContract = new SoftwareStorageContract(SmallSoftwareDbContext);
|
||||
_softwareStorageContract = new SoftwareStorageContract(SmallSoftwareDbContext, StringLocalizerMockCreator.GetObject());
|
||||
_manufacturer = SmallSoftwareDbContext.InsertManufacturerToDatabaseAndReturn();
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,7 @@ internal class WorkerStorageContractTests : BaseStorageContractTest
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_workerStorageContract = new
|
||||
WorkerStorageContract(SmallSoftwareDbContext);
|
||||
_workerStorageContract = new WorkerStorageContract(SmallSoftwareDbContext, StringLocalizerMockCreator.GetObject());
|
||||
}
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
|
||||
@@ -303,7 +303,7 @@ internal class ManufacturerControllerTests : BaseWebApiControllerTest
|
||||
//Act
|
||||
var response = await HttpClient.DeleteAsync($"/api/manufacturers/{manufacturerId}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.InternalServerError));
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -70,8 +70,7 @@ internal class ReportControllerTests : BaseWebApiControllerTest
|
||||
SmallSoftwareDbContext.InsertRequestToDatabaseAndReturn(worker.Id, softwares: [(software1.Id, 10, 1.1)]);
|
||||
//Act
|
||||
var response = await
|
||||
HttpClient.GetAsync($"/api/report/getrequests?fromDate={DateTime.UtcNow.AddDays(-
|
||||
1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
HttpClient.GetAsync($"/api/report/getrequests?fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
var data = await
|
||||
@@ -87,7 +86,7 @@ internal class ReportControllerTests : BaseWebApiControllerTest
|
||||
{
|
||||
//Act
|
||||
var response = await
|
||||
HttpClient.GetAsync($"/api/report/getrequests?fromDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
HttpClient.GetAsync($"/api/report/getrequests?fromDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode,
|
||||
Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -130,8 +129,7 @@ internal class ReportControllerTests : BaseWebApiControllerTest
|
||||
// Act
|
||||
var response = await HttpClient.GetAsync(
|
||||
$"/api/report/getsalary?" +
|
||||
$"fromDate={DateTime.UtcNow.AddDays(-7):MM/dd/yyyy HH:mm:ss}&" +
|
||||
$"toDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
$"fromDate={DateTime.Now.AddDays(-7):MM/dd/yyyy HH:mm:ss}&" + $"toDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
|
||||
// Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
@@ -159,8 +157,7 @@ internal class ReportControllerTests : BaseWebApiControllerTest
|
||||
// Act
|
||||
var response = await HttpClient.GetAsync(
|
||||
$"/api/report/getsalary?" +
|
||||
$"fromDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}&" +
|
||||
$"toDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
$"fromDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}&" + $"toDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
|
||||
// Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -227,8 +224,7 @@ internal class ReportControllerTests : BaseWebApiControllerTest
|
||||
// Act
|
||||
var response = await HttpClient.GetAsync(
|
||||
$"/api/report/loadrequests?" +
|
||||
$"fromDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}&" +
|
||||
$"toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
$"fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&" + $"toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
|
||||
// Assert
|
||||
await AssertStreamAsync(response, "file.xlsx");
|
||||
@@ -240,8 +236,7 @@ internal class ReportControllerTests : BaseWebApiControllerTest
|
||||
// Act
|
||||
var response = await HttpClient.GetAsync(
|
||||
$"/api/report/loadrequests?" +
|
||||
$"fromDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}&" +
|
||||
$"toDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
$"fromDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}&" + $"toDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
|
||||
// Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
@@ -289,8 +284,7 @@ internal class ReportControllerTests : BaseWebApiControllerTest
|
||||
// Act
|
||||
var response = await HttpClient.GetAsync(
|
||||
$"/api/report/loadsalary?" +
|
||||
$"fromDate={DateTime.UtcNow.AddDays(-7):MM/dd/yyyy HH:mm:ss}&" +
|
||||
$"toDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
$"fromDate={DateTime.Now.AddDays(-7):MM/dd/yyyy HH:mm:ss}&" + $"toDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
|
||||
// Assert
|
||||
await AssertStreamAsync(response, "file.pdf");
|
||||
@@ -302,8 +296,7 @@ internal class ReportControllerTests : BaseWebApiControllerTest
|
||||
// Act
|
||||
var response = await HttpClient.GetAsync(
|
||||
$"/api/report/loadsalary?" +
|
||||
$"fromDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}&" +
|
||||
$"toDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
$"fromDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}&" + $"toDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
|
||||
// Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
|
||||
@@ -56,7 +56,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
|
||||
public async Task GetList_WhenNoRecords_ShouldSuccess_Test()
|
||||
{
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getrecords?fromDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getrecords?fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
var data = await GetModelFromResponseAsync<List<RequestViewModel>>(response);
|
||||
@@ -77,7 +77,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
|
||||
SmallSoftwareDbContext.InsertRequestToDatabaseAndReturn(_workerId, "test@mail.ru", sum: 10, false, softwares: [(_softwareId, 10, 1.1)]);
|
||||
SmallSoftwareDbContext.InsertRequestToDatabaseAndReturn(worker.Id, "test@mail.ru", sum: 10, false, softwares: [(_softwareId, 10, 1.1)]);
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getworkerrecords?id={_workerId}&fromDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getworkerrecords?id={_workerId}&fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
var data = await GetModelFromResponseAsync<List<RequestViewModel>>(response);
|
||||
@@ -96,7 +96,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
|
||||
var worker = SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(fio: "Other worker");
|
||||
SmallSoftwareDbContext.InsertRequestToDatabaseAndReturn(_workerId, "test@mail.ru", sum: 10, false, softwares: [(_softwareId, 10, 1.1)]);
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getworkerrecords?id={worker.Id}&fromDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getworkerrecords?id={worker.Id}&fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
var data = await GetModelFromResponseAsync<List<RequestViewModel>>(response);
|
||||
@@ -108,7 +108,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
|
||||
public async Task GetList_ByWorkerId_WhenDateIsIncorrect_ShouldBadRequest_Test()
|
||||
{
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getworkerrecords?id={_workerId}&fromDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getworkerrecords?id={_workerId}&fromDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
}
|
||||
@@ -117,7 +117,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
|
||||
public async Task GetList_ByWorkerId_WhenIdIsIncorrect_ShouldBadRequest_Test()
|
||||
{
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getworkerrecords?id=Id&fromDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getworkerrecords?id=Id&fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
}
|
||||
@@ -132,7 +132,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
|
||||
SmallSoftwareDbContext.InsertRequestToDatabaseAndReturn(_workerId, "test@mail.ru", sum: 10, false, softwares: [(software.Id, 10, 1.1)], requestDate: DateTime.UtcNow.AddHours(12));
|
||||
SmallSoftwareDbContext.InsertRequestToDatabaseAndReturn(_workerId, "test@mail.ru", softwares: [(software.Id, 1, 1.1), (_softwareId, 1, 1.1)], requestDate: DateTime.UtcNow.AddHours(12));
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getsoftwarerecords?id={_softwareId}&fromDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getsoftwarerecords?id={_softwareId}&fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
Console.WriteLine($"Response: {response.StatusCode}, Content: {responseContent}");
|
||||
//Assert
|
||||
@@ -153,7 +153,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
|
||||
var software = SmallSoftwareDbContext.InsertSoftwareToDatabaseAndReturn(_manufacturerId, softwareName: "Other software");
|
||||
SmallSoftwareDbContext.InsertRequestToDatabaseAndReturn(_workerId, "test@mail.ru", sum: 10, false, softwares: [(_softwareId, 10, 1.1)]);
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getsoftwarerecords?id={software.Id}&fromDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getsoftwarerecords?id={software.Id}&fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
Console.WriteLine($"Response: {response.StatusCode}, Content: {responseContent}");
|
||||
//Assert
|
||||
@@ -167,7 +167,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
|
||||
public async Task GetList_BySoftwareId_WhenDateIsIncorrect_ShouldBadRequest_Test()
|
||||
{
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getsoftwarerecords?id={_softwareId}&fromDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getsoftwarerecords?id={_softwareId}&fromDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
}
|
||||
@@ -176,7 +176,7 @@ internal class RequestControllerTests : BaseWebApiControllerTest
|
||||
public async Task GetList_BySoftwareId_WhenIdIsIncorrect_ShouldBadRequest_Test()
|
||||
{
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getsoftwarerecords?id=Id&fromDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
var response = await HttpClient.GetAsync($"/api/requests/getsoftwarerecords?id=Id&fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
|
||||
SmallSoftwareDbContext.InsertSalaryToDatabaseAndReturn(worker2.Id, salaryDate: DateTime.UtcNow.AddDays(1).AddMinutes(-5));
|
||||
SmallSoftwareDbContext.InsertSalaryToDatabaseAndReturn(worker1.Id, salaryDate: DateTime.UtcNow.AddDays(-2));
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/salaries/getworkerrecords?fromDate={DateTime.UtcNow.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddDays(1):MM/dd/yyyy HH:mm:ss}&id={worker1.Id}");
|
||||
var response = await HttpClient.GetAsync($"/api/salaries/getworkerrecords?fromDate={DateTime.Now.AddDays(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1):MM/dd/yyyy HH:mm:ss}&id={worker1.Id}");
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
Console.WriteLine($"Response: {response.StatusCode}, Content: {responseContent}");
|
||||
//Assert
|
||||
@@ -238,7 +238,7 @@ internal class SalaryControllerTests : BaseWebApiControllerTest
|
||||
Console.WriteLine($"Response: {response.StatusCode}, Content: {responseContent}");
|
||||
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.NotFound));
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.InternalServerError));
|
||||
}
|
||||
|
||||
private static void AssertElement(SalaryViewModel? actual, Salary expected)
|
||||
|
||||
@@ -202,8 +202,8 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
|
||||
{
|
||||
//Act
|
||||
var response = await
|
||||
HttpClient.GetAsync($"/api/workers/getbirthdaterecords?fromDate={DateTime.UtcNow.
|
||||
AddMinutes(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddMinutes(-
|
||||
HttpClient.GetAsync($"/api/workers/getbirthdaterecords?fromDate={DateTime.Now.
|
||||
AddMinutes(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddMinutes(-
|
||||
1):MM/dd/yyyy HH:mm:ss}&includeDeleted=true");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode,
|
||||
@@ -213,24 +213,17 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
|
||||
public async Task GetList_ByEmploymentDate_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(fio: "fio 1",
|
||||
employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(fio: "fio 2",
|
||||
employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(fio: "fio 3",
|
||||
employmentDate: DateTime.UtcNow.AddDays(1), isDeleted: true);
|
||||
SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(fio: "fio 4",
|
||||
employmentDate: DateTime.UtcNow.AddDays(2));
|
||||
//Act
|
||||
|
||||
var response = await
|
||||
HttpClient.GetAsync($"/api/workers/getemploymentrecords?fromDate={DateTime.UtcNow
|
||||
.AddDays(-1).AddMinutes(-1):o}&toDate={DateTime.UtcNow
|
||||
.AddDays(1).AddMinutes(1):o}&includeDeleted=true");
|
||||
SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(fio: "fio 1", employmentDate: DateTime.UtcNow.AddDays(-2));
|
||||
SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(fio: "fio 2", employmentDate: DateTime.UtcNow.AddDays(-1));
|
||||
SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(fio: "fio 3", employmentDate: DateTime.UtcNow.AddDays(1), isDeleted: true);
|
||||
SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(fio: "fio 4", employmentDate: DateTime.UtcNow.AddDays(2));
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/workers/getemploymentrecords?fromDate={DateTime.Now.AddDays(-1).AddMinutes(-1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddDays(1).AddMinutes(1):MM/dd/yyyy HH:mm:ss}&includeDeleted=true");
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
Console.WriteLine($"Response: {response.StatusCode}, Content: {responseContent}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
var data = await
|
||||
GetModelFromResponseAsync<List<WorkerViewModel>>(response);
|
||||
var data = await GetModelFromResponseAsync<List<WorkerViewModel>>(response);
|
||||
Assert.That(data, Is.Not.Null);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -242,8 +235,8 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
|
||||
{
|
||||
//Act
|
||||
var response = await
|
||||
HttpClient.GetAsync($"/api/workers/getemploymentrecords?fromDate={DateTime.UtcNow
|
||||
.AddMinutes(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.UtcNow.AddMinutes(-
|
||||
HttpClient.GetAsync($"/api/workers/getemploymentrecords?fromDate={DateTime.Now
|
||||
.AddMinutes(1):MM/dd/yyyy HH:mm:ss}&toDate={DateTime.Now.AddMinutes(-
|
||||
1):MM/dd/yyyy HH:mm:ss}&includeDeleted=true");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode,
|
||||
@@ -352,11 +345,11 @@ internal class WorkerControllerTests : BaseWebApiControllerTest
|
||||
var workerModel = CreateModel(_post.Id);
|
||||
SmallSoftwareDbContext.InsertWorkerToDatabaseAndReturn(workerModel.Id);
|
||||
//Act
|
||||
var response = await HttpClient.PostAsync($"/api/workers/register",
|
||||
MakeContent(workerModel));
|
||||
var response = await HttpClient.PostAsync($"/api/workers/register", MakeContent(workerModel));
|
||||
var responseContent = await response.Content.ReadAsStringAsync();
|
||||
Console.WriteLine($"Response: {response.StatusCode}, Content: {responseContent}");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode,
|
||||
Is.EqualTo(HttpStatusCode.BadRequest));
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.InternalServerError));
|
||||
}
|
||||
[Test]
|
||||
public async Task Post_WhenDataIsIncorrect_ShouldBadRequest_Test()
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.AdapterContracts;
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BindingModels;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
|
||||
namespace SmallSoftwareWebApi.Adapters;
|
||||
|
||||
public class ManufacturerAdapter : IManufacturerAdapter
|
||||
internal class ManufacturerAdapter : IManufacturerAdapter
|
||||
{
|
||||
private readonly IManufacturerBusinessLogicContract _manufacturerBusinessLogicContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
public ManufacturerAdapter(IManufacturerBusinessLogicContract manufacturerBusinessLogicContract, ILogger<ManufacturerAdapter> logger)
|
||||
public ManufacturerAdapter(IManufacturerBusinessLogicContract manufacturerBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<ManufacturerAdapter> logger)
|
||||
{
|
||||
_manufacturerBusinessLogicContract = manufacturerBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -24,6 +27,7 @@ public class ManufacturerAdapter : IManufacturerAdapter
|
||||
cfg.CreateMap<ManufacturerDataModel, ManufacturerViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
public ManufacturerOperationResponse GetList()
|
||||
{
|
||||
@@ -33,16 +37,10 @@ public class ManufacturerAdapter : IManufacturerAdapter
|
||||
_manufacturerBusinessLogicContract.GetAllManufacturers().Select(x =>
|
||||
_mapper.Map<ManufacturerViewModel>(x))]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return ManufacturerOperationResponse.NotFound("The list is not initialized");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return
|
||||
ManufacturerOperationResponse.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message} ");
|
||||
return ManufacturerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -61,83 +59,40 @@ public class ManufacturerAdapter : IManufacturerAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ManufacturerOperationResponse.BadRequest("Data is empty");
|
||||
return ManufacturerOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return ManufacturerOperationResponse.NotFound($"Not found element by data { data} ");
|
||||
return ManufacturerOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementNotFoundException"], data));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return
|
||||
ManufacturerOperationResponse.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message} ");
|
||||
return ManufacturerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ManufacturerOperationResponse.InternalServerError(ex.Message);
|
||||
return ManufacturerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public ManufacturerOperationResponse
|
||||
RegisterManufacturer(ManufacturerBindingModel manufacturerModel)
|
||||
public ManufacturerOperationResponse RegisterManufacturer(ManufacturerBindingModel manufacturerModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_manufacturerBusinessLogicContract.InsertManufacturer(_mapper.Map < ManufacturerDataModel > (manufacturerModel));
|
||||
_manufacturerBusinessLogicContract.InsertManufacturer(_mapper.Map<ManufacturerDataModel>(manufacturerModel));
|
||||
return ManufacturerOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ManufacturerOperationResponse.BadRequest("Data is empty");
|
||||
return ManufacturerOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ManufacturerOperationResponse.BadRequest($"Incorrect data transmitted: { ex.Message} ");
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return ManufacturerOperationResponse.BadRequest(ex.Message);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ManufacturerOperationResponse.BadRequest($"Error while working with data storage: { ex.InnerException!.Message} ");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ManufacturerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public ManufacturerOperationResponse
|
||||
ChangeManufacturerInfo(ManufacturerBindingModel manufacturerModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_manufacturerBusinessLogicContract.UpdateManufacturer(_mapper.Map < ManufacturerDataModel > (manufacturerModel));
|
||||
return ManufacturerOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ManufacturerOperationResponse.BadRequest("Data is empty");
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ManufacturerOperationResponse.BadRequest($"Incorrect data transmitted: { ex.Message}");
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return ManufacturerOperationResponse.BadRequest($"Not found element by Id { manufacturerModel.Id} ");
|
||||
return ManufacturerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -147,14 +102,50 @@ public class ManufacturerAdapter : IManufacturerAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ManufacturerOperationResponse
|
||||
.BadRequest($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return ManufacturerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ManufacturerOperationResponse.InternalServerError(ex.Message);
|
||||
return ManufacturerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public ManufacturerOperationResponse ChangeManufacturerInfo(ManufacturerBindingModel manufacturerModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
_manufacturerBusinessLogicContract.UpdateManufacturer(_mapper.Map<ManufacturerDataModel>(manufacturerModel));
|
||||
return ManufacturerOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ManufacturerOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ManufacturerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return ManufacturerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], manufacturerModel.Id));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementExistsException");
|
||||
return ManufacturerOperationResponse.BadRequest(ex.Message);
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ManufacturerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return ManufacturerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public ManufacturerOperationResponse RemoveManufacturer(string id)
|
||||
@@ -167,29 +158,27 @@ public class ManufacturerAdapter : IManufacturerAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ManufacturerOperationResponse.BadRequest("Id is empty");
|
||||
return ManufacturerOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ManufacturerOperationResponse.BadRequest($"Incorrect data transmitted: { ex.Message} ");
|
||||
return ManufacturerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return ManufacturerOperationResponse.BadRequest($"Not found element by id: { id} ");
|
||||
return ManufacturerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ManufacturerOperationResponse
|
||||
.BadRequest($"Error while working with data storage: { ex.InnerException!.Message} ");
|
||||
return ManufacturerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ManufacturerOperationResponse.InternalServerError(ex.Message);
|
||||
return ManufacturerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.AdapterContracts;
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BindingModels;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
|
||||
namespace SmallSoftwareWebApi.Adapters;
|
||||
|
||||
public class PostAdapter : IPostAdapter
|
||||
internal class PostAdapter : IPostAdapter
|
||||
{
|
||||
private readonly IPostBusinessLogicContract _postBusinessLogicContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public PostAdapter(IPostBusinessLogicContract postBusinessLogicContract, ILogger<PostAdapter> logger)
|
||||
public PostAdapter(IPostBusinessLogicContract postBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<PostAdapter> logger)
|
||||
{
|
||||
_postBusinessLogicContract = postBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -27,6 +31,7 @@ public class PostAdapter : IPostAdapter
|
||||
cfg.CreateMap<PostDataModel, PostViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public PostOperationResponse GetList()
|
||||
@@ -36,15 +41,10 @@ public class PostAdapter : IPostAdapter
|
||||
return PostOperationResponse
|
||||
.OK([.. _postBusinessLogicContract.GetAllPosts().Select(x => _mapper.Map<PostViewModel>(x))]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return PostOperationResponse.NotFound("The list is not initialized");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return PostOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return PostOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -62,17 +62,17 @@ public class PostAdapter : IPostAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return PostOperationResponse.BadRequest("Data is empty");
|
||||
return PostOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return PostOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return PostOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -90,22 +90,22 @@ public class PostAdapter : IPostAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return PostOperationResponse.BadRequest("Data is empty");
|
||||
return PostOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return PostOperationResponse.NotFound($"Not found element by data {data}");
|
||||
return PostOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementNotFoundException"], data));
|
||||
}
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return PostOperationResponse.BadRequest($"Element by data: {data} was deleted");
|
||||
return PostOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementDeletedException"], data));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return PostOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return PostOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -124,12 +124,12 @@ public class PostAdapter : IPostAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return PostOperationResponse.BadRequest("Data is empty");
|
||||
return PostOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -139,7 +139,7 @@ public class PostAdapter : IPostAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return PostOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return PostOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -158,17 +158,17 @@ public class PostAdapter : IPostAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return PostOperationResponse.BadRequest("Data is empty");
|
||||
return PostOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return PostOperationResponse.BadRequest($"Not found element by Id {postModel.Id}");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], postModel.Id));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -178,12 +178,12 @@ public class PostAdapter : IPostAdapter
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return PostOperationResponse.BadRequest($"Element by id: {postModel.Id} was deleted");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementDeletedException"], postModel.Id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return PostOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return PostOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -202,27 +202,27 @@ public class PostAdapter : IPostAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return PostOperationResponse.BadRequest("Id is empty");
|
||||
return PostOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return PostOperationResponse.BadRequest($"Not found element by id: {id}");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return PostOperationResponse.BadRequest($"Element by id: {id} was deleted");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementDeletedException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return PostOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return PostOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -241,22 +241,22 @@ public class PostAdapter : IPostAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return PostOperationResponse.BadRequest("Id is empty");
|
||||
return PostOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return PostOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return PostOperationResponse.BadRequest($"Not found element by id: {id}");
|
||||
return PostOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return PostOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return PostOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,20 +1,23 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.AdapterContracts;
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
|
||||
namespace SmallSoftwareWebApi.Adapters;
|
||||
|
||||
public class ReportAdapter : IReportAdapter
|
||||
internal class ReportAdapter : IReportAdapter
|
||||
{
|
||||
|
||||
private readonly IReportContract _reportContract;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
public ReportAdapter(IReportContract reportContract, ILogger<SoftwareAdapter> logger)
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
public ReportAdapter(IReportContract reportContract, ILogger<SoftwareAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_reportContract = reportContract;
|
||||
_logger = logger;
|
||||
@@ -26,9 +29,10 @@ public class ReportAdapter : IReportAdapter
|
||||
cfg.CreateMap<WorkerSalaryByPeriodDataModel, WorkerSalaryByPeriodViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
|
||||
}
|
||||
public async Task<ReportOperationResponse> GetDataSoftwaresByManufacturerAsync(CancellationToken ct)
|
||||
public async Task<ReportOperationResponse> GetDataSoftwaresByHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -38,22 +42,21 @@ public class ReportAdapter : IReportAdapter
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "InvalidOperationException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageInvalidOperationException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ReportOperationResponse.InternalServerError(ex.Message);
|
||||
return ReportOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ReportOperationResponse> CreateDocumentSoftwaresByManufacturerAsync(CancellationToken ct)
|
||||
public async Task<ReportOperationResponse> CreateDocumentSoftwaresByHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -64,20 +67,17 @@ public class ReportAdapter : IReportAdapter
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "InvalidOperationException");
|
||||
return ReportOperationResponse
|
||||
.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageInvalidOperationException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse
|
||||
.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
}
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ReportOperationResponse.InternalServerError(ex.Message);
|
||||
return ReportOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,54 +85,52 @@ public class ReportAdapter : IReportAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ReportOperationResponse.OK((await _reportContract.GetDataRequestByPeriodAsync(dateStart, dateFinish, ct)).Select(x =>
|
||||
return ReportOperationResponse.OK((await _reportContract.GetDataRequestByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct)).Select(x =>
|
||||
_mapper.Map<RequestViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ReportOperationResponse.BadRequest($"Incorrect dates:{ ex.Message} ");
|
||||
return ReportOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "InvalidOperationException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageInvalidOperationException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ReportOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
|
||||
return ReportOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<ReportOperationResponse> CreateDocumentRequestsByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SendStream(await _reportContract.CreateDocumentRequestsByPeriodAsync(dateStart, dateFinish, ct),
|
||||
return SendStream(await _reportContract.CreateDocumentRequestsByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct),
|
||||
"sales.xslx");
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ReportOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return ReportOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "InvalidOperationException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageInvalidOperationException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -151,57 +149,55 @@ public class ReportAdapter : IReportAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return ReportOperationResponse.OK((await _reportContract.GetDataSalaryByPeriodAsync(dateStart, dateFinish, ct))
|
||||
return ReportOperationResponse.OK((await _reportContract.GetDataSalaryByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct))
|
||||
.Select(x => _mapper.Map<WorkerSalaryByPeriodViewModel>(x)).ToList());
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ReportOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return ReportOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "InvalidOperationException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageInvalidOperationException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ReportOperationResponse.InternalServerError(ex.Message);
|
||||
return ReportOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public async Task<ReportOperationResponse> CreateDocumentSalaryByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SendStream(await _reportContract.CreateDocumentSalaryByPeriodAsync(dateStart, dateFinish, ct), "salary.pdf");
|
||||
return SendStream(await _reportContract.CreateDocumentSalaryByPeriodAsync(dateStart.ToUniversalTime(), dateFinish.ToUniversalTime(), ct), "salary.pdf");
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return ReportOperationResponse.BadRequest($"Incorrect dates: {ex.Message} ");
|
||||
return ReportOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (InvalidOperationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "InvalidOperationException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageInvalidOperationException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ReportOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ReportOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
ReportOperationResponse.InternalServerError(ex.Message);
|
||||
return ReportOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,27 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.AdapterContracts;
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BindingModels;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
|
||||
namespace SmallSoftwareWebApi.Adapters;
|
||||
|
||||
public class RequestAdapter : IRequestAdapter
|
||||
internal class RequestAdapter : IRequestAdapter
|
||||
{
|
||||
private readonly IRequestBusinessLogicContract _requestBusinessLogicContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public RequestAdapter(IRequestBusinessLogicContract requestBusinessLogicContract, ILogger<RequestAdapter> logger)
|
||||
public RequestAdapter(IRequestBusinessLogicContract requestBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<RequestAdapter> logger)
|
||||
{
|
||||
_requestBusinessLogicContract = requestBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -29,28 +33,24 @@ public class RequestAdapter : IRequestAdapter
|
||||
cfg.CreateMap<InstallationRequestDataModel, InstallationRequestViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public RequestOperationResponse GetList(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
return RequestOperationResponse.OK([.. _requestBusinessLogicContract.GetAllRequestsByPeriod(fromDate, toDate).Select(x => _mapper.Map<RequestViewModel>(x))]);
|
||||
return RequestOperationResponse.OK([.. _requestBusinessLogicContract.GetAllRequestsByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<RequestViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return RequestOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return RequestOperationResponse.NotFound("The list is not initialized");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RequestOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RequestOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -63,27 +63,22 @@ public class RequestAdapter : IRequestAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return RequestOperationResponse.OK([.. _requestBusinessLogicContract.GetAllRequestsByWorkerByPeriod(id, fromDate, toDate).Select(x => _mapper.Map<RequestViewModel>(x))]);
|
||||
return RequestOperationResponse.OK([.. _requestBusinessLogicContract.GetAllRequestsByWorkerByPeriod(id, fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<RequestViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return RequestOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return RequestOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return RequestOperationResponse.NotFound("The list is not initialized");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RequestOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RequestOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -98,27 +93,22 @@ public class RequestAdapter : IRequestAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return RequestOperationResponse.OK([.. _requestBusinessLogicContract.GetAllRequestsBySoftwareByPeriod(id, fromDate, toDate).Select(x => _mapper.Map<RequestViewModel>(x))]);
|
||||
return RequestOperationResponse.OK([.. _requestBusinessLogicContract.GetAllRequestsBySoftwareByPeriod(id, fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<RequestViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return RequestOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return RequestOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return RequestOperationResponse.NotFound("The list is not initialized");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RequestOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RequestOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -136,22 +126,22 @@ public class RequestAdapter : IRequestAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return RequestOperationResponse.BadRequest("Data is empty");
|
||||
return RequestOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return RequestOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return RequestOperationResponse.NotFound($"Not found element by data {id}");
|
||||
return RequestOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RequestOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RequestOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -171,17 +161,17 @@ public class RequestAdapter : IRequestAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return RequestOperationResponse.BadRequest("Data is empty");
|
||||
return RequestOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return RequestOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RequestOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RequestOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -200,27 +190,27 @@ public class RequestAdapter : IRequestAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return RequestOperationResponse.BadRequest("Id is empty");
|
||||
return RequestOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return RequestOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return RequestOperationResponse.BadRequest($"Not found element by id: {id}");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return RequestOperationResponse.BadRequest($"Element by id: {id} was deleted");
|
||||
return RequestOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementDeletedException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return RequestOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return RequestOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -5,10 +5,12 @@ using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareWebApi.Adapters;
|
||||
|
||||
public class SalaryAdapter : ISalaryAdapter
|
||||
internal class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
private readonly ISalaryBusinessLogicContract _salaryBusinessLogicContract;
|
||||
|
||||
@@ -16,7 +18,9 @@ public class SalaryAdapter : ISalaryAdapter
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public SalaryAdapter(ISalaryBusinessLogicContract salaryBusinessLogicContract, ILogger<SalaryAdapter> logger)
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public SalaryAdapter(ISalaryBusinessLogicContract salaryBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<SalaryAdapter> logger)
|
||||
{
|
||||
_salaryBusinessLogicContract = salaryBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -25,33 +29,29 @@ public class SalaryAdapter : ISalaryAdapter
|
||||
cfg.CreateMap<SalaryDataModel, SalaryViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public SalaryOperationResponse GetListByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
try
|
||||
{
|
||||
return SalaryOperationResponse.OK([.. _salaryBusinessLogicContract.GetAllSalariesByPeriod(fromDate, toDate).Select(x => _mapper.Map<SalaryViewModel>(x))]);
|
||||
return SalaryOperationResponse.OK([.. _salaryBusinessLogicContract.GetAllSalariesByPeriod(fromDate.ToUniversalTime(), toDate.ToUniversalTime()).Select(x => _mapper.Map<SalaryViewModel>(x))]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SalaryOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SalaryOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return SalaryOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SalaryOperationResponse.NotFound("The list is not initialized");
|
||||
return SalaryOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SalaryOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SalaryOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -64,27 +64,22 @@ public class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return SalaryOperationResponse.OK([.. _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(fromDate, toDate, workerId).Select(x => _mapper.Map<SalaryViewModel>(x))]);
|
||||
return SalaryOperationResponse.OK([.. _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), workerId).Select(x => _mapper.Map<SalaryViewModel>(x))]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SalaryOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SalaryOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return SalaryOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SalaryOperationResponse.NotFound("The list is not initialized");
|
||||
return SalaryOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SalaryOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SalaryOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -97,18 +92,13 @@ public class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMonth(date);
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMonth(date.ToUniversalTime());
|
||||
return SalaryOperationResponse.NoContent();
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SalaryOperationResponse.NotFound("The list is not initialized");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SalaryOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SalaryOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
using AutoMapper;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.AdapterContracts;
|
||||
using SmallSoftwareContracts.AdapterContracts.OperationResponses;
|
||||
using SmallSoftwareContracts.BindingModels;
|
||||
using SmallSoftwareContracts.BusinessLogicsContracts;
|
||||
using SmallSoftwareContracts.DataModels;
|
||||
using SmallSoftwareContracts.Exceptions;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
using SmallSoftwareContracts.ViewModels;
|
||||
|
||||
namespace SmallSoftwareWebApi.Adapters;
|
||||
|
||||
public class SoftwareAdapter : ISoftwareAdapter
|
||||
internal class SoftwareAdapter : ISoftwareAdapter
|
||||
{
|
||||
private readonly ISoftwareBusinessLogicContract _softwareBusinessLogicContract;
|
||||
|
||||
@@ -17,7 +19,9 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public SoftwareAdapter(ISoftwareBusinessLogicContract softwareBusinessLogicContract, ILogger<SoftwareAdapter> logger)
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public SoftwareAdapter(ISoftwareBusinessLogicContract softwareBusinessLogicContract, ILogger<SoftwareAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_softwareBusinessLogicContract = softwareBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -28,6 +32,7 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
cfg.CreateMap<SoftwareHistoryDataModel, SoftwareHistoryViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public SoftwareOperationResponse GetList(bool includeDeleted)
|
||||
@@ -36,15 +41,10 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
{
|
||||
return SoftwareOperationResponse.OK([.. _softwareBusinessLogicContract.GetAllSoftwares(!includeDeleted).Select(x => _mapper.Map<SoftwareViewModel>(x))]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SoftwareOperationResponse.NotFound("The list is not initialized");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SoftwareOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SoftwareOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -92,20 +92,20 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
{
|
||||
return SoftwareOperationResponse.OK([.. _softwareBusinessLogicContract.GetSoftwareHistoryBySoftware(id).Select(x => _mapper.Map<SoftwareHistoryViewModel>(x))]);
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SoftwareOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SoftwareOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SoftwareOperationResponse.NotFound("The list is not initialized");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SoftwareOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SoftwareOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -123,22 +123,22 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SoftwareOperationResponse.BadRequest("Data is empty");
|
||||
return SoftwareOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return SoftwareOperationResponse.NotFound($"Not found element by data {data}");
|
||||
return SoftwareOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementNotFoundException"], data));
|
||||
}
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return SoftwareOperationResponse.BadRequest($"Element by data: {data} was deleted");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementDeletedException"], data));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SoftwareOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SoftwareOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -157,12 +157,12 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SoftwareOperationResponse.BadRequest("Data is empty");
|
||||
return SoftwareOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SoftwareOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -172,7 +172,7 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SoftwareOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -191,17 +191,17 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SoftwareOperationResponse.BadRequest("Data is empty");
|
||||
return SoftwareOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SoftwareOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return SoftwareOperationResponse.BadRequest($"Not found element by Id {softwareModel.Id}");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], softwareModel));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -211,12 +211,12 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return SoftwareOperationResponse.BadRequest($"Element by id: {softwareModel.Id} was deleted");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementDeletedException"], softwareModel));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SoftwareOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -235,27 +235,27 @@ public class SoftwareAdapter : ISoftwareAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SoftwareOperationResponse.BadRequest("Id is empty");
|
||||
return SoftwareOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SoftwareOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return SoftwareOperationResponse.BadRequest($"Not found element by id: {id}");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return SoftwareOperationResponse.BadRequest($"Element by id: {id} was deleted");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementDeletedException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SoftwareOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SoftwareOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -9,22 +9,25 @@ using SmallSoftwareContracts.ViewModels;
|
||||
using SmallSoftwareDatabase.Models;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Text.Json;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using SmallSoftwareContracts.Resources;
|
||||
|
||||
namespace SmallSoftwareWebApi.Adapters;
|
||||
|
||||
|
||||
public class WorkerAdapter : IWorkerAdapter
|
||||
internal class WorkerAdapter : IWorkerAdapter
|
||||
{
|
||||
private readonly IWorkerBusinessLogicContract _workerBusinessLogicContract;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
private readonly JsonSerializerOptions JsonSerializerOptions = new()
|
||||
{
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public WorkerAdapter(IWorkerBusinessLogicContract
|
||||
workerBusinessLogicContract, ILogger<WorkerAdapter> logger)
|
||||
workerBusinessLogicContract, ILogger<WorkerAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_workerBusinessLogicContract = workerBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -36,6 +39,7 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
JsonSerializer.Serialize(src.ConfigurationModel, JsonSerializerOptions)));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
public WorkerOperationResponse GetList(bool includeDeleted)
|
||||
{
|
||||
@@ -44,22 +48,15 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
return WorkerOperationResponse.OK([.. _workerBusinessLogicContract.GetAllWorkers(!includeDeleted)
|
||||
.Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkerOperationResponse.NotFound("The list is not initialized");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse
|
||||
.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public WorkerOperationResponse GetPostList(string id, bool includeDeleted)
|
||||
@@ -72,24 +69,17 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: { ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkerOperationResponse.NotFound("The list is not initialized");
|
||||
return WorkerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse
|
||||
.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public WorkerOperationResponse GetListByBirthDate(DateTime fromDate,
|
||||
@@ -98,62 +88,48 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK([..
|
||||
_workerBusinessLogicContract.GetAllWorkersByBirthDate(fromDate, toDate,
|
||||
!includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect dates: { ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkerOperationResponse.NotFound("The list is not initialized");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse
|
||||
.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public WorkerOperationResponse GetListByEmploymentDate(DateTime fromDate,
|
||||
DateTime toDate, bool includeDeleted)
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK([..
|
||||
_workerBusinessLogicContract.GetAllWorkersByEmploymentDate(fromDate, toDate,
|
||||
_workerBusinessLogicContract.GetAllWorkersByBirthDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(),
|
||||
!includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect dates: { ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return WorkerOperationResponse.NotFound("The list is not initialized");
|
||||
return WorkerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse
|
||||
.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(
|
||||
string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public WorkerOperationResponse GetListByEmploymentDate(DateTime fromDate, DateTime toDate, bool includeDeleted)
|
||||
{
|
||||
try
|
||||
{
|
||||
return WorkerOperationResponse.OK([..
|
||||
_workerBusinessLogicContract.GetAllWorkersByEmploymentDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(),
|
||||
!includeDeleted).Select(x => _mapper.Map<WorkerViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return WorkerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public WorkerOperationResponse GetElement(string data)
|
||||
@@ -166,29 +142,27 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkerOperationResponse.BadRequest("Data is empty");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: { ex.Message}");
|
||||
return WorkerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return WorkerOperationResponse.NotFound($"Not found element by data { data}");
|
||||
return WorkerOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementNotFoundException"], data));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse
|
||||
.InternalServerError($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public WorkerOperationResponse RegisterWorker(WorkerBindingModel
|
||||
@@ -202,12 +176,12 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkerOperationResponse.BadRequest("Data is empty");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: { ex.Message}");
|
||||
return WorkerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -217,15 +191,12 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
|
||||
return WorkerOperationResponse
|
||||
.BadRequest($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public WorkerOperationResponse ChangeWorkerInfo(WorkerBindingModel
|
||||
@@ -239,17 +210,19 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkerOperationResponse.BadRequest("Data is empty");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: { ex.Message}");
|
||||
return WorkerOperationResponse.BadRequest(
|
||||
string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return WorkerOperationResponse.BadRequest($"Not found element by Id { workerModel.Id}");
|
||||
return WorkerOperationResponse.BadRequest(
|
||||
string.Format(_localizer["AdapterMessageElementNotFoundException"], workerModel.Id));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -259,14 +232,13 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse
|
||||
.BadRequest($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
return WorkerOperationResponse.InternalServerError(
|
||||
string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
public WorkerOperationResponse RemoveWorker(string id)
|
||||
@@ -276,32 +248,30 @@ public class WorkerAdapter : IWorkerAdapter
|
||||
_workerBusinessLogicContract.DeleteWorker(id);
|
||||
return WorkerOperationResponse.NoContent();
|
||||
}
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkerOperationResponse.BadRequest("Id is empty");
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest($"Incorrect data transmitted: { ex.Message}");
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return WorkerOperationResponse.BadRequest($"Not found element by id: { id}");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse
|
||||
.BadRequest($"Error while working with data storage: { ex.InnerException!.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return WorkerOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return WorkerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return WorkerOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return WorkerOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Exception");
|
||||
return
|
||||
WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
return WorkerOperationResponse.InternalServerError(ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class ReportController(IReportAdapter adapter) : ControllerBase
|
||||
public async Task<IActionResult> GetSoftwares(CancellationToken ct)
|
||||
{
|
||||
return (await
|
||||
_adapter.GetDataSoftwaresByManufacturerAsync(ct)).GetResponse(Request, Response);
|
||||
_adapter.GetDataSoftwaresByHistoryAsync(ct)).GetResponse(Request, Response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
@@ -23,7 +23,7 @@ public class ReportController(IReportAdapter adapter) : ControllerBase
|
||||
public async Task<IActionResult> LoadSoftwares(CancellationToken cancellationToken)
|
||||
{
|
||||
return (await
|
||||
_adapter.CreateDocumentSoftwaresByManufacturerAsync(cancellationToken)).GetResponse(Request, Response);
|
||||
_adapter.CreateDocumentSoftwaresByHistoryAsync(cancellationToken)).GetResponse(Request, Response);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Localization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Serilog;
|
||||
using SmallSoftwareBusinessLogic.Implementations;
|
||||
@@ -13,6 +15,7 @@ using SmallSoftwareDatabase.Implementations;
|
||||
using SmallSoftwareWebApi;
|
||||
using SmallSoftwareWebApi.Adapters;
|
||||
using SmallSoftwareWebApi.Infrastructure;
|
||||
using System.Globalization;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
|
||||
@@ -49,6 +52,22 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddLocalization();
|
||||
builder.Services.Configure<RequestLocalizationOptions>(
|
||||
options =>
|
||||
{
|
||||
var supportedCultures = new List<CultureInfo>
|
||||
{
|
||||
new("en-US"),
|
||||
new("ru-RU"),
|
||||
new("de-DE")
|
||||
};
|
||||
|
||||
options.DefaultRequestCulture = new RequestCulture(culture: "ru-RU", uiCulture: "ru-RU");
|
||||
options.SupportedCultures = supportedCultures;
|
||||
options.SupportedUICultures = supportedCultures;
|
||||
});
|
||||
|
||||
builder.Services.AddSingleton<IConfigurationDatabase, ConfigurationDatabase>();
|
||||
builder.Services.AddSingleton<IConfigurationSalary, ConfigurationSalary>();
|
||||
|
||||
@@ -119,4 +138,10 @@ app.Map("/login/{username}", (string username) =>
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
var localizeOptions = app.Services.GetService<IOptions<RequestLocalizationOptions>>();
|
||||
if (localizeOptions is not null)
|
||||
{
|
||||
app.UseRequestLocalization(localizeOptions.Value);
|
||||
}
|
||||
|
||||
app.Run();
|
||||
|
||||
Reference in New Issue
Block a user