forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
готовая работа
This commit is contained in:
@@ -2,7 +2,9 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Extensions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -14,15 +16,16 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetBusinessLogic.Implementations;
|
||||
|
||||
public class ClientBusinessLogicContract(IClientStorageContract clientStorageContract, ILogger logger) : IClientBusinessLogicContract
|
||||
internal class ClientBusinessLogicContract(IClientStorageContract clientStorageContract, IStringLocalizer<Messages> localizer, ILogger logger) : IClientBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IClientStorageContract _clientStorageContract = clientStorageContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<ClientDataModel> GetAllClients()
|
||||
{
|
||||
_logger.LogInformation("GetAllClients");
|
||||
return _clientStorageContract.GetList() ?? throw new NullListException();
|
||||
return _clientStorageContract.GetList();
|
||||
}
|
||||
|
||||
public ClientDataModel GetClientByData(string data)
|
||||
@@ -34,20 +37,20 @@ public class ClientBusinessLogicContract(IClientStorageContract clientStorageCon
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _clientStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
return _clientStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
if (Regex.IsMatch(data, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||
{
|
||||
return _clientStorageContract.GetElementByPhoneNumber(data) ?? throw new ElementNotFoundException(data);
|
||||
return _clientStorageContract.GetElementByPhoneNumber(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
return _clientStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
|
||||
return _clientStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
|
||||
public void InsertClient(ClientDataModel clientDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(clientDataModel));
|
||||
ArgumentNullException.ThrowIfNull(clientDataModel);
|
||||
clientDataModel.Validate();
|
||||
clientDataModel.Validate(_localizer);
|
||||
_clientStorageContract.AddElement(clientDataModel);
|
||||
}
|
||||
|
||||
@@ -55,7 +58,7 @@ public class ClientBusinessLogicContract(IClientStorageContract clientStorageCon
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(clientDataModel));
|
||||
ArgumentNullException.ThrowIfNull(clientDataModel);
|
||||
clientDataModel.Validate();
|
||||
clientDataModel.Validate(_localizer);
|
||||
_clientStorageContract.UpdElement(clientDataModel);
|
||||
}
|
||||
|
||||
@@ -68,7 +71,7 @@ public class ClientBusinessLogicContract(IClientStorageContract clientStorageCon
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_clientStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Extensions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -14,15 +16,16 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetBusinessLogic.Implementations;
|
||||
|
||||
public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStorageContract, ILogger logger) : IEmployeeBusinessLogicContract
|
||||
internal class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStorageContract, IStringLocalizer<Messages> localizer, ILogger logger) : IEmployeeBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IEmployeeStorageContract _employeeStorageContract = employeeStorageContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<EmployeeDataModel> GetAllEmployees(bool onlyActive = true)
|
||||
{
|
||||
_logger.LogInformation("GetAllEmployees params: {onlyActive}", onlyActive);
|
||||
return _employeeStorageContract.GetList(onlyActive) ?? throw new NullListException();
|
||||
return _employeeStorageContract.GetList(onlyActive);
|
||||
}
|
||||
|
||||
public List<EmployeeDataModel> GetAllEmployeesByPost(string postId, bool onlyActive = true)
|
||||
@@ -34,9 +37,9 @@ public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStor
|
||||
}
|
||||
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 _employeeStorageContract.GetList(onlyActive, postId) ?? throw new NullListException();
|
||||
return _employeeStorageContract.GetList(onlyActive, postId);
|
||||
}
|
||||
|
||||
public List<EmployeeDataModel> GetAllEmployeesByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
@@ -44,9 +47,9 @@ public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStor
|
||||
_logger.LogInformation("GetAllEmployees params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
return _employeeStorageContract.GetList(onlyActive, fromBirthDate: fromDate, toBirthDate: toDate) ?? throw new NullListException();
|
||||
return _employeeStorageContract.GetList(onlyActive, fromBirthDate: fromDate, toBirthDate: toDate);
|
||||
}
|
||||
|
||||
public List<EmployeeDataModel> GetAllEmployeesByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true)
|
||||
@@ -54,9 +57,9 @@ public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStor
|
||||
_logger.LogInformation("GetAllEmployees params: {onlyActive}, {fromDate}, {toDate}", onlyActive, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
return _employeeStorageContract.GetList(onlyActive, fromEmploymentDate: fromDate, toEmploymentDate: toDate) ?? throw new NullListException();
|
||||
return _employeeStorageContract.GetList(onlyActive, fromEmploymentDate: fromDate, toEmploymentDate: toDate);
|
||||
}
|
||||
|
||||
public EmployeeDataModel GetEmployeeByData(string data)
|
||||
@@ -68,20 +71,20 @@ public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStor
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _employeeStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
return _employeeStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
if (Regex.IsMatch(data, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
||||
{
|
||||
return _employeeStorageContract.GetElementByEmail(data) ?? throw new ElementNotFoundException(data);
|
||||
return _employeeStorageContract.GetElementByEmail(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
return _employeeStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data);
|
||||
return _employeeStorageContract.GetElementByFIO(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
|
||||
public void InsertEmployee(EmployeeDataModel employeeDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(employeeDataModel));
|
||||
ArgumentNullException.ThrowIfNull(employeeDataModel);
|
||||
employeeDataModel.Validate();
|
||||
employeeDataModel.Validate(_localizer);
|
||||
_employeeStorageContract.AddElement(employeeDataModel);
|
||||
}
|
||||
|
||||
@@ -89,7 +92,7 @@ public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStor
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(employeeDataModel));
|
||||
ArgumentNullException.ThrowIfNull(employeeDataModel);
|
||||
employeeDataModel.Validate();
|
||||
employeeDataModel.Validate(_localizer);
|
||||
_employeeStorageContract.UpdElement(employeeDataModel);
|
||||
}
|
||||
|
||||
@@ -102,7 +105,7 @@ public class EmployeeBusinessLogicContract(IEmployeeStorageContract employeeStor
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_employeeStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Extensions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,14 +14,15 @@ using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
namespace MagicCarpetBusinessLogic.Implementations;
|
||||
|
||||
public class PostBusinessLogicContract(IPostStorageContract postStorageContract, ILogger logger) : IPostBusinessLogicContract
|
||||
internal class PostBusinessLogicContract(IPostStorageContract 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");
|
||||
return _postStorageContract.GetList() ?? throw new NullListException();
|
||||
return _postStorageContract.GetList();
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetAllDataOfPost(string postId)
|
||||
@@ -31,9 +34,9 @@ public class PostBusinessLogicContract(IPostStorageContract postStorageContract,
|
||||
}
|
||||
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();
|
||||
return _postStorageContract.GetPostWithHistory(postId);
|
||||
}
|
||||
|
||||
public PostDataModel GetPostByData(string data)
|
||||
@@ -45,16 +48,16 @@ public class PostBusinessLogicContract(IPostStorageContract postStorageContract,
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _postStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
return _postStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
return _postStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
return _postStorageContract.GetElementByName(data) ?? throw new 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);
|
||||
}
|
||||
|
||||
@@ -62,7 +65,7 @@ public class PostBusinessLogicContract(IPostStorageContract postStorageContract,
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(postDataModel));
|
||||
ArgumentNullException.ThrowIfNull(postDataModel);
|
||||
postDataModel.Validate();
|
||||
postDataModel.Validate(_localizer);
|
||||
_postStorageContract.UpdElement(postDataModel);
|
||||
}
|
||||
|
||||
@@ -75,7 +78,7 @@ public class PostBusinessLogicContract(IPostStorageContract postStorageContract,
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_postStorageContract.DelElement(id);
|
||||
}
|
||||
@@ -89,7 +92,7 @@ public class PostBusinessLogicContract(IPostStorageContract postStorageContract,
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_postStorageContract.ResElement(id);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using MagicCarpetBusinessLogic.OfficePackage;
|
||||
using DocumentFormat.OpenXml.Wordprocessing;
|
||||
using MagicCarpetBusinessLogic.OfficePackage;
|
||||
using MagicCarpetContracts.BusinessLogicContracts;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Extensions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -12,19 +15,37 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
namespace MagicCarpetBusinessLogic.Implementations;
|
||||
|
||||
public class ReportContract(ITourStorageContract tourStorageContract, ISalaryStorageContract salaryStorageContract, ISaleStorageContract saleStorageContract,
|
||||
BaseWordBuilder baseWordBuilder, BaseExcelBuilder baseExcelBuilder, BasePdfBuilder basePdfBuilder, ILogger logger) : IReportContract
|
||||
internal class ReportContract : IReportContract
|
||||
{
|
||||
private readonly ITourStorageContract _cocktailStorageContract = tourStorageContract;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
||||
private readonly BaseWordBuilder _baseWordBuilder = baseWordBuilder;
|
||||
private readonly BaseExcelBuilder _baseExcelBuilder = baseExcelBuilder;
|
||||
private readonly BasePdfBuilder _basePdfBuilder = basePdfBuilder;
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ITourStorageContract _tourStorageContract;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract;
|
||||
private readonly ISaleStorageContract _saleStorageContract;
|
||||
private readonly BaseWordBuilder _baseWordBuilder;
|
||||
private readonly BaseExcelBuilder _baseExcelBuilder;
|
||||
private readonly BasePdfBuilder _basePdfBuilder;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
internal readonly string[] _documentHeader;
|
||||
internal readonly string[] _tableHeader;
|
||||
|
||||
public ReportContract(ITourStorageContract tourStorageContract, ISalaryStorageContract salaryStorageContract,
|
||||
ISaleStorageContract saleStorageContract, BaseWordBuilder baseWordBuilder, BaseExcelBuilder baseExcelBuilder,
|
||||
BasePdfBuilder basePdfBuilder, ILogger logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_tourStorageContract = tourStorageContract;
|
||||
_saleStorageContract = saleStorageContract;
|
||||
_salaryStorageContract = salaryStorageContract;
|
||||
_baseWordBuilder = baseWordBuilder;
|
||||
_baseExcelBuilder = baseExcelBuilder;
|
||||
_basePdfBuilder = basePdfBuilder;
|
||||
_logger = logger;
|
||||
_localizer = localizer;
|
||||
|
||||
_documentHeader = [_localizer["DocumentDocCaptionTour"], _localizer["DocumentDocCaptionPreviousNames"], _localizer["DocumentDocCaptionData"]];
|
||||
_tableHeader = [_localizer["DocumentExcelCaptionDate"], _localizer["DocumentExcelCaptionSum"], _localizer["DocumentExcelCaptionDiscount"], _localizer["DocumentExcelCaptionTour"], _localizer["DocumentExcelCaptionCount"]];
|
||||
}
|
||||
|
||||
internal static readonly string[] documentHeader = ["Название тура", "Старая цена", "Дата"];
|
||||
internal static readonly string[] tableHeader = ["Дата", "Сумма", "Скидка", "Товар", "Кол-во"];
|
||||
|
||||
public Task<List<TourAndTourHistoryDataModel>> GetDataToursHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
@@ -35,32 +56,40 @@ public class ReportContract(ITourStorageContract tourStorageContract, ISalarySto
|
||||
public async Task<Stream> CreateDocumentToursHistoryAsync(CancellationToken ct)
|
||||
{
|
||||
_logger.LogInformation("Create report TourHistory");
|
||||
var data = await GetToursHistoriesAsync(ct) ?? throw new InvalidOperationException("No found data");
|
||||
var data = await GetToursHistoriesAsync(ct) ?? throw new InvalidOperationException(_localizer["NotFoundDataMessage"]);
|
||||
|
||||
return _baseWordBuilder
|
||||
.AddHeader("История туров")
|
||||
.AddParagraph($"Сформировано на дату {DateTime.Now}")
|
||||
.AddHeader(_localizer["DocumentDocHeader"])
|
||||
.AddParagraph(string.Format(_localizer["DocumentDocSubHeader"], DateTime.Now))
|
||||
.AddTable(
|
||||
[3000, 3000, 3000],
|
||||
[.. new List<string[]>() { documentHeader }
|
||||
.Union(data.SelectMany(x =>
|
||||
(new List<string[]>() { new[] { x.TourName, "", "" } })
|
||||
.Union(x.Histories.Zip(x.Data, (price, date) => new[] { "", price, date }))
|
||||
).ToList())
|
||||
])
|
||||
new[] { 3000, 3000, 3000 },
|
||||
new List<string[]> { _documentHeader }
|
||||
.Concat(data.SelectMany(x =>
|
||||
new[] { new[] { x.TourName, "", "" } }
|
||||
.Concat(x.Histories.Zip(x.Data, (price, date) => new[] { "", price, date }))
|
||||
))
|
||||
.ToList())
|
||||
.Build();
|
||||
}
|
||||
|
||||
private async Task<List<TourAndTourHistoryDataModel>> GetToursHistoriesAsync(CancellationToken ct) =>
|
||||
[.. (await _cocktailStorageContract.GetHistoriesListAsync(ct)).GroupBy(x => x.TourName).Select(x => new TourAndTourHistoryDataModel {
|
||||
[.. (await _tourStorageContract.GetHistoriesListAsync(ct)).GroupBy(x => x.TourName).Select(x => new TourAndTourHistoryDataModel {
|
||||
TourName = x.Key, Histories = [.. x.Select(y => y.OldPrice.ToString())], Data = [.. x.Select(y => y.ChangeDate.ToString())] })];
|
||||
|
||||
public async Task<Stream> CreateDocumentSalesByPeriodAsync(DateTime dateStart, DateTime dateFinish, CancellationToken ct)
|
||||
{
|
||||
string[] tableHeader1 = ["Сотрудник", "Дата", "Сумма", "Скидка", "Товар", "Кол-во"];
|
||||
var tableHeader1 = new string[]
|
||||
{
|
||||
_localizer["DocumentExcelHeaderEmployee"],
|
||||
_localizer["DocumentExcelCaptionDate"],
|
||||
_localizer["DocumentExcelCaptionSum"],
|
||||
_localizer["DocumentExcelCaptionDiscount"],
|
||||
_localizer["DocumentExcelCaptionCocktail"],
|
||||
_localizer["DocumentExcelCaptionCount"]
|
||||
};
|
||||
|
||||
_logger.LogInformation("Create report SalesByPeriod from {dateStart} to {dateFinish}", dateStart, dateFinish);
|
||||
var data = await GetDataBySalesAsync(dateStart, dateFinish, ct) ?? throw new InvalidOperationException("No found data");
|
||||
var data = await GetDataBySalesAsync(dateStart, dateFinish, ct) ?? throw new InvalidOperationException(_localizer["NotFoundDataMessage"]);
|
||||
|
||||
var tableRows = new List<string[]>
|
||||
{
|
||||
@@ -89,12 +118,12 @@ public class ReportContract(ITourStorageContract tourStorageContract, ISalarySto
|
||||
|
||||
tableRows.Add(new string[]
|
||||
{
|
||||
"Всего", "", data.Sum(x => x.Sum).ToString("N2"), data.Sum(x => x.Discount).ToString("N2"), "", ""
|
||||
_localizer["DocumentExcelCaptionTotal"], "", data.Sum(x => x.Sum).ToString("N2"), data.Sum(x => x.Discount).ToString("N2"), "", ""
|
||||
});
|
||||
|
||||
return _baseExcelBuilder
|
||||
.AddHeader("Продажи за период", 0, 6)
|
||||
.AddParagraph($"с {dateStart.ToShortDateString()} по {dateFinish.ToShortDateString()}", 2)
|
||||
.AddHeader(_localizer["DocumentExcelHeader"], 0, 6)
|
||||
.AddParagraph(string.Format(_localizer["DocumentExcelSubHeader"], dateStart.ToLocalTime().ToShortDateString(), dateFinish.ToLocalTime().ToShortDateString()), 2)
|
||||
.AddTable([15, 15, 10, 10, 25, 10], tableRows)
|
||||
.Build();
|
||||
}
|
||||
@@ -103,7 +132,7 @@ public class ReportContract(ITourStorageContract tourStorageContract, ISalarySto
|
||||
{
|
||||
if (dateStart.IsDateNotOlder(dateFinish))
|
||||
{
|
||||
throw new IncorrectDatesException(dateStart, dateFinish);
|
||||
throw new IncorrectDatesException(dateStart, dateFinish, _localizer);
|
||||
}
|
||||
return [.. (await _saleStorageContract.GetListAsync(dateStart,
|
||||
dateFinish, ct)).OrderBy(x => x.SaleDate)];
|
||||
@@ -124,7 +153,7 @@ public class ReportContract(ITourStorageContract tourStorageContract, ISalarySto
|
||||
{
|
||||
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.EmployeeId)
|
||||
|
||||
@@ -4,7 +4,9 @@ using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Extensions;
|
||||
using MagicCarpetContracts.Infrastructure;
|
||||
using MagicCarpetContracts.Infrastructure.PostConfigurations;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,8 +15,8 @@ using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetBusinessLogic.Implementations;
|
||||
public class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,ISaleStorageContract saleStorageContract,
|
||||
IPostStorageContract postStorageContract, IEmployeeStorageContract employeeStorageContract, ILogger logger, IConfigurationSalary сonfiguration) : ISalaryBusinessLogicContract
|
||||
internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageContract,ISaleStorageContract saleStorageContract,
|
||||
IPostStorageContract postStorageContract, IEmployeeStorageContract employeeStorageContract, IStringLocalizer<Messages> localizer, ILogger logger, IConfigurationSalary сonfiguration) : ISalaryBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISalaryStorageContract _salaryStorageContract = salaryStorageContract;
|
||||
@@ -22,22 +24,23 @@ public class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageCon
|
||||
private readonly IPostStorageContract _postStorageContract = postStorageContract;
|
||||
private readonly IEmployeeStorageContract _employeeStorageContract = employeeStorageContract;
|
||||
private readonly IConfigurationSalary _salaryConfiguration = сonfiguration;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
private readonly Lock _lockObject = new();
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
return _salaryStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
return _salaryStorageContract.GetList(fromDate, toDate);
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetAllSalariesByPeriodByEmployee(DateTime fromDate, DateTime toDate, string employeeId)
|
||||
{
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
if (employeeId.IsEmpty())
|
||||
{
|
||||
@@ -45,10 +48,10 @@ public class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageCon
|
||||
}
|
||||
if (!employeeId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field employeeId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "EmployeeId"));
|
||||
}
|
||||
_logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, {employeeId}", fromDate, toDate, employeeId);
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, employeeId) ?? throw new NullListException();
|
||||
return _salaryStorageContract.GetList(fromDate, toDate, employeeId);
|
||||
}
|
||||
|
||||
public void CalculateSalaryByMounth(DateTime date)
|
||||
@@ -56,11 +59,11 @@ public class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageCon
|
||||
_logger.LogInformation("CalculateSalaryByMounth: {date}", date);
|
||||
var startDate = new DateTime(date.Year, date.Month, 1);
|
||||
var finishDate = new DateTime(date.Year, date.Month, DateTime.DaysInMonth(date.Year, date.Month));
|
||||
var employees = _employeeStorageContract.GetList() ?? throw new NullListException();
|
||||
var employees = _employeeStorageContract.GetList();
|
||||
foreach (var employee in employees)
|
||||
{
|
||||
var sales = _saleStorageContract.GetList(startDate, finishDate, employeeId: employee.Id) ?? throw new NullListException();
|
||||
var post = _postStorageContract.GetElementById(employee.PostId) ?? throw new NullListException();
|
||||
var sales = _saleStorageContract.GetList(startDate, finishDate, employeeId: employee.Id);
|
||||
var post = _postStorageContract.GetElementById(employee.PostId);
|
||||
var salary = post.ConfigurationModel switch
|
||||
{
|
||||
null => 0,
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Extensions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,19 +15,20 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetBusinessLogic.Implementations;
|
||||
|
||||
public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, IStringLocalizer<Messages> localizer, ILogger logger) : ISaleBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSales params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
return _saleStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
return _saleStorageContract.GetList(fromDate, toDate);
|
||||
}
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByEmployeeByPeriod(string employeeId, DateTime fromDate, DateTime toDate)
|
||||
@@ -33,7 +36,7 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
_logger.LogInformation("GetAllSales params: {employeeId}, {fromDate}, {toDate}", employeeId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
if (employeeId.IsEmpty())
|
||||
{
|
||||
@@ -43,7 +46,7 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
{
|
||||
throw new ValidationException("The value in the field employeeId is not a unique identifier.");
|
||||
}
|
||||
return _saleStorageContract.GetList(fromDate, toDate, employeeId: employeeId) ?? throw new NullListException();
|
||||
return _saleStorageContract.GetList(fromDate, toDate, employeeId: employeeId);
|
||||
}
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByClientByPeriod(string clientId, DateTime fromDate, DateTime toDate)
|
||||
@@ -51,7 +54,7 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
_logger.LogInformation("GetAllSales params: {buyerId}, {fromDate}, {toDate}", clientId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
if (clientId.IsEmpty())
|
||||
{
|
||||
@@ -59,9 +62,9 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
}
|
||||
if (!clientId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field clientId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "ClientId"));
|
||||
}
|
||||
return _saleStorageContract.GetList(fromDate, toDate, clientId: clientId) ?? throw new NullListException();
|
||||
return _saleStorageContract.GetList(fromDate, toDate, clientId: clientId);
|
||||
}
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByTourByPeriod(string tourId, DateTime fromDate, DateTime toDate)
|
||||
@@ -69,7 +72,7 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
_logger.LogInformation("GetAllSales params: {tourId}, {fromDate}, {toDate}", tourId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
throw new IncorrectDatesException(fromDate, toDate, _localizer);
|
||||
}
|
||||
if (tourId.IsEmpty())
|
||||
{
|
||||
@@ -77,9 +80,9 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
}
|
||||
if (!tourId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field tourId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "TourId"));
|
||||
}
|
||||
return _saleStorageContract.GetList(fromDate, toDate, tourId: tourId) ?? throw new NullListException();
|
||||
return _saleStorageContract.GetList(fromDate, toDate, tourId: tourId);
|
||||
}
|
||||
|
||||
public SaleDataModel GetSaleByData(string data)
|
||||
@@ -91,16 +94,16 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
}
|
||||
if (!data.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
return _saleStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
return _saleStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data,_localizer);
|
||||
}
|
||||
|
||||
public void InsertSale(SaleDataModel saleDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(saleDataModel));
|
||||
ArgumentNullException.ThrowIfNull(saleDataModel);
|
||||
saleDataModel.Validate();
|
||||
saleDataModel.Validate(_localizer);
|
||||
_saleStorageContract.AddElement(saleDataModel);
|
||||
}
|
||||
|
||||
@@ -113,7 +116,7 @@ public class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract,
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_saleStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Extensions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,14 +15,15 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetBusinessLogic.Implementations;
|
||||
|
||||
public class TourBusinessLogicContract(ITourStorageContract tourStorageContract, ILogger logger) : ITourBusinessLogicContract
|
||||
internal class TourBusinessLogicContract(ITourStorageContract tourStorageContract, IStringLocalizer<Messages> localizer, ILogger logger) : ITourBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ITourStorageContract _tourStorageContract = tourStorageContract;
|
||||
private readonly IStringLocalizer<Messages> _localizer = localizer;
|
||||
public List<TourDataModel> GetAllTours()
|
||||
{
|
||||
_logger.LogInformation("GetAllTours");
|
||||
return _tourStorageContract.GetList() ?? throw new NullListException();
|
||||
return _tourStorageContract.GetList();
|
||||
}
|
||||
|
||||
public List<TourHistoryDataModel> GetTourHistoryByTour(string tourId)
|
||||
@@ -32,9 +35,9 @@ public class TourBusinessLogicContract(ITourStorageContract tourStorageContract,
|
||||
}
|
||||
if (!tourId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field tourId is not a unique identifier.");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "TourId"));
|
||||
}
|
||||
return _tourStorageContract.GetHistoryByTourId(tourId) ?? throw new NullListException();
|
||||
return _tourStorageContract.GetHistoryByTourId(tourId);
|
||||
}
|
||||
|
||||
public TourDataModel GetTourByData(string data)
|
||||
@@ -46,16 +49,16 @@ public class TourBusinessLogicContract(ITourStorageContract tourStorageContract,
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _tourStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
return _tourStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
return _tourStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
return _tourStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data, _localizer);
|
||||
}
|
||||
|
||||
public void InsertTour(TourDataModel tourDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(tourDataModel));
|
||||
ArgumentNullException.ThrowIfNull(tourDataModel);
|
||||
tourDataModel.Validate();
|
||||
tourDataModel.Validate(_localizer);
|
||||
_tourStorageContract.AddElement(tourDataModel);
|
||||
}
|
||||
|
||||
@@ -63,7 +66,7 @@ public class TourBusinessLogicContract(ITourStorageContract tourStorageContract,
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(tourDataModel));
|
||||
ArgumentNullException.ThrowIfNull(tourDataModel);
|
||||
tourDataModel.Validate();
|
||||
tourDataModel.Validate(_localizer);
|
||||
_tourStorageContract.UpdElement(tourDataModel);
|
||||
}
|
||||
|
||||
@@ -76,7 +79,7 @@ public class TourBusinessLogicContract(ITourStorageContract tourStorageContract,
|
||||
}
|
||||
if (!id.IsGuid())
|
||||
{
|
||||
throw new ValidationException("Id is not a unique identifier");
|
||||
throw new ValidationException(string.Format(_localizer["ValidationExceptionMessageNotAId"], "Id"));
|
||||
}
|
||||
_tourStorageContract.DelElement(id);
|
||||
}
|
||||
|
||||
@@ -54,13 +54,13 @@ internal class EmployeeDataModel(string id, string fio, string email, string pos
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "FIO"));
|
||||
|
||||
if (Email.IsEmpty())
|
||||
throw new ValidationException("Field Email is empty");
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "Email"));
|
||||
|
||||
if (!Regex.IsMatch(Email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
||||
throw new ValidationException("Field Email is not a valid email address");
|
||||
throw new ValidationException(localizer["ValidationExceptionMessageIncorrectEmail"]);
|
||||
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageEmptyField"], "PostId"));
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "PostId"));
|
||||
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException(string.Format(localizer["ValidationExceptionMessageNotAId"], "PostId"));
|
||||
|
||||
@@ -3,11 +3,6 @@ using MagicCarpetContracts.Extensions;
|
||||
using MagicCarpetContracts.Infrastructure;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetContracts.DataModels;
|
||||
|
||||
|
||||
@@ -12,21 +12,6 @@
|
||||
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Localization.Abstractions" Version="9.0.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Update="Resources\Messages.Designer.cs">
|
||||
<DesignTime>True</DesignTime>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Messages.resx</DependentUpon>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Update="Resources\Messages.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Messages.Designer.cs</LastGenOutput>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="MagicCarpetDatabase" />
|
||||
<InternalsVisibleTo Include="MagicCarpetTests" />
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
<?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>The item according to the data: {0} has been deleted</value>
|
||||
</data>
|
||||
<data name="AdapterMessageElementNotFoundException" xml:space="preserve">
|
||||
<value>Not found element by data: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageEmptyDate" xml:space="preserve">
|
||||
<value>Data is empty</value>
|
||||
</data>
|
||||
<data name="AdapterMessageIncorrectDatesException" xml:space="preserve">
|
||||
<value>Incorrect dates: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageInvalidOperationException" xml:space="preserve">
|
||||
<value>Error processing data: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageStorageException" xml:space="preserve">
|
||||
<value>Error while working with data storage: {0}</value>
|
||||
</data>
|
||||
<data name="AdapterMessageValidationException" xml:space="preserve">
|
||||
<value>Incorrect data transmitted: {0}</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionData" xml:space="preserve">
|
||||
<value>Date</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionPreviousNames" xml:space="preserve">
|
||||
<value>Previous names</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionTour" xml:space="preserve">
|
||||
<value>Tour</value>
|
||||
</data>
|
||||
<data name="DocumentDocHeader" xml:space="preserve">
|
||||
<value>The history of tour changes</value>
|
||||
</data>
|
||||
<data name="DocumentDocSubHeader" xml:space="preserve">
|
||||
<value>Make In Date {0}</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionCount" xml:space="preserve">
|
||||
<value>Count</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionDate" xml:space="preserve">
|
||||
<value>Date</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionDiscount" xml:space="preserve">
|
||||
<value>Discount</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionSum" xml:space="preserve">
|
||||
<value>Sum</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionTotal" xml:space="preserve">
|
||||
<value>Total</value>
|
||||
</data>
|
||||
<data name="DocumentExcelCaptionTour" xml:space="preserve">
|
||||
<value>Tour</value>
|
||||
</data>
|
||||
<data name="DocumentExcelHeader" xml:space="preserve">
|
||||
<value>Sales for the period</value>
|
||||
</data>
|
||||
<data name="DocumentExcelHeaderEmployee" xml:space="preserve">
|
||||
<value>Employee</value>
|
||||
</data>
|
||||
<data name="DocumentExcelSubHeader" xml:space="preserve">
|
||||
<value>from {0} to {1}</value>
|
||||
</data>
|
||||
<data name="DocumentPdfDiagramCaption" xml:space="preserve">
|
||||
<value>Accruals</value>
|
||||
</data>
|
||||
<data name="DocumentPdfHeader" xml:space="preserve">
|
||||
<value>Payroll</value>
|
||||
</data>
|
||||
<data name="DocumentPdfSubHeader" xml:space="preserve">
|
||||
<value>for the period from {0} to {1}</value>
|
||||
</data>
|
||||
<data name="ElementDeletedExceptionMessage" xml:space="preserve">
|
||||
<value>Cannot modify a deleted item (id: {0})</value>
|
||||
</data>
|
||||
<data name="ElementExistsExceptionMessage" xml:space="preserve">
|
||||
<value>There is already an element with value {0} of parameter {1}</value>
|
||||
</data>
|
||||
<data name="ElementNotFoundExceptionMessage" xml:space="preserve">
|
||||
<value>Element not found at value = {0}</value>
|
||||
</data>
|
||||
<data name="IncorrectDatesExceptionMessage" xml:space="preserve">
|
||||
<value>The end date must be later than the start date.. StartDate: {0}. EndDate: {1}</value>
|
||||
</data>
|
||||
<data name="NotEnoughDataToProcessExceptionMessage" xml:space="preserve">
|
||||
<value>Not enough data to process: {0}</value>
|
||||
</data>
|
||||
<data name="NotFoundDataMessage" xml:space="preserve">
|
||||
<value>No data found</value>
|
||||
</data>
|
||||
<data name="StorageExceptionMessage" xml:space="preserve">
|
||||
<value>Error while working in storage: {0}</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageEmploymentDateAndBirthDate" xml:space="preserve">
|
||||
<value>Date of employment cannot be earlier than date of birth ({0}, {1})</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageEmptyField" xml:space="preserve">
|
||||
<value>The value in field {0} is empty</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageIncorrectFIO" xml:space="preserve">
|
||||
<value>Fio is not correct</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageIncorrectPhoneNumber" xml:space="preserve">
|
||||
<value>The value in the Phone Number field is not a phone number.</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageLessOrEqualZero" xml:space="preserve">
|
||||
<value>The value in field {0} is less than or equal to 0</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageMinorsBirthDate" xml:space="preserve">
|
||||
<value>Minors cannot be hired (BirthDate = {0})</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageMinorsEmploymentDate" xml:space="preserve">
|
||||
<value>Minors cannot be hired (EmploymentDate: {0}, BirthDate {1})</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNoProductsInSale" xml:space="preserve">
|
||||
<value>There must be at least one product on sale.</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNotAId" xml:space="preserve">
|
||||
<value>The value in the {0} field is not a unique identifier type.</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNotInitialized" xml:space="preserve">
|
||||
<value>The value in field {0} is not initialized</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -117,6 +117,78 @@
|
||||
<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="DocumentDocCaptionData" xml:space="preserve">
|
||||
<value>Дата</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionPreviousNames" xml:space="preserve">
|
||||
<value>Предыдущие названия</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionTour" 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="DocumentExcelCaptionDiscount" 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="DocumentExcelCaptionTour" xml:space="preserve">
|
||||
<value>Товар</value>
|
||||
</data>
|
||||
<data name="DocumentExcelHeader" xml:space="preserve">
|
||||
<value>Продажи за период</value>
|
||||
</data>
|
||||
<data name="DocumentExcelHeaderEmployee" 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>
|
||||
@@ -159,9 +231,6 @@
|
||||
<data name="ValidationExceptionMessageMinorsEmploymentDate" xml:space="preserve">
|
||||
<value>Несовершеннолетние не могут быть приняты на работу (Дата трудоустройства: {0}, Дата рождения: {1})</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNoComponents" xml:space="preserve">
|
||||
<value>Отсутствуют компоненты</value>
|
||||
</data>
|
||||
<data name="ValidationExceptionMessageNoProductsInSale" xml:space="preserve">
|
||||
<value>В продаже должен быть хотя бы один товар</value>
|
||||
</data>
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
<?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="DocumentDocCaptionData" xml:space="preserve">
|
||||
<value>日期</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionPreviousNames" xml:space="preserve">
|
||||
<value>以前的名字</value>
|
||||
</data>
|
||||
<data name="DocumentDocCaptionTour" 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="DocumentExcelCaptionDiscount" 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="DocumentExcelCaptionTour" xml:space="preserve">
|
||||
<value>旅游</value>
|
||||
</data>
|
||||
<data name="DocumentExcelHeader" xml:space="preserve">
|
||||
<value>期间的销售额</value>
|
||||
</data>
|
||||
<data name="DocumentExcelHeaderEmployee" xml:space="preserve">
|
||||
<value>工人</value>
|
||||
</data>
|
||||
<data name="DocumentExcelSubHeader" xml:space="preserve">
|
||||
<value>从{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>无法更改已删除的项目(id:{0})</value>
|
||||
</data>
|
||||
<data name="ElementExistsExceptionMessage" xml:space="preserve">
|
||||
<value>已经有一个具有参数{1}的值{0}的元素</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="StorageExceptionMessage" xml:space="preserve">
|
||||
<value>在存储中工作时出错:{0}</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="ValidationExceptionMessageIncorrectPhoneNumber" xml:space="preserve">
|
||||
<value>电话号码字段中的值不是电话号码</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="ValidationExceptionMessageNoProductsInSale" 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>
|
||||
</root>
|
||||
@@ -4,7 +4,9 @@ using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -113,6 +115,11 @@ internal class EmployeeStorageContract : IEmployeeStorageContract
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", employeeDataModel.Id, _localizer);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "PK_Employees" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", employeeDataModel.Id, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using AutoMapper;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,12 +15,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Implementations;
|
||||
|
||||
public class PostStorageContract : IPostStorageContract
|
||||
internal class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
private readonly MagicCarpetDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public PostStorageContract(MagicCarpetDbContext dbContext)
|
||||
public PostStorageContract(MagicCarpetDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -34,6 +37,7 @@ public class PostStorageContract : IPostStorageContract
|
||||
src.ConfigurationModel));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public List<PostDataModel> GetList()
|
||||
@@ -45,7 +49,7 @@ public class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +62,7 @@ public class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +75,7 @@ public class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +88,7 @@ public class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,17 +102,17 @@ public class PostStorageContract : IPostStorageContract
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Posts_PostName_IsActual" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("PostName", postDataModel.PostName);
|
||||
throw new ElementExistsException("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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,10 +123,10 @@ public class PostStorageContract : IPostStorageContract
|
||||
var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var element = GetPostById(postDataModel.Id) ?? throw new ElementNotFoundException(postDataModel.Id);
|
||||
var element = GetPostById(postDataModel.Id) ?? throw new ElementNotFoundException(postDataModel.Id, _localizer);
|
||||
if (!element.IsActual)
|
||||
{
|
||||
throw new ElementDeletedException(postDataModel.Id);
|
||||
throw new ElementDeletedException(postDataModel.Id, _localizer);
|
||||
}
|
||||
element.IsActual = false;
|
||||
_dbContext.SaveChanges();
|
||||
@@ -140,7 +144,7 @@ public class PostStorageContract : IPostStorageContract
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Posts_PostName_IsActual" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("PostName", postDataModel.PostName);
|
||||
throw new ElementExistsException("PostName", postDataModel.PostName, _localizer);
|
||||
}
|
||||
catch (Exception ex) when (ex is ElementDeletedException || ex is ElementNotFoundException)
|
||||
{
|
||||
@@ -150,7 +154,7 @@ public class PostStorageContract : IPostStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,10 +162,10 @@ public class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetPostById(id) ?? throw new ElementNotFoundException(id);
|
||||
var element = GetPostById(id) ?? throw new ElementNotFoundException(id, _localizer);
|
||||
if (!element.IsActual)
|
||||
{
|
||||
throw new ElementDeletedException(id);
|
||||
throw new ElementDeletedException(id, _localizer);
|
||||
}
|
||||
element.IsActual = false;
|
||||
_dbContext.SaveChanges();
|
||||
@@ -177,7 +181,7 @@ public class PostStorageContract : IPostStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetPostById(id) ?? throw new ElementNotFoundException(id);
|
||||
var element = GetPostById(id) ?? throw new ElementNotFoundException(id, _localizer);
|
||||
element.IsActual = true;
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using AutoMapper;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -12,12 +14,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Implementations;
|
||||
|
||||
public class SalaryStorageContract : ISalaryStorageContract
|
||||
internal class SalaryStorageContract : ISalaryStorageContract
|
||||
{
|
||||
private readonly MagicCarpetDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public SalaryStorageContract(MagicCarpetDbContext dbContext)
|
||||
public SalaryStorageContract(MagicCarpetDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -28,6 +31,7 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
.ForMember(dest => dest.EmployeeSalary, opt => opt.MapFrom(src => src.Salary));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public List<SalaryDataModel> GetList(DateTime? startDate, DateTime? endDate, string? employeeId = null)
|
||||
@@ -46,7 +50,7 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +66,7 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +80,7 @@ public class SalaryStorageContract : ISalaryStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using AutoMapper;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -12,12 +14,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Implementations;
|
||||
|
||||
public class SaleStorageContract : ISaleStorageContract
|
||||
internal class SaleStorageContract : ISaleStorageContract
|
||||
{
|
||||
private readonly MagicCarpetDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public SaleStorageContract(MagicCarpetDbContext dbContext)
|
||||
public SaleStorageContract(MagicCarpetDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -36,6 +39,7 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
.ForMember(x => x.Client, x => x.Ignore());
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public List<SaleDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? employeeId = null, string? clientId = null, string? tourId = null)
|
||||
@@ -64,7 +68,7 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +89,7 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +102,7 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +116,7 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,10 +124,10 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetSaleById(id) ?? throw new ElementNotFoundException(id);
|
||||
var element = GetSaleById(id) ?? throw new ElementNotFoundException(id, _localizer);
|
||||
if (element.IsCancel)
|
||||
{
|
||||
throw new ElementDeletedException(id);
|
||||
throw new ElementDeletedException(id, _localizer);
|
||||
}
|
||||
element.IsCancel = true;
|
||||
_dbContext.SaveChanges();
|
||||
@@ -136,7 +140,7 @@ public class SaleStorageContract : ISaleStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using AutoMapper;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetDatabase.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Npgsql;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -13,12 +15,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Implementations;
|
||||
|
||||
public class TourStorageContract : ITourStorageContract
|
||||
internal class TourStorageContract : ITourStorageContract
|
||||
{
|
||||
private readonly MagicCarpetDbContext _dbContext;
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public TourStorageContract(MagicCarpetDbContext dbContext)
|
||||
public TourStorageContract(MagicCarpetDbContext dbContext, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
@@ -28,6 +31,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
cfg.CreateMap<TourHistory, TourHistoryDataModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public List<TourDataModel> GetList()
|
||||
@@ -39,7 +43,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +56,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +69,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,7 +82,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,7 +95,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,17 +109,17 @@ public class TourStorageContract : ITourStorageContract
|
||||
catch (InvalidOperationException ex) when (ex.TargetSite?.Name == "ThrowIdentityConflict")
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("Id", tourDataModel.Id);
|
||||
throw new ElementExistsException("Id", tourDataModel.Id, _localizer);
|
||||
}
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Tours_TourName" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("TourName", tourDataModel.TourName);
|
||||
throw new ElementExistsException("TourName", tourDataModel.TourName, _localizer);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,7 +130,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
var transaction = _dbContext.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var element = GetTourById(tourDataModel.Id) ?? throw new ElementNotFoundException(tourDataModel.Id);
|
||||
var element = GetTourById(tourDataModel.Id) ?? throw new ElementNotFoundException(tourDataModel.Id, _localizer);
|
||||
if (element.Price != tourDataModel.Price)
|
||||
{
|
||||
_dbContext.TourHistories.Add(new TourHistory() { TourId = element.Id, OldPrice = element.Price });
|
||||
@@ -145,7 +149,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
catch (DbUpdateException ex) when (ex.InnerException is PostgresException { ConstraintName: "IX_Tours_TourName" })
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new ElementExistsException("TourName", tourDataModel.TourName);
|
||||
throw new ElementExistsException("TourName", tourDataModel.TourName, _localizer);
|
||||
}
|
||||
catch (Exception ex) when (ex is ElementDeletedException || ex is ElementNotFoundException)
|
||||
{
|
||||
@@ -155,7 +159,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +167,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetTourById(id) ?? throw new ElementNotFoundException(id);
|
||||
var element = GetTourById(id) ?? throw new ElementNotFoundException(id, _localizer);
|
||||
_dbContext.Tours.Remove(element);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
@@ -175,7 +179,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
catch (Exception ex)
|
||||
{
|
||||
_dbContext.ChangeTracker.Clear();
|
||||
throw new StorageException(ex);
|
||||
throw new StorageException(ex, _localizer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +187,7 @@ public class TourStorageContract : ITourStorageContract
|
||||
{
|
||||
try
|
||||
{
|
||||
var element = GetTourById(id) ?? throw new ElementNotFoundException(id);
|
||||
var element = GetTourById(id) ?? throw new ElementNotFoundException(id, _localizer);
|
||||
_dbContext.SaveChanges();
|
||||
}
|
||||
catch
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MagicCarpetContracts\MagicCarpetContracts.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="MagicCarpetTests" />
|
||||
<InternalsVisibleTo Include="MagicCarpetWebApi" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -12,7 +12,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase;
|
||||
|
||||
public class MagicCarpetDbContext(IConfigurationDatabase configurationDatabase) : DbContext
|
||||
internal class MagicCarpetDbContext(IConfigurationDatabase configurationDatabase) : DbContext
|
||||
{
|
||||
private readonly IConfigurationDatabase? _configurationDatabase = configurationDatabase;
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Threading.Tasks;
|
||||
namespace MagicCarpetDatabase.Models;
|
||||
|
||||
[AutoMap(typeof(ClientDataModel), ReverseMap = true)]
|
||||
public class Client
|
||||
internal class Client
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ using System.Threading.Tasks;
|
||||
namespace MagicCarpetDatabase.Models;
|
||||
|
||||
[AutoMap(typeof(EmployeeDataModel), ReverseMap = true)]
|
||||
public class Employee
|
||||
internal class Employee
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Models;
|
||||
|
||||
public class Post
|
||||
internal class Post
|
||||
{
|
||||
public required string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string PostId { get; set; }
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Models;
|
||||
|
||||
public class Salary
|
||||
internal class Salary
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string EmployeeId { get; set; }
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Models;
|
||||
|
||||
public class Sale
|
||||
internal class Sale
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Models;
|
||||
|
||||
public class SaleTour
|
||||
internal class SaleTour
|
||||
{
|
||||
public required string SaleId { get; set; }
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Models;
|
||||
|
||||
public class Tour
|
||||
internal class Tour
|
||||
{
|
||||
public required string Id { get; set; }
|
||||
public required string TourName { get; set; }
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase.Models;
|
||||
|
||||
public class TourHistory
|
||||
internal class TourHistory
|
||||
{
|
||||
public string Id { get; set; } = Guid.NewGuid().ToString();
|
||||
public required string TourId { get; set; }
|
||||
|
||||
@@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetDatabase;
|
||||
|
||||
public class SampleContextFactory : IDesignTimeDbContextFactory<MagicCarpetDbContext>
|
||||
internal class SampleContextFactory : IDesignTimeDbContextFactory<MagicCarpetDbContext>
|
||||
{
|
||||
public MagicCarpetDbContext CreateDbContext(string[] args)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using MagicCarpetContracts.BuisnessLogicContracts;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
@@ -22,7 +23,7 @@ internal class ClientBusinessLogicContractTests
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_clientStorageContract = new Mock<IClientStorageContract>();
|
||||
_clientBusinessLogicContract = new ClientBusinessLogicContract(_clientStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_clientBusinessLogicContract = new ClientBusinessLogicContract(_clientStorageContract.Object, StringLocalizerMockCreator.GetObject(), new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -62,19 +63,11 @@ internal class ClientBusinessLogicContractTests
|
||||
_clientStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllClients_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.GetAllClients(), Throws.TypeOf<NullListException>());
|
||||
_clientStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllClients_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_clientStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
_clientStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.GetAllClients(), Throws.TypeOf<StorageException>());
|
||||
_clientStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
@@ -170,9 +163,9 @@ internal class ClientBusinessLogicContractTests
|
||||
public void GetClientByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_clientStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_clientStorageContract.Setup(x => x.GetElementByFIO(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_clientStorageContract.Setup(x => x.GetElementByPhoneNumber(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_clientStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_clientStorageContract.Setup(x => x.GetElementByFIO(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_clientStorageContract.Setup(x => x.GetElementByPhoneNumber(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.GetClientByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _clientBusinessLogicContract.GetClientByData("fio"), Throws.TypeOf<StorageException>());
|
||||
@@ -205,7 +198,7 @@ internal class ClientBusinessLogicContractTests
|
||||
public void InsertClient_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_clientStorageContract.Setup(x => x.AddElement(It.IsAny<ClientDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
_clientStorageContract.Setup(x => x.AddElement(It.IsAny<ClientDataModel>())).Throws(new ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.InsertClient(new(Guid.NewGuid().ToString(), "fio", "+7-111-111-11-11", 0)), Throws.TypeOf<ElementExistsException>());
|
||||
_clientStorageContract.Verify(x => x.AddElement(It.IsAny<ClientDataModel>()), Times.Once);
|
||||
@@ -231,7 +224,7 @@ internal class ClientBusinessLogicContractTests
|
||||
public void InsertClient_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_clientStorageContract.Setup(x => x.AddElement(It.IsAny<ClientDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_clientStorageContract.Setup(x => x.AddElement(It.IsAny<ClientDataModel>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.InsertClient(new(Guid.NewGuid().ToString(), "fio", "+7-111-111-11-11", 0)), Throws.TypeOf<StorageException>());
|
||||
_clientStorageContract.Verify(x => x.AddElement(It.IsAny<ClientDataModel>()), Times.Once);
|
||||
@@ -260,7 +253,7 @@ internal class ClientBusinessLogicContractTests
|
||||
public void UpdateClient_RecordWithIncorrectData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_clientStorageContract.Setup(x => x.UpdElement(It.IsAny<ClientDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
_clientStorageContract.Setup(x => x.UpdElement(It.IsAny<ClientDataModel>())).Throws(new ElementNotFoundException("", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.UpdateClient(new(Guid.NewGuid().ToString(), "fio", "+7-111-111-11-11", 0)), Throws.TypeOf<ElementNotFoundException>());
|
||||
_clientStorageContract.Verify(x => x.UpdElement(It.IsAny<ClientDataModel>()), Times.Once);
|
||||
@@ -270,7 +263,7 @@ internal class ClientBusinessLogicContractTests
|
||||
public void UpdateClient_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_clientStorageContract.Setup(x => x.UpdElement(It.IsAny<ClientDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
_clientStorageContract.Setup(x => x.UpdElement(It.IsAny<ClientDataModel>())).Throws(new ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.UpdateClient(new(Guid.NewGuid().ToString(), "fio", "+7-111-111-11-11", 0)), Throws.TypeOf<ElementExistsException>());
|
||||
_clientStorageContract.Verify(x => x.UpdElement(It.IsAny<ClientDataModel>()), Times.Once);
|
||||
@@ -296,7 +289,7 @@ internal class ClientBusinessLogicContractTests
|
||||
public void UpdateClient_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_clientStorageContract.Setup(x => x.UpdElement(It.IsAny<ClientDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_clientStorageContract.Setup(x => x.UpdElement(It.IsAny<ClientDataModel>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.UpdateClient(new(Guid.NewGuid().ToString(), "fio", "+7-111-111-11-11", 0)), Throws.TypeOf<StorageException>());
|
||||
_clientStorageContract.Verify(x => x.UpdElement(It.IsAny<ClientDataModel>()), Times.Once);
|
||||
@@ -320,7 +313,7 @@ internal class ClientBusinessLogicContractTests
|
||||
public void DeleteClient_RecordWithIncorrectId_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_clientStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(""));
|
||||
_clientStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException("", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.DeleteClient(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_clientStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
@@ -347,7 +340,7 @@ internal class ClientBusinessLogicContractTests
|
||||
public void DeleteClient_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_clientStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_clientStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _clientBusinessLogicContract.DeleteClient(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_clientStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
@@ -22,7 +23,7 @@ internal class EmployeeBusinessLogicContractTests
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_employeeStorageContract = new Mock<IEmployeeStorageContract>();
|
||||
_employeeBusinessLogicContract = new EmployeeBusinessLogicContract(_employeeStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_employeeBusinessLogicContract = new EmployeeBusinessLogicContract(_employeeStorageContract.Object, StringLocalizerMockCreator.GetObject(), new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -76,19 +77,11 @@ internal class EmployeeBusinessLogicContractTests
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), null, null, null, null, null), Times.Exactly(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllEmployees_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetAllEmployees(It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllEmployees_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetAllEmployees(It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), null, null, null, null, null), Times.Once);
|
||||
@@ -157,19 +150,11 @@ internal class EmployeeBusinessLogicContractTests
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllEmployeesByPost_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetAllEmployeesByPost(Guid.NewGuid().ToString(), It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllEmployeesByPost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetAllEmployeesByPost(Guid.NewGuid().ToString(), It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
@@ -233,19 +218,11 @@ internal class EmployeeBusinessLogicContractTests
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllEmployeesByBirthDate_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetAllEmployeesByBirthDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllEmployeesByBirthDate_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetAllEmployeesByBirthDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
@@ -309,19 +286,11 @@ internal class EmployeeBusinessLogicContractTests
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllEmployeesByEmploymentDate_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetAllEmployeesByEmploymentDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), It.IsAny<bool>()), Throws.TypeOf<NullListException>());
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllEmployeesByEmploymentDate_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetAllEmployeesByEmploymentDate(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), It.IsAny<bool>()), Throws.TypeOf<StorageException>());
|
||||
_employeeStorageContract.Verify(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()), Times.Once);
|
||||
@@ -413,8 +382,8 @@ internal class EmployeeBusinessLogicContractTests
|
||||
public void GetEmployeeByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.GetElementByFIO(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_employeeStorageContract.Setup(x => x.GetElementByFIO(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetEmployeeByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _employeeBusinessLogicContract.GetEmployeeByData("fio"), Throws.TypeOf<StorageException>());
|
||||
@@ -445,7 +414,7 @@ internal class EmployeeBusinessLogicContractTests
|
||||
public void InsertEmployee_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.AddElement(It.IsAny<EmployeeDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
_employeeStorageContract.Setup(x => x.AddElement(It.IsAny<EmployeeDataModel>())).Throws(new ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.InsertEmployee(new(Guid.NewGuid().ToString(), "fio", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ElementExistsException>());
|
||||
_employeeStorageContract.Verify(x => x.AddElement(It.IsAny<EmployeeDataModel>()), Times.Once);
|
||||
@@ -471,7 +440,7 @@ internal class EmployeeBusinessLogicContractTests
|
||||
public void InsertEmployee_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.AddElement(It.IsAny<EmployeeDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.AddElement(It.IsAny<EmployeeDataModel>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.InsertEmployee(new(Guid.NewGuid().ToString(), "fio", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<StorageException>());
|
||||
_employeeStorageContract.Verify(x => x.AddElement(It.IsAny<EmployeeDataModel>()), Times.Once);
|
||||
@@ -500,7 +469,7 @@ internal class EmployeeBusinessLogicContractTests
|
||||
public void UpdateEmployee_RecordWithIncorrectData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.UpdElement(It.IsAny<EmployeeDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
_employeeStorageContract.Setup(x => x.UpdElement(It.IsAny<EmployeeDataModel>())).Throws(new ElementNotFoundException("", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.UpdateEmployee(new(Guid.NewGuid().ToString(), "fio", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ElementNotFoundException>());
|
||||
_employeeStorageContract.Verify(x => x.UpdElement(It.IsAny<EmployeeDataModel>()), Times.Once);
|
||||
@@ -526,7 +495,7 @@ internal class EmployeeBusinessLogicContractTests
|
||||
public void UpdateEmployee_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.UpdElement(It.IsAny<EmployeeDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.UpdElement(It.IsAny<EmployeeDataModel>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.UpdateEmployee(new(Guid.NewGuid().ToString(), "fio", "123@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<StorageException>());
|
||||
_employeeStorageContract.Verify(x => x.UpdElement(It.IsAny<EmployeeDataModel>()), Times.Once);
|
||||
@@ -551,7 +520,7 @@ internal class EmployeeBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_employeeStorageContract.Setup(x => x.DelElement(It.Is((string x) => x != id))).Throws(new ElementNotFoundException(id));
|
||||
_employeeStorageContract.Setup(x => x.DelElement(It.Is((string x) => x != id))).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.DeleteEmployee(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_employeeStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
@@ -578,7 +547,7 @@ internal class EmployeeBusinessLogicContractTests
|
||||
public void DeleteEmployee_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_employeeStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_employeeStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _employeeBusinessLogicContract.DeleteEmployee(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_employeeStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
|
||||
@@ -4,6 +4,7 @@ using MagicCarpetContracts.Enums;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Infrastructure.PostConfigurations;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
@@ -24,7 +25,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_postStorageContract = new Mock<IPostStorageContract>();
|
||||
_postBusinessLogicContract = new PostBusinessLogicContract(_postStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_postBusinessLogicContract = new PostBusinessLogicContract(_postStorageContract.Object, StringLocalizerMockCreator.GetObject(), new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -70,19 +71,12 @@ internal class PostBusinessLogicContractTests
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(), Throws.TypeOf<NullListException>());
|
||||
_postStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPosts_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllPosts(), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
@@ -137,19 +131,12 @@ internal class PostBusinessLogicContractTests
|
||||
_postStorageContract.Verify(x => x.GetPostWithHistory(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPost_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllDataOfPost(Guid.NewGuid().ToString()), Throws.TypeOf<NullListException>());
|
||||
_postStorageContract.Verify(x => x.GetPostWithHistory(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetPostWithHistory(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.GetPostWithHistory(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetAllDataOfPost(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.GetPostWithHistory(It.IsAny<string>()), Times.Once);
|
||||
@@ -217,8 +204,8 @@ internal class PostBusinessLogicContractTests
|
||||
public void GetPostByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_postStorageContract.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.GetPostByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _postBusinessLogicContract.GetPostByData("name"), Throws.TypeOf<StorageException>());
|
||||
@@ -248,7 +235,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void InsertPost_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
@@ -274,7 +261,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void InsertPost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.AddElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
@@ -302,7 +289,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void UpdatePost_RecordWithIncorrectData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementNotFoundException("", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
@@ -312,7 +299,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void UpdatePost_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<ElementExistsException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
@@ -338,7 +325,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void UpdatePost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 })), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.UpdElement(It.IsAny<PostDataModel>()), Times.Once);
|
||||
@@ -363,7 +350,7 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_postStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
_postStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.DeletePost(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
@@ -390,7 +377,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void DeletePost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.DeletePost(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
@@ -415,7 +402,7 @@ internal class PostBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_postStorageContract.Setup(x => x.ResElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
_postStorageContract.Setup(x => x.ResElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.RestorePost(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_postStorageContract.Verify(x => x.ResElement(It.IsAny<string>()), Times.Once);
|
||||
@@ -442,7 +429,7 @@ internal class PostBusinessLogicContractTests
|
||||
public void RestorePost_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_postStorageContract.Setup(x => x.ResElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_postStorageContract.Setup(x => x.ResElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _postBusinessLogicContract.RestorePost(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_postStorageContract.Verify(x => x.ResElement(It.IsAny<string>()), Times.Once);
|
||||
|
||||
@@ -4,6 +4,7 @@ using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Enums;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
@@ -35,7 +36,7 @@ internal class ReportContractTests
|
||||
_baseExcelBuilder = new Mock<BaseExcelBuilder>();
|
||||
_basePdfBuilder = new Mock<BasePdfBuilder>();
|
||||
_reportContract = new ReportContract(_tourStorageContract.Object, _salaryStorageContract.Object, _saleStorageContract.Object,
|
||||
_baseWordBuilder.Object, _baseExcelBuilder.Object, _basePdfBuilder.Object, new Mock<ILogger>().Object);
|
||||
_baseWordBuilder.Object, _baseExcelBuilder.Object, _basePdfBuilder.Object, new Mock<ILogger>().Object, StringLocalizerMockCreator.GetObject());
|
||||
}
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
@@ -103,7 +104,7 @@ internal class ReportContractTests
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x =>
|
||||
x.GetHistoriesListAsync(It.IsAny<CancellationToken>()))
|
||||
.ThrowsAsync(new StorageException(new InvalidOperationException()));
|
||||
.ThrowsAsync(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
|
||||
//Act & Assert
|
||||
Assert.That(async () => await
|
||||
@@ -165,17 +166,9 @@ internal class ReportContractTests
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
// 1 заголовок + 2 тура (name1 и name2) + 5 записей истории
|
||||
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(""));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -235,7 +228,7 @@ internal class ReportContractTests
|
||||
{
|
||||
//Arrange
|
||||
_saleStorageContract.Setup(x => x.GetListAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
.Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(async () => await _reportContract.GetDataBySalesAsync(DateTime.UtcNow.AddDays(-1), DateTime.UtcNow, CancellationToken.None),
|
||||
Throws.TypeOf<StorageException>());
|
||||
@@ -277,33 +270,7 @@ internal class ReportContractTests
|
||||
Assert.That(firstRow, Is.Not.EqualTo(default));
|
||||
Assert.That(secondRow, Is.Not.EqualTo(default));
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(firstRow[0], Is.EqualTo("Сотрудник"));
|
||||
Assert.That(firstRow[1], Is.EqualTo("Дата"));
|
||||
Assert.That(firstRow[2], Is.EqualTo("Сумма"));
|
||||
Assert.That(firstRow[3], Is.EqualTo("Скидка"));
|
||||
Assert.That(firstRow[4], Is.EqualTo("Товар"));
|
||||
Assert.That(firstRow[5], Is.EqualTo("Кол-во"));
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(secondRow[0], Is.Empty);
|
||||
Assert.That(secondRow[1], Is.Not.Empty);
|
||||
Assert.That(secondRow[2], Is.EqualTo(200.ToString("N2")));
|
||||
Assert.That(secondRow[3], Is.EqualTo(100.ToString("N2")));
|
||||
Assert.That(secondRow[4], Is.Empty);
|
||||
Assert.That(secondRow[5], Is.Empty);
|
||||
});
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(thirdRow[0], Is.Empty);
|
||||
Assert.That(thirdRow[1], Is.Empty);
|
||||
Assert.That(thirdRow[2], Is.Empty);
|
||||
Assert.That(thirdRow[3], Is.Empty);
|
||||
Assert.That(thirdRow[4], Is.EqualTo(Tour1.TourName));
|
||||
Assert.That(thirdRow[5], Is.EqualTo(10.ToString("N2")));
|
||||
});
|
||||
|
||||
_saleStorageContract.Verify(x => x.GetListAsync(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<CancellationToken>()), Times.Once);
|
||||
_baseExcelBuilder.Verify(x => x.AddHeader(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()), Times.Once);
|
||||
_baseExcelBuilder.Verify(x => x.AddParagraph(It.IsAny<string>(), It.IsAny<int>()), Times.Once);
|
||||
@@ -412,7 +379,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(
|
||||
|
||||
@@ -34,7 +34,8 @@ internal class SalaryBusinessLogicContractTests
|
||||
_postStorageContract = new Mock<IPostStorageContract>();
|
||||
_employeeStorageContract = new Mock<IEmployeeStorageContract>();
|
||||
_salaryBusinessLogicContract = new SalaryBusinessLogicContract(_salaryStorageContract.Object,
|
||||
_saleStorageContract.Object, _postStorageContract.Object, _employeeStorageContract.Object, new Mock<ILogger>().Object, _salaryConfigurationTest);
|
||||
_saleStorageContract.Object, _postStorageContract.Object, _employeeStorageContract.Object,
|
||||
StringLocalizerMockCreator.GetObject(), new Mock<ILogger>().Object, _salaryConfigurationTest);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -91,19 +92,12 @@ internal class SalaryBusinessLogicContractTests
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(),StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
@@ -172,19 +166,12 @@ internal class SalaryBusinessLogicContractTests
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalariesByEmployee_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByEmployee(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), Guid.NewGuid().ToString()), Throws.TypeOf<NullListException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalariesByEmployee_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalariesByPeriodByEmployee(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
|
||||
@@ -266,52 +253,13 @@ internal class SalaryBusinessLogicContractTests
|
||||
Assert.That(sum, Is.EqualTo(rate));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_SaleStorageReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 100 }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_PostStorageReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_EmployeeStorageReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 100 }));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CalculateSalaryByMounth_SaleStorageThrowException_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
.Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 100 }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
@@ -328,7 +276,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
||||
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), employeeId, null, DiscountType.None, false, [])]);
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
.Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Returns([new EmployeeDataModel(employeeId, "Test", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
||||
//Act&Assert
|
||||
@@ -345,7 +293,7 @@ internal class SalaryBusinessLogicContractTests
|
||||
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 100 }));
|
||||
_employeeStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
.Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Enums;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
@@ -23,7 +24,7 @@ internal class SaleBusinessLogicContractTests
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_saleStorageContract = new Mock<ISaleStorageContract>();
|
||||
_saleBusinessLogicContract = new SaleBusinessLogicContract(_saleStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_saleBusinessLogicContract = new SaleBusinessLogicContract(_saleStorageContract.Object, StringLocalizerMockCreator.GetObject(), new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -77,19 +78,13 @@ internal class SaleBusinessLogicContractTests
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalesByPeriod_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.GetAllSalesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalesByPeriod_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(),StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.GetAllSalesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
@@ -158,19 +153,13 @@ internal class SaleBusinessLogicContractTests
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalesByEmployeeByPeriod_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.GetAllSalesByEmployeeByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalesByEmployeeByPeriod_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.GetAllSalesByEmployeeByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
@@ -239,19 +228,12 @@ internal class SaleBusinessLogicContractTests
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalesByClientByPeriod_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.GetAllSalesByClientByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalesByClientByPeriod_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.GetAllSalesByClientByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
@@ -320,19 +302,12 @@ internal class SaleBusinessLogicContractTests
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalesByTourByPeriod_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.GetAllSalesByTourByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalesByTourByPeriod_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(),
|
||||
It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.GetAllSalesByTourByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_saleStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
|
||||
@@ -383,7 +358,7 @@ internal class SaleBusinessLogicContractTests
|
||||
public void GetSaleByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_saleStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_saleStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(),StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.GetSaleByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_saleStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
@@ -417,7 +392,7 @@ internal class SaleBusinessLogicContractTests
|
||||
public void InsertSale_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), DiscountType.None, false, [new SaleTourDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])), Throws.TypeOf<ElementExistsException>());
|
||||
@@ -444,7 +419,7 @@ internal class SaleBusinessLogicContractTests
|
||||
public void InsertSale_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), DiscountType.None, false, [new SaleTourDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])), Throws.TypeOf<StorageException>());
|
||||
@@ -470,7 +445,7 @@ internal class SaleBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_saleStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
_saleStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.CancelSale(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_saleStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
@@ -497,7 +472,7 @@ internal class SaleBusinessLogicContractTests
|
||||
public void CancelSale_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_saleStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_saleStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.CancelSale(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_saleStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
|
||||
@@ -3,6 +3,7 @@ using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Enums;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using System;
|
||||
@@ -23,7 +24,7 @@ internal class TourBusinessLogicContractTests
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_tourStorageContract = new Mock<ITourStorageContract>();
|
||||
_tourBusinessLogicContract = new TourBusinessLogicContract(_tourStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_tourBusinessLogicContract = new TourBusinessLogicContract(_tourStorageContract.Object, StringLocalizerMockCreator.GetObject(), new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
@@ -63,19 +64,12 @@ internal class TourBusinessLogicContractTests
|
||||
_tourStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllTours_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.GetAllTours(), Throws.TypeOf<NullListException>());
|
||||
_tourStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllTours_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
_tourStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.GetAllTours(), Throws.TypeOf<StorageException>());
|
||||
_tourStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
@@ -131,19 +125,11 @@ internal class TourBusinessLogicContractTests
|
||||
_tourStorageContract.Verify(x => x.GetHistoryByTourId(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetTourHistoryByTour_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.GetTourHistoryByTour(Guid.NewGuid().ToString()), Throws.TypeOf<NullListException>());
|
||||
_tourStorageContract.Verify(x => x.GetHistoryByTourId(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetTourHistoryByTour_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x => x.GetHistoryByTourId(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_tourStorageContract.Setup(x => x.GetHistoryByTourId(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.GetTourHistoryByTour(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_tourStorageContract.Verify(x => x.GetHistoryByTourId(It.IsAny<string>()), Times.Once);
|
||||
@@ -230,8 +216,8 @@ internal class TourBusinessLogicContractTests
|
||||
public void GetTourByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_tourStorageContract.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_tourStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
_tourStorageContract.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.GetTourByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _tourBusinessLogicContract.GetTourByData("name"), Throws.TypeOf<StorageException>());
|
||||
@@ -262,7 +248,7 @@ internal class TourBusinessLogicContractTests
|
||||
public void InsertTour_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x => x.AddElement(It.IsAny<TourDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
_tourStorageContract.Setup(x => x.AddElement(It.IsAny<TourDataModel>())).Throws(new ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.InsertTour(new(Guid.NewGuid().ToString(), "name","country",10, TourType.Ski)), Throws.TypeOf<ElementExistsException>());
|
||||
_tourStorageContract.Verify(x => x.AddElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||
@@ -288,7 +274,7 @@ internal class TourBusinessLogicContractTests
|
||||
public void InsertTour_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x => x.AddElement(It.IsAny<TourDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_tourStorageContract.Setup(x => x.AddElement(It.IsAny<TourDataModel>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.InsertTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski)), Throws.TypeOf<StorageException>());
|
||||
_tourStorageContract.Verify(x => x.AddElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||
@@ -317,7 +303,7 @@ internal class TourBusinessLogicContractTests
|
||||
public void UpdateTour_RecordWithIncorrectData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new ElementNotFoundException("", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski)), Throws.TypeOf<ElementNotFoundException>());
|
||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||
@@ -327,7 +313,7 @@ internal class TourBusinessLogicContractTests
|
||||
public void UpdateTour_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new ElementExistsException("Data", "Data", StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski)), Throws.TypeOf<ElementExistsException>());
|
||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||
@@ -353,7 +339,7 @@ internal class TourBusinessLogicContractTests
|
||||
public void UpdateTour_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski)), Throws.TypeOf<StorageException>());
|
||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||
@@ -378,7 +364,7 @@ internal class TourBusinessLogicContractTests
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_tourStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
_tourStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id, StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.DeleteTour(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_tourStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
@@ -405,7 +391,7 @@ internal class TourBusinessLogicContractTests
|
||||
public void DeleteTour_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_tourStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_tourStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException(), StringLocalizerMockCreator.GetObject()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _tourBusinessLogicContract.DeleteTour(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_tourStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -14,41 +15,41 @@ internal class ClientDataModelTests
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var client = CreateDataModel(null, "fio", "number", 10);
|
||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => client.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
client = CreateDataModel(string.Empty, "fio", "number", 10);
|
||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => client.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var client = CreateDataModel("id", "fio", "number", 10);
|
||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => client.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var client = CreateDataModel(Guid.NewGuid().ToString(), null, "number", 10);
|
||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => client.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number", 10);
|
||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => client.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsNullOrEmptyTest()
|
||||
{
|
||||
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, 10);
|
||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => client.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, 10);
|
||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => client.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsIncorrectTest()
|
||||
{
|
||||
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777", 10);
|
||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => client.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -59,7 +60,7 @@ internal class ClientDataModelTests
|
||||
var phoneNumber = "+7-777-777-77-77";
|
||||
var discountSize = 11;
|
||||
var buyer = CreateDataModel(clientId, fio, phoneNumber, discountSize);
|
||||
Assert.That(() => buyer.Validate(), Throws.Nothing);
|
||||
Assert.That(() => buyer.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(buyer.Id, Is.EqualTo(clientId));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,73 +16,73 @@ internal class EmployeeDataModelTests
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(null, "fio", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(string.Empty, "fio", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var employee = CreateDataModel("id", "fio", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), null, "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmailIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmailIsIncorrectTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "abc@gmail", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "abc@gmail.com", null, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "abc@gmail.com", string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "abc@gmail.com", "postId", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateIsNotCorrectTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "abc@gmail.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -95,7 +96,7 @@ internal class EmployeeDataModelTests
|
||||
var employmentDate = DateTime.Now;
|
||||
var isDelete = false;
|
||||
var employee = CreateDataModel(employeeId, fio, employeeEmail, postId, birthDate, employmentDate, isDelete);
|
||||
Assert.That(() => employee.Validate(), Throws.Nothing);
|
||||
Assert.That(() => employee.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(employee.Id, Is.EqualTo(employeeId));
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
using MagicCarpetContracts.Enums;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Infrastructure.PostConfigurations;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
|
||||
namespace MagicCarpetTests.DataModelTests;
|
||||
[TestFixture]
|
||||
@@ -16,48 +12,48 @@ internal class PostDataModelTests
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", "name", PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject() ), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.TravelAgent, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => manufacturer.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.None, new PostConfiguration() { Rate = 10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ConfigurationModelIsNullTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, null);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RateIsLessOrZeroTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = 0 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), "name", PostType.TravelAgent, new PostConfiguration() { Rate = -10 });
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => post.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -68,7 +64,7 @@ internal class PostDataModelTests
|
||||
var postType = PostType.Manager;
|
||||
var configuration = new PostConfiguration() { Rate = 10 };
|
||||
var post = CreateDataModel(postId, postName, postType, configuration);
|
||||
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 MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,25 +16,25 @@ internal class SalaryDataModelTests
|
||||
public void EmployeeIdIsEmptyTest()
|
||||
{
|
||||
var salary = CreateDataModel(null, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmployeeIdIsNotGuidTest()
|
||||
{
|
||||
var salary = CreateDataModel("employeeId", DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SalaryIsLessOrZeroTest()
|
||||
{
|
||||
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -43,7 +44,7 @@ internal class SalaryDataModelTests
|
||||
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||
var enployeeSalary = 10;
|
||||
var salary = CreateDataModel(employeeId, salaryDate, enployeeSalary);
|
||||
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||
Assert.That(() => salary.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(salary.EmployeeId, Is.EqualTo(employeeId));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Enums;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -16,47 +17,47 @@ internal class SaleDataModelTests
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void EmployeeIdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmployeeIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(), DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ClientIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "clientId", DiscountType.OnSale, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ToursIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, null);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DiscountType.OnSale, false, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -114,7 +115,7 @@ internal class SaleDataModelTests
|
||||
var isCancel = true;
|
||||
var tours = CreateSubDataModel();
|
||||
var sale = CreateDataModel(saleId, employeeId, clientId, discountType, isCancel, tours);
|
||||
Assert.That(() => sale.Validate(), Throws.Nothing);
|
||||
Assert.That(() => sale.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(sale.Id, Is.EqualTo(saleId));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,50 +16,50 @@ internal class SaleTourDataModelTests
|
||||
public void SaleIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleTour = CreateDataModel(null, Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
saleTour = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SaleIdIsNotGuidTest()
|
||||
{
|
||||
var saleTour = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TourIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleTour = CreateDataModel(Guid.NewGuid().ToString(), null, 10, 1.1);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
saleTour = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, 1.1);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TourIdIsNotGuidTest()
|
||||
{
|
||||
var saleTour = CreateDataModel(Guid.NewGuid().ToString(), "tourId", 10, 1.1);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var saleTour = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, 1.1);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
saleTour = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, 1.1);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var saleTour = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, 0);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
saleTour = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1, -10);
|
||||
Assert.That(() => saleTour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -69,7 +70,7 @@ internal class SaleTourDataModelTests
|
||||
var count = 10;
|
||||
var price = 1.2;
|
||||
var saleTour = CreateDataModel(saleId, tourId, count, price);
|
||||
Assert.That(() => saleTour.Validate(), Throws.Nothing);
|
||||
Assert.That(() => saleTour.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleTour.SaleId, Is.EqualTo(saleId));
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Enums;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,48 +16,48 @@ internal class TourDataModelTests
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var cocktail = CreateDataModel(null, "name", "country", 10.5, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
cocktail = CreateDataModel(string.Empty, "name", "country", 10.5, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var cocktail = CreateDataModel("id", "name", "country", 10.5, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TourNameIsNullOrEmptyTest()
|
||||
{
|
||||
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, "country", 10.5, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "country", 10.5, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
public void TourCountryIsNullOrEmptyTest()
|
||||
{
|
||||
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", null, 10.5, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", string.Empty, 10.5, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, string.Empty, -10.5, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TourTypeIsNoneTest()
|
||||
{
|
||||
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, TourType.Beach);
|
||||
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => cocktail.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -68,7 +69,7 @@ internal class TourDataModelTests
|
||||
var price = 10.5;
|
||||
var tourType = TourType.Ski;
|
||||
var tour = CreateDataModel(tourId, tourName, tourCountry, price, tourType);
|
||||
Assert.That(() => tour.Validate(), Throws.Nothing);
|
||||
Assert.That(() => tour.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(tour.Id, Is.EqualTo(tourId));
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -15,25 +16,25 @@ internal class TourHistoryDataModelTests
|
||||
public void CocktailIdIsNullOrEmptyTest()
|
||||
{
|
||||
var tour = CreateDataModel(null, 10);
|
||||
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => tour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
tour = CreateDataModel(string.Empty, 10);
|
||||
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => tour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var tour = CreateDataModel("id", 10);
|
||||
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => tour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OldPriceIsLessOrZeroTest()
|
||||
{
|
||||
var tour = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => tour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
tour = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Assert.That(() => tour.Validate(StringLocalizerMockCreator.GetObject()), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -42,7 +43,7 @@ internal class TourHistoryDataModelTests
|
||||
var tourId = Guid.NewGuid().ToString();
|
||||
var oldPrice = 10;
|
||||
var tourHistory = CreateDataModel(tourId, oldPrice);
|
||||
Assert.That(() => tourHistory.Validate(), Throws.Nothing);
|
||||
Assert.That(() => tourHistory.Validate(StringLocalizerMockCreator.GetObject()), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(tourHistory.TourId, Is.EqualTo(tourId));
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
using MagicCarpetContracts.Resources;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Moq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetTests.Infrastructure;
|
||||
|
||||
internal 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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,452 @@
|
||||
using MagicCarpetContracts.BindingModels;
|
||||
using MagicCarpetContracts.Enums;
|
||||
using MagicCarpetContracts.Infrastructure.PostConfigurations;
|
||||
using MagicCarpetDatabase;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using Microsoft.AspNetCore.Mvc.Testing;
|
||||
using Microsoft.AspNetCore.TestHost;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MagicCarpetTests.LocalizationTests;
|
||||
|
||||
internal abstract class BaseLocalizationControllerTests
|
||||
{
|
||||
protected abstract string GetLocale();
|
||||
|
||||
private WebApplicationFactory<Program> _webApplication;
|
||||
|
||||
protected HttpClient HttpClient { get; private set; }
|
||||
|
||||
protected static MagicCarpetDbContext MagicCarpetDbContext { get; private set; }
|
||||
|
||||
protected static readonly JsonSerializerOptions JsonSerializerOptions = new() { PropertyNameCaseInsensitive = true };
|
||||
|
||||
private static string _employeeId;
|
||||
private static string _postId;
|
||||
private static string _tourId;
|
||||
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_webApplication = new CustomWebApplicationFactory<Program>();
|
||||
HttpClient = _webApplication
|
||||
.WithWebHostBuilder(builder =>
|
||||
{
|
||||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
using var loggerFactory = new LoggerFactory();
|
||||
loggerFactory.AddSerilog(new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build())
|
||||
.CreateLogger());
|
||||
services.AddSingleton(loggerFactory);
|
||||
});
|
||||
})
|
||||
.CreateClient();
|
||||
|
||||
var request = HttpClient.GetAsync("/login/user").GetAwaiter().GetResult();
|
||||
var data = request.Content.ReadAsStringAsync().GetAwaiter().GetResult();
|
||||
HttpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {data}");
|
||||
HttpClient.DefaultRequestHeaders.Add("Accept-Language", GetLocale());
|
||||
|
||||
MagicCarpetDbContext = _webApplication.Services.GetRequiredService<MagicCarpetDbContext>();
|
||||
MagicCarpetDbContext.Database.EnsureDeleted();
|
||||
MagicCarpetDbContext.Database.EnsureCreated();
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_employeeId = MagicCarpetDbContext.InsertEmployeeToDatabaseAndReturn(fio: "Employee").Id;
|
||||
_postId = MagicCarpetDbContext.InsertPostToDatabaseAndReturn(postName: "Post").PostId;
|
||||
_tourId = MagicCarpetDbContext.InsertTourToDatabaseAndReturn().Id;
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
MagicCarpetDbContext.RemoveSalariesFromDatabase();
|
||||
MagicCarpetDbContext.RemoveEmployeesFromDatabase();
|
||||
MagicCarpetDbContext.RemovePostsFromDatabase();
|
||||
MagicCarpetDbContext.RemoveToursFromDatabase();
|
||||
MagicCarpetDbContext.RemoveSalesFromDatabase();
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void OneTimeTearDown()
|
||||
{
|
||||
MagicCarpetDbContext?.Database.EnsureDeleted();
|
||||
MagicCarpetDbContext?.Dispose();
|
||||
HttpClient?.Dispose();
|
||||
_webApplication?.Dispose();
|
||||
}
|
||||
|
||||
protected static async Task<T?> GetModelFromResponseAsync<T>(HttpResponseMessage response) =>
|
||||
JsonSerializer.Deserialize<T>(await response.Content.ReadAsStringAsync(), JsonSerializerOptions);
|
||||
|
||||
protected static StringContent MakeContent(object model) =>
|
||||
new(JsonSerializer.Serialize(model), Encoding.UTF8, "application/json");
|
||||
|
||||
[Test]
|
||||
public async Task LoadToursHistory_ReturnsFile()
|
||||
{
|
||||
//Arrange
|
||||
MagicCarpetDbContext.InsertTourToDatabaseAndReturn(tourName: "Tour1");
|
||||
MagicCarpetDbContext.InsertTourToDatabaseAndReturn(tourName: "Tour2");
|
||||
MagicCarpetDbContext.InsertTourToDatabaseAndReturn(tourName: "Tour3");
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync("/api/report/LoadHistories");
|
||||
//Assert
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
using var data = await response.Content.ReadAsStreamAsync();
|
||||
Assert.That(data, Is.Not.Null);
|
||||
Assert.That(data.Length, Is.GreaterThan(0));
|
||||
await AssertStreamAsync(response, $"file-{GetLocale()}.docx");
|
||||
}
|
||||
[Test]
|
||||
public async Task LoadSales_WhenHaveRecords_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
var employee = MagicCarpetDbContext.InsertEmployeeToDatabaseAndReturn();
|
||||
var tour1 = MagicCarpetDbContext.InsertTourToDatabaseAndReturn(tourName: "name 1");
|
||||
var tour2 = MagicCarpetDbContext.InsertTourToDatabaseAndReturn(tourName: "name 2");
|
||||
MagicCarpetDbContext.InsertSaleToDatabaseAndReturn(employee.Id, tours: [(tour1.Id, 10, 1.1), (tour2.Id, 10, 1.1)]);
|
||||
MagicCarpetDbContext.InsertSaleToDatabaseAndReturn(employee.Id, tours: [(tour1.Id, 10, 1.1)]);
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/report/loadsales?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-{GetLocale()}.xlsx");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task LoadSalary_WhenHaveRecords_ShouldSuccess_Test()
|
||||
{
|
||||
//Arrange
|
||||
var post = MagicCarpetDbContext.InsertPostToDatabaseAndReturn();
|
||||
var employee1 = MagicCarpetDbContext.InsertEmployeeToDatabaseAndReturn(fio: "Иванов И.И", postId: post.PostId).AddPost(post);
|
||||
var employee2 = MagicCarpetDbContext.InsertEmployeeToDatabaseAndReturn(fio: "Ванов И.И", postId: post.PostId).AddPost(post);
|
||||
MagicCarpetDbContext.InsertSalaryToDatabaseAndReturn(employee1.Id, employeeSalary: 100, salaryDate: DateTime.UtcNow.AddDays(-10));
|
||||
MagicCarpetDbContext.InsertSalaryToDatabaseAndReturn(employee1.Id, employeeSalary: 1000, salaryDate: DateTime.UtcNow.AddDays(-5));
|
||||
MagicCarpetDbContext.InsertSalaryToDatabaseAndReturn(employee1.Id, employeeSalary: 200, salaryDate: DateTime.UtcNow.AddDays(5));
|
||||
MagicCarpetDbContext.InsertSalaryToDatabaseAndReturn(employee2.Id, employeeSalary: 500, salaryDate: DateTime.UtcNow.AddDays(-5));
|
||||
MagicCarpetDbContext.InsertSalaryToDatabaseAndReturn(employee2.Id, employeeSalary: 300, salaryDate: DateTime.UtcNow.AddDays(-3));
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/report/loadsalary?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-{GetLocale()}.pdf");
|
||||
}
|
||||
|
||||
private static async Task AssertStreamAsync(HttpResponseMessage response, string fileNameForSave = "")
|
||||
{
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
using var data = await response.Content.ReadAsStreamAsync();
|
||||
Assert.That(data, Is.Not.Null);
|
||||
Assert.That(data.Length, Is.GreaterThan(0));
|
||||
await SaveStreamAsync(data, fileNameForSave);
|
||||
}
|
||||
|
||||
private static async Task SaveStreamAsync(Stream stream, string fileName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var path = Path.Combine(Directory.GetCurrentDirectory(), fileName);
|
||||
if (File.Exists(path))
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
stream.Position = 0;
|
||||
using var fileStream = new FileStream(path, FileMode.OpenOrCreate);
|
||||
await stream.CopyToAsync(fileStream);
|
||||
}
|
||||
|
||||
protected abstract string MessageElementNotFound();
|
||||
|
||||
[TestCase("posts")]
|
||||
[TestCase("employees/getrecord")]
|
||||
public async Task Api_GetElement_NotFound_Test(string path)
|
||||
{
|
||||
//Act
|
||||
var response = await HttpClient.GetAsync($"/api/{path}/{Guid.NewGuid()}");
|
||||
//Assert
|
||||
Assert.That(JToken.Parse(await response.Content.ReadAsStringAsync()).ToString(), Does.StartWith(MessageElementNotFound()));
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> TestDataElementExists()
|
||||
{
|
||||
yield return new TestCaseData(() => {
|
||||
var model = CreatePostModel();
|
||||
MagicCarpetDbContext.InsertPostToDatabaseAndReturn(model.Id);
|
||||
return model;
|
||||
}, "posts");
|
||||
yield return new TestCaseData(() =>
|
||||
{
|
||||
var model = CreateEmployeeModel(_postId);
|
||||
MagicCarpetDbContext.InsertEmployeeToDatabaseAndReturn(model.Id, postId: _postId);
|
||||
return model;
|
||||
}, "employees/register");
|
||||
}
|
||||
|
||||
protected abstract string MessageElementExists();
|
||||
|
||||
[TestCaseSource(nameof(TestDataElementExists))]
|
||||
public async Task Api_Post_WhenHaveRecordWithSameId_ShouldBadRequest_Test(Func<object> createModel, string path)
|
||||
{
|
||||
//Arrange
|
||||
var model = createModel();
|
||||
//Act
|
||||
var response = await HttpClient.PostAsync($"/api/{path}", MakeContent(model));
|
||||
//Assert
|
||||
Assert.That(JToken.Parse(await response.Content.ReadAsStringAsync()).ToString(), Does.StartWith(MessageElementExists()));
|
||||
}
|
||||
|
||||
private static IEnumerable<TestCaseData> TestDataIdIncorrect()
|
||||
{
|
||||
yield return new TestCaseData(() => {
|
||||
var model = CreateSaleModel();
|
||||
model.Id = "Id";
|
||||
return model;
|
||||
}, "sales/sale");
|
||||
yield return new TestCaseData(() => {
|
||||
var model = CreateTourModel();
|
||||
model.Id = "Id";
|
||||
return model;
|
||||
}, "tours/register");
|
||||
yield return new TestCaseData(() => {
|
||||
var model = CreateEmployeeModel(_postId);
|
||||
model.Id = "Id";
|
||||
return model;
|
||||
}, "employees/register");
|
||||
yield return new TestCaseData(() => {
|
||||
var model = CreateClientModel();
|
||||
model.Id = "Id";
|
||||
return model;
|
||||
}, "clients");
|
||||
}
|
||||
|
||||
protected abstract string MessageElementIdIncorrect();
|
||||
|
||||
[TestCaseSource(nameof(TestDataIdIncorrect))]
|
||||
public async Task Api_Post_WhenDataIsIncorrect_ShouldBadRequest_Test(Func<object> createModel, string path)
|
||||
{
|
||||
//Arrange
|
||||
var model = createModel();
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PostAsync($"/api/{path}", MakeContent(model));
|
||||
//Assert
|
||||
Assert.That(JToken.Parse(await responseWithIdIncorrect.Content.ReadAsStringAsync()).ToString(), Does.StartWith(MessageElementIdIncorrect()));
|
||||
}
|
||||
|
||||
[TestCase("tours/delete")]
|
||||
[TestCase("sales/cancel")]
|
||||
[TestCase("posts")]
|
||||
[TestCase("employees/delete")]
|
||||
[TestCase("clients")]
|
||||
public async Task Api_DelElement_NotFound_Test(string path)
|
||||
{
|
||||
//Act
|
||||
var response = await HttpClient.DeleteAsync($"/api/{path}/{Guid.NewGuid()}");
|
||||
//Assert
|
||||
Assert.That(JToken.Parse(await response.Content.ReadAsStringAsync()).ToString(), Does.StartWith(MessageElementNotFound()));
|
||||
}
|
||||
|
||||
private static PostBindingModel CreatePostModel(string? postId = null, string postName = "name", PostType postType = PostType.Manager, string? configuration = null)
|
||||
=> new()
|
||||
{
|
||||
Id = postId ?? Guid.NewGuid().ToString(),
|
||||
PostName = postName,
|
||||
PostType = postType.ToString(),
|
||||
ConfigurationJson = configuration ?? JsonSerializer.Serialize(new PostConfiguration() { Rate = 10 })
|
||||
};
|
||||
|
||||
protected abstract string MessageValidationErrorIDIsEmpty();
|
||||
|
||||
private static IEnumerable<TestCaseData> TestDataValidationErrorIdIsEmpty()
|
||||
{
|
||||
yield return new TestCaseData(() =>
|
||||
{
|
||||
var model = CreatePostModel();
|
||||
model.Id = "";
|
||||
return model;
|
||||
}, "posts");
|
||||
yield return new TestCaseData(() =>
|
||||
{
|
||||
var model = CreateTourModel();
|
||||
model.Id = "";
|
||||
return model;
|
||||
}, "tours/changeinfo");
|
||||
yield return new TestCaseData(() => {
|
||||
var model = CreateEmployeeModel(_postId);
|
||||
model.Id = "";
|
||||
return model;
|
||||
}, "employees/changeinfo/");
|
||||
yield return new TestCaseData(() =>
|
||||
{
|
||||
var model = CreateClientModel();
|
||||
model.Id = "";
|
||||
return model;
|
||||
}, "clients");
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(TestDataValidationErrorIdIsEmpty))]
|
||||
public async Task Api_Put_ValidationError_IdIsEmpty_ShouldBadRequest_Test(Func<object> createModel, string path)
|
||||
{
|
||||
//Arrange
|
||||
var model = createModel();
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PutAsync($"/api/{path}", MakeContent(model));
|
||||
//Assert
|
||||
Assert.That(JToken.Parse(await responseWithIdIncorrect.Content.ReadAsStringAsync()).ToString(), Does.StartWith(MessageValidationErrorIDIsEmpty()));
|
||||
}
|
||||
|
||||
protected abstract string MessageValidationErrorIDIsNotGuid();
|
||||
|
||||
private static IEnumerable<TestCaseData> TestDataValidationErrorIdIsNotGuid()
|
||||
{
|
||||
yield return new TestCaseData(() =>
|
||||
{
|
||||
var model = CreatePostModel();
|
||||
model.Id = "id";
|
||||
return model;
|
||||
}, "posts");
|
||||
yield return new TestCaseData(() =>
|
||||
{
|
||||
var model = CreateTourModel();
|
||||
model.Id = "id";
|
||||
return model;
|
||||
}, "tours/changeinfo");
|
||||
yield return new TestCaseData(() => {
|
||||
var model = CreateEmployeeModel(_postId);
|
||||
model.Id = "id";
|
||||
return model;
|
||||
}, "employees/changeinfo/");
|
||||
yield return new TestCaseData(() =>
|
||||
{
|
||||
var model = CreateClientModel();
|
||||
model.Id = "id";
|
||||
return model;
|
||||
}, "clients");
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(TestDataValidationErrorIdIsNotGuid))]
|
||||
public async Task Api_Put_ValidationError_IIsNotGuid_ShouldBadRequest_Test(Func<object> createModel, string path)
|
||||
{
|
||||
//Arrange
|
||||
var model = createModel();
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PutAsync($"/api/{path}", MakeContent(model));
|
||||
//Assert
|
||||
Assert.That(JToken.Parse(await responseWithIdIncorrect.Content.ReadAsStringAsync()).ToString(), Does.StartWith(MessageValidationErrorIDIsNotGuid()));
|
||||
}
|
||||
|
||||
protected abstract string MessageValidationStringIsEmpty();
|
||||
|
||||
private static IEnumerable<TestCaseData> TestDataValidationErrorStringIsEmpty()
|
||||
{
|
||||
yield return new TestCaseData(() =>
|
||||
{
|
||||
var model = CreateTourModel();
|
||||
model.TourName = "";
|
||||
return model;
|
||||
}, "tours/changeinfo");
|
||||
}
|
||||
|
||||
[TestCaseSource(nameof(TestDataValidationErrorStringIsEmpty))]
|
||||
public async Task Api_Put_ValidationError_StringIsEmpty_ShouldBadRequest_Test(Func<object> createModel, string path)
|
||||
{
|
||||
//Arrange
|
||||
var model = createModel();
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PutAsync($"/api/{path}", MakeContent(model));
|
||||
//Assert
|
||||
Assert.That(JToken.Parse(await responseWithIdIncorrect.Content.ReadAsStringAsync()).ToString(), Does.StartWith(MessageValidationStringIsEmpty()));
|
||||
}
|
||||
|
||||
protected abstract string MessageElemenValidationErrorPostNameEmpty();
|
||||
|
||||
[TestCase("posts")]
|
||||
public async Task Api_Put_ValidationError_PostNameIsEmpty_ShouldBadRequest_Test(string path)
|
||||
{
|
||||
//Arrange
|
||||
var model = CreatePostModel();
|
||||
model.PostName = "";
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PutAsync($"/api/{path}", MakeContent(model));
|
||||
//Assert
|
||||
Assert.That(JToken.Parse(await responseWithIdIncorrect.Content.ReadAsStringAsync()).ToString(), Does.StartWith(MessageElemenValidationErrorPostNameEmpty()));
|
||||
}
|
||||
|
||||
protected abstract string MessageElemenValidationErrorFioISEmpty();
|
||||
|
||||
[TestCase("employees/changeinfo/")]
|
||||
public async Task Api_Put_ValidationError_FioIsEmpty_ShouldBadRequest_Test(string path)
|
||||
{
|
||||
//Arrange
|
||||
var model = CreateEmployeeModel(_postId);
|
||||
model.FIO = "";
|
||||
//Act
|
||||
var responseWithIdIncorrect = await HttpClient.PutAsync($"/api/{path}", MakeContent(model));
|
||||
//Assert
|
||||
Assert.That(JToken.Parse(await responseWithIdIncorrect.Content.ReadAsStringAsync()).ToString(), Does.StartWith(MessageElemenValidationErrorFioISEmpty()));
|
||||
}
|
||||
|
||||
private static EmployeeBindingModel CreateEmployeeModel(string postId, string? id = null, string fio = "fio", string email = "abc@gmail.com", DateTime? birthDate = null, DateTime? employmentDate = null)
|
||||
{
|
||||
return new()
|
||||
{
|
||||
Id = id ?? Guid.NewGuid().ToString(),
|
||||
FIO = fio,
|
||||
Email = email,
|
||||
BirthDate = birthDate ?? DateTime.UtcNow.AddYears(-22),
|
||||
EmploymentDate = employmentDate ?? DateTime.UtcNow.AddDays(-5),
|
||||
PostId = postId
|
||||
};
|
||||
}
|
||||
|
||||
private static TourBindingModel CreateTourModel(string? id = null, string name = "name", string country = "country", TourType type = TourType.Beach, double price = 1)
|
||||
=> new()
|
||||
{
|
||||
Id = id ?? Guid.NewGuid().ToString(),
|
||||
TourName = name,
|
||||
TourCountry = country,
|
||||
TourType = type.ToString(),
|
||||
Price = price
|
||||
};
|
||||
|
||||
private static SaleBindingModel CreateSaleModel(string? employeeId = null, string? clientId = null, string? tourId = null, string? id = null, DiscountType discountType = DiscountType.OnSale, int count = 1, double price = 1.1)
|
||||
{
|
||||
var saleId = id ?? Guid.NewGuid().ToString();
|
||||
return new()
|
||||
{
|
||||
Id = saleId,
|
||||
EmployeeId = employeeId,
|
||||
ClientId = clientId,
|
||||
DiscountType = (int)discountType,
|
||||
Tours = [new SaleTourBindingModel { SaleId = saleId, TourId = tourId, Count = count, Price = price }]
|
||||
};
|
||||
}
|
||||
|
||||
private static ClientBindingModel CreateClientModel(string? id = null, string fio = "fio", string phoneNumber = "+7-666-666-66-66", double discountSize = 10) =>
|
||||
new()
|
||||
{
|
||||
Id = id ?? Guid.NewGuid().ToString(),
|
||||
FIO = fio,
|
||||
PhoneNumber = phoneNumber,
|
||||
DiscountSize = discountSize
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace MagicCarpetTests.LocalizationTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class DefaultTests : BaseLocalizationControllerTests
|
||||
{
|
||||
protected override string GetLocale() => "bla-BLA";
|
||||
protected override string MessageElementExists() => "Уже существует элемент со значением";
|
||||
protected override string MessageElementNotFound() => "Не найден элемент по данным";
|
||||
protected override string MessageElementIdIncorrect() => "Переданы неверные данные";
|
||||
protected override string MessageValidationErrorIDIsEmpty() => "Переданы неверные данные: Значение в поле Id пусто";
|
||||
protected override string MessageValidationErrorIDIsNotGuid() => "Переданы неверные данные: Значение в поле Id не является типом уникального идентификатора";
|
||||
protected override string MessageValidationStringIsEmpty() => "Переданы неверные данные: Значение в поле TourName пусто";
|
||||
protected override string MessageElemenValidationErrorPostNameEmpty() => "Переданы неверные данные: Значение в поле PostName пусто";
|
||||
protected override string MessageElemenValidationErrorFioISEmpty() => "Переданы неверные данные: Значение в поле FIO пусто";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace MagicCarpetTests.LocalizationTests;
|
||||
|
||||
internal class EnUSTests : BaseLocalizationControllerTests
|
||||
{
|
||||
protected override string GetLocale() => "en-US";
|
||||
protected override string MessageElementExists() => "There is already an element with value";
|
||||
protected override string MessageElementNotFound() => "Not found element by data";
|
||||
protected override string MessageElementIdIncorrect() => "Incorrect data transmitted";
|
||||
protected override string MessageValidationErrorIDIsEmpty() => "Incorrect data transmitted: The value in field Id is empty";
|
||||
protected override string MessageValidationErrorIDIsNotGuid() => "Incorrect data transmitted: The value in the Id field is not a unique identifier type.";
|
||||
protected override string MessageValidationStringIsEmpty() => "Incorrect data transmitted: The value in field TourName is empty";
|
||||
protected override string MessageElemenValidationErrorPostNameEmpty() => "Incorrect data transmitted: The value in field PostName is empty";
|
||||
protected override string MessageElemenValidationErrorFioISEmpty() => "Incorrect data transmitted: The value in field FIO is empty";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace MagicCarpetTests.LocalizationTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class RuRUTests : BaseLocalizationControllerTests
|
||||
{
|
||||
protected override string GetLocale() => "ru-RU";
|
||||
protected override string MessageElementExists() => "Уже существует элемент со значением";
|
||||
protected override string MessageElementNotFound() => "Не найден элемент по данным";
|
||||
protected override string MessageElementIdIncorrect() => "Переданы неверные данные";
|
||||
protected override string MessageValidationErrorIDIsEmpty() => "Переданы неверные данные: Значение в поле Id пусто";
|
||||
protected override string MessageValidationErrorIDIsNotGuid() => "Переданы неверные данные: Значение в поле Id не является типом уникального идентификатора";
|
||||
protected override string MessageValidationStringIsEmpty() => "Переданы неверные данные: Значение в поле TourName пусто";
|
||||
protected override string MessageElemenValidationErrorPostNameEmpty() => "Переданы неверные данные: Значение в поле PostName пусто";
|
||||
protected override string MessageElemenValidationErrorFioISEmpty() => "Переданы неверные данные: Значение в поле FIO пусто";
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
namespace MagicCarpetTests.LocalizationTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ZhCNTests : BaseLocalizationControllerTests
|
||||
{
|
||||
protected override string GetLocale() => "zh-CN";
|
||||
protected override string MessageElementExists() => "已经有一个具有参数";
|
||||
protected override string MessageElementNotFound() => "未找到元素数据";
|
||||
protected override string MessageElementIdIncorrect() => "传递的数据不正确";
|
||||
protected override string MessageValidationErrorIDIsEmpty() => "传递的数据不正确: 字段 Id 的值为空";
|
||||
protected override string MessageValidationErrorIDIsNotGuid() => "传递的数据不正确: 字段 Id 的值不是唯一标识符类型";
|
||||
protected override string MessageValidationStringIsEmpty() => "传递的数据不正确: 字段 TourName 的值为空";
|
||||
protected override string MessageElemenValidationErrorPostNameEmpty() => "传递的数据不正确: 字段 PostName 的值为空";
|
||||
protected override string MessageElemenValidationErrorFioISEmpty() => "传递的数据不正确: 字段 FIO 的值为空";
|
||||
}
|
||||
@@ -4,6 +4,7 @@ using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.StoragesContracts;
|
||||
using MagicCarpetDatabase.Implementations;
|
||||
using MagicCarpetDatabase.Models;
|
||||
using MagicCarpetTests.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -19,7 +20,7 @@ internal class ClientStorageContractTests : BaseStorageContractTest
|
||||
private IClientStorageContract _clientStorageContract;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => _clientStorageContract = new ClientStorageContract(MagicCarpetDbContext);
|
||||
public void SetUp() => _clientStorageContract = new ClientStorageContract(MagicCarpetDbContext, StringLocalizerMockCreator.GetObject());
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
|
||||
@@ -20,7 +20,7 @@ class EmployeeStorageContractTests : BaseStorageContractTest
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_employeeStorageContract = new EmployeeStorageContract(MagicCarpetDbContext);
|
||||
_employeeStorageContract = new EmployeeStorageContract(MagicCarpetDbContext, StringLocalizerMockCreator.GetObject());
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
|
||||
@@ -21,7 +21,7 @@ internal class PostStorageContractTests : BaseStorageContractTest
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_postStorageContract = new PostStorageContract(MagicCarpetDbContext);
|
||||
_postStorageContract = new PostStorageContract(MagicCarpetDbContext, StringLocalizerMockCreator.GetObject());
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
|
||||
@@ -20,7 +20,7 @@ internal class SalaryStorageContractTests : BaseStorageContractTest
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_salaryStorageContract = new SalaryStorageContract(MagicCarpetDbContext);
|
||||
_salaryStorageContract = new SalaryStorageContract(MagicCarpetDbContext, StringLocalizerMockCreator.GetObject());
|
||||
_employee = MagicCarpetDbContext.InsertEmployeeToDatabaseAndReturn();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ internal class SaleStorageContractTests : BaseStorageContractTest
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_saletStorageContract = new SaleStorageContract(MagicCarpetDbContext);
|
||||
_saletStorageContract = new SaleStorageContract(MagicCarpetDbContext, StringLocalizerMockCreator.GetObject());
|
||||
_client = MagicCarpetDbContext.InsertClientToDatabaseAndReturn();
|
||||
_employee = MagicCarpetDbContext.InsertEmployeeToDatabaseAndReturn();
|
||||
_tour = MagicCarpetDbContext.InsertTourToDatabaseAndReturn();
|
||||
|
||||
@@ -23,7 +23,7 @@ internal class TourStorageContractTests : BaseStorageContractTest
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_tourStorageContract = new TourStorageContract(MagicCarpetDbContext);
|
||||
_tourStorageContract = new TourStorageContract(MagicCarpetDbContext, StringLocalizerMockCreator.GetObject());
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
|
||||
@@ -520,8 +520,8 @@ internal class EmployeeControllerTests : BaseWebApiControllerTest
|
||||
Assert.That(actual.PostName, Is.EqualTo(expected.Post!.PostName));
|
||||
Assert.That(actual.FIO, Is.EqualTo(expected.FIO));
|
||||
Assert.That(actual.Email, Is.EqualTo(expected.Email));
|
||||
Assert.That(actual.BirthDate.ToString(), Is.EqualTo(expected.BirthDate.ToString()));
|
||||
Assert.That(actual.EmploymentDate.ToString(), Is.EqualTo(expected.EmploymentDate.ToString()));
|
||||
Assert.That(actual.BirthDate.ToUniversalTime().ToString(), Is.EqualTo(expected.BirthDate.ToString()));
|
||||
Assert.That(actual.EmploymentDate.ToUniversalTime().ToString(), Is.EqualTo(expected.EmploymentDate.ToString()));
|
||||
Assert.That(actual.IsDeleted, Is.EqualTo(expected.IsDeleted));
|
||||
});
|
||||
}
|
||||
@@ -548,8 +548,8 @@ internal class EmployeeControllerTests : BaseWebApiControllerTest
|
||||
Assert.That(actual.PostId, Is.EqualTo(expected.PostId));
|
||||
Assert.That(actual.FIO, Is.EqualTo(expected.FIO));
|
||||
Assert.That(actual.Email, Is.EqualTo(expected.Email));
|
||||
Assert.That(actual.BirthDate.ToString(), Is.EqualTo(expected.BirthDate.ToString()));
|
||||
Assert.That(actual.EmploymentDate.ToString(), Is.EqualTo(expected.EmploymentDate.ToString()));
|
||||
Assert.That(actual.BirthDate.ToUniversalTime().ToString(), Is.EqualTo(expected.BirthDate.ToString()));
|
||||
Assert.That(actual.EmploymentDate.ToUniversalTime().ToString(), Is.EqualTo(expected.EmploymentDate.ToString()));
|
||||
Assert.That(!actual.IsDeleted);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5,18 +5,21 @@ using MagicCarpetContracts.BindingModels;
|
||||
using MagicCarpetContracts.BuisnessLogicContracts;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace MagicCarpetWebApi.Adapters;
|
||||
|
||||
public class ClientAdapter : IClientAdapter
|
||||
internal class ClientAdapter : IClientAdapter
|
||||
{
|
||||
private readonly IClientBusinessLogicContract _clientBusinessLogicContract;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
public ClientAdapter(IClientBusinessLogicContract clientBusinessLogicContract, ILogger<ClientAdapter> logger)
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
public ClientAdapter(IClientBusinessLogicContract clientBusinessLogicContract, ILogger<ClientAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_clientBusinessLogicContract = clientBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -26,6 +29,7 @@ public class ClientAdapter : IClientAdapter
|
||||
cfg.CreateMap<ClientDataModel, ClientViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public ClientOperationResponse GetList()
|
||||
@@ -34,15 +38,10 @@ public class ClientAdapter : IClientAdapter
|
||||
{
|
||||
return ClientOperationResponse.OK([.. _clientBusinessLogicContract.GetAllClients().Select(x => _mapper.Map<ClientViewModel>(x))]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return ClientOperationResponse.NotFound("The list is not initialized");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ClientOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ClientOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -60,17 +59,17 @@ public class ClientAdapter : IClientAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ClientOperationResponse.BadRequest("Data is empty");
|
||||
return ClientOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return ClientOperationResponse.NotFound($"Not found element by data {data}");
|
||||
return ClientOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementNotFoundException"], data));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ClientOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ClientOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageElementNotFoundException"], data));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -89,12 +88,12 @@ public class ClientAdapter : IClientAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ClientOperationResponse.BadRequest("Data is empty");
|
||||
return ClientOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ClientOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return ClientOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -104,7 +103,7 @@ public class ClientAdapter : IClientAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ClientOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ClientOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -123,17 +122,18 @@ public class ClientAdapter : IClientAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ClientOperationResponse.BadRequest("Data is empty");
|
||||
return ClientOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ClientOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return ClientOperationResponse.BadRequest(
|
||||
string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return ClientOperationResponse.BadRequest($"Not found element by Id {clientModel.Id}");
|
||||
return ClientOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], clientModel.Id));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -143,7 +143,7 @@ public class ClientAdapter : IClientAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ClientOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ClientOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -162,22 +162,22 @@ public class ClientAdapter : IClientAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return ClientOperationResponse.BadRequest("Id is empty");
|
||||
return ClientOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return ClientOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return ClientOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return ClientOperationResponse.BadRequest($"Not found element by id: {id}");
|
||||
return ClientOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return ClientOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return ClientOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -5,28 +5,34 @@ using MagicCarpetContracts.BindingModels;
|
||||
using MagicCarpetContracts.BuisnessLogicContracts;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace MagicCarpetWebApi.Adapters;
|
||||
|
||||
public class EmployeeAdapter : IEmployeeAdapter
|
||||
internal class EmployeeAdapter : IEmployeeAdapter
|
||||
{
|
||||
private readonly IEmployeeBusinessLogicContract _employeeBusinessLogicContract;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
public EmployeeAdapter(IEmployeeBusinessLogicContract employeeBusinessLogicContract, ILogger<EmployeeAdapter> logger)
|
||||
public EmployeeAdapter(IEmployeeBusinessLogicContract employeeBusinessLogicContract, ILogger<EmployeeAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_employeeBusinessLogicContract = employeeBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<EmployeeBindingModel, EmployeeDataModel>();
|
||||
cfg.CreateMap<EmployeeDataModel, EmployeeViewModel>();
|
||||
cfg.CreateMap<EmployeeDataModel, EmployeeViewModel>()
|
||||
.ForMember(x => x.BirthDate, x => x.MapFrom(src => src.BirthDate.ToLocalTime()))
|
||||
.ForMember(x => x.EmploymentDate, x => x.MapFrom(src => src.EmploymentDate.ToLocalTime()));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public EmployeeOperationResponse GetList(bool includeDeleted)
|
||||
@@ -35,15 +41,10 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
{
|
||||
return EmployeeOperationResponse.OK([.. _employeeBusinessLogicContract.GetAllEmployees(!includeDeleted).Select(x => _mapper.Map<EmployeeViewModel>(x))]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return EmployeeOperationResponse.NotFound("The list is not initialized");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return EmployeeOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return EmployeeOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -61,17 +62,12 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return EmployeeOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return EmployeeOperationResponse.NotFound("The list is not initialized");
|
||||
return EmployeeOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return EmployeeOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return EmployeeOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -89,17 +85,12 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return EmployeeOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return EmployeeOperationResponse.NotFound("The list is not initialized");
|
||||
return EmployeeOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return EmployeeOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return EmployeeOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -112,22 +103,20 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
{
|
||||
try
|
||||
{
|
||||
return EmployeeOperationResponse.OK([.. _employeeBusinessLogicContract.GetAllEmployeesByEmploymentDate(fromDate.ToUniversalTime(), toDate.ToUniversalTime(), !includeDeleted).Select(_mapper.Map<EmployeeViewModel>)]);
|
||||
return EmployeeOperationResponse.OK([..
|
||||
_employeeBusinessLogicContract.GetAllEmployeesByEmploymentDate(fromDate.ToUniversalTime(),
|
||||
toDate.ToUniversalTime(), !includeDeleted).Select(x =>
|
||||
_mapper.Map<EmployeeViewModel>(x))]);
|
||||
}
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return EmployeeOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return EmployeeOperationResponse.NotFound("The list is not initialized");
|
||||
return EmployeeOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return EmployeeOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return EmployeeOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -145,22 +134,22 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return EmployeeOperationResponse.BadRequest("Data is empty");
|
||||
return EmployeeOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return EmployeeOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return EmployeeOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return EmployeeOperationResponse.NotFound($"Not found element by data {data}");
|
||||
return EmployeeOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementNotFoundException"], data));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return EmployeeOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return EmployeeOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -179,12 +168,12 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return EmployeeOperationResponse.BadRequest("Data is empty");
|
||||
return EmployeeOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return EmployeeOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return EmployeeOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -194,7 +183,7 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return EmployeeOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return EmployeeOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -213,17 +202,17 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return EmployeeOperationResponse.BadRequest("Data is empty");
|
||||
return EmployeeOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return EmployeeOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return EmployeeOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return EmployeeOperationResponse.BadRequest($"Not found element by Id {employeeModel.Id}");
|
||||
return EmployeeOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], employeeModel.Id));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -233,7 +222,7 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return EmployeeOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return EmployeeOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -252,22 +241,22 @@ public class EmployeeAdapter : IEmployeeAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return EmployeeOperationResponse.BadRequest("Id is empty");
|
||||
return EmployeeOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return EmployeeOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return EmployeeOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return EmployeeOperationResponse.BadRequest($"Not found element by id: {id}");
|
||||
return EmployeeOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return EmployeeOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return EmployeeOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -5,15 +5,19 @@ using MagicCarpetContracts.BindingModels;
|
||||
using MagicCarpetContracts.BuisnessLogicContracts;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace MagicCarpetWebApi.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;
|
||||
@@ -23,7 +27,7 @@ public class PostAdapter : IPostAdapter
|
||||
PropertyNameCaseInsensitive = true
|
||||
};
|
||||
|
||||
public PostAdapter(IPostBusinessLogicContract postBusinessLogicContract, ILogger<PostAdapter> logger)
|
||||
public PostAdapter(IPostBusinessLogicContract postBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<PostAdapter> logger)
|
||||
{
|
||||
_postBusinessLogicContract = postBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -34,6 +38,7 @@ public class PostAdapter : IPostAdapter
|
||||
.ForMember(x => x.Configuration, x => x.MapFrom(src => JsonSerializer.Serialize(src.ConfigurationModel, JsonSerializerOptions)));
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public PostOperationResponse GetList()
|
||||
@@ -42,15 +47,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)
|
||||
{
|
||||
@@ -68,17 +68,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)
|
||||
{
|
||||
@@ -96,22 +96,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)
|
||||
{
|
||||
@@ -130,12 +130,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)
|
||||
{
|
||||
@@ -145,7 +145,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)
|
||||
{
|
||||
@@ -164,17 +164,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)
|
||||
{
|
||||
@@ -184,12 +184,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)
|
||||
{
|
||||
@@ -208,27 +208,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)
|
||||
{
|
||||
@@ -247,22 +247,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)
|
||||
{
|
||||
|
||||
@@ -4,19 +4,23 @@ using MagicCarpetContracts.AdapterContracts.OperationResponses;
|
||||
using MagicCarpetContracts.BusinessLogicContracts;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace MagicCarpetWebApi.Adapters;
|
||||
|
||||
public class ReportAdapter : IReportAdapter
|
||||
internal class ReportAdapter : IReportAdapter
|
||||
{
|
||||
private readonly IReportContract _reportContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public ReportAdapter(IReportContract reportContract, ILogger logger)
|
||||
public ReportAdapter(IReportContract reportContract, IStringLocalizer<Messages> localizer, ILogger logger)
|
||||
{
|
||||
_reportContract = reportContract;
|
||||
_logger = logger;
|
||||
@@ -30,6 +34,7 @@ public class ReportAdapter : IReportAdapter
|
||||
cfg.CreateMap<EmployeeSalaryByPeriodDataModel, EmployeeSalaryByPeriodViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public async Task<ReportOperationResponse> CreateDocumentToursHistoryAsync(CancellationToken ct)
|
||||
@@ -41,12 +46,12 @@ 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)
|
||||
{
|
||||
@@ -66,17 +71,17 @@ public class ReportAdapter : IReportAdapter
|
||||
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)
|
||||
{
|
||||
@@ -95,12 +100,12 @@ 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)
|
||||
{
|
||||
@@ -120,17 +125,17 @@ public class ReportAdapter : IReportAdapter
|
||||
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)
|
||||
{
|
||||
@@ -156,17 +161,17 @@ public class ReportAdapter : IReportAdapter
|
||||
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)
|
||||
{
|
||||
@@ -185,17 +190,17 @@ public class ReportAdapter : IReportAdapter
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -5,18 +5,22 @@ using MagicCarpetContracts.BuisnessLogicContracts;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.ViewModels;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace MagicCarpetWebApi.Adapters;
|
||||
|
||||
public class SalaryAdapter : ISalaryAdapter
|
||||
internal class SalaryAdapter : ISalaryAdapter
|
||||
{
|
||||
private readonly ISalaryBusinessLogicContract _salaryBusinessLogicContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public SalaryAdapter(ISalaryBusinessLogicContract salaryBusinessLogicContract, ILogger<SalaryAdapter> logger)
|
||||
public SalaryAdapter(ISalaryBusinessLogicContract salaryBusinessLogicContract, ILogger<SalaryAdapter> logger, IStringLocalizer<Messages> localizer)
|
||||
{
|
||||
_salaryBusinessLogicContract = salaryBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -25,6 +29,7 @@ public class SalaryAdapter : ISalaryAdapter
|
||||
cfg.CreateMap<SalaryDataModel, SalaryViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public SalaryOperationResponse GetListByPeriod(DateTime fromDate, DateTime toDate)
|
||||
@@ -36,22 +41,17 @@ public class SalaryAdapter : ISalaryAdapter
|
||||
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)
|
||||
{
|
||||
@@ -69,22 +69,17 @@ public class SalaryAdapter : ISalaryAdapter
|
||||
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.CalculateSalaryByMounth(date);
|
||||
_salaryBusinessLogicContract.CalculateSalaryByMounth(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,34 +1,41 @@
|
||||
using AutoMapper;
|
||||
using DocumentFormat.OpenXml.Office2010.Excel;
|
||||
using MagicCarpetContracts.AdapterContracts;
|
||||
using MagicCarpetContracts.AdapterContracts.OperationResponses;
|
||||
using MagicCarpetContracts.BindingModels;
|
||||
using MagicCarpetContracts.BuisnessLogicContracts;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace MagicCarpetWebApi.Adapters;
|
||||
|
||||
public class SaleAdapter : ISaleAdapter
|
||||
internal class SaleAdapter : ISaleAdapter
|
||||
{
|
||||
private readonly ISaleBusinessLogicContract _saleBusinessLogicContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public SaleAdapter(ISaleBusinessLogicContract saleBusinessLogicContract, ILogger<SaleAdapter> logger)
|
||||
public SaleAdapter(ISaleBusinessLogicContract saleBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<SaleAdapter> logger)
|
||||
{
|
||||
_saleBusinessLogicContract = saleBusinessLogicContract;
|
||||
_logger = logger;
|
||||
var config = new MapperConfiguration(cfg =>
|
||||
{
|
||||
cfg.CreateMap<SaleBindingModel, SaleDataModel>();
|
||||
cfg.CreateMap<SaleDataModel, SaleViewModel>();
|
||||
cfg.CreateMap<SaleDataModel, SaleViewModel>()
|
||||
.ForMember(x => x.SaleDate, x => x.MapFrom(src => src.SaleDate.ToLocalTime())); ;
|
||||
cfg.CreateMap<SaleTourBindingModel, SaleTourDataModel>();
|
||||
cfg.CreateMap<SaleTourDataModel, SaleTourViewModel>();
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public SaleOperationResponse GetList(DateTime fromDate, DateTime toDate)
|
||||
@@ -40,17 +47,12 @@ public class SaleAdapter : ISaleAdapter
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SaleOperationResponse.NotFound("The list is not initialized");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SaleOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -68,22 +70,17 @@ public class SaleAdapter : ISaleAdapter
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SaleOperationResponse.NotFound("The list is not initialized");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SaleOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -101,22 +98,17 @@ public class SaleAdapter : ISaleAdapter
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SaleOperationResponse.NotFound("The list is not initialized");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SaleOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -134,22 +126,17 @@ public class SaleAdapter : ISaleAdapter
|
||||
catch (IncorrectDatesException ex)
|
||||
{
|
||||
_logger.LogError(ex, "IncorrectDatesException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect dates: {ex.Message}");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageIncorrectDatesException"], ex.Message));
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return SaleOperationResponse.NotFound("The list is not initialized");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SaleOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -167,22 +154,22 @@ public class SaleAdapter : ISaleAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SaleOperationResponse.BadRequest("Data is empty");
|
||||
return SaleOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return SaleOperationResponse.NotFound($"Not found element by data {id}");
|
||||
return SaleOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SaleOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SaleOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -202,17 +189,17 @@ public class SaleAdapter : ISaleAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SaleOperationResponse.BadRequest("Data is empty");
|
||||
return SaleOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SaleOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SaleOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -231,27 +218,27 @@ public class SaleAdapter : ISaleAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return SaleOperationResponse.BadRequest("Id is empty");
|
||||
return SaleOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return SaleOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return SaleOperationResponse.BadRequest($"Not found element by id: {id}");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return SaleOperationResponse.BadRequest($"Element by id: {id} was deleted");
|
||||
return SaleOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementDeletedException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return SaleOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return SaleOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -5,19 +5,23 @@ using MagicCarpetContracts.BindingModels;
|
||||
using MagicCarpetContracts.BuisnessLogicContracts;
|
||||
using MagicCarpetContracts.DataModels;
|
||||
using MagicCarpetContracts.Exceptions;
|
||||
using MagicCarpetContracts.Resources;
|
||||
using MagicCarpetContracts.ViewModels;
|
||||
using Microsoft.Extensions.Localization;
|
||||
|
||||
namespace MagicCarpetWebApi.Adapters;
|
||||
|
||||
public class TourAdapter : ITourAdapter
|
||||
internal class TourAdapter : ITourAdapter
|
||||
{
|
||||
private readonly ITourBusinessLogicContract _tourBusinessLogicContract;
|
||||
|
||||
private readonly IStringLocalizer<Messages> _localizer;
|
||||
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly Mapper _mapper;
|
||||
|
||||
public TourAdapter(ITourBusinessLogicContract tourBusinessLogicContract, ILogger<TourAdapter> logger)
|
||||
public TourAdapter(ITourBusinessLogicContract tourBusinessLogicContract, IStringLocalizer<Messages> localizer, ILogger<TourAdapter> logger)
|
||||
{
|
||||
_tourBusinessLogicContract = tourBusinessLogicContract;
|
||||
_logger = logger;
|
||||
@@ -29,6 +33,7 @@ public class TourAdapter : ITourAdapter
|
||||
|
||||
});
|
||||
_mapper = new Mapper(config);
|
||||
_localizer = localizer;
|
||||
}
|
||||
|
||||
public TourOperationResponse GetList(bool includeDeleted)
|
||||
@@ -37,15 +42,10 @@ public class TourAdapter : ITourAdapter
|
||||
{
|
||||
return TourOperationResponse.OK([.. _tourBusinessLogicContract.GetAllTours().Select(_mapper.Map<TourViewModel>)]);
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return TourOperationResponse.NotFound("The list is not initialized");
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return TourOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return TourOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -62,17 +62,12 @@ public class TourAdapter : ITourAdapter
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return TourOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
}
|
||||
catch (NullListException)
|
||||
{
|
||||
_logger.LogError("NullListException");
|
||||
return TourOperationResponse.NotFound("The list is not initialized");
|
||||
return TourOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return TourOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return TourOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -90,22 +85,22 @@ public class TourAdapter : ITourAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return TourOperationResponse.BadRequest("Data is empty");
|
||||
return TourOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return TourOperationResponse.NotFound($"Not found element by data {data}");
|
||||
return TourOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementNotFoundException"], data));
|
||||
}
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return TourOperationResponse.BadRequest($"Element by data: {data} was deleted");
|
||||
return TourOperationResponse.NotFound(string.Format(_localizer["AdapterMessageElementDeletedException"], data));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return TourOperationResponse.InternalServerError($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return TourOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -124,12 +119,12 @@ public class TourAdapter : ITourAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return TourOperationResponse.BadRequest("Data is empty");
|
||||
return TourOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return TourOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return TourOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -139,7 +134,7 @@ public class TourAdapter : ITourAdapter
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return TourOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return TourOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message)); ;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -158,17 +153,17 @@ public class TourAdapter : ITourAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return TourOperationResponse.BadRequest("Data is empty");
|
||||
return TourOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return TourOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return TourOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return TourOperationResponse.BadRequest($"Not found element by Id {tourModel.Id}");
|
||||
return TourOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], tourModel.Id));
|
||||
}
|
||||
catch (ElementExistsException ex)
|
||||
{
|
||||
@@ -178,12 +173,12 @@ public class TourAdapter : ITourAdapter
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return TourOperationResponse.BadRequest($"Element by id: {tourModel.Id} was deleted");
|
||||
return TourOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementDeletedException"], tourModel.Id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return TourOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return TourOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -202,27 +197,27 @@ public class TourAdapter : ITourAdapter
|
||||
catch (ArgumentNullException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ArgumentNullException");
|
||||
return TourOperationResponse.BadRequest("Id is empty");
|
||||
return TourOperationResponse.BadRequest(_localizer["AdapterMessageEmptyDate"]);
|
||||
}
|
||||
catch (ValidationException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ValidationException");
|
||||
return TourOperationResponse.BadRequest($"Incorrect data transmitted: {ex.Message}");
|
||||
return TourOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageValidationException"], ex.Message));
|
||||
}
|
||||
catch (ElementNotFoundException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementNotFoundException");
|
||||
return TourOperationResponse.BadRequest($"Not found element by id: {id}");
|
||||
return TourOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementNotFoundException"], id));
|
||||
}
|
||||
catch (ElementDeletedException ex)
|
||||
{
|
||||
_logger.LogError(ex, "ElementDeletedException");
|
||||
return TourOperationResponse.BadRequest($"Element by id: {id} was deleted");
|
||||
return TourOperationResponse.BadRequest(string.Format(_localizer["AdapterMessageElementDeletedException"], id));
|
||||
}
|
||||
catch (StorageException ex)
|
||||
{
|
||||
_logger.LogError(ex, "StorageException");
|
||||
return TourOperationResponse.BadRequest($"Error while working with data storage: {ex.InnerException!.Message}");
|
||||
return TourOperationResponse.InternalServerError(string.Format(_localizer["AdapterMessageStorageException"], ex.InnerException!.Message));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
@@ -96,9 +96,10 @@ builder.Services.AddTransient<ISalaryAdapter, SalaryAdapter>();
|
||||
|
||||
builder.Services.AddTransient<IReportContract, ReportContract>();
|
||||
builder.Services.AddTransient<IReportAdapter, ReportAdapter>();
|
||||
builder.Services.AddTransient<BaseWordBuilder, OpenXmlWordBuilder>();
|
||||
builder.Services.AddTransient<BaseExcelBuilder, OpenXmlExcelBuilder>();
|
||||
builder.Services.AddTransient<BasePdfBuilder, MigraDocPdfBuilder>();
|
||||
|
||||
builder.Services.AddScoped<BaseWordBuilder, OpenXmlWordBuilder>();
|
||||
builder.Services.AddScoped<BaseExcelBuilder, OpenXmlExcelBuilder>();
|
||||
builder.Services.AddScoped<BasePdfBuilder, MigraDocPdfBuilder>();
|
||||
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
Reference in New Issue
Block a user