2 Commits

Author SHA1 Message Date
50a0807cdf семафор 2025-05-21 12:43:59 +04:00
4abc5ebcfb забыл тесты раскомитить 2025-05-21 12:26:01 +04:00
6 changed files with 190 additions and 165 deletions

View File

@@ -77,41 +77,61 @@ internal class SalaryBusinessLogicContract(ISalaryStorageContract salaryStorageC
private double CalculateSalaryForCashier(List<ProductionDataModel> sales, DateTime startDate, DateTime finishDate, ManufacturerPostConfiguration config)
{
int maxConcurrency = сonfiguration.MaxParallelThreads;
var semaphore = new SemaphoreSlim(maxConcurrency);
var tasks = new List<Task>();
var calcPercent = 0.0;
for (var date = startDate; date < finishDate; date = date.AddDays(1))
{
tasks.Add(Task.Factory.StartNew((object? obj) =>
var dateCopy = date; // Нужно, чтобы замыкание захватило корректную дату
tasks.Add(Task.Run(async () =>
{
var dateInTask = (DateTime)obj!;
var salesInDay = sales.Where(x => x.ProductionDate >= dateInTask && x.ProductionDate < dateInTask.AddDays(1)).ToArray();
if (salesInDay.Length > 0)
await semaphore.WaitAsync();
try
{
lock (_lockObject)
var salesInDay = sales
.Where(x => x.ProductionDate >= dateCopy && x.ProductionDate < dateCopy.AddDays(1))
.ToArray();
if (salesInDay.Length > 0)
{
calcPercent += (salesInDay.Sum(x => x.Sum) / salesInDay.Length) * config.SalePercent;
lock (_lockObject)
{
calcPercent += (salesInDay.Sum(x => x.Sum) / salesInDay.Length) * config.SalePercent;
}
}
}
}, date));
finally
{
semaphore.Release();
}
}));
}
var calcBonusTask = Task.Run(() =>
{
return sales.Where(x => x.Sum > _salaryConfiguration.ExtraSaleSum).Sum(x => x.Sum) * config.BonusForExtraSales;
});
try
{
Task.WaitAll([Task.WhenAll(tasks), calcBonusTask]);
Task.WaitAll(tasks.ToArray()); // Ждём завершения всех задач по дням
calcBonusTask.Wait(); // Ждём завершения бонуса
}
catch (AggregateException agEx)
{
foreach (var ex in agEx.InnerExceptions)
{
_logger.LogError(ex, "Error in the cashier payroll process");
}
return 0;
}
return config.Rate + calcPercent + calcBonusTask.Result;
}
private double CalculateSalaryForSupervisor(DateTime startDate, DateTime finishDate, PackerPostConfiguration config)
{
try

View File

@@ -9,4 +9,5 @@ namespace SladkieBulkiContrakts.Infrastructure;
public interface IConfigurationSalary
{
double ExtraSaleSum { get; }
int MaxParallelThreads { get; }
}

View File

@@ -4,6 +4,7 @@ using SladkieBulkiBusinessLogic.Implementations;
using SladkieBulkiContrakts.DataModels;
using SladkieBulkiContrakts.Enums;
using SladkieBulkiContrakts.Exceptions;
using SladkieBulkiContrakts.Infrastructure.PostConfigurations;
using SladkieBulkiContrakts.StoragesContarcts;
using SladkieBulkiTests.Infrastructure;
using System;
@@ -188,166 +189,166 @@ internal class SalaryBusinessLogicContractTests
_salaryStorageContract.Verify(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>()), Times.Once);
}
//[Test]
//public void CalculateSalaryByMounth_CalculateSalary_Test()
//{
// //Arrange
// var workerId = Guid.NewGuid().ToString();
// var saleSum = 200.0;
// var postSalary = 2000.0;
// _productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
// .Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, saleSum, workerId, null)]);
// _postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, postSalary));
// _workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
// .Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru"),]);
// var sum = 0.0;
// var expectedSum = postSalary + saleSum * 0.1;
// _salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
// .Callback((SalaryDataModel x) =>
// {
// sum = x.WorkerSalary;
// });
// //Act
// _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
// //Assert
// Assert.That(sum, Is.EqualTo(expectedSum));
//}
[Test]
public void CalculateSalaryByMounth_CalculateSalary_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
var saleSum = 200.0;
var postSalary = 2000.0;
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, saleSum, workerId, null)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new ManufacturerPostConfiguration { Rate = postSalary, SalePercent = 0.1 }));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru"),]);
var sum = 0.0;
var expectedSum = postSalary + saleSum * 0.1;
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
.Callback((SalaryDataModel x) =>
{
sum = x.WorkerSalary;
});
//Act
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
//Assert
Assert.That(sum, Is.EqualTo(expectedSum));
}
//[Test]
//public void CalculateSalaryByMounth_WithSeveralWorkers_Test()
//{
// //Arrange
// var worker1Id = Guid.NewGuid().ToString();
// var worker2Id = Guid.NewGuid().ToString();
// var worker3Id = Guid.NewGuid().ToString();
// var list = new List<WorkerDataModel>() {
// new(worker1Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru"),
// new(worker2Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru"),
// new(worker3Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")
// };
// _productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
// .Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker1Id, null),
// new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker1Id, null),
// new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker2Id, null),
// new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker3Id, null),
// new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker3Id, null)]);
// _postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, 2000));
// _workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
// .Returns(list);
// //Act
// _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
// //Assert
// _salaryStorageContract.Verify(x => x.AddElement(It.IsAny<SalaryDataModel>()), Times.Exactly(list.Count));
//}
[Test]
public void CalculateSalaryByMounth_WithSeveralWorkers_Test()
{
//Arrange
var worker1Id = Guid.NewGuid().ToString();
var worker2Id = Guid.NewGuid().ToString();
var worker3Id = Guid.NewGuid().ToString();
var list = new List<WorkerDataModel>() {
new(worker1Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru"),
new(worker2Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru"),
new(worker3Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")
};
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker1Id, null),
new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker1Id, null),
new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker2Id, null),
new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker3Id, null),
new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 0.0, worker3Id, null)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 2000 }));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns(list);
//Act
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
//Assert
_salaryStorageContract.Verify(x => x.AddElement(It.IsAny<SalaryDataModel>()), Times.Exactly(list.Count));
}
//[Test]
//public void CalculateSalaryByMounth_WithoitSalesByWorker_Test()
//{
// //Arrange
// var postSalary = 2000.0;
// var workerId = Guid.NewGuid().ToString();
// _productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
// .Returns([]);
// _postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, postSalary));
// _workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
// .Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
// var sum = 0.0;
// var expectedSum = postSalary;
// _salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
// .Callback((SalaryDataModel x) =>
// {
// sum = x.WorkerSalary;
// });
// //Act
// _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
// //Assert
// Assert.That(sum, Is.EqualTo(expectedSum));
//}
[Test]
public void CalculateSalaryByMounth_WithoitSalesByWorker_Test()
{
//Arrange
var postSalary = 2000.0;
var workerId = Guid.NewGuid().ToString();
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = postSalary }));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
var sum = 0.0;
var expectedSum = postSalary;
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
.Callback((SalaryDataModel x) =>
{
sum = x.WorkerSalary;
});
//Act
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
//Assert
Assert.That(sum, Is.EqualTo(expectedSum));
}
//[Test]
//public void CalculateSalaryByMounth_SaleStorageReturnNull_ThrowException_Test()
//{
// //Arrange
// var workerId = Guid.NewGuid().ToString();
// _postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, 2000));
// _workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
// .Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
// //Act&Assert
// Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
//}
[Test]
public void CalculateSalaryByMounth_SaleStorageReturnNull_ThrowException_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 2000 }));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
}
//[Test]
//public void CalculateSalaryByMounth_PostStorageReturnNull_ThrowException_Test()
//{
// //Arrange
// var workerId = Guid.NewGuid().ToString();
// _productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
// .Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
// _workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
// .Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
// //Act&Assert
// Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
//}
[Test]
public void CalculateSalaryByMounth_PostStorageReturnNull_ThrowException_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
}
//[Test]
//public void CalculateSalaryByMounth_WorkerStorageReturnNull_ThrowException_Test()
//{
// //Arrange
// var workerId = Guid.NewGuid().ToString();
// _productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
// .Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
// _postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, 2000));
// //Act&Assert
// Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
//}
[Test]
public void CalculateSalaryByMounth_WorkerStorageReturnNull_ThrowException_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 2000 }));
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
}
//[Test]
//public void CalculateSalaryByMounth_SaleStorageThrowException_ThrowException_Test()
//{
// //Arrange
// var workerId = Guid.NewGuid().ToString();
// _productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
// .Throws(new StorageException(new InvalidOperationException()));
// _postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, 2000));
// _workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
// .Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
// //Act&Assert
// Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
//}
[Test]
public void CalculateSalaryByMounth_SaleStorageThrowException_ThrowException_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Throws(new StorageException(new InvalidOperationException()));
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 2000 }));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
}
//[Test]
//public void CalculateSalaryByMounth_PostStorageThrowException_ThrowException_Test()
//{
// //Arrange
// var workerId = Guid.NewGuid().ToString();
// _productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
// .Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
// _postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
// .Throws(new StorageException(new InvalidOperationException()));
// _workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
// .Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
// //Act&Assert
// Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
//}
[Test]
public void CalculateSalaryByMounth_PostStorageThrowException_ThrowException_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Throws(new StorageException(new InvalidOperationException()));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false, "1@mail.ru")]);
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
}
//[Test]
//public void CalculateSalaryByMounth_WorkerStorageThrowException_ThrowException_Test()
//{
// //Arrange
// var workerId = Guid.NewGuid().ToString();
// _productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
// .Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
// _postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, 2000));
// _workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
// .Throws(new StorageException(new InvalidOperationException()));
// //Act&Assert
// Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
//}
[Test]
public void CalculateSalaryByMounth_WorkerStorageThrowException_ThrowException_Test()
{
//Arrange
var workerId = Guid.NewGuid().ToString();
_productionStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new ProductionDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 200.0, workerId, null)]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Manufacturer, new PostConfiguration() { Rate = 200 }));
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
}
}

View File

@@ -10,4 +10,5 @@ namespace SladkieBulkiTests.Infrastructure;
class ConfigurationSalaryTest : IConfigurationSalary
{
public double ExtraSaleSum => 10;
public int MaxParallelThreads { get; set; } = 4;
}

View File

@@ -10,5 +10,6 @@ public class ConfigurationSalary(IConfiguration configuration) : IConfigurationS
});
public double ExtraSaleSum => _salarySettings.Value.ExtraSaleSum;
public int MaxParallelThreads { get; set; } = 4;
}

View File

@@ -26,6 +26,7 @@
"ConnectionString": "Host=localhost;Port=5432;Database=rpp;Username=postgres;Password=postgres;"
},
"SalarySettings": {
"ExtraSaleSum": 1000
"ExtraSaleSum": 1000,
"MaxParallelThreads": 4
}
}