PiBD-23_Ivanov_D.A._LabWork2 #2

Open
145Game wants to merge 7 commits from LabWork2 into LabWork1
7 changed files with 152 additions and 208 deletions
Showing only changes of commit 5b336ae1ca - Show all commits

View File

@ -1,6 +1,5 @@
using North_Bridge_Contract.BusinessLogicsContracts;
using North_Bridge_Contract.DataModels;
using North_Bridge_Contract.Enums;
using North_Bridge_Contract.StoragesContracts;
using Microsoft.Extensions.Logging;
using North_Bridge_Contract.Exceptions;

View File

@ -22,7 +22,6 @@ public class SaleDataModel : IValidation
{
Id = id;
WorkerId = workerId;
SaleDate = DateTime.UtcNow;
Sum = sum;
IsCancel = isCancel;
Products = products;

View File

@ -35,12 +35,12 @@ internal class PostBusinessLogicContractTests
//Arrange
var listOriginal = new List<PostDataModel>()
{
new(Guid.NewGuid().ToString(),"name 1", PostType.Consultant,
10, true, DateTime.UtcNow),
new(Guid.NewGuid().ToString(), "name 2", PostType.Consultant,
10, false, DateTime.UtcNow),
new(Guid.NewGuid().ToString(), "name 3", PostType.Consultant,
10, true, DateTime.UtcNow),
new(Guid.NewGuid().ToString(),"name 1", PostType.Consultant,
10, true, DateTime.UtcNow),
new(Guid.NewGuid().ToString(), "name 2", PostType.Consultant,
10, false, DateTime.UtcNow),
new(Guid.NewGuid().ToString(), "name 3", PostType.Consultant,
10, true, DateTime.UtcNow),
};
_postStorageContract.Setup(x =>
x.GetList(It.IsAny<bool>())).Returns(listOriginal);
@ -96,8 +96,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
_postStorageContract.Setup(x =>
x.GetList(It.IsAny<bool>())).Throws(new StorageException(new
InvalidOperationException()));
x.GetList(It.IsAny<bool>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_postBusinessLogicContract.GetAllPosts(It.IsAny<bool>()),
@ -113,10 +112,10 @@ internal class PostBusinessLogicContractTests
var postId = Guid.NewGuid().ToString();
var listOriginal = new List<PostDataModel>()
{
new(postId, "name 1", PostType.Consultant, 10, true,
DateTime.UtcNow),
new(postId, "name 2", PostType.Consultant, 10, false,
DateTime.UtcNow)
new(postId, "name 1", PostType.Consultant, 10, true,
DateTime.UtcNow),
new(postId, "name 2", PostType.Consultant, 10, false,
DateTime.UtcNow)
};
_postStorageContract.Setup(x =>
x.GetPostWithHistory(It.IsAny<string>())).Returns(listOriginal);
@ -183,8 +182,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
_postStorageContract.Setup(x =>
x.GetPostWithHistory(It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
x.GetPostWithHistory(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_postBusinessLogicContract.GetAllDataOfPost(Guid.NewGuid().ToString()),
@ -274,11 +272,9 @@ internal class PostBusinessLogicContractTests
{
//Arrange
_postStorageContract.Setup(x =>
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
_postStorageContract.Setup(x =>
x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_postBusinessLogicContract.GetPostByData(Guid.NewGuid().ToString()),
@ -356,8 +352,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
_postStorageContract.Setup(x =>
x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new
InvalidOperationException()));
x.AddElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_postBusinessLogicContract.InsertPost(new(Guid.NewGuid().ToString(), "name",
@ -411,8 +406,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
_postStorageContract.Setup(x =>
x.UpdElement(It.IsAny<PostDataModel>())).Throws(new
ElementExistsException("Data", "Data"));
x.UpdElement(It.IsAny<PostDataModel>())).Throws(new ElementExistsException("Data", "Data"));
//Act&Assert
Assert.That(() =>
_postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "anme",
@ -448,8 +442,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
_postStorageContract.Setup(x =>
x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new
InvalidOperationException()));
x.UpdElement(It.IsAny<PostDataModel>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_postBusinessLogicContract.UpdatePost(new(Guid.NewGuid().ToString(), "name",
@ -518,8 +511,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
_postStorageContract.Setup(x =>
x.DelElement(It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_postBusinessLogicContract.DeletePost(Guid.NewGuid().ToString()),
@ -587,8 +579,7 @@ internal class PostBusinessLogicContractTests
{
//Arrange
_postStorageContract.Setup(x =>
x.ResElement(It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
x.ResElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_postBusinessLogicContract.RestorePost(Guid.NewGuid().ToString()),

View File

@ -35,17 +35,16 @@ internal class ProductBusinessLogicContractTests
//Arrange
var listOriginal = new List<ProductDataModel>()
{
new(Guid.NewGuid().ToString(), "name 1",
ProductType.SystemUnit , 10, false),
new(Guid.NewGuid().ToString(), "name 2",
ProductType.SystemUnit, 10, true),
new(Guid.NewGuid().ToString(), "name 3",
ProductType.SystemUnit, 10, false),
new(Guid.NewGuid().ToString(), "name 1",
ProductType.SystemUnit , 10, false),
new(Guid.NewGuid().ToString(), "name 2",
ProductType.SystemUnit, 10, true),
new(Guid.NewGuid().ToString(), "name 3",
ProductType.SystemUnit, 10, false),
};
_productStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Returns(listOriginal);
//Act
var listOnlyActive =
_productBusinessLogicContract.GetAllProducts(true);
var listOnlyActive = _productBusinessLogicContract.GetAllProducts(true);
var list = _productBusinessLogicContract.GetAllProducts(false);
//Assert
Assert.Multiple(() =>
@ -67,8 +66,7 @@ internal class ProductBusinessLogicContractTests
//Arrange
_productStorageContract.Setup(x => x.GetList(It.IsAny<bool>())).Returns([]);
//Act
var listOnlyActive =
_productBusinessLogicContract.GetAllProducts(true);
var listOnlyActive = _productBusinessLogicContract.GetAllProducts(true);
var list = _productBusinessLogicContract.GetAllProducts(false);
//Assert
Assert.Multiple(() =>
@ -110,15 +108,14 @@ internal class ProductBusinessLogicContractTests
var productId = Guid.NewGuid().ToString();
var listOriginal = new List<ProductHistoryDataModel>()
{
new(Guid.NewGuid().ToString(), 10),
new(Guid.NewGuid().ToString(), 15),
new(Guid.NewGuid().ToString(), 10),
new(Guid.NewGuid().ToString(), 10),
new(Guid.NewGuid().ToString(), 15),
new(Guid.NewGuid().ToString(), 10),
};
_productStorageContract.Setup(x =>
x.GetHistoryByProductId(It.IsAny<string>())).Returns(listOriginal);
//Act
var list =
_productBusinessLogicContract.GetProductHistoryByProduct(productId);
var list = _productBusinessLogicContract.GetProductHistoryByProduct(productId);
//Assert
Assert.That(list, Is.Not.Null);
Assert.That(list, Is.EquivalentTo(listOriginal));
@ -133,9 +130,7 @@ internal class ProductBusinessLogicContractTests
_productStorageContract.Setup(x =>
x.GetHistoryByProductId(It.IsAny<string>())).Returns([]);
//Act
var list =
_productBusinessLogicContract.GetProductHistoryByProduct(Guid.NewGuid().ToString(
));
var list = _productBusinessLogicContract.GetProductHistoryByProduct(Guid.NewGuid().ToString());
//Assert
Assert.That(list, Is.Not.Null);
Assert.That(list, Has.Count.EqualTo(0));
@ -174,8 +169,7 @@ internal class ProductBusinessLogicContractTests
{
//Act&Assert
Assert.That(() =>
_productBusinessLogicContract.GetProductHistoryByProduct(Guid.NewGuid().ToString(
)), Throws.TypeOf<NullListException>());
_productBusinessLogicContract.GetProductHistoryByProduct(Guid.NewGuid().ToString()), Throws.TypeOf<NullListException>());
_productStorageContract.Verify(x =>
x.GetHistoryByProductId(It.IsAny<string>()), Times.Once);
}
@ -190,8 +184,7 @@ internal class ProductBusinessLogicContractTests
InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_productBusinessLogicContract.GetProductHistoryByProduct(Guid.NewGuid().ToString(
)), Throws.TypeOf<StorageException>());
_productBusinessLogicContract.GetProductHistoryByProduct(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
_productStorageContract.Verify(x =>
x.GetHistoryByProductId(It.IsAny<string>()), Times.Once);
}
@ -275,11 +268,9 @@ internal class ProductBusinessLogicContractTests
{
//Arrange
_productStorageContract.Setup(x =>
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
_productStorageContract.Setup(x =>
x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_productBusinessLogicContract.GetProductByData(Guid.NewGuid().ToString()),
@ -321,8 +312,7 @@ internal class ProductBusinessLogicContractTests
{
//Arrange
_productStorageContract.Setup(x =>
x.AddElement(It.IsAny<ProductDataModel>())).Throws(new
ElementExistsException("Data", "Data"));
x.AddElement(It.IsAny<ProductDataModel>())).Throws(new ElementExistsException("Data", "Data"));
//Act&Assert
Assert.That(() =>
_productBusinessLogicContract.InsertProduct(new(Guid.NewGuid().ToString(),
@ -438,8 +428,7 @@ internal class ProductBusinessLogicContractTests
public void UpdateProduct_InvalidRecord_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new
ProductDataModel("id", "name", ProductType.SystemUnit,
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new ProductDataModel("id", "name", ProductType.SystemUnit,
10, false)), Throws.TypeOf<ValidationException>());
_productStorageContract.Verify(x =>
x.UpdElement(It.IsAny<ProductDataModel>()), Times.Never);

View File

@ -52,11 +52,9 @@ internal class SalaryBusinessLogicContractTests
var endDate = DateTime.UtcNow.AddDays(1);
var listOriginal = new List<SalaryDataModel>()
{
new(Guid.NewGuid().ToString(), DateTime.UtcNow, 10),
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(1),
14),
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(-1),
30),
new(Guid.NewGuid().ToString(), DateTime.UtcNow, 10),
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(1), 14),
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(-1), 30),
};
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(),
It.IsAny<DateTime>(), It.IsAny<string>())).Returns(listOriginal);
@ -119,8 +117,7 @@ internal class SalaryBusinessLogicContractTests
{
//Arrange
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(),
It.IsAny<DateTime>(), It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
It.IsAny<DateTime>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_salaryBusinessLogicContract.GetAllSalariesByPeriod(DateTime.UtcNow,
@ -138,17 +135,14 @@ internal class SalaryBusinessLogicContractTests
var workerId = Guid.NewGuid().ToString();
var listOriginal = new List<SalaryDataModel>()
{
new(Guid.NewGuid().ToString(), DateTime.UtcNow, 10),
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(1),
14),
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(-1),
30),
new(Guid.NewGuid().ToString(), DateTime.UtcNow, 10),
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(1), 14),
new(Guid.NewGuid().ToString(), DateTime.UtcNow.AddDays(-1), 30),
};
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(),
It.IsAny<DateTime>(), It.IsAny<string>())).Returns(listOriginal);
//Act
var list =
_salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(startDate, endDate,
var list = _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(startDate, endDate,
workerId);
//Assert
Assert.That(list, Is.Not.Null);
@ -164,8 +158,7 @@ internal class SalaryBusinessLogicContractTests
_salaryStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(),
It.IsAny<DateTime>(), It.IsAny<string>())).Returns([]);
//Act
var list =
_salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(DateTime.UtcNow,
var list = _salaryBusinessLogicContract.GetAllSalariesByPeriodByWorker(DateTime.UtcNow,
DateTime.UtcNow.AddDays(1), Guid.NewGuid().ToString());
//Assert
Assert.That(list, Is.Not.Null);
@ -286,14 +279,15 @@ internal class SalaryBusinessLogicContractTests
var worker1Id = Guid.NewGuid().ToString();
var worker2Id = Guid.NewGuid().ToString();
var worker3Id = Guid.NewGuid().ToString();
var list = new List<WorkerDataModel>() {
new(worker1Id, "Test","example@example.com", Guid.NewGuid().ToString(),
DateTime.UtcNow, DateTime.UtcNow, false),
new(worker2Id, "Test","example@example.com", Guid.NewGuid().ToString(),
DateTime.UtcNow, DateTime.UtcNow, false),
new(worker3Id, "Test","example@example.com", Guid.NewGuid().ToString(),
DateTime.UtcNow, DateTime.UtcNow, false)
};
var list = new List<WorkerDataModel>()
{
new(worker1Id, "Test","example@example.com", Guid.NewGuid().ToString(),
DateTime.UtcNow, DateTime.UtcNow, false),
new(worker2Id, "Test","example@example.com", Guid.NewGuid().ToString(),
DateTime.UtcNow, DateTime.UtcNow, false),
new(worker3Id, "Test","example@example.com", Guid.NewGuid().ToString(),
DateTime.UtcNow, DateTime.UtcNow, false)
};
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(),
It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Returns([new SaleDataModel(Guid.NewGuid().ToString(),
@ -419,8 +413,7 @@ internal class SalaryBusinessLogicContractTests
var workerId = Guid.NewGuid().ToString();
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime>(),
It.IsAny<DateTime>(), It.IsAny<string>(), It.IsAny<string>()))
.Throws(new StorageException(new
InvalidOperationException()));
.Throws(new StorageException(new InvalidOperationException()));
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Returns(new PostDataModel(Guid.NewGuid().ToString(), "name",
PostType.Consultant, 2000, true, DateTime.UtcNow));
@ -446,8 +439,7 @@ internal class SalaryBusinessLogicContractTests
.Returns([new SaleDataModel(Guid.NewGuid().ToString(),
workerId, 200, false, [])]);
_postStorageContract.Setup(x => x.GetElementById(It.IsAny<string>()))
.Throws(new StorageException(new
InvalidOperationException()));
.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?>()))
@ -475,8 +467,7 @@ internal class SalaryBusinessLogicContractTests
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<DateTime?>()))
.Throws(new StorageException(new
InvalidOperationException()));
.Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_salaryBusinessLogicContract.CalculateSalaryByMounth(DateTime.UtcNow),

View File

@ -35,14 +35,14 @@ internal class SaleBusinessLogicContractTests
var date = DateTime.UtcNow;
var listOriginal = new List<SaleDataModel>()
{
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false,
[new ProductForSaleDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), 5)]),
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false, []),
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false, []),
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false,
[new ProductForSaleDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), 5)]),
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false, []),
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false, []),
};
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
@ -63,8 +63,7 @@ internal class SaleBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>())).Returns([]);
//Act
var list =
_saleBusinessLogicContract.GetAllSalesByPeriod(DateTime.UtcNow,
var list = _saleBusinessLogicContract.GetAllSalesByPeriod(DateTime.UtcNow,
DateTime.UtcNow.AddDays(1));
//Assert
Assert.That(list, Is.Not.Null);
@ -135,8 +134,7 @@ internal class SaleBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
//Act
var list =
_saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(workerId, date,
var list = _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(workerId, date,
date.AddDays(1));
//Assert
Assert.That(list, Is.Not.Null);
@ -152,8 +150,7 @@ internal class SaleBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>())).Returns([]);
//Act
var list =
_saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(Guid.NewGuid().ToString(),
var list = _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(Guid.NewGuid().ToString(),
DateTime.UtcNow, DateTime.UtcNow.AddDays(1));
//Assert
Assert.That(list, Is.Not.Null);
@ -243,19 +240,18 @@ internal class SaleBusinessLogicContractTests
var productId = Guid.NewGuid().ToString();
var listOriginal = new List<SaleDataModel>()
{
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false,
[new ProductForSaleDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), 5)]),
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false, []),new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false, []),
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false,
[new ProductForSaleDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), 5)]),
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false, []),new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
10, false, []),
};
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>())).Returns(listOriginal);
//Act
var list =
_saleBusinessLogicContract.GetAllSalesByProductByPeriod(productId, date,
var list = _saleBusinessLogicContract.GetAllSalesByProductByPeriod(productId, date,
date.AddDays(1));
//Assert
Assert.That(list, Is.Not.Null);
@ -271,9 +267,8 @@ internal class SaleBusinessLogicContractTests
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>())).Returns([]);
//Act
var list =
_saleBusinessLogicContract.GetAllSalesByProductByPeriod(Guid.NewGuid().ToString()
, DateTime.UtcNow, DateTime.UtcNow.AddDays(1));
var list = _saleBusinessLogicContract.GetAllSalesByProductByPeriod(Guid.NewGuid().ToString(),
DateTime.UtcNow, DateTime.UtcNow.AddDays(1));
//Assert
Assert.That(list, Is.Not.Null);
Assert.That(list, Has.Count.EqualTo(0));
@ -345,12 +340,11 @@ internal class SaleBusinessLogicContractTests
{
//Arrange
_saleStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
It.IsAny<DateTime?>(), It.IsAny<string>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_saleBusinessLogicContract.GetAllSalesByProductByPeriod(Guid.NewGuid().ToString()
, DateTime.UtcNow, DateTime.UtcNow.AddDays(1)),
_saleBusinessLogicContract.GetAllSalesByProductByPeriod(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>()), Times.Once);

View File

@ -35,22 +35,21 @@ internal class WorkerBusinessLogicContractTests
//Arrange
var listOriginal = new List<WorkerDataModel>()
{
new(Guid.NewGuid().ToString(), "fio 1", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 2", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
true),
new(Guid.NewGuid().ToString(), "fio 3", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 1", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 2", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
true),
new(Guid.NewGuid().ToString(), "fio 3", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
};
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
//Act
var listOnlyActive =
_workerBusinessLogicContract.GetAllWorkers(true);
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkers(true);
var list = _workerBusinessLogicContract.GetAllWorkers(false);
//Assert
Assert.Multiple(() =>
@ -74,8 +73,7 @@ internal class WorkerBusinessLogicContractTests
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns([]);
//Act
var listOnlyActive =
_workerBusinessLogicContract.GetAllWorkers(true);
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkers(true);
var list = _workerBusinessLogicContract.GetAllWorkers(false);
//Assert
Assert.Multiple(() =>
@ -124,22 +122,21 @@ internal class WorkerBusinessLogicContractTests
var postId = Guid.NewGuid().ToString();
var listOriginal = new List<WorkerDataModel>()
{
new(Guid.NewGuid().ToString(), "fio 1", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 2", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
true),
new(Guid.NewGuid().ToString(), "fio 3", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 1", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 2", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
true),
new(Guid.NewGuid().ToString(), "fio 3", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
};
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
//Act
var listOnlyActive =
_workerBusinessLogicContract.GetAllWorkersByPost(postId, true);
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByPost(postId, true);
var list = _workerBusinessLogicContract.GetAllWorkersByPost(postId,
false);
//Assert
@ -164,11 +161,9 @@ internal class WorkerBusinessLogicContractTests
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns([]);
//Act
var listOnlyActive =
_workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(),
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(),
true);
var list =
_workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(),
var list = _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(),
false);
//Assert
Assert.Multiple(() =>
@ -246,25 +241,23 @@ internal class WorkerBusinessLogicContractTests
var date = DateTime.UtcNow;
var listOriginal = new List<WorkerDataModel>()
{
new(Guid.NewGuid().ToString(), "fio 1", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 2", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
true),
new(Guid.NewGuid().ToString(), "fio 3", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 1", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 2", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
true),
new(Guid.NewGuid().ToString(), "fio 3", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
};
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
//Act
var listOnlyActive =
_workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddDays(1),
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddDays(1),
true);
var list =
_workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddDays(1),
var list = _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddDays(1),
false);
//Assert
Assert.Multiple(() =>
@ -288,8 +281,7 @@ internal class WorkerBusinessLogicContractTests
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns([]);
//Act
var listOnlyActive =
_workerBusinessLogicContract.GetAllWorkersByBirthDate(DateTime.UtcNow,
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByBirthDate(DateTime.UtcNow,
DateTime.UtcNow.AddDays(1), true);
var list = _workerBusinessLogicContract.GetAllWorkers(false);
//Assert
@ -362,25 +354,23 @@ internal class WorkerBusinessLogicContractTests
var date = DateTime.UtcNow;
var listOriginal = new List<WorkerDataModel>()
{
new(Guid.NewGuid().ToString(), "fio 1", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 2", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
true),
new(Guid.NewGuid().ToString(), "fio 3", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 1", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
new(Guid.NewGuid().ToString(), "fio 2", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
true),
new(Guid.NewGuid().ToString(), "fio 3", "example@example.com",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now,
false),
};
_workerStorageContract.Setup(x => x.GetList(It.IsAny<bool>(),
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns(listOriginal);
//Act
var listOnlyActive =
_workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date.AddDays(1),
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date.AddDays(1),
true);
var list =
_workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date.AddDays(1),
var list = _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date.AddDays(1),
false);
//Assert
Assert.Multiple(() =>
@ -404,16 +394,14 @@ internal class WorkerBusinessLogicContractTests
It.IsAny<string?>(), It.IsAny<DateTime?>(), It.IsAny<DateTime?>(),
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Returns([]);
//Act
var listOnlyActive =
_workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow,
var listOnlyActive = _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow,
DateTime.UtcNow.AddDays(1), true);
var list =
_workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow,
var list = _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow,
DateTime.UtcNow.AddDays(1), false);
//Assert
Assert.Multiple(() =>
{
Assert.That(listOnlyActive, Is.Not.Null);
Assert.That(listOnlyActive, Is.Not.Null);
Assert.That(list, Is.Not.Null);
Assert.That(listOnlyActive, Has.Count.EqualTo(0));
Assert.That(list, Has.Count.EqualTo(0));
@ -463,8 +451,7 @@ internal class WorkerBusinessLogicContractTests
//Arrange
_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()));
It.IsAny<DateTime?>(), It.IsAny<DateTime?>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow,
@ -559,11 +546,9 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
_workerStorageContract.Setup(x =>
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
_workerStorageContract.Setup(x =>
x.GetElementByFIO(It.IsAny<string>())).Throws(new StorageException(new
InvalidOperationException()));
x.GetElementByFIO(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_workerBusinessLogicContract.GetWorkerByData(Guid.NewGuid().ToString()),
@ -607,8 +592,7 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
_workerStorageContract.Setup(x =>
x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new
ElementExistsException("Data", "Data"));
x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new ElementExistsException("Data", "Data"));
//Act&Assert
Assert.That(() =>
_workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "fio", "example@example.com",
@ -632,9 +616,9 @@ internal class WorkerBusinessLogicContractTests
public void InsertWorker_InvalidRecord_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new
WorkerDataModel("id", "fio", "example@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-
16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ValidationException>());
Assert.That(() => _workerBusinessLogicContract.InsertWorker(new WorkerDataModel("id",
"fio", "example@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18)
.AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ValidationException>());
_workerStorageContract.Verify(x =>
x.AddElement(It.IsAny<WorkerDataModel>()), Times.Never);
}
@ -644,8 +628,7 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
_workerStorageContract.Setup(x =>
x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new
InvalidOperationException()));
x.AddElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "fio", "example@example.com",
@ -667,10 +650,10 @@ internal class WorkerBusinessLogicContractTests
x.UpdElement(It.IsAny<WorkerDataModel>()))
.Callback((WorkerDataModel x) =>
{
flag = x.Id == record.Id && x.FIO == record.FIO && x.Email == record.Email &&
x.PostId == record.PostId && x.BirthDate == record.BirthDate &&
x.EmploymentDate == record.EmploymentDate &&
x.IsDeleted == record.IsDeleted;
flag = x.Id == record.Id && x.FIO == record.FIO && x.Email == record.Email &&
x.PostId == record.PostId && x.BirthDate == record.BirthDate &&
x.EmploymentDate == record.EmploymentDate &&
x.IsDeleted == record.IsDeleted;
});
//Act
_workerBusinessLogicContract.UpdateWorker(record);
@ -685,8 +668,7 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
_workerStorageContract.Setup(x =>
x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new
ElementNotFoundException(""));
x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new ElementNotFoundException(""));
//Act&Assert
Assert.That(() =>
_workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "fio", "example@example.com",
@ -711,8 +693,8 @@ internal class WorkerBusinessLogicContractTests
{
//Act&Assert
Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new
WorkerDataModel("id", "fio", "example@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(
-16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ValidationException>());
WorkerDataModel("id", "fio", "example@example.com", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18)
.AddDays(-1), DateTime.Now, false)), Throws.TypeOf<ValidationException>());
_workerStorageContract.Verify(x =>
x.UpdElement(It.IsAny<WorkerDataModel>()), Times.Never);
}
@ -722,8 +704,7 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
_workerStorageContract.Setup(x =>
x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new
InvalidOperationException()));
x.UpdElement(It.IsAny<WorkerDataModel>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() =>
_workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "fio", "example@example.com",
@ -739,8 +720,8 @@ internal class WorkerBusinessLogicContractTests
//Arrange
var id = Guid.NewGuid().ToString();
var flag = false;
_workerStorageContract.Setup(x => x.DelElement(It.Is((string x) => x
== id))).Callback(() => { flag = true; });
_workerStorageContract.Setup(x => x.DelElement(It.Is((string x) => x== id)))
.Callback(() => { flag = true; });
//Act
_workerBusinessLogicContract.DeleteWorker(id);
//Assert
@ -754,8 +735,8 @@ internal class WorkerBusinessLogicContractTests
{
//Arrange
var id = Guid.NewGuid().ToString();
_workerStorageContract.Setup(x => x.DelElement(It.Is((string x) => x
!= id))).Throws(new ElementNotFoundException(id));
_workerStorageContract.Setup(x => x.DelElement(It.Is((string x) => x != id)))
.Throws(new ElementNotFoundException(id));
//Act&Assert
Assert.That(() =>
_workerBusinessLogicContract.DeleteWorker(Guid.NewGuid().ToString()),