|
|
|
|
@@ -2,7 +2,9 @@
|
|
|
|
|
using CatHasPawsContratcs.DataModels;
|
|
|
|
|
using CatHasPawsContratcs.Enums;
|
|
|
|
|
using CatHasPawsContratcs.Exceptions;
|
|
|
|
|
using CatHasPawsContratcs.Infrastructure.PostConfigurations;
|
|
|
|
|
using CatHasPawsContratcs.StoragesContracts;
|
|
|
|
|
using CatHasPawsTests.Infrastructure;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using Moq;
|
|
|
|
|
|
|
|
|
|
@@ -16,6 +18,7 @@ internal class SalaryBusinessLogicContractTests
|
|
|
|
|
private Mock<ISaleStorageContract> _saleStorageContract;
|
|
|
|
|
private Mock<IPostStorageContract> _postStorageContract;
|
|
|
|
|
private Mock<IWorkerStorageContract> _workerStorageContract;
|
|
|
|
|
private readonly ConfigurationSalaryTest _salaryConfigurationTest = new();
|
|
|
|
|
|
|
|
|
|
[OneTimeSetUp]
|
|
|
|
|
public void OneTimeSetUp()
|
|
|
|
|
@@ -25,7 +28,7 @@ internal class SalaryBusinessLogicContractTests
|
|
|
|
|
_postStorageContract = new Mock<IPostStorageContract>();
|
|
|
|
|
_workerStorageContract = new Mock<IWorkerStorageContract>();
|
|
|
|
|
_salaryBusinessLogicContract = new SalaryBusinessLogicContract(_salaryStorageContract.Object,
|
|
|
|
|
_saleStorageContract.Object, _postStorageContract.Object, _workerStorageContract.Object, new Mock<ILogger>().Object);
|
|
|
|
|
_saleStorageContract.Object, _postStorageContract.Object, _workerStorageContract.Object, new Mock<ILogger>().Object, _salaryConfigurationTest);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
|
@@ -185,92 +188,89 @@ internal class SalaryBusinessLogicContractTests
|
|
|
|
|
public void CalculateSalaryByMounth_CalculateSalary_Test()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
//var workerId = Guid.NewGuid().ToString();
|
|
|
|
|
//var saleSum = 1.2 * 5;
|
|
|
|
|
//var postSalary = 2000.0;
|
|
|
|
|
//_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
|
// .Returns([new SaleDataModel(Guid.NewGuid().ToString(), workerId, null, DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])]);
|
|
|
|
|
//_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 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)]);
|
|
|
|
|
//var sum = 0.0;
|
|
|
|
|
//var expectedSum = postSalary + saleSum * 0.1;
|
|
|
|
|
//_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
|
|
|
|
// .Callback((SalaryDataModel x) =>
|
|
|
|
|
// {
|
|
|
|
|
// sum = x.Salary;
|
|
|
|
|
// });
|
|
|
|
|
////Act
|
|
|
|
|
//_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
|
|
|
|
////Assert
|
|
|
|
|
//Assert.That(sum, Is.EqualTo(expectedSum));
|
|
|
|
|
var workerId = Guid.NewGuid().ToString();
|
|
|
|
|
var rate = 2000.0;
|
|
|
|
|
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
|
.Returns([new SaleDataModel(Guid.NewGuid().ToString(), workerId, null, DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])]);
|
|
|
|
|
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, new PostConfiguration() { Rate = rate }));
|
|
|
|
|
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
|
|
|
|
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
|
|
|
|
var sum = 0.0;
|
|
|
|
|
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
|
|
|
|
.Callback((SalaryDataModel x) =>
|
|
|
|
|
{
|
|
|
|
|
sum = x.Salary;
|
|
|
|
|
});
|
|
|
|
|
//Act
|
|
|
|
|
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.That(sum, Is.EqualTo(rate));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CalculateSalaryByMounth_WithSeveralWorkers_Test()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
//var worker1Id = Guid.NewGuid().ToString();
|
|
|
|
|
//var worker2Id = Guid.NewGuid().ToString();
|
|
|
|
|
//var worker3Id = Guid.NewGuid().ToString();
|
|
|
|
|
//var list = new List<WorkerDataModel>() {
|
|
|
|
|
// new(worker1Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
|
|
|
|
// new(worker2Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
|
|
|
|
// new(worker3Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)
|
|
|
|
|
//};
|
|
|
|
|
//_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(), worker1Id, null, DiscountType.None, false, []),
|
|
|
|
|
// new SaleDataModel(Guid.NewGuid().ToString(), worker1Id, null, DiscountType.None, false, []),
|
|
|
|
|
// new SaleDataModel(Guid.NewGuid().ToString(), worker2Id, null, DiscountType.None, false, []),
|
|
|
|
|
// new SaleDataModel(Guid.NewGuid().ToString(), worker3Id, null, DiscountType.None, false, []),
|
|
|
|
|
// new SaleDataModel(Guid.NewGuid().ToString(), worker3Id, null, DiscountType.None, false, [])]);
|
|
|
|
|
//_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 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));
|
|
|
|
|
var worker1Id = Guid.NewGuid().ToString();
|
|
|
|
|
var worker2Id = Guid.NewGuid().ToString();
|
|
|
|
|
var worker3Id = Guid.NewGuid().ToString();
|
|
|
|
|
var list = new List<WorkerDataModel>() {
|
|
|
|
|
new(worker1Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
|
|
|
|
new(worker2Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false),
|
|
|
|
|
new(worker3Id, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)
|
|
|
|
|
};
|
|
|
|
|
_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(), worker1Id, null, DiscountType.None, false, []),
|
|
|
|
|
new SaleDataModel(Guid.NewGuid().ToString(), worker1Id, null, DiscountType.None, false, []),
|
|
|
|
|
new SaleDataModel(Guid.NewGuid().ToString(), worker2Id, null, DiscountType.None, false, []),
|
|
|
|
|
new SaleDataModel(Guid.NewGuid().ToString(), worker3Id, null, DiscountType.None, false, []),
|
|
|
|
|
new SaleDataModel(Guid.NewGuid().ToString(), worker3Id, null, DiscountType.None, false, [])]);
|
|
|
|
|
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, new PostConfiguration() { Rate = 100 }));
|
|
|
|
|
_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_WithoutSalesByWorker_Test()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
//var postSalary = 2000.0;
|
|
|
|
|
//var workerId = Guid.NewGuid().ToString();
|
|
|
|
|
//_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
|
// .Returns([]);
|
|
|
|
|
//_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 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)]);
|
|
|
|
|
//var sum = 0.0;
|
|
|
|
|
//var expectedSum = postSalary;
|
|
|
|
|
//_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
|
|
|
|
// .Callback((SalaryDataModel x) =>
|
|
|
|
|
// {
|
|
|
|
|
// sum = x.Salary;
|
|
|
|
|
// });
|
|
|
|
|
////Act
|
|
|
|
|
//_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
|
|
|
|
////Assert
|
|
|
|
|
//Assert.That(sum, Is.EqualTo(expectedSum));
|
|
|
|
|
var rate = 2000.0;
|
|
|
|
|
var workerId = Guid.NewGuid().ToString();
|
|
|
|
|
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
|
.Returns([]);
|
|
|
|
|
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, new PostConfiguration() { Rate = rate }));
|
|
|
|
|
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
|
|
|
|
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
|
|
|
|
var sum = 0.0;
|
|
|
|
|
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
|
|
|
|
.Callback((SalaryDataModel x) =>
|
|
|
|
|
{
|
|
|
|
|
sum = x.Salary;
|
|
|
|
|
});
|
|
|
|
|
//Act
|
|
|
|
|
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.That(sum, Is.EqualTo(rate));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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.Assistant, 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)]);
|
|
|
|
|
////Act&Assert
|
|
|
|
|
//Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
|
|
|
|
var workerId = Guid.NewGuid().ToString();
|
|
|
|
|
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, new PostConfiguration() { Rate = 100 }));
|
|
|
|
|
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
|
|
|
|
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
|
|
|
|
//Act&Assert
|
|
|
|
|
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
@@ -290,28 +290,28 @@ internal class SalaryBusinessLogicContractTests
|
|
|
|
|
public void CalculateSalaryByMounth_WorkerStorageReturnNull_ThrowException_Test()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
//var workerId = 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(), workerId, null, DiscountType.None, false, [])]);
|
|
|
|
|
//_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 2000));
|
|
|
|
|
////Act&Assert
|
|
|
|
|
//Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
|
|
|
|
var workerId = 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(), workerId, null, DiscountType.None, false, [])]);
|
|
|
|
|
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, new PostConfiguration() { Rate = 100 }));
|
|
|
|
|
//Act&Assert
|
|
|
|
|
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<NullListException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CalculateSalaryByMounth_SaleStorageThrowException_ThrowException_Test()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
//var workerId = 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()));
|
|
|
|
|
//_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 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)]);
|
|
|
|
|
////Act&Assert
|
|
|
|
|
//Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
|
|
|
|
|
var workerId = 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()));
|
|
|
|
|
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, new PostConfiguration() { Rate = 100 }));
|
|
|
|
|
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
|
|
|
|
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
|
|
|
|
//Act&Assert
|
|
|
|
|
Assert.That(() => _salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow), Throws.TypeOf<StorageException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
@@ -333,14 +333,77 @@ internal class SalaryBusinessLogicContractTests
|
|
|
|
|
public void CalculateSalaryByMounth_WorkerStorageThrowException_ThrowException_Test()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
//var workerId = 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(), workerId, null, DiscountType.None, false, [])]);
|
|
|
|
|
//_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
// .Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, 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>());
|
|
|
|
|
var workerId = 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(), workerId, null, DiscountType.None, false, [])]);
|
|
|
|
|
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, new PostConfiguration() { Rate = 100 }));
|
|
|
|
|
_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 CalculateSalaryByMountht_WithCashierPostConfiguration_CalculateSalary_Test()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
var workerId = Guid.NewGuid().ToString();
|
|
|
|
|
var rate = 2000.0;
|
|
|
|
|
var percent = 0.1;
|
|
|
|
|
var bonus = 0.5;
|
|
|
|
|
var sales = new List<SaleDataModel>()
|
|
|
|
|
{
|
|
|
|
|
new(Guid.NewGuid().ToString(), workerId, null, DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
|
|
|
|
new(Guid.NewGuid().ToString(), workerId, null, DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)]),
|
|
|
|
|
new(Guid.NewGuid().ToString(), workerId, null, DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5000, 12)])
|
|
|
|
|
};
|
|
|
|
|
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()))
|
|
|
|
|
.Returns(sales);
|
|
|
|
|
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, new CashierPostConfiguration() { Rate = rate, SalePercent = percent, BonusForExtraSales = bonus }));
|
|
|
|
|
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(), It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
|
|
|
|
|
.Returns([new WorkerDataModel(workerId, "Test", Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow, false)]);
|
|
|
|
|
var sum = 0.0;
|
|
|
|
|
var expectedSum = rate + percent * (sales.Sum(x => x.Sum) / sales.Count) + sales.Where(x => x.Sum > _salaryConfigurationTest.ExtraSaleSum).Sum(x => x.Sum) * bonus;
|
|
|
|
|
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
|
|
|
|
.Callback((SalaryDataModel x) =>
|
|
|
|
|
{
|
|
|
|
|
sum = x.Salary;
|
|
|
|
|
});
|
|
|
|
|
//Act
|
|
|
|
|
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.That(sum, Is.EqualTo(expectedSum));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CalculateSalaryByMountht_WithSupervisorPostConfiguration_CalculateSalary_Test()
|
|
|
|
|
{
|
|
|
|
|
//Arrange
|
|
|
|
|
var workerId = Guid.NewGuid().ToString();
|
|
|
|
|
var rate = 2000.0;
|
|
|
|
|
var trend = 3;
|
|
|
|
|
var bonus = 100;
|
|
|
|
|
_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(), workerId, null, DiscountType.None, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5, 1.2)])]);
|
|
|
|
|
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
|
|
|
|
|
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name", PostType.Assistant, new SupervisorPostConfiguration() { Rate = rate, PersonalCountTrendPremium = bonus }));
|
|
|
|
|
_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)]);
|
|
|
|
|
_workerStorageContract.Setup(x => x.GetWorkerTrend(It.IsAny<DateTime>(), It.IsAny<DateTime>()))
|
|
|
|
|
.Returns(trend);
|
|
|
|
|
var sum = 0.0;
|
|
|
|
|
var expectedSum = rate + trend * bonus;
|
|
|
|
|
_salaryStorageContract.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
|
|
|
|
.Callback((SalaryDataModel x) =>
|
|
|
|
|
{
|
|
|
|
|
sum = x.Salary;
|
|
|
|
|
});
|
|
|
|
|
//Act
|
|
|
|
|
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow);
|
|
|
|
|
//Assert
|
|
|
|
|
Assert.That(sum, Is.EqualTo(expectedSum));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|