forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
изменение безнес логики при нехватке продукта
This commit is contained in:
@@ -13,10 +13,11 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace MagicCarpetBusinessLogic.Implementations;
|
namespace MagicCarpetBusinessLogic.Implementations;
|
||||||
|
|
||||||
internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, IAgencyStorageContract agencyStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger = logger;
|
private readonly ILogger _logger = logger;
|
||||||
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
||||||
|
private readonly IAgencyStorageContract _agencyStorageContract = agencyStorageContract;
|
||||||
|
|
||||||
public List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate)
|
public List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate)
|
||||||
{
|
{
|
||||||
@@ -101,6 +102,10 @@ internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContrac
|
|||||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(saleDataModel));
|
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(saleDataModel));
|
||||||
ArgumentNullException.ThrowIfNull(saleDataModel);
|
ArgumentNullException.ThrowIfNull(saleDataModel);
|
||||||
saleDataModel.Validate();
|
saleDataModel.Validate();
|
||||||
|
if (!_agencyStorageContract.CheckComponents(saleDataModel))
|
||||||
|
{
|
||||||
|
throw new InsufficientException("Dont have tour in agency");
|
||||||
|
}
|
||||||
_saleStorageContract.AddElement(saleDataModel);
|
_saleStorageContract.AddElement(saleDataModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,11 +13,10 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace MagicCarpetBusinessLogic.Implementations;
|
namespace MagicCarpetBusinessLogic.Implementations;
|
||||||
|
|
||||||
internal class TourBusinessLogicContract(ITourStorageContract tourStorageContract, IAgencyStorageContract agencyStorageContract,ILogger logger) : ITourBusinessLogicContract
|
internal class TourBusinessLogicContract(ITourStorageContract tourStorageContract, ILogger logger) : ITourBusinessLogicContract
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger = logger;
|
private readonly ILogger _logger = logger;
|
||||||
private readonly ITourStorageContract _tourStorageContract = tourStorageContract;
|
private readonly ITourStorageContract _tourStorageContract = tourStorageContract;
|
||||||
private readonly IAgencyStorageContract _agencyStorageContract = agencyStorageContract;
|
|
||||||
public List<TourDataModel> GetAllTours()
|
public List<TourDataModel> GetAllTours()
|
||||||
{
|
{
|
||||||
_logger.LogInformation("GetAllTours");
|
_logger.LogInformation("GetAllTours");
|
||||||
@@ -57,11 +56,6 @@ internal class TourBusinessLogicContract(ITourStorageContract tourStorageContrac
|
|||||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(tourDataModel));
|
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(tourDataModel));
|
||||||
ArgumentNullException.ThrowIfNull(tourDataModel);
|
ArgumentNullException.ThrowIfNull(tourDataModel);
|
||||||
tourDataModel.Validate();
|
tourDataModel.Validate();
|
||||||
if (!_agencyStorageContract.CheckComponents(tourDataModel))
|
|
||||||
{
|
|
||||||
throw new InsufficientException("Dont have tour in agency");
|
|
||||||
}
|
|
||||||
_tourStorageContract.AddElement(tourDataModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateTour(TourDataModel tourDataModel)
|
public void UpdateTour(TourDataModel tourDataModel)
|
||||||
@@ -69,11 +63,6 @@ internal class TourBusinessLogicContract(ITourStorageContract tourStorageContrac
|
|||||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(tourDataModel));
|
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(tourDataModel));
|
||||||
ArgumentNullException.ThrowIfNull(tourDataModel);
|
ArgumentNullException.ThrowIfNull(tourDataModel);
|
||||||
tourDataModel.Validate();
|
tourDataModel.Validate();
|
||||||
if (!_agencyStorageContract.CheckComponents(tourDataModel))
|
|
||||||
{
|
|
||||||
throw new InsufficientException("Dont have tour in agency");
|
|
||||||
}
|
|
||||||
_tourStorageContract.UpdElement(tourDataModel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DeleteTour(string id)
|
public void DeleteTour(string id)
|
||||||
|
|||||||
@@ -14,5 +14,5 @@ public interface IAgencyStorageContract
|
|||||||
void AddElement(AgencyDataModel agencyDataModel);
|
void AddElement(AgencyDataModel agencyDataModel);
|
||||||
void UpdElement(AgencyDataModel agencyDataModel);
|
void UpdElement(AgencyDataModel agencyDataModel);
|
||||||
void DelElement(string id);
|
void DelElement(string id);
|
||||||
bool CheckComponents(TourDataModel tourDataModel);
|
bool CheckComponents(SaleDataModel saleDataModel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,18 +18,22 @@ internal class SaleBusinessLogicContractTests
|
|||||||
{
|
{
|
||||||
private SaleBusinessLogicContract _saleBusinessLogicContract;
|
private SaleBusinessLogicContract _saleBusinessLogicContract;
|
||||||
private Mock<ISaleStorageContract> _saleStorageContract;
|
private Mock<ISaleStorageContract> _saleStorageContract;
|
||||||
|
private Mock<IAgencyStorageContract> _agencyStorageContract;
|
||||||
|
|
||||||
[OneTimeSetUp]
|
[OneTimeSetUp]
|
||||||
public void OneTimeSetUp()
|
public void OneTimeSetUp()
|
||||||
{
|
{
|
||||||
_saleStorageContract = new Mock<ISaleStorageContract>();
|
_saleStorageContract = new Mock<ISaleStorageContract>();
|
||||||
_saleBusinessLogicContract = new SaleBusinessLogicContract(_saleStorageContract.Object, new Mock<ILogger>().Object);
|
_agencyStorageContract = new Mock<IAgencyStorageContract>();
|
||||||
|
_saleBusinessLogicContract = new SaleBusinessLogicContract(_saleStorageContract.Object,
|
||||||
|
_agencyStorageContract.Object, new Mock<ILogger>().Object);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TearDown]
|
[TearDown]
|
||||||
public void TearDown()
|
public void TearDown()
|
||||||
{
|
{
|
||||||
_saleStorageContract.Reset();
|
_saleStorageContract.Reset();
|
||||||
|
_agencyStorageContract.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -396,6 +400,7 @@ internal class SaleBusinessLogicContractTests
|
|||||||
var flag = false;
|
var flag = false;
|
||||||
var record = new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 10,
|
var record = new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 10,
|
||||||
false, [new SaleTourDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
false, [new SaleTourDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||||
|
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<SaleDataModel>())).Returns(true);
|
||||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>()))
|
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>()))
|
||||||
.Callback((SaleDataModel x) =>
|
.Callback((SaleDataModel x) =>
|
||||||
{
|
{
|
||||||
@@ -409,6 +414,7 @@ internal class SaleBusinessLogicContractTests
|
|||||||
//Act
|
//Act
|
||||||
_saleBusinessLogicContract.InsertSale(record);
|
_saleBusinessLogicContract.InsertSale(record);
|
||||||
//Assert
|
//Assert
|
||||||
|
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<SaleDataModel>()), Times.Once);
|
||||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||||
Assert.That(flag);
|
Assert.That(flag);
|
||||||
}
|
}
|
||||||
@@ -417,11 +423,13 @@ internal class SaleBusinessLogicContractTests
|
|||||||
public void InsertSale_RecordWithExistsData_ThrowException_Test()
|
public void InsertSale_RecordWithExistsData_ThrowException_Test()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
|
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<SaleDataModel>())).Returns(true);
|
||||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||||
//Act&Assert
|
//Act&Assert
|
||||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleTourDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleTourDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||||
|
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<SaleDataModel>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@@ -444,13 +452,27 @@ internal class SaleBusinessLogicContractTests
|
|||||||
public void InsertSale_StorageThrowError_ThrowException_Test()
|
public void InsertSale_StorageThrowError_ThrowException_Test()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
|
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<SaleDataModel>())).Returns(true);
|
||||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||||
//Act&Assert
|
//Act&Assert
|
||||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleTourDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleTourDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||||
|
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<SaleDataModel>()), Times.Once);
|
||||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void InsertSale_InsufficientError_ThrowException_Test()
|
||||||
|
{
|
||||||
|
//Arrange
|
||||||
|
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<SaleDataModel>())).Returns(false);
|
||||||
|
Assert.That(() => _saleBusinessLogicContract.InsertSale(new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||||
|
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false,
|
||||||
|
[new SaleTourDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<InsufficientException>());
|
||||||
|
//Act&Assert
|
||||||
|
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<SaleDataModel>()), Times.Once);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CancelSale_CorrectRecord_Test()
|
public void CancelSale_CorrectRecord_Test()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,22 +18,18 @@ namespace MagicCarpetTests.BusinessLogicContractsTests;
|
|||||||
internal class TourBusinessLogicContractTests
|
internal class TourBusinessLogicContractTests
|
||||||
{
|
{
|
||||||
private TourBusinessLogicContract _tourBusinessLogicContract;
|
private TourBusinessLogicContract _tourBusinessLogicContract;
|
||||||
private Mock<IAgencyStorageContract> _agencyStorageContract;
|
|
||||||
private Mock<ITourStorageContract> _tourStorageContract;
|
private Mock<ITourStorageContract> _tourStorageContract;
|
||||||
|
|
||||||
[OneTimeSetUp]
|
[OneTimeSetUp]
|
||||||
public void OneTimeSetUp()
|
public void OneTimeSetUp()
|
||||||
{
|
{
|
||||||
_tourStorageContract = new Mock<ITourStorageContract>();
|
_tourStorageContract = new Mock<ITourStorageContract>();
|
||||||
_agencyStorageContract = new Mock<IAgencyStorageContract>();
|
_tourBusinessLogicContract = new TourBusinessLogicContract(_tourStorageContract.Object, new Mock<ILogger>().Object);
|
||||||
_tourBusinessLogicContract = new TourBusinessLogicContract(_tourStorageContract.Object,
|
|
||||||
_agencyStorageContract.Object, new Mock<ILogger>().Object);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void SetUp()
|
public void SetUp()
|
||||||
{
|
{
|
||||||
_agencyStorageContract.Reset();
|
|
||||||
_tourStorageContract.Reset();
|
_tourStorageContract.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -270,12 +266,10 @@ internal class TourBusinessLogicContractTests
|
|||||||
public void InsertTour_RecordWithExistsData_ThrowException_Test()
|
public void InsertTour_RecordWithExistsData_ThrowException_Test()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<TourDataModel>())).Returns(true);
|
|
||||||
_tourStorageContract.Setup(x => x.AddElement(It.IsAny<TourDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
_tourStorageContract.Setup(x => x.AddElement(It.IsAny<TourDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||||
//Act&Assert
|
//Act&Assert
|
||||||
Assert.That(() => _tourBusinessLogicContract.InsertTour(new(Guid.NewGuid().ToString(), "name","country",10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
Assert.That(() => _tourBusinessLogicContract.InsertTour(new(Guid.NewGuid().ToString(), "name","country",10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
||||||
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||||
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<TourDataModel>()), Times.Once);
|
|
||||||
_tourStorageContract.Verify(x => x.AddElement(It.IsAny<TourDataModel>()), Times.Once);
|
_tourStorageContract.Verify(x => x.AddElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,11 +293,9 @@ internal class TourBusinessLogicContractTests
|
|||||||
public void InsertTour_StorageThrowError_ThrowException_Test()
|
public void InsertTour_StorageThrowError_ThrowException_Test()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<TourDataModel>())).Returns(false);
|
|
||||||
Assert.That(() => _tourBusinessLogicContract.InsertTour(new TourDataModel(Guid.NewGuid().ToString(), "name","country", 10, TourType.Ski,
|
Assert.That(() => _tourBusinessLogicContract.InsertTour(new TourDataModel(Guid.NewGuid().ToString(), "name","country", 10, TourType.Ski,
|
||||||
[new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)], [new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<InsufficientException>());
|
[new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)], [new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<InsufficientException>());
|
||||||
//Act&Assert
|
//Act&Assert
|
||||||
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<TourDataModel>()), Times.Once);
|
|
||||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Never);
|
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -311,11 +303,9 @@ internal class TourBusinessLogicContractTests
|
|||||||
public void InsertFurniture_InsufficientError_ThrowException_Test()
|
public void InsertFurniture_InsufficientError_ThrowException_Test()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<TourDataModel>())).Returns(false);
|
|
||||||
Assert.That(() => _tourBusinessLogicContract.InsertTour(new TourDataModel(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
Assert.That(() => _tourBusinessLogicContract.InsertTour(new TourDataModel(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
||||||
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])),Throws.TypeOf<InsufficientException>());
|
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])),Throws.TypeOf<InsufficientException>());
|
||||||
//Act&Assert
|
//Act&Assert
|
||||||
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<TourDataModel>()), Times.Once);
|
|
||||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Never);
|
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,7 +316,6 @@ internal class TourBusinessLogicContractTests
|
|||||||
var flag = false;
|
var flag = false;
|
||||||
var record = new TourDataModel(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
var record = new TourDataModel(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
||||||
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||||
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<TourDataModel>())).Returns(true);
|
|
||||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>()))
|
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>()))
|
||||||
.Callback((TourDataModel x) =>
|
.Callback((TourDataModel x) =>
|
||||||
{
|
{
|
||||||
@@ -336,7 +325,6 @@ internal class TourBusinessLogicContractTests
|
|||||||
//Act
|
//Act
|
||||||
_tourBusinessLogicContract.UpdateTour(record);
|
_tourBusinessLogicContract.UpdateTour(record);
|
||||||
//Assert
|
//Assert
|
||||||
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<TourDataModel>()), Times.Once);
|
|
||||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||||
Assert.That(flag);
|
Assert.That(flag);
|
||||||
}
|
}
|
||||||
@@ -345,12 +333,10 @@ internal class TourBusinessLogicContractTests
|
|||||||
public void UpdateTour_RecordWithIncorrectData_ThrowException_Test()
|
public void UpdateTour_RecordWithIncorrectData_ThrowException_Test()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<TourDataModel>())).Returns(true);
|
|
||||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new ElementNotFoundException(""));
|
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new ElementNotFoundException(""));
|
||||||
//Act&Assert
|
//Act&Assert
|
||||||
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
||||||
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementNotFoundException>());
|
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementNotFoundException>());
|
||||||
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<TourDataModel>()), Times.Once);
|
|
||||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,12 +344,10 @@ internal class TourBusinessLogicContractTests
|
|||||||
public void UpdateTour_RecordWithExistsData_ThrowException_Test()
|
public void UpdateTour_RecordWithExistsData_ThrowException_Test()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<TourDataModel>())).Returns(true);
|
|
||||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||||
//Act&Assert
|
//Act&Assert
|
||||||
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
||||||
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf <ElementExistsException>());
|
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf <ElementExistsException>());
|
||||||
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<TourDataModel>()), Times.Once);
|
|
||||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -388,27 +372,13 @@ internal class TourBusinessLogicContractTests
|
|||||||
public void UpdateTour_StorageThrowError_ThrowException_Test()
|
public void UpdateTour_StorageThrowError_ThrowException_Test()
|
||||||
{
|
{
|
||||||
//Arrange
|
//Arrange
|
||||||
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<TourDataModel>())).Returns(true);
|
|
||||||
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
_tourStorageContract.Setup(x => x.UpdElement(It.IsAny<TourDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||||
//Act&Assert
|
//Act&Assert
|
||||||
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski, [new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
|
||||||
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
[new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||||
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<TourDataModel>()), Times.Once);
|
|
||||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Once);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void UpdateFurniture_InsufficientError_ThrowException_Test()
|
|
||||||
{
|
|
||||||
//Arrange
|
|
||||||
_agencyStorageContract.Setup(x => x.CheckComponents(It.IsAny<TourDataModel>())).Returns(false);
|
|
||||||
//Act&Assert
|
|
||||||
Assert.That(() => _tourBusinessLogicContract.UpdateTour(new(Guid.NewGuid().ToString(), "name", "country", 10, TourType.Ski,
|
|
||||||
[new TourSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)], [new TourAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<InsufficientException>());
|
|
||||||
_agencyStorageContract.Verify(x => x.CheckComponents(It.IsAny<TourDataModel>()), Times.Once);
|
|
||||||
_tourStorageContract.Verify(x => x.UpdElement(It.IsAny<TourDataModel>()), Times.Never);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DeleteTour_CorrectRecord_Test()
|
public void DeleteTour_CorrectRecord_Test()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user