diff --git a/PuferFishContracts/PuferFishBusinessLogic/Implementations/PointsBusinessLogicContract.cs b/PuferFishContracts/PuferFishBusinessLogic/Implementations/PointsBusinessLogicContract.cs index b8b9386..4467b9b 100644 --- a/PuferFishContracts/PuferFishBusinessLogic/Implementations/PointsBusinessLogicContract.cs +++ b/PuferFishContracts/PuferFishBusinessLogic/Implementations/PointsBusinessLogicContract.cs @@ -6,28 +6,63 @@ using System.Threading.Tasks; using Microsoft.Extensions.Logging; using PuferFishContracts.BusinessLogicsContracts; using PuferFishContracts.DataModels; +using PuferFishContracts.Exceptions; +using PuferFishContracts.Extensions; using PuferFishContracts.StoragesContracts; namespace PuferFishBusinessLogic.Implementations; -internal class PointsBusinessLogicContract(IPointsStorageContract pointsStorageContract, ISaleStorageContract saleStorageContract, IPostStorageContract -postStorageContract, IBuyerStorageContract buyerStorageContract, ILogger logger) : IPointsBusinessLogicContract +internal class PointsBusinessLogicContract(IPointsStorageContract pointsStorageContract, ISaleStorageContract saleStorageContract, IBuyerStorageContract buyerStorageContract, ILogger logger) : IPointsBusinessLogicContract { private readonly ILogger _logger = logger; private readonly IPointsStorageContract _pointsStorageContract = pointsStorageContract; private readonly ISaleStorageContract _saleStorageContract = saleStorageContract; - private readonly IPostStorageContract _postStorageContract = postStorageContract; + //private readonly IPostStorageContract _postStorageContract = postStorageContract; private readonly IBuyerStorageContract _buyerStorageContract = buyerStorageContract; - public List GetAllPointsByPeriod(DateTime fromDate, - DateTime toDate) + public List GetAllPointsByPeriod(DateTime fromDate, DateTime toDate) { - return []; + _logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}", + fromDate, toDate); + if (fromDate.IsDateNotOlder(toDate)) + { + throw new IncorrectDatesException(fromDate, toDate); + } + return _pointsStorageContract.GetList(fromDate, toDate) ?? throw new + NullListException(); } public List GetAllPointsByPeriodByBuyer(DateTime fromDate, DateTime toDate, string buyerId) { - return []; + if (fromDate.IsDateNotOlder(toDate)) + { + throw new IncorrectDatesException(fromDate, toDate); + } + if (buyerId.IsEmpty()) + { + throw new ArgumentNullException(nameof(buyerId)); + } + if (!buyerId.IsGuid()) + { + throw new ValidationException("The value in the field buyerId is not a unique identifier."); + } + _logger.LogInformation("GetAllSalaries params: {fromDate}, {toDate}, { buyerId}", fromDate, toDate, buyerId); + return _pointsStorageContract.GetList(fromDate, toDate, buyerId) ?? + throw new NullListException(); } public void CalculatePointsByMounth(DateTime date) { + _logger.LogInformation("CalculatePointsByMonth: {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 buyers = _buyerStorageContract.GetList() ?? throw new NullListException(); + + foreach (var buyer in buyers) + { + var points = buyer.Points; + + _logger.LogDebug("The buyer {buyerId} was awarded {points} points", buyer.Id, points); + + _pointsStorageContract.AddElement(new PointsDataModel(buyer.Id, finishDate, points)); + } } } diff --git a/PuferFishContracts/PuferFishBusinessLogic/Implementations/PostBusinessLogicContract.cs b/PuferFishContracts/PuferFishBusinessLogic/Implementations/PostBusinessLogicContract.cs index 7afc413..1bb0b24 100644 --- a/PuferFishContracts/PuferFishBusinessLogic/Implementations/PostBusinessLogicContract.cs +++ b/PuferFishContracts/PuferFishBusinessLogic/Implementations/PostBusinessLogicContract.cs @@ -2,11 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using PuferFishContracts.BusinessLogicsContracts; using PuferFishContracts.DataModels; using PuferFishContracts.Enums; +using PuferFishContracts.Exceptions; +using PuferFishContracts.Extensions; using PuferFishContracts.StoragesContracts; namespace PuferFishBusinessLogic.Implementations; @@ -18,26 +21,80 @@ internal class PostBusinessLogicContract(IPostStorageContract postStorageContrac postStorageContract; public List GetAllPosts(bool onlyActive = true) { - return []; + _logger.LogInformation("GetAllPosts params: {onlyActive}", + onlyActive); + return _postStorageContract.GetList(onlyActive) ?? throw new + NullListException(); } public List GetAllDataOfPost(string postId) { - return []; + _logger.LogInformation("GetAllDataOfPost for {postId}", postId); + if (postId.IsEmpty()) + { + throw new ArgumentNullException(nameof(postId)); + } + if (!postId.IsGuid()) + { + throw new ValidationException("The value in the field postId is not a unique identifier."); + } + return _postStorageContract.GetPostWithHistory(postId) ?? throw new + NullListException(); } public PostDataModel GetPostByData(string data) { - return new("", "", PostType.None, true, DateTime.UtcNow); + _logger.LogInformation("Get element by data: {data}", data); + if (data.IsEmpty()) + { + throw new ArgumentNullException(nameof(data)); + } + if (data.IsGuid()) + { + return _postStorageContract.GetElementById(data) ?? throw new + ElementNotFoundException(data); + } + return _postStorageContract.GetElementByName(data) ?? throw new + ElementNotFoundException(data); } public void InsertPost(PostDataModel postDataModel) { + _logger.LogInformation("New data: {json}", + JsonSerializer.Serialize(postDataModel)); + ArgumentNullException.ThrowIfNull(postDataModel); + postDataModel.Validate(); + _postStorageContract.AddElement(postDataModel); } public void UpdatePost(PostDataModel postDataModel) { + _logger.LogInformation("Update data: {json}", + JsonSerializer.Serialize(postDataModel)); + ArgumentNullException.ThrowIfNull(postDataModel); + postDataModel.Validate(); + _postStorageContract.UpdElement(postDataModel); } public void DeletePost(string id) { + _logger.LogInformation("Delete by id: {id}", id); + if (id.IsEmpty()) + { + throw new ArgumentNullException(nameof(id)); + } + if (!id.IsGuid()) + { + throw new ValidationException("Id is not a unique identifier"); + } + _postStorageContract.DelElement(id); } public void RestorePost(string id) { + _logger.LogInformation("Restore by id: {id}", id); + if (id.IsEmpty()) + { + throw new ArgumentNullException(nameof(id)); + } + if (!id.IsGuid()) + { + throw new ValidationException("Id is not a unique identifier"); + } + _postStorageContract.ResElement(id); } -} +} \ No newline at end of file diff --git a/PuferFishContracts/PuferFishBusinessLogic/Implementations/ProductBusinessLogicContract.cs b/PuferFishContracts/PuferFishBusinessLogic/Implementations/ProductBusinessLogicContract.cs index 51529d2..f6962e5 100644 --- a/PuferFishContracts/PuferFishBusinessLogic/Implementations/ProductBusinessLogicContract.cs +++ b/PuferFishContracts/PuferFishBusinessLogic/Implementations/ProductBusinessLogicContract.cs @@ -2,11 +2,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using PuferFishContracts.BusinessLogicsContracts; using PuferFishContracts.DataModels; using PuferFishContracts.Enums; +using PuferFishContracts.Exceptions; +using PuferFishContracts.Extensions; using PuferFishContracts.StoragesContracts; namespace PuferFishBusinessLogic.Implementations; @@ -14,33 +17,70 @@ namespace PuferFishBusinessLogic.Implementations; internal class ProductBusinessLogicContract(IProductStorageContract productStorageContract, ILogger logger) : IProductBusinessLogicContract { private readonly ILogger _logger = logger; - private readonly IProductStorageContract _productStorageContract = -productStorageContract; + private readonly IProductStorageContract _productStorageContract = productStorageContract; public List GetAllProducts(bool onlyActive) { - return []; - } - public List GetAllProductsByManufacturer(string - manufacturerId, bool onlyActive = true) - { - return []; + _logger.LogInformation("GetAllProducts params: {onlyActive}", onlyActive); + return _productStorageContract.GetList(onlyActive) ?? throw new NullListException(); } public List GetProductHistoryByProduct(string productId) { - return []; + _logger.LogInformation("GetProductHistoryByProduct for {productId}", + productId); + if (productId.IsEmpty()) + { + throw new ArgumentNullException(nameof(productId)); + } + if (!productId.IsGuid()) + { + throw new ValidationException("The value in the field productId is not a unique identifier."); + } + return _productStorageContract.GetHistoryByProductId(productId) ?? + throw new NullListException(); } public ProductDataModel GetProductByData(string data) { - return new("", "", ProductType.None, 0, true); + _logger.LogInformation("Get element by data: {data}", data); + if (data.IsEmpty()) + { + throw new ArgumentNullException(nameof(data)); + } + if (data.IsGuid()) + { + return _productStorageContract.GetElementById(data) ?? throw + new ElementNotFoundException(data); + } + return _productStorageContract.GetElementByName(data) ?? throw new + ElementNotFoundException(data); } public void InsertProduct(ProductDataModel productDataModel) { + _logger.LogInformation("New data: {json}", + JsonSerializer.Serialize(productDataModel)); + ArgumentNullException.ThrowIfNull(productDataModel); + productDataModel.Validate(); + _productStorageContract.AddElement(productDataModel); } public void UpdateProduct(ProductDataModel productDataModel) { + _logger.LogInformation("Update data: {json}", + JsonSerializer.Serialize(productDataModel)); + ArgumentNullException.ThrowIfNull(productDataModel); + productDataModel.Validate(); + _productStorageContract.UpdElement(productDataModel); } public void DeleteProduct(string id) { + _logger.LogInformation("Delete by id: {id}", id); + if (id.IsEmpty()) + { + throw new ArgumentNullException(nameof(id)); + } + if (!id.IsGuid()) + { + throw new ValidationException("Id is not a unique identifier"); + } + _productStorageContract.DelElement(id); } } diff --git a/PuferFishContracts/PuferFishBusinessLogic/Implementations/SaleBusinessLogicContract.cs b/PuferFishContracts/PuferFishBusinessLogic/Implementations/SaleBusinessLogicContract.cs index 989c67a..f8596a4 100644 --- a/PuferFishContracts/PuferFishBusinessLogic/Implementations/SaleBusinessLogicContract.cs +++ b/PuferFishContracts/PuferFishBusinessLogic/Implementations/SaleBusinessLogicContract.cs @@ -2,10 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using PuferFishContracts.BusinessLogicsContracts; using PuferFishContracts.DataModels; +using PuferFishContracts.Exceptions; +using PuferFishContracts.Extensions; using PuferFishContracts.StoragesContracts; namespace PuferFishBusinessLogic.Implementations; @@ -18,31 +21,105 @@ internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContrac public List GetAllSalesByPeriod(DateTime fromDate, DateTime toDate) { - return []; + _logger.LogInformation("GetAllSales params: {fromDate}, {toDate}", + fromDate, toDate); + if (fromDate.IsDateNotOlder(toDate)) + { + throw new IncorrectDatesException(fromDate, toDate); + } + return _saleStorageContract.GetList(fromDate, toDate) ?? throw new + NullListException(); } public List GetAllSalesByWorkerByPeriod(string workerId, DateTime fromDate, DateTime toDate) { - return []; + _logger.LogInformation("GetAllSales params: {workerId}, {fromDate}, { toDate}", workerId, fromDate, toDate); + if (fromDate.IsDateNotOlder(toDate)) + { + throw new IncorrectDatesException(fromDate, toDate); + } + if (workerId.IsEmpty()) + { + throw new ArgumentNullException(nameof(workerId)); + } + if (!workerId.IsGuid()) + { + throw new ValidationException("The value in the field workerId is not a unique identifier."); + } + return _saleStorageContract.GetList(fromDate, toDate, workerId: + workerId) ?? throw new NullListException(); } - public List GetAllSalesByBuyerByPeriod(string? buyerId, + public List GetAllSalesByBuyerByPeriod(string buyerId, DateTime fromDate, DateTime toDate) { - return []; + _logger.LogInformation("GetAllSales params: {buyerId}, {fromDate}, { toDate}", buyerId, fromDate, toDate); + if (fromDate.IsDateNotOlder(toDate)) + { + throw new IncorrectDatesException(fromDate, toDate); + } + if (buyerId.IsEmpty()) + { + throw new ArgumentNullException(nameof(buyerId)); + } + if (!buyerId.IsGuid()) + { + throw new ValidationException("The value in the field buyerId is not a unique identifier."); + } + return _saleStorageContract.GetList(fromDate, toDate, buyerId: + buyerId) ?? throw new NullListException(); } public List GetAllSalesByProductByPeriod(string productId, DateTime fromDate, DateTime toDate) { - return []; + _logger.LogInformation("GetAllSales params: {productId}, {fromDate}, { toDate}", productId, fromDate, toDate); + if (fromDate.IsDateNotOlder(toDate)) + { + throw new IncorrectDatesException(fromDate, toDate); + } + if (productId.IsEmpty()) + { + throw new ArgumentNullException(nameof(productId)); + } + if (!productId.IsGuid()) + { + throw new ValidationException("The value in the field productId is not a unique identifier."); + } + return _saleStorageContract.GetList(fromDate, toDate, productId: + productId) ?? throw new NullListException(); } public SaleDataModel GetSaleByData(string data) { - return new("", "", "", 0, 0, false, []); + _logger.LogInformation("Get element by data: {data}", data); + if (data.IsEmpty()) + { + throw new ArgumentNullException(nameof(data)); + } + if (!data.IsGuid()) + { + throw new ValidationException("Id is not a unique identifier"); + } + return _saleStorageContract.GetElementById(data) ?? throw new + ElementNotFoundException(data); } public void InsertSale(SaleDataModel saleDataModel) { + _logger.LogInformation("New data: {json}", +JsonSerializer.Serialize(saleDataModel)); + ArgumentNullException.ThrowIfNull(saleDataModel); + saleDataModel.Validate(); + _saleStorageContract.AddElement(saleDataModel); } public void CancelSale(string id) { + _logger.LogInformation("Cancel by id: {id}", id); + if (id.IsEmpty()) + { + throw new ArgumentNullException(nameof(id)); + } + if (!id.IsGuid()) + { + throw new ValidationException("Id is not a unique identifier"); + } + _saleStorageContract.DelElement(id); } -} +} \ No newline at end of file diff --git a/PuferFishContracts/PuferFishBusinessLogic/Implementations/WorkerBusinessLogicContract.cs b/PuferFishContracts/PuferFishBusinessLogic/Implementations/WorkerBusinessLogicContract.cs index e711a47..510aa61 100644 --- a/PuferFishContracts/PuferFishBusinessLogic/Implementations/WorkerBusinessLogicContract.cs +++ b/PuferFishContracts/PuferFishBusinessLogic/Implementations/WorkerBusinessLogicContract.cs @@ -2,10 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using PuferFishContracts.BusinessLogicsContracts; using PuferFishContracts.DataModels; +using PuferFishContracts.Exceptions; +using PuferFishContracts.Extensions; using PuferFishContracts.StoragesContracts; namespace PuferFishBusinessLogic.Implementations; @@ -17,31 +20,90 @@ internal class WorkerBusinessLogicContract(IWorkerStorageContract workerStorageC workerStorageContract; public List GetAllWorkers(bool onlyActive = true) { - return []; + _logger.LogInformation("GetAllWorkers params: {onlyActive}", + onlyActive); + return _workerStorageContract.GetList(onlyActive) ?? throw new + NullListException(); } - public List GetAllWorkersByPost(string postId, bool onlyActive = true) + public List GetAllWorkersByPost(string postId, bool + onlyActive = true) { - return []; + _logger.LogInformation("GetAllWorkers params: {postId}, { onlyActive},", postId, onlyActive); + if (postId.IsEmpty()) + { + throw new ArgumentNullException(nameof(postId)); + } + if (!postId.IsGuid()) + { + throw new ValidationException("The value in the field postId is not a unique identifier."); + } + return _workerStorageContract.GetList(onlyActive, postId) ?? throw +new NullListException(); } - public List GetAllWorkersByBirthDate(DateTime fromDate, DateTime toDate, bool onlyActive = true) + public List GetAllWorkersByBirthDate(DateTime fromDate, + DateTime toDate, bool onlyActive = true) { - return []; + _logger.LogInformation("GetAllWorkers params: {onlyActive}, { fromDate}, { toDate} ", onlyActive, fromDate, toDate); + if (fromDate.IsDateNotOlder(toDate)) + { + throw new IncorrectDatesException(fromDate, toDate); + } + return _workerStorageContract.GetList(onlyActive, fromBirthDate: + fromDate, toBirthDate: toDate) ?? throw new NullListException(); } - public List GetAllWorkersByEmploymentDate(DateTime fromDate, DateTime toDate, bool onlyActive = true) + public List GetAllWorkersByEmploymentDate(DateTime + fromDate, DateTime toDate, bool onlyActive = true) { - return []; + _logger.LogInformation("GetAllWorkers params: {onlyActive}, { fromDate}, { toDate}", onlyActive, fromDate, toDate); + if (fromDate.IsDateNotOlder(toDate)) + { + throw new IncorrectDatesException(fromDate, toDate); + } + return _workerStorageContract.GetList(onlyActive, fromEmploymentDate: + fromDate, toEmploymentDate: toDate) ?? throw new NullListException(); } public WorkerDataModel GetWorkerByData(string data) { - return new("", "", "", DateTime.Now, DateTime.Now, true); + _logger.LogInformation("Get element by data: {data}", data); + if (data.IsEmpty()) + { + throw new ArgumentNullException(nameof(data)); + } + if (data.IsGuid()) + { + return _workerStorageContract.GetElementById(data) ?? throw + new ElementNotFoundException(data); + } + return _workerStorageContract.GetElementByFIO(data) ?? throw new + ElementNotFoundException(data); } public void InsertWorker(WorkerDataModel workerDataModel) { + _logger.LogInformation("New data: {json}", + JsonSerializer.Serialize(workerDataModel)); + ArgumentNullException.ThrowIfNull(workerDataModel); + workerDataModel.Validate(); + _workerStorageContract.AddElement(workerDataModel); } public void UpdateWorker(WorkerDataModel workerDataModel) { + _logger.LogInformation("Update data: {json}", + JsonSerializer.Serialize(workerDataModel)); + ArgumentNullException.ThrowIfNull(workerDataModel); + workerDataModel.Validate(); + _workerStorageContract.UpdElement(workerDataModel); } public void DeleteWorker(string id) { + _logger.LogInformation("Delete by id: {id}", id); + if (id.IsEmpty()) + { + throw new ArgumentNullException(nameof(id)); + } + if (!id.IsGuid()) + { + throw new ValidationException("Id is not a unique identifier"); + } + _workerStorageContract.DelElement(id); } } diff --git a/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/BuyerBusinessLogicContractTests.cs b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/BuyerBusinessLogicContractTests.cs index 7d69db0..4d72150 100644 --- a/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/BuyerBusinessLogicContractTests.cs +++ b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/BuyerBusinessLogicContractTests.cs @@ -120,8 +120,7 @@ new(Guid.NewGuid().ToString(), "fio 3", "+7-777-777-7777", 0),}; _buyerStorageContract.Setup(x => x.GetElementByPhoneNumber(phoneNumber)).Returns(record); //Act - var element = -_buyerBusinessLogicContract.GetBuyerByData(phoneNumber); + var element = _buyerBusinessLogicContract.GetBuyerByData(phoneNumber); //Assert Assert.That(element, Is.Not.Null); Assert.That(element.PhoneNumber, Is.EqualTo(phoneNumber)); diff --git a/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/PointsBusinessLogicContractTests.cs b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/PointsBusinessLogicContractTests.cs new file mode 100644 index 0000000..a3af953 --- /dev/null +++ b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/PointsBusinessLogicContractTests.cs @@ -0,0 +1,295 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Moq; +using PuferFishBusinessLogic.Implementations; +using PuferFishContracts.DataModels; +using PuferFishContracts.Enums; +using PuferFishContracts.Exceptions; +using PuferFishContracts.StoragesContracts; + +namespace PuferFishTests.BusinessLogicsContractsTests; + +[TestFixture] +internal class PointsBusinessLogicContractTests +{ + + private PointsBusinessLogicContract _pointsBusinessLogicContract; + + private Mock _pointsStorageContract; + private Mock _saleStorageContract; + private Mock _buyerStorageContract; + + + [OneTimeSetUp] + public void OneTimeSetUp() + { + _pointsStorageContract = new Mock(); + _buyerStorageContract = new Mock(); + _saleStorageContract = new Mock(); + + _pointsBusinessLogicContract = new PointsBusinessLogicContract(_pointsStorageContract.Object, _saleStorageContract.Object, _buyerStorageContract.Object, new Mock().Object); + } + + [SetUp] + public void SetUp() + { + _pointsStorageContract.Reset(); + } + + [Test] + public void GetAllPoints_ReturnListOfRecords_Test() + { + // Arrange + var startDate = DateTime.UtcNow; + var endDate = DateTime.UtcNow.AddDays(1); + var listOriginal = new List + { + 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), + }; + _pointsStorageContract.Setup(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny())).Returns(listOriginal); + + // Act + var list = _pointsBusinessLogicContract.GetAllPointsByPeriod(startDate, endDate); + + // Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Is.EquivalentTo(listOriginal)); + _pointsStorageContract.Verify(x => x.GetList(startDate, endDate, null), Times.Once); + } + + [Test] + public void GetAllPoints_ReturnEmptyList_Test() + { + // Arrange + _pointsStorageContract.Setup(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny())).Returns(new List()); + + // Act + var list = _pointsBusinessLogicContract.GetAllPointsByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)); + + // Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Has.Count.EqualTo(0)); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Test] + public void GetAllPoints_IncorrectDates_ThrowException_Test() + { + // Arrange + var dateTime = DateTime.UtcNow; + + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriod(dateTime, dateTime), Throws.TypeOf()); + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriod(dateTime, dateTime.AddSeconds(-1)), Throws.TypeOf()); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + } + + [Test] + public void GetAllPoints_ReturnNull_ThrowException_Test() + { + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Test] + public void GetAllPoints_StorageThrowError_ThrowException_Test() + { + // Arrange + _pointsStorageContract.Setup(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Test] + public void GetAllPointsByBuyer_ReturnListOfRecords_Test() + { + // Arrange + var startDate = DateTime.UtcNow; + var endDate = DateTime.UtcNow.AddDays(1); + var buyerId = Guid.NewGuid().ToString(); + var listOriginal = new List + { + 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), + }; + _pointsStorageContract.Setup(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny())).Returns(listOriginal); + + // Act + var list = _pointsBusinessLogicContract.GetAllPointsByPeriodByBuyer(startDate, endDate, buyerId); + + // Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Is.EquivalentTo(listOriginal)); + _pointsStorageContract.Verify(x => x.GetList(startDate, endDate, buyerId), Times.Once); + } + + [Test] + public void GetAllPointsByBuyer_ReturnEmptyList_Test() + { + // Arrange + _pointsStorageContract.Setup(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny())).Returns(new List()); + + // Act + var list = _pointsBusinessLogicContract.GetAllPointsByPeriodByBuyer(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), Guid.NewGuid().ToString()); + + // Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Has.Count.EqualTo(0)); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Test] + public void GetAllPointsByBuyer_IncorrectDates_ThrowException_Test() + { + // Arrange + var dateTime = DateTime.UtcNow; + + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriodByBuyer(dateTime, dateTime, Guid.NewGuid().ToString()), Throws.TypeOf()); + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriodByBuyer(dateTime, dateTime.AddSeconds(-1), Guid.NewGuid().ToString()), Throws.TypeOf()); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + } + + [Test] + public void GetAllPointsByBuyer_BuyerIdIsNUllOrEmpty_ThrowException_Test() + { + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriodByBuyer(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), null), Throws.TypeOf()); + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriodByBuyer(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), string.Empty), Throws.TypeOf()); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + } + + [Test] + public void GetAllPointsByBuyer_BuyerIdIsNotGuid_ThrowException_Test() + { + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriodByBuyer(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), "buyerId"), Throws.TypeOf()); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + } + + [Test] + public void GetAllPointsByBuyer_ReturnNull_ThrowException_Test() + { + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriodByBuyer(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), Guid.NewGuid().ToString()), Throws.TypeOf()); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Test] + public void GetAllPointsByBuyer_StorageThrowError_ThrowException_Test() + { + // Arrange + _pointsStorageContract.Setup(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny())).Throws(new StorageException(new InvalidOperationException())); + + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.GetAllPointsByPeriodByBuyer(DateTime.UtcNow, DateTime.UtcNow.AddDays(1), Guid.NewGuid().ToString()), Throws.TypeOf()); + _pointsStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [Test] + public void CalculatePointsByMonth_CalculatePoints_Test() + { + // Arrange + var buyerId = Guid.NewGuid().ToString(); + var expectedPoints = 100.0; // Ожидаемое количество баллов + + // Установим значение Points для покупателя равным expectedPoints + _buyerStorageContract.Setup(x => x.GetList()) + .Returns(new List { new BuyerDataModel(buyerId, "Test", "123456789", expectedPoints) }); + + var calculatedPoints = 0.0; + _pointsStorageContract.Setup(x => x.AddElement(It.IsAny())) + .Callback((PointsDataModel x) => + { + calculatedPoints = x.Points; + }); + + // Act + _pointsBusinessLogicContract.CalculatePointsByMounth(DateTime.UtcNow); + + // Assert + Assert.That(calculatedPoints, Is.EqualTo(expectedPoints)); + } + + [Test] + public void CalculatePointsByMonth_WithSeveralBuyers_Test() + { + // Arrange + var buyer1Id = Guid.NewGuid().ToString(); + var buyer2Id = Guid.NewGuid().ToString(); + var buyer3Id = Guid.NewGuid().ToString(); + + var buyers = new List + { + new(buyer1Id, "Test", "123456789", 0), + new(buyer2Id, "Test", "123456789", 0), + new(buyer3Id, "Test", "123456789", 0) + }; + + _buyerStorageContract.Setup(x => x.GetList()) + .Returns(buyers); + + // Act + _pointsBusinessLogicContract.CalculatePointsByMounth(DateTime.UtcNow); + + // Assert + _pointsStorageContract.Verify(x => x.AddElement(It.IsAny()), Times.Exactly(buyers.Count)); + } + + [Test] + public void CalculatePointsByMonth_WithoutPurchasesByBuyer_Test() + { + // Arrange + var buyerId = Guid.NewGuid().ToString(); + + // Убедитесь, что мок возвращает непустой список + _buyerStorageContract.Setup(x => x.GetList()) + .Returns(new List { new BuyerDataModel(buyerId, "Test", "123456789", 0) }); + + // Установите начальное значение баллов в 0 + var calculatedPoints = 0.0; + _pointsStorageContract.Setup(x => x.AddElement(It.IsAny())) + .Callback((PointsDataModel x) => + { + calculatedPoints = x.Points; + }); + + // Act + _pointsBusinessLogicContract.CalculatePointsByMounth(DateTime.UtcNow); + + // Assert + Assert.That(calculatedPoints, Is.EqualTo(0)); + } + + [Test] + public void CalculatePointsByMonth_BuyerStorageReturnNull_ThrowException_Test() + { + // Arrange + _buyerStorageContract.Setup(x => x.GetList()) + .Returns((List)null); + + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.CalculatePointsByMounth(DateTime.UtcNow), Throws.TypeOf()); + } + + [Test] + public void CalculatePointsByMonth_BuyerStorageThrowException_ThrowException_Test() + { + // Arrange + _buyerStorageContract.Setup(x => x.GetList()) + .Throws(new StorageException(new InvalidOperationException())); + + // Act & Assert + Assert.That(() => _pointsBusinessLogicContract.CalculatePointsByMounth(DateTime.UtcNow), Throws.TypeOf()); + } +} diff --git a/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/ProductBusinessLogicContractTests.cs b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/ProductBusinessLogicContractTests.cs index 5ca5624..df3b40f 100644 --- a/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/ProductBusinessLogicContractTests.cs +++ b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/ProductBusinessLogicContractTests.cs @@ -39,8 +39,7 @@ new(Guid.NewGuid().ToString(), "name 1", ProductType.Onigiri, 10, false), new(Guid.NewGuid().ToString(), "name 2", ProductType.Onigiri, 10, true), new(Guid.NewGuid().ToString(), "name 3", ProductType.Onigiri, 10, false), }; - _productStorageContract.Setup(x => x.GetList(It.IsAny(), - It.IsAny())).Returns(listOriginal); + _productStorageContract.Setup(x => x.GetList(It.IsAny(), It.IsAny())).Returns(listOriginal); //Act var listOnlyActive = _productBusinessLogicContract.GetAllProducts(true); @@ -103,110 +102,7 @@ It.IsAny()), Times.Once); _productStorageContract.Verify(x => x.GetList(It.IsAny(), It.IsAny()), Times.Once); } - [Test] - public void GetAllProductsByManufacturer_ReturnListOfRecords_Test() - { - //Arrange - var manufacturerId = Guid.NewGuid().ToString(); - var listOriginal = new List() -{ -new(Guid.NewGuid().ToString(), "name 1", ProductType.Onigiri, 10, false), -new(Guid.NewGuid().ToString(), "name 2", ProductType.Onigiri, 10, true), -new(Guid.NewGuid().ToString(), "name 3", ProductType.Onigiri, 10, false), -}; - _productStorageContract.Setup(x => x.GetList(It.IsAny(), - It.IsAny())).Returns(listOriginal); - //Act - var listOnlyActive = - _productBusinessLogicContract.GetAllProductsByManufacturer(manufacturerId, true); - var list = - _productBusinessLogicContract.GetAllProductsByManufacturer(manufacturerId, - false); - //Assert - Assert.Multiple(() => - { - Assert.That(listOnlyActive, Is.Not.Null); - Assert.That(list, Is.Not.Null); - Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal)); - Assert.That(list, Is.EquivalentTo(listOriginal)); - }); - _productStorageContract.Verify(x => x.GetList(true, manufacturerId), - Times.Once); - _productStorageContract.Verify(x => x.GetList(false, manufacturerId), - Times.Once); - } - [Test] - public void GetAllProductsByManufacturer_ReturnEmptyList_Test() - { - //Arrange - var manufacturerId = Guid.NewGuid().ToString(); - _productStorageContract.Setup(x => x.GetList(It.IsAny(), - It.IsAny())).Returns([]); - //Act - var listOnlyActive = -_productBusinessLogicContract.GetAllProductsByManufacturer(manufacturerId, true); - var list = - _productBusinessLogicContract.GetAllProductsByManufacturer(manufacturerId, - false); - //Assert - Assert.Multiple(() => - { - 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)); - }); - _productStorageContract.Verify(x => x.GetList(It.IsAny(), - manufacturerId), Times.Exactly(2)); - } - [Test] - public void - GetAllProductsByManufacturer_ManufacturerIdIsNullOrEmpty_ThrowException_Test() - { - //Act&Assert - Assert.That(() => - _productBusinessLogicContract.GetAllProductsByManufacturer(null, - It.IsAny()), Throws.TypeOf()); - Assert.That(() => - _productBusinessLogicContract.GetAllProductsByManufacturer(string.Empty, - It.IsAny()), Throws.TypeOf()); - _productStorageContract.Verify(x => x.GetList(It.IsAny(), - It.IsAny()), Times.Never); - } - [Test] - public void - GetAllProductsByManufacturer_ManufacturerIdIsNotGuid_ThrowException_Test() - { - //Act&Assert - Assert.That(() => - _productBusinessLogicContract.GetAllProductsByManufacturer("manufacturerId", - It.IsAny()), Throws.TypeOf()); - _productStorageContract.Verify(x => x.GetList(It.IsAny(), - It.IsAny()), Times.Never); - } - [Test] - public void GetAllProductsByManufacturer_ReturnNull_ThrowException_Test() - { - //Act&Assert - Assert.That(() => - _productBusinessLogicContract.GetAllProductsByManufacturer(Guid.NewGuid().ToString(), It.IsAny()), Throws.TypeOf()); - _productStorageContract.Verify(x => x.GetList(It.IsAny(), - It.IsAny()), Times.Once); - } - [Test] - public void - GetAllProductsByManufacturer_StorageThrowError_ThrowException_Test() - { - //Arrange - _productStorageContract.Setup(x => x.GetList(It.IsAny(), - It.IsAny())).Throws(new StorageException(new - InvalidOperationException())); - //Act&Assert - Assert.That(() => -_productBusinessLogicContract.GetAllProductsByManufacturer(Guid.NewGuid().ToString(), It.IsAny()), Throws.TypeOf()); - _productStorageContract.Verify(x => x.GetList(It.IsAny(), - It.IsAny()), Times.Once); - } + [Test] public void GetProductHistoryByProduct_ReturnListOfRecords_Test() { @@ -537,13 +433,11 @@ Throws.TypeOf()); //Arrange var id = Guid.NewGuid().ToString(); var flag = false; - _productStorageContract.Setup(x => x.DelElement(It.Is((string x) => x - == id))).Callback(() => { flag = true; }); + _productStorageContract.Setup(x => x.DelElement(It.Is((string x) => x == id))).Callback(() => { flag = true; }); //Act _productBusinessLogicContract.DeleteProduct(id); //Assert - _productStorageContract.Verify(x => x.DelElement(It.IsAny()), -Times.Once); + _productStorageContract.Verify(x => x.DelElement(It.IsAny()), Times.Once); Assert.That(flag); } [Test] diff --git a/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/SaleBusinessLogicContractTests.cs b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/SaleBusinessLogicContractTests.cs new file mode 100644 index 0000000..6a5b5aa --- /dev/null +++ b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/SaleBusinessLogicContractTests.cs @@ -0,0 +1,671 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Moq; +using PuferFishBusinessLogic.Implementations; +using PuferFishContracts.DataModels; +using PuferFishContracts.Exceptions; +using PuferFishContracts.StoragesContracts; + +namespace PuferFishTests.BusinessLogicsContractsTests; + +[TestFixture] +internal class SaleBusinessLogicContractTests +{ + private SaleBusinessLogicContract _saleBusinessLogicContract; + private Mock _saleStorageContract; + [OneTimeSetUp] + public void OneTimeSetUp() + { + _saleStorageContract = new Mock(); + _saleBusinessLogicContract = new SaleBusinessLogicContract(_saleStorageContract.Object, new Mock().Object); + } + [SetUp] + public void SetUp() + { + _saleStorageContract.Reset(); + } + [Test] + public void GetAllSalesByPeriod_ReturnListOfRecords_Test() + { + //Arrange + var date = DateTime.UtcNow; + var listOriginal = new List() + { + new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, + [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]), + new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, []), + new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, []), +}; + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Returns(listOriginal); + //Act + var list = _saleBusinessLogicContract.GetAllSalesByPeriod(date, + date.AddDays(1)); + //Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Is.EquivalentTo(listOriginal)); + _saleStorageContract.Verify(x => x.GetList(date, date.AddDays(1), + null, null, null), Times.Once); + } + [Test] + public void GetAllSalesByPeriod_ReturnEmptyList_Test() + { + //Arrange + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Returns([]); + //Act + var list = + _saleBusinessLogicContract.GetAllSalesByPeriod(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1)); + //Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Has.Count.EqualTo(0)); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void GetAllSalesByPeriod_IncorrectDates_ThrowException_Test() + { + //Arrange + var date = DateTime.UtcNow; + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByPeriod(date, date), + Throws.TypeOf()); + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByPeriod(date, date.AddSeconds(-1)), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Never); + } + [Test] + public void GetAllSalesByPeriod_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByPeriod(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void GetAllSalesByPeriod_StorageThrowError_ThrowException_Test() + { + //Arrange + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByPeriod(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void GetAllSalesByWorkerByPeriod_ReturnListOfRecords_Test() + { + //Arrange + var date = DateTime.UtcNow; + var workerId = Guid.NewGuid().ToString(); + var listOriginal = new List() +{ +new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, +[new SaleProductDataModel(Guid.NewGuid().ToString(), +Guid.NewGuid().ToString(), 5)]), new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, []), +new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, []), +}; + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Returns(listOriginal); + //Act + + var list = +_saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(workerId, date, +date.AddDays(1)); + //Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Is.EquivalentTo(listOriginal)); + _saleStorageContract.Verify(x => x.GetList(date, date.AddDays(1), + workerId, null, null), Times.Once); + } + [Test] + public void GetAllSalesByWorkerByPeriod_ReturnEmptyList_Test() + { + //Arrange + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Returns([]); + //Act + var list = + _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(Guid.NewGuid().ToString(), + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)); + //Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Has.Count.EqualTo(0)); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void + GetAllSalesByWorkerByPeriod_IncorrectDates_ThrowException_Test() + { + //Arrange + var date = DateTime.UtcNow; + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(Guid.NewGuid().ToString(), + date, date), Throws.TypeOf()); + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(Guid.NewGuid().ToString(), + date, date.AddSeconds(-1)), Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Never); + } + [Test] + public void + GetAllSalesByWorkerByPeriod_WorkerIdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(null, DateTime.UtcNow, + DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(string.Empty, + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Never); + } + [Test] + public void +GetAllSalesByWorkerByPeriod_WorkerIdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod("workerId", + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Never); + } + [Test] + public void GetAllSalesByWorkerByPeriod_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(Guid.NewGuid().ToString(), + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void + GetAllSalesByWorkerByPeriod_StorageThrowError_ThrowException_Test() + { + //Arrange + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByWorkerByPeriod(Guid.NewGuid().ToString(), + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void GetAllSalesByBuyerByPeriod_ReturnListOfRecords_Test() + { + //Arrange + var date = DateTime.UtcNow; + var buyerId = Guid.NewGuid().ToString(); + var listOriginal = new List() +{ +new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, +[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]), +new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, []), +new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, []), +}; + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), +It.IsAny(), It.IsAny(), It.IsAny(), +It.IsAny())).Returns(listOriginal); + //Act + var list = + _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod(buyerId, date, + date.AddDays(1)); + //Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Is.EquivalentTo(listOriginal)); + _saleStorageContract.Verify(x => x.GetList(date, date.AddDays(1), + null, buyerId, null), Times.Once); + } + [Test] + public void GetAllSalesByBuyerByPeriod_ReturnEmptyList_Test() + { + //Arrange + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Returns([]); + //Act + var list = + _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod(Guid.NewGuid().ToString(), + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)); + //Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Has.Count.EqualTo(0)); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void GetAllSalesByBuyerByPeriod_IncorrectDates_ThrowException_Test() + { + //Arrange + var date = DateTime.UtcNow; + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod(Guid.NewGuid().ToString(), + date, date), Throws.TypeOf()); + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod(Guid.NewGuid().ToString(), + date, date.AddSeconds(-1)), Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Never); + } + [Test] + public void + GetAllSalesByBuyerByPeriod_BuyerIdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod(null, DateTime.UtcNow, + DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod(string.Empty, + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), +It.IsAny(), It.IsAny(), It.IsAny(), +It.IsAny()), Times.Never); + } + [Test] + public void + GetAllSalesByBuyerByPeriod_BuyerIdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod("buyerId", DateTime.UtcNow, + DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Never); + } + [Test] + public void GetAllSalesByBuyerByPeriod_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod(Guid.NewGuid().ToString(), + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void + GetAllSalesByBuyerByPeriod_StorageThrowError_ThrowException_Test() + { + //Arrange + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByBuyerByPeriod(Guid.NewGuid().ToString(), + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void GetAllSalesByProductByPeriod_ReturnListOfRecords_Test() + { + //Arrange + var date = DateTime.UtcNow; + var productId = Guid.NewGuid().ToString(); + var listOriginal = new List() +{ +new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, +[new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]), +new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, []), +new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 0, false, []), +}; + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Returns(listOriginal); + //Act + var list = + _saleBusinessLogicContract.GetAllSalesByProductByPeriod(productId, date, + date.AddDays(1)); + //Assert + Assert.That(list, Is.Not.Null); + Assert.That(list, Is.EquivalentTo(listOriginal)); + _saleStorageContract.Verify(x => x.GetList(date, date.AddDays(1), + null, null, productId), Times.Once); + } + [Test] + public void GetAllSalesByProductByPeriod_ReturnEmptyList_Test() + { + //Arrange + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Returns([]); + //Act + 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)); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void + GetAllSalesByProductByPeriod_IncorrectDates_ThrowException_Test() + { + //Arrange + var date = DateTime.UtcNow; + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByProductByPeriod(Guid.NewGuid().ToString() + , date, date), Throws.TypeOf()); + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByProductByPeriod(Guid.NewGuid().ToString() + , date, date.AddSeconds(-1)), Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Never); + } + [Test] + public void + GetAllSalesByProductByPeriod_ProductIdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByProductByPeriod(null, DateTime.UtcNow, + DateTime.UtcNow.AddDays(1)), Throws.TypeOf()); + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByProductByPeriod(string.Empty, + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), +Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Never); + } + [Test] + public void + GetAllSalesByProductByPeriod_ProductIdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByProductByPeriod("productId", + DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Never); + } + [Test] + public void GetAllSalesByProductByPeriod_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByProductByPeriod(Guid.NewGuid().ToString() + , DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void + GetAllSalesByProductByPeriod_StorageThrowError_ThrowException_Test() + { + //Arrange + _saleStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetAllSalesByProductByPeriod(Guid.NewGuid().ToString() + , DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny()), Times.Once); + } + [Test] + public void GetSaleByData_GetById_ReturnRecord_Test() + { + //Arrange + var id = Guid.NewGuid().ToString(); + var record = new SaleDataModel(id, Guid.NewGuid().ToString(), null, + 10, 0, false, + [new SaleProductDataModel(Guid.NewGuid().ToString(), +Guid.NewGuid().ToString(), 5)]); + _saleStorageContract.Setup(x => + x.GetElementById(id)).Returns(record); + //Act + var element = _saleBusinessLogicContract.GetSaleByData(id); + //Assert + Assert.That(element, Is.Not.Null); + Assert.That(element.Id, Is.EqualTo(id)); + _saleStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Once); + } + [Test] + public void GetSaleByData_EmptyData_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _saleBusinessLogicContract.GetSaleByData(null), + Throws.TypeOf()); + Assert.That(() => + _saleBusinessLogicContract.GetSaleByData(string.Empty), + Throws.TypeOf()); + _saleStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Never); + } + [Test] + public void GetSaleByData_IdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _saleBusinessLogicContract.GetSaleByData("saleId"), + Throws.TypeOf()); + _saleStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Never); + } + [Test] + public void GetSaleByData_GetById_NotFoundRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetSaleByData(Guid.NewGuid().ToString()), + Throws.TypeOf()); + _saleStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Once); + } + [Test] + public void GetSaleByData_StorageThrowError_ThrowException_Test() + { + //Arrange + _saleStorageContract.Setup(x => + x.GetElementById(It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.GetSaleByData(Guid.NewGuid().ToString()), + Throws.TypeOf()); + _saleStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Once); + } + [Test] + public void InsertSale_CorrectRecord_Test() + { + //Arrange + var flag = false; + var record = new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 10, false, [new SaleProductDataModel(Guid.NewGuid().ToString(), +Guid.NewGuid().ToString(), 5)]); + _saleStorageContract.Setup(x => + x.AddElement(It.IsAny())) + .Callback((SaleDataModel x) => + { + flag = x.Id == record.Id && x.WorkerId == record.WorkerId && x.BuyerId == record.BuyerId && x.SaleDate == record.SaleDate && x.Sum == + record.Sum && x.IsCancel == record.IsCancel && x.Products.Count == record.Products.Count && + x.Products.First().ProductId == record.Products.First().ProductId && x.Products.First().SaleId == record.Products.First().SaleId && x.Products.First().Count == record.Products.First().Count; + }); + //Act + _saleBusinessLogicContract.InsertSale(record); + //Assert + _saleStorageContract.Verify(x => + x.AddElement(It.IsAny()), Times.Once); + Assert.That(flag); + } + [Test] + public void InsertSale_RecordWithExistsData_ThrowException_Test() + { + //Arrange + _saleStorageContract.Setup(x => + x.AddElement(It.IsAny())).Throws(new + ElementExistsException("Data", "Data")); + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 10, false, + [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf()); + _saleStorageContract.Verify(x => + x.AddElement(It.IsAny()), Times.Once); + } + [Test] + public void InsertSale_NullRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _saleBusinessLogicContract.InsertSale(null), + Throws.TypeOf()); + _saleStorageContract.Verify(x => + x.AddElement(It.IsAny()), Times.Never); + } + [Test] + public void InsertSale_InvalidRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _saleBusinessLogicContract.InsertSale(new + SaleDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 10, false, [])), Throws.TypeOf()); + _saleStorageContract.Verify(x => +x.AddElement(It.IsAny()), Times.Never); + } + [Test] + public void InsertSale_StorageThrowError_ThrowException_Test() + { + //Arrange + _saleStorageContract.Setup(x => + x.AddElement(It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), + Guid.NewGuid().ToString(), 10, 10, false, + [new SaleProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf()); + _saleStorageContract.Verify(x => + x.AddElement(It.IsAny()), Times.Once); + } + [Test] + public void CancelSale_CorrectRecord_Test() + { + //Arrange + var id = Guid.NewGuid().ToString(); + var flag = false; + _saleStorageContract.Setup(x => x.DelElement(It.Is((string x) => x == + id))).Callback(() => { flag = true; }); + //Act + _saleBusinessLogicContract.CancelSale(id); + //Assert + _saleStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Once); + Assert.That(flag); + } + [Test] + public void CancelSale_RecordWithIncorrectId_ThrowException_Test() + { + //Arrange + var id = Guid.NewGuid().ToString(); + _saleStorageContract.Setup(x => + x.DelElement(It.IsAny())).Throws(new ElementNotFoundException(id)); + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.CancelSale(Guid.NewGuid().ToString()), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Once); + } + [Test] + public void CancelSale_IdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _saleBusinessLogicContract.CancelSale(null), + Throws.TypeOf()); + Assert.That(() => + _saleBusinessLogicContract.CancelSale(string.Empty), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Never); + } + [Test] + public void CancelSale_IdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _saleBusinessLogicContract.CancelSale("id"), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Never); + } + [Test] + public void CancelSale_StorageThrowError_ThrowException_Test() + { + //Arrange + _saleStorageContract.Setup(x => + x.DelElement(It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _saleBusinessLogicContract.CancelSale(Guid.NewGuid().ToString()), + Throws.TypeOf()); + _saleStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Once); + } +} diff --git a/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/WorkerBusinessLogicContractTests.cs b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/WorkerBusinessLogicContractTests.cs new file mode 100644 index 0000000..22fbacb --- /dev/null +++ b/PuferFishContracts/PuferFishTests/BusinessLogicsContractsTests/WorkerBusinessLogicContractTests.cs @@ -0,0 +1,729 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Moq; +using PuferFishBusinessLogic.Implementations; +using PuferFishContracts.DataModels; +using PuferFishContracts.Exceptions; +using PuferFishContracts.StoragesContracts; + +namespace PuferFishTests.BusinessLogicsContractsTests; + +[TestFixture] +internal class WorkerBusinessLogicContractTests +{ + private WorkerBusinessLogicContract _workerBusinessLogicContract; + private Mock _workerStorageContract; + [OneTimeSetUp] + public void OneTimeSetUp() + { + _workerStorageContract = new Mock(); + _workerBusinessLogicContract = new WorkerBusinessLogicContract(_workerStorageContract.Object, new Mock().Object); + } + [SetUp] + public void SetUp() + { + _workerStorageContract.Reset(); + } + [Test] + public void GetAllWorkers_ReturnListOfRecords_Test() + { + //Arrange + var listOriginal = new List() + { +new(Guid.NewGuid().ToString(), "fio 1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false), +new(Guid.NewGuid().ToString(), "fio 2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true), +new(Guid.NewGuid().ToString(), "fio 3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false), +}; + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Returns(listOriginal); + //Act + var listOnlyActive = + _workerBusinessLogicContract.GetAllWorkers(true); + var list = _workerBusinessLogicContract.GetAllWorkers(false); + //Assert + Assert.Multiple(() => + { + Assert.That(listOnlyActive, Is.Not.Null); + Assert.That(list, Is.Not.Null); + Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal)); + Assert.That(list, Is.EquivalentTo(listOriginal)); + }); + _workerStorageContract.Verify(x => x.GetList(true, null, null, null, null, null), Times.Once); + _workerStorageContract.Verify(x => x.GetList(false, null, null, null, null, null), Times.Once); + } + [Test] + public void GetAllWorkers_ReturnEmptyList_Test() + { + //Arrange + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Returns([]); + //Act + var listOnlyActive = + _workerBusinessLogicContract.GetAllWorkers(true); + var list = _workerBusinessLogicContract.GetAllWorkers(false); + //Assert + Assert.Multiple(() => + { + 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)); + }); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), null, null, null, null, null), Times.Exactly(2)); + } + [Test] + public void GetAllWorkers_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkers(It.IsAny()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), +It.IsAny(), It.IsAny(), It.IsAny(), +It.IsAny(), It.IsAny()), Times.Once); + } + [Test] + public void GetAllWorkers_StorageThrowError_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkers(It.IsAny()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), null, null, null, null, null), Times.Once); + } + [Test] + public void GetAllWorkersByPost_ReturnListOfRecords_Test() + { + //Arrange + var postId = Guid.NewGuid().ToString(); + var listOriginal = new List() +{ +new(Guid.NewGuid().ToString(), "fio 1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false), +new(Guid.NewGuid().ToString(), "fio 2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true), +new(Guid.NewGuid().ToString(), "fio 3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false), +}; + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Returns(listOriginal); + //Act + var listOnlyActive = + _workerBusinessLogicContract.GetAllWorkersByPost(postId, true); + var list = _workerBusinessLogicContract.GetAllWorkersByPost(postId, + false); + //Assert + Assert.Multiple(() => + { + Assert.That(listOnlyActive, Is.Not.Null); + Assert.That(list, Is.Not.Null); + Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal)); + Assert.That(list, Is.EquivalentTo(listOriginal)); + }); + _workerStorageContract.Verify(x => x.GetList(true, postId, null, null, null, null), Times.Once); + _workerStorageContract.Verify(x => x.GetList(false, postId, null, null, null, null), Times.Once); + } + [Test] + public void GetAllWorkersByPost_ReturnEmptyList_Test() + { + //Arrange + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Returns([]); + //Act + var listOnlyActive = + _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(), + true); + var list = + _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(), + false); + //Assert + Assert.Multiple(() => + { + 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)); + }); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Exactly(2)); + } + [Test] + public void GetAllWorkersByPost_PostIdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByPost(null, It.IsAny()), + Throws.TypeOf()); + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByPost(string.Empty, It.IsAny()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Never); + } + [Test] + public void GetAllWorkersByPost_PostIdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByPost("postId", It.IsAny()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Never); + } + [Test] + public void GetAllWorkersByPost_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(), + It.IsAny()), Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Once); + } + [Test] + public void GetAllWorkersByPost_StorageThrowError_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByPost(Guid.NewGuid().ToString(), + It.IsAny()), Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Once); + } + [Test] + public void GetAllWorkersByBirthDate_ReturnListOfRecords_Test() + { + //Arrange + var date = DateTime.UtcNow; + var listOriginal = new List() +{ +new(Guid.NewGuid().ToString(), "fio 1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false), +new(Guid.NewGuid().ToString(), "fio 2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true), +new(Guid.NewGuid().ToString(), "fio 3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false), +}; + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Returns(listOriginal); + //Act + var listOnlyActive = + _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddDays(1), + true); + var list = + _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddDays(1), + false); + //Assert + Assert.Multiple(() => + { + Assert.That(listOnlyActive, Is.Not.Null); + Assert.That(list, Is.Not.Null); + Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal)); + Assert.That(list, Is.EquivalentTo(listOriginal)); + }); + _workerStorageContract.Verify(x => x.GetList(true, null, date, + date.AddDays(1), null, null), Times.Once); + _workerStorageContract.Verify(x => x.GetList(false, null, date, + date.AddDays(1), null, null), Times.Once); + } + [Test] + public void GetAllWorkersByBirthDate_ReturnEmptyList_Test() + { + //Arrange + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Returns([]); + //Act + var listOnlyActive = + _workerBusinessLogicContract.GetAllWorkersByBirthDate(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1), true); + var list = _workerBusinessLogicContract.GetAllWorkers(false); + //Assert + Assert.Multiple(() => + { + 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)); + }); + _workerStorageContract.Verify(x => x.GetList(true, null, + It.IsAny(), It.IsAny(), null, null), Times.Once); + _workerStorageContract.Verify(x => x.GetList(false, null, + It.IsAny(), It.IsAny(), null, null), Times.Once); + } + [Test] + public void GetAllWorkersByBirthDate_IncorrectDates_ThrowException_Test() + { + //Arrange + var date = DateTime.UtcNow; + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date, + It.IsAny()), Throws.TypeOf()); + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByBirthDate(date, date.AddSeconds(-1), + It.IsAny()), Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Never); + } + [Test] + public void GetAllWorkersByBirthDate_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByBirthDate(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1), It.IsAny()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Once); + } + [Test] + public void + GetAllWorkersByBirthDate_StorageThrowError_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByBirthDate(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1), It.IsAny()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), +It.IsAny(), It.IsAny(), It.IsAny(), +It.IsAny(), It.IsAny()), Times.Once); + } + [Test] + public void GetAllWorkersByEmploymentDate_ReturnListOfRecords_Test() + { + //Arrange + var date = DateTime.UtcNow; + var listOriginal = new List() +{ +new(Guid.NewGuid().ToString(), "fio 1", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false), +new(Guid.NewGuid().ToString(), "fio 2", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, true), +new(Guid.NewGuid().ToString(), "fio 3", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false), +}; + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Returns(listOriginal); + //Act + var listOnlyActive = + _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date.AddDays(1), + true); + var list = + _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date.AddDays(1), + false); + //Assert + Assert.Multiple(() => + { + Assert.That(listOnlyActive, Is.Not.Null); + Assert.That(list, Is.Not.Null); + Assert.That(listOnlyActive, Is.EquivalentTo(listOriginal)); + Assert.That(list, Is.EquivalentTo(listOriginal)); + }); + _workerStorageContract.Verify(x => x.GetList(true, null, null, null, date, date.AddDays(1)), Times.Once); + _workerStorageContract.Verify(x => x.GetList(false, null, null, null, date, date.AddDays(1)), Times.Once); + } + [Test] + public void GetAllWorkersByEmploymentDate_ReturnEmptyList_Test() + { + //Arrange + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Returns([]); + //Act + var listOnlyActive = + _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1), true); + var list = + _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1), false); + //Assert + Assert.Multiple(() => + { + 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)); + }); + _workerStorageContract.Verify(x => x.GetList(true, null, null, null, + It.IsAny(), It.IsAny()), Times.Once); + _workerStorageContract.Verify(x => x.GetList(false, null, null, null, + It.IsAny(), It.IsAny()), Times.Once); + } + [Test] + public void + GetAllWorkersByEmploymentDate_IncorrectDates_ThrowException_Test() + { + //Arrange + var date = DateTime.UtcNow; + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, date, + It.IsAny()), Throws.TypeOf()); + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(date, + date.AddSeconds(-1), It.IsAny()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Never); + } + [Test] + public void GetAllWorkersByEmploymentDate_ReturnNull_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1), It.IsAny()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Once); + } + [Test] + public void + GetAllWorkersByEmploymentDate_StorageThrowError_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetAllWorkersByEmploymentDate(DateTime.UtcNow, + DateTime.UtcNow.AddDays(1), It.IsAny()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.GetList(It.IsAny(), + It.IsAny(), It.IsAny(), It.IsAny(), + It.IsAny(), It.IsAny()), Times.Once); + } + [Test] + public void GetWorkerByData_GetById_ReturnRecord_Test() + { + //Arrange + var id = Guid.NewGuid().ToString(); + var record = new WorkerDataModel(id, "fio", + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, + false); + _workerStorageContract.Setup(x => + x.GetElementById(id)).Returns(record); + //Act + var element = _workerBusinessLogicContract.GetWorkerByData(id); + //Assert + Assert.That(element, Is.Not.Null); + Assert.That(element.Id, Is.EqualTo(id)); + _workerStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Once); + } + [Test] + public void GetWorkerByData_GetByFio_ReturnRecord_Test() + { + //Arrange + var fio = "fio"; + var record = new WorkerDataModel(Guid.NewGuid().ToString(), fio, + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, + false); + _workerStorageContract.Setup(x => + x.GetElementByFIO(fio)).Returns(record); + //Act + var element = _workerBusinessLogicContract.GetWorkerByData(fio); + //Assert + Assert.That(element, Is.Not.Null); + Assert.That(element.FIO, Is.EqualTo(fio)); + _workerStorageContract.Verify(x => + x.GetElementByFIO(It.IsAny()), Times.Once); + } + [Test] + public void GetWorkerByData_EmptyData_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _workerBusinessLogicContract.GetWorkerByData(null), + Throws.TypeOf()); + Assert.That(() => + _workerBusinessLogicContract.GetWorkerByData(string.Empty), + Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Never); + _workerStorageContract.Verify(x => + x.GetElementByFIO(It.IsAny()), Times.Never); + } + [Test] + public void GetWorkerByData_GetById_NotFoundRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetWorkerByData(Guid.NewGuid().ToString()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Once); + _workerStorageContract.Verify(x => + x.GetElementByFIO(It.IsAny()), Times.Never); + } + [Test] + public void GetWorkerByData_GetByFio_NotFoundRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetWorkerByData("fio"), + Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Never); + _workerStorageContract.Verify(x => + x.GetElementByFIO(It.IsAny()), Times.Once); + } + [Test] + public void GetWorkerByData_StorageThrowError_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => + x.GetElementById(It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + _workerStorageContract.Setup(x => + x.GetElementByFIO(It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.GetWorkerByData(Guid.NewGuid().ToString()), + Throws.TypeOf()); + Assert.That(() => + _workerBusinessLogicContract.GetWorkerByData("fio"), + Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.GetElementById(It.IsAny()), Times.Once); + _workerStorageContract.Verify(x => + x.GetElementByFIO(It.IsAny()), Times.Once); + } + [Test] + public void InsertWorker_CorrectRecord_Test() + { + //Arrange + var flag = false; + var record = new WorkerDataModel(Guid.NewGuid().ToString(), "Фамилия Имя Отчество", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, false); + _workerStorageContract.Setup(x => + x.AddElement(It.IsAny())) + .Callback((WorkerDataModel x) => + { + flag = x.Id == record.Id && x.FIO == record.FIO && + x.PostId == record.PostId && x.BirthDate == record.BirthDate && + x.EmploymentDate == record.EmploymentDate && + x.IsDeleted == record.IsDeleted; + }); + //Act + _workerBusinessLogicContract.InsertWorker(record); + //Assert + _workerStorageContract.Verify(x => + x.AddElement(It.IsAny()), Times.Once); + Assert.That(flag); + } + [Test] + public void InsertWorker_RecordWithExistsData_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => + x.AddElement(It.IsAny())).Throws(new + ElementExistsException("Data", "Data")); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "Фамилия Имя Отчество", + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, + false)), Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.AddElement(It.IsAny()), Times.Once); + } + [Test] + public void InsertWorker_NullRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _workerBusinessLogicContract.InsertWorker(null), + Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.AddElement(It.IsAny()), Times.Never); + } + [Test] + public void InsertWorker_InvalidRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _workerBusinessLogicContract.InsertWorker(new + WorkerDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(- + 16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.AddElement(It.IsAny()), Times.Never); + } + [Test] + public void InsertWorker_StorageThrowError_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => + x.AddElement(It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.InsertWorker(new(Guid.NewGuid().ToString(), "Фамилия Имя Отчество", + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, + false)), Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.AddElement(It.IsAny()), Times.Once); + } + [Test] + public void UpdateWorker_CorrectRecord_Test() + { + //Arrange + var flag = false; + var record = new WorkerDataModel(Guid.NewGuid().ToString(), "Фамилия Имя Отчество", + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, + false); + _workerStorageContract.Setup(x => + x.UpdElement(It.IsAny())) + .Callback((WorkerDataModel x) => + { + flag = x.Id == record.Id && x.FIO == record.FIO && + x.PostId == record.PostId && x.BirthDate == record.BirthDate && + x.EmploymentDate == record.EmploymentDate && +x.IsDeleted == record.IsDeleted; + }); + //Act + _workerBusinessLogicContract.UpdateWorker(record); + //Assert + _workerStorageContract.Verify(x => + x.UpdElement(It.IsAny()), Times.Once); + Assert.That(flag); + } + [Test] + public void UpdateWorker_RecordWithIncorrectData_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => + x.UpdElement(It.IsAny())).Throws(new + ElementNotFoundException("")); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "Фамилия Имя Отчество", + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, + false)), Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.UpdElement(It.IsAny()), Times.Once); + } + [Test] + public void UpdateWorker_NullRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _workerBusinessLogicContract.UpdateWorker(null), + Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.UpdElement(It.IsAny()), Times.Never); + } + [Test] + public void UpdateWorker_InvalidRecord_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _workerBusinessLogicContract.UpdateWorker(new + WorkerDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(- + 16).AddDays(-1), DateTime.Now, false)), Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.UpdElement(It.IsAny()), Times.Never); + } + [Test] + public void UpdateWorker_StorageThrowError_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => + x.UpdElement(It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.UpdateWorker(new(Guid.NewGuid().ToString(), "Фамилия Имя Отчество", + Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(-1), DateTime.Now, + false)), Throws.TypeOf()); + _workerStorageContract.Verify(x => + x.UpdElement(It.IsAny()), Times.Once); + } + [Test] + public void DeleteWorker_CorrectRecord_Test() + { + //Arrange + var id = Guid.NewGuid().ToString(); + var flag = false; + _workerStorageContract.Setup(x => x.DelElement(It.Is((string x) => x + == id))).Callback(() => { flag = true; }); + //Act + _workerBusinessLogicContract.DeleteWorker(id); + //Assert + _workerStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Once); + Assert.That(flag); + } + [Test] + public void DeleteWorker_RecordWithIncorrectId_ThrowException_Test() + { + //Arrange + var id = Guid.NewGuid().ToString(); + _workerStorageContract.Setup(x => x.DelElement(It.Is((string x) => x + != id))).Throws(new ElementNotFoundException(id)); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.DeleteWorker(Guid.NewGuid().ToString()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Once); + } + [Test] + public void DeleteWorker_IdIsNullOrEmpty_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _workerBusinessLogicContract.DeleteWorker(null), + Throws.TypeOf()); + Assert.That(() => + _workerBusinessLogicContract.DeleteWorker(string.Empty), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Never); + } + [Test] + public void DeleteWorker_IdIsNotGuid_ThrowException_Test() + { + //Act&Assert + Assert.That(() => _workerBusinessLogicContract.DeleteWorker("id"), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Never); + } + [Test] + public void DeleteWorker_StorageThrowError_ThrowException_Test() + { + //Arrange + _workerStorageContract.Setup(x => + x.DelElement(It.IsAny())).Throws(new StorageException(new + InvalidOperationException())); + //Act&Assert + Assert.That(() => + _workerBusinessLogicContract.DeleteWorker(Guid.NewGuid().ToString()), + Throws.TypeOf()); + _workerStorageContract.Verify(x => x.DelElement(It.IsAny()), + Times.Once); + } +}