Compare commits
14 Commits
Task_6
...
Task_2Hard
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78d614b893 | ||
|
|
22c101c77c | ||
|
|
4e3fd46750 | ||
|
|
2cb5ce2793 | ||
|
|
cc7d7289f7 | ||
|
|
015a963762 | ||
|
|
69c63f5499 | ||
| 72d33599fc | |||
| c9753ff960 | |||
|
|
98f99f607f | ||
| 03e10326d0 | |||
| 679672a33b | |||
|
|
21258b1c31 | ||
| 9730a641c4 |
@@ -8,11 +8,11 @@ using System.Text.Json;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class SaleBusinessLogicContract(ISaleStorageContract
|
||||
saleStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
internal class SaleBusinessLogicContract(ISaleStorageContract saleStorageContract, IWarehouseStorageContract warehouseStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISaleStorageContract _saleStorageContract = saleStorageContract;
|
||||
private readonly IWarehouseStorageContract _warehouseStorageContract = warehouseStorageContract;
|
||||
|
||||
public List<SaleDataModel> GetAllSalesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
@@ -97,6 +97,10 @@ saleStorageContract, ILogger logger) : ISaleBusinessLogicContract
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(saleDataModel));
|
||||
ArgumentNullException.ThrowIfNull(saleDataModel);
|
||||
saleDataModel.Validate();
|
||||
if (!_warehouseStorageContract.CheckCocktails(saleDataModel))
|
||||
{
|
||||
throw new InsufficientStockException("Dont have cocktails in warehouse");
|
||||
}
|
||||
_saleStorageContract.AddElement(saleDataModel);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SquirrelContract.BusinessLogicContracts;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class SupplyBusinessLogicContract(ISupplyStorageContract supplyStorageContract, IWarehouseStorageContract warehouseStorageContract, ILogger logger) : ISupplyBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly ISupplyStorageContract _supplyStorageContract = supplyStorageContract;
|
||||
private readonly IWarehouseStorageContract _warehouseStorageContract = warehouseStorageContract;
|
||||
public List<SupplyDataModel> GetAllSuppliesByPeriod(DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSupplies params: {fromDate}, {toDate}", fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
return _supplyStorageContract.GetList(fromDate, toDate) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public List<SupplyDataModel> GetAllSuppliesByCocktailByPeriod(string cocktailId, DateTime fromDate, DateTime toDate)
|
||||
{
|
||||
_logger.LogInformation("GetAllSupplies params: {cocktailId}, {fromDate}, {toDate}", cocktailId, fromDate, toDate);
|
||||
if (fromDate.IsDateNotOlder(toDate))
|
||||
{
|
||||
throw new IncorrectDatesException(fromDate, toDate);
|
||||
}
|
||||
if (cocktailId.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(cocktailId));
|
||||
}
|
||||
if (!cocktailId.IsGuid())
|
||||
{
|
||||
throw new ValidationException("The value in the field cocktailId is not a unique identifier.");
|
||||
}
|
||||
return _supplyStorageContract.GetList(fromDate, toDate, cocktailId: cocktailId) ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public SupplyDataModel GetSupplyByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get supply by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (!data.IsGuid())
|
||||
{
|
||||
throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _supplyStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
|
||||
public void ProcessSupply(SupplyDataModel supplyDataModel)
|
||||
{
|
||||
_logger.LogInformation("Processing supply: {json}", JsonSerializer.Serialize(supplyDataModel));
|
||||
|
||||
ArgumentNullException.ThrowIfNull(supplyDataModel);
|
||||
supplyDataModel.Validate();
|
||||
|
||||
foreach (var supplyCocktail in supplyDataModel.Cocktails)
|
||||
{
|
||||
var warehouses = _warehouseStorageContract.GetList();
|
||||
|
||||
var targetWarehouse = warehouses.FirstOrDefault(w =>
|
||||
w.Cocktails.Any(c => c.CocktailId == supplyCocktail.CocktailId));
|
||||
|
||||
if (targetWarehouse == null)
|
||||
{
|
||||
targetWarehouse = warehouses.FirstOrDefault();
|
||||
if (targetWarehouse == null)
|
||||
{
|
||||
throw new ElementNotFoundException("No warehouse found for supply.");
|
||||
}
|
||||
}
|
||||
|
||||
_warehouseStorageContract.UpdWarehouseOnSupply(targetWarehouse.Id, supplyCocktail.CocktailId, supplyCocktail.Count);
|
||||
}
|
||||
}
|
||||
|
||||
public void InsertSupply(SupplyDataModel supplyDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(supplyDataModel));
|
||||
ArgumentNullException.ThrowIfNull(supplyDataModel);
|
||||
supplyDataModel.Validate();
|
||||
_supplyStorageContract.AddElement(supplyDataModel);
|
||||
ProcessSupply(supplyDataModel);
|
||||
}
|
||||
|
||||
public void UpdateSupply(SupplyDataModel supplyDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(supplyDataModel));
|
||||
ArgumentNullException.ThrowIfNull(supplyDataModel);
|
||||
supplyDataModel.Validate();
|
||||
_supplyStorageContract.UpdateElement(supplyDataModel);
|
||||
ProcessSupply(supplyDataModel);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SquirrelContract.BusinessLogicContracts;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace SquirrelBusinessLogic.Implementations;
|
||||
|
||||
internal class WarehouseBusinessLogicContract(IWarehouseStorageContract warehouseStorageContract, ILogger logger) : IWarehouseBusinessLogicContract
|
||||
{
|
||||
private readonly ILogger _logger = logger;
|
||||
private readonly IWarehouseStorageContract _warehouseStorageContract = warehouseStorageContract;
|
||||
public List<WarehouseDataModel> GetAllWarehouses()
|
||||
{
|
||||
_logger.LogInformation("GetAllWarehouses");
|
||||
return _warehouseStorageContract.GetList() ?? throw new NullListException();
|
||||
}
|
||||
|
||||
public WarehouseDataModel GetWarehouseByData(string data)
|
||||
{
|
||||
_logger.LogInformation("Get element by data: {data}", data);
|
||||
if (data.IsEmpty())
|
||||
{
|
||||
throw new ArgumentNullException(nameof(data));
|
||||
}
|
||||
if (data.IsGuid())
|
||||
{
|
||||
return _warehouseStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
|
||||
}
|
||||
return _warehouseStorageContract.GetElementByName(data) ?? throw new ElementNotFoundException(data);
|
||||
|
||||
}
|
||||
|
||||
public void InsertWarehouse(WarehouseDataModel warehouseDataModel)
|
||||
{
|
||||
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(warehouseDataModel));
|
||||
ArgumentNullException.ThrowIfNull(warehouseDataModel);
|
||||
warehouseDataModel.Validate();
|
||||
_warehouseStorageContract.AddElement(warehouseDataModel);
|
||||
}
|
||||
|
||||
public void UpdateWarehouse(WarehouseDataModel warehouseDataModel)
|
||||
{
|
||||
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(warehouseDataModel));
|
||||
ArgumentNullException.ThrowIfNull(warehouseDataModel);
|
||||
warehouseDataModel.Validate();
|
||||
_warehouseStorageContract.UpdElement(warehouseDataModel);
|
||||
}
|
||||
|
||||
public void DeleteWarehouse(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");
|
||||
}
|
||||
_warehouseStorageContract.DelElement(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using SquirrelContract.DataModels;
|
||||
|
||||
namespace SquirrelContract.BusinessLogicContracts;
|
||||
|
||||
public interface ISupplyBusinessLogicContract
|
||||
{
|
||||
List<SupplyDataModel> GetAllSuppliesByPeriod(DateTime fromDate, DateTime toDate);
|
||||
|
||||
List<SupplyDataModel> GetAllSuppliesByCocktailByPeriod(string cocktailId, DateTime fromDate, DateTime toDate);
|
||||
|
||||
SupplyDataModel GetSupplyByData(string data);
|
||||
|
||||
void InsertSupply(SupplyDataModel supplyDataModel);
|
||||
|
||||
void UpdateSupply(SupplyDataModel supplyDataModel);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
using SquirrelContract.DataModels;
|
||||
|
||||
namespace SquirrelContract.BusinessLogicContracts;
|
||||
|
||||
public interface IWarehouseBusinessLogicContract
|
||||
{
|
||||
List<WarehouseDataModel> GetAllWarehouses();
|
||||
|
||||
WarehouseDataModel GetWarehouseByData(string data);
|
||||
|
||||
void InsertWarehouse(WarehouseDataModel cocktailDataModel);
|
||||
|
||||
void UpdateWarehouse(WarehouseDataModel cocktailDataModel);
|
||||
|
||||
void DeleteWarehouse(string id);
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class SupplyCocktailDataModel(string? supplyId, string? cocktailId, int count) : IValidation
|
||||
{
|
||||
public string SupplyId { get; private set; } = supplyId;
|
||||
|
||||
public string CocktailId { get; private set; } = cocktailId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SupplyId.IsEmpty())
|
||||
throw new ValidationException("Field SupplyId is empty");
|
||||
|
||||
if (!SupplyId.IsGuid())
|
||||
throw new ValidationException("The value in the field SupplyId is not a unique identifier");
|
||||
|
||||
if (CocktailId.IsEmpty())
|
||||
throw new ValidationException("Field CocktailId is empty");
|
||||
|
||||
if (!CocktailId.IsGuid())
|
||||
throw new ValidationException("The value in the field CocktailId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class SupplyDataModel(string? id, DateTime dateTime, List<SupplyCocktailDataModel> cocktails) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public DateTime SupplyDate { get; private set; } = dateTime;
|
||||
|
||||
public List<SupplyCocktailDataModel> Cocktails { get; private set; } = cocktails;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (SupplyDate.Date > DateTime.Now)
|
||||
throw new ValidationException($"It is impossible to supply things in the future");
|
||||
|
||||
if ((Cocktails?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The components must include products");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class WarehouseCocktailDataModel(string? warehouseId, string? cocktailId, int count) : IValidation
|
||||
{
|
||||
public string WarehouseId { get; private set; } = warehouseId;
|
||||
|
||||
public string CocktailId { get; private set; } = cocktailId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (WarehouseId.IsEmpty())
|
||||
throw new ValidationException("Field WarehouseId is empty");
|
||||
|
||||
if (!WarehouseId.IsGuid())
|
||||
throw new ValidationException("The value in the field WarehouseId is not a unique identifier");
|
||||
|
||||
if (CocktailId.IsEmpty())
|
||||
throw new ValidationException("Field CocktailId is empty");
|
||||
|
||||
if (!CocktailId.IsGuid())
|
||||
throw new ValidationException("The value in the field CocktailId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class WarehouseDataModel(string? id, string name, List<WarehouseCocktailDataModel> cocktails) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string Name { get; private set; } = name;
|
||||
|
||||
public List<WarehouseCocktailDataModel> Cocktails { get; private set; } = cocktails;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (Name.IsEmpty())
|
||||
throw new ValidationException("Field Name is empty");
|
||||
|
||||
if ((Cocktails?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The cocktails must include drinks");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
namespace SquirrelContract.Exceptions;
|
||||
|
||||
public class InsufficientStockException(string message) : Exception(message)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using SquirrelContract.DataModels;
|
||||
|
||||
namespace SquirrelContract.StoragesContracts;
|
||||
|
||||
public interface ISupplyStorageContract
|
||||
{
|
||||
List<SupplyDataModel> GetList(DateTime? startDate = null, DateTime? endDate = null, string? cocktailId = null);
|
||||
SupplyDataModel? GetElementById(string id);
|
||||
void AddElement(SupplyDataModel warehouseDataModel);
|
||||
void UpdateElement(SupplyDataModel warehouseDataModel);
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using SquirrelContract.DataModels;
|
||||
|
||||
namespace SquirrelContract.StoragesContracts;
|
||||
|
||||
public interface IWarehouseStorageContract
|
||||
{
|
||||
List<WarehouseDataModel> GetList();
|
||||
WarehouseDataModel? GetElementByName(string name);
|
||||
WarehouseDataModel? GetElementById(string id);
|
||||
void AddElement(WarehouseDataModel warehouseDataModel);
|
||||
void UpdElement(WarehouseDataModel warehouseDataModel);
|
||||
void UpdWarehouseOnSupply(string warehouseId, string cocktailId, int count);
|
||||
void DelElement(string id);
|
||||
bool CheckCocktails(SaleDataModel saleDataModel);
|
||||
}
|
||||
@@ -13,18 +13,21 @@ internal class SaleBusinessLogicContractTests
|
||||
{
|
||||
private SaleBusinessLogicContract _saleBusinessLogicContract;
|
||||
private Mock<ISaleStorageContract> _saleStorageContract;
|
||||
private Mock<IWarehouseStorageContract> _warehouseStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_saleStorageContract = new Mock<ISaleStorageContract>();
|
||||
_saleBusinessLogicContract = new SaleBusinessLogicContract(_saleStorageContract.Object, new Mock<ILogger>().Object);
|
||||
_warehouseStorageContract = new Mock<IWarehouseStorageContract>();
|
||||
_saleBusinessLogicContract = new SaleBusinessLogicContract(_saleStorageContract.Object, _warehouseStorageContract.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_saleStorageContract.Reset();
|
||||
_warehouseStorageContract.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -391,6 +394,7 @@ internal class SaleBusinessLogicContractTests
|
||||
var flag = false;
|
||||
var record = new SaleDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.None, 10,
|
||||
false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_warehouseStorageContract.Setup(x => x.CheckCocktails(It.IsAny<SaleDataModel>())).Returns(true);
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>()))
|
||||
.Callback((SaleDataModel x) =>
|
||||
{
|
||||
@@ -404,6 +408,7 @@ internal class SaleBusinessLogicContractTests
|
||||
//Act
|
||||
_saleBusinessLogicContract.InsertSale(record);
|
||||
//Assert
|
||||
_warehouseStorageContract.Verify(x => x.CheckCocktails(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
@@ -412,11 +417,13 @@ internal class SaleBusinessLogicContractTests
|
||||
public void InsertSale_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_warehouseStorageContract.Setup(x => x.CheckCocktails(It.IsAny<SaleDataModel>())).Returns(true);
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
_warehouseStorageContract.Verify(x => x.CheckCocktails(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -439,13 +446,27 @@ internal class SaleBusinessLogicContractTests
|
||||
public void InsertSale_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_warehouseStorageContract.Setup(x => x.CheckCocktails(It.IsAny<SaleDataModel>())).Returns(true);
|
||||
_saleStorageContract.Setup(x => x.AddElement(It.IsAny<SaleDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _saleBusinessLogicContract.InsertSale(new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.None, 10, false, [new SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_warehouseStorageContract.Verify(x => x.CheckCocktails(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
_saleStorageContract.Verify(x => x.AddElement(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSale_InsufficientError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_warehouseStorageContract.Setup(x => x.CheckCocktails(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 SaleCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<InsufficientStockException>());
|
||||
//Act&Assert
|
||||
_warehouseStorageContract.Verify(x => x.CheckCocktails(It.IsAny<SaleDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CancelSale_CorrectRecord_Test()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,284 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using SquirrelBusinessLogic.Implementations;
|
||||
using SquirrelContract.BusinessLogicContracts;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Enums;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SquirrelTests.BusinessLogicContractsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplyBusinessLogicContractTests
|
||||
{
|
||||
private SupplyBusinessLogicContract _supplyBusinessLogicContract;
|
||||
private Mock<ISupplyStorageContract> _supplyStorageContract;
|
||||
private Mock<IWarehouseStorageContract> _warehouseStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_supplyStorageContract = new Mock<ISupplyStorageContract>();
|
||||
_warehouseStorageContract = new Mock<IWarehouseStorageContract>();
|
||||
_supplyBusinessLogicContract = new SupplyBusinessLogicContract(_supplyStorageContract.Object, _warehouseStorageContract.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_supplyStorageContract.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByPeriod_ReturnListOfRecords_Test()
|
||||
{
|
||||
var date = DateTime.UtcNow;
|
||||
// Arrange
|
||||
var listOriginal = new List<SupplyDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), DateTime.Now, []),
|
||||
new(Guid.NewGuid().ToString(), DateTime.Now, []),
|
||||
new(Guid.NewGuid().ToString(), DateTime.Now, [])
|
||||
};
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
// Act
|
||||
var list = _supplyBusinessLogicContract.GetAllSuppliesByPeriod(date, date.AddDays(1));
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
_supplyStorageContract.Verify(x => x.GetList(date, date.AddDays(1), null), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByPeriod_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var list = _supplyBusinessLogicContract.GetAllSuppliesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1));
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByPeriod_IncorrectDates_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByPeriod(date, date), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByPeriod(date, date.AddSeconds(-1)), Throws.TypeOf<IncorrectDatesException>());
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByPeriod_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByPeriod_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByPeriod(DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByCocktailByPeriod_ReturnListOfRecords_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
var cocktailId = Guid.NewGuid().ToString();
|
||||
var listOriginal = new List<SupplyDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), DateTime.Now,
|
||||
[new SupplyCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]),
|
||||
new(Guid.NewGuid().ToString(), DateTime.Now, []),
|
||||
new(Guid.NewGuid().ToString(), DateTime.Now, []),
|
||||
};
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Returns(listOriginal);
|
||||
//Act
|
||||
var list = _supplyBusinessLogicContract.GetAllSuppliesByCocktailByPeriod(cocktailId, date, date.AddDays(1));
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
_supplyStorageContract.Verify(x => x.GetList(date, date.AddDays(1), cocktailId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByCocktailByPeriod_ReturnEmptyList_Test()
|
||||
{
|
||||
//Arrange
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Returns([]);
|
||||
//Act
|
||||
var list = _supplyBusinessLogicContract.GetAllSuppliesByCocktailByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1));
|
||||
//Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByCocktailByPeriod_IncorrectDates_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var date = DateTime.UtcNow;
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByCocktailByPeriod(Guid.NewGuid().ToString(), date, date), Throws.TypeOf<IncorrectDatesException>());
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByCocktailByPeriod(Guid.NewGuid().ToString(), date, date.AddSeconds(-1)), Throws.TypeOf<IncorrectDatesException>());
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByCocktailByPeriod_CocktailIdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByCocktailByPeriod(null, DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByCocktailByPeriod(string.Empty, DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<ArgumentNullException>());
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByCocktailByPeriod_CocktailIdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByCocktailByPeriod("cocktailId", DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<ValidationException>());
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByCocktailByPeriod_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByCocktailByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<NullListException>());
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSuppliesByCocktailByPeriod_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_supplyStorageContract.Setup(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetAllSuppliesByCocktailByPeriod(Guid.NewGuid().ToString(), DateTime.UtcNow, DateTime.UtcNow.AddDays(1)), Throws.TypeOf<StorageException>());
|
||||
_supplyStorageContract.Verify(x => x.GetList(It.IsAny<DateTime?>(), It.IsAny<DateTime?>(), It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
[Test]
|
||||
public void GetSupplyByData_GetById_ReturnRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new SupplyDataModel(id, DateTime.Now, []);
|
||||
_supplyStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
// Act
|
||||
var element = _supplyBusinessLogicContract.GetSupplyByData(id);
|
||||
// Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
_supplyStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSupplyByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetSupplyByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetSupplyByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_supplyStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSupplyByData_GetById_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_supplyStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new ElementNotFoundException(""));
|
||||
// Act & Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetSupplyByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_supplyStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSuppliesByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_supplyStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.GetSupplyByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_supplyStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSupply_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var cocktailId = Guid.NewGuid().ToString();
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
|
||||
var record = new SupplyDataModel(supplyId, DateTime.Now,
|
||||
[new SupplyCocktailDataModel(supplyId, cocktailId, 5)]);
|
||||
|
||||
var warehouse = new WarehouseDataModel(warehouseId, "Main Warehouse",
|
||||
[new WarehouseCocktailDataModel(warehouseId, cocktailId, 10)]);
|
||||
|
||||
_supplyStorageContract.Setup(x => x.AddElement(It.IsAny<SupplyDataModel>()));
|
||||
_warehouseStorageContract.Setup(x => x.GetList()).Returns([warehouse]);
|
||||
_warehouseStorageContract.Setup(x => x.UpdWarehouseOnSupply(warehouseId, cocktailId, 5));
|
||||
|
||||
// Act
|
||||
_supplyBusinessLogicContract.InsertSupply(record);
|
||||
|
||||
// Assert
|
||||
_supplyStorageContract.Verify(x => x.AddElement(It.IsAny<SupplyDataModel>()), Times.Once);
|
||||
_warehouseStorageContract.Verify(x => x.UpdWarehouseOnSupply(warehouseId, cocktailId, 5), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSupply_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_supplyStorageContract.Setup(x => x.AddElement(It.IsAny<SupplyDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
// Act & Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.InsertSupply(new(Guid.NewGuid().ToString(), DateTime.Now,
|
||||
[new SupplyCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_supplyStorageContract.Verify(x => x.AddElement(It.IsAny<SupplyDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSupply_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.InsertSupply(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_supplyStorageContract.Verify(x => x.AddElement(It.IsAny<SupplyDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSupply_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.InsertSupply(new SupplyDataModel("id", DateTime.UtcNow, [])), Throws.TypeOf<ValidationException>());
|
||||
_supplyStorageContract.Verify(x => x.AddElement(It.IsAny<SupplyDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSupply_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_supplyStorageContract.Setup(x => x.AddElement(It.IsAny<SupplyDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _supplyBusinessLogicContract.InsertSupply(new(Guid.NewGuid().ToString(), DateTime.Now,
|
||||
[new SupplyCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_supplyStorageContract.Verify(x => x.AddElement(It.IsAny<SupplyDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,320 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Moq;
|
||||
using SquirrelBusinessLogic.Implementations;
|
||||
using SquirrelContract.BusinessLogicContracts;
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Enums;
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.StoragesContracts;
|
||||
|
||||
namespace SquirrelTests.BusinessLogicContractsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WarehouseBusinessLogicContractTests
|
||||
{
|
||||
private WarehouseBusinessLogicContract _warehouseBusinessLogicContract;
|
||||
private Mock<IWarehouseStorageContract> _warehouseStorageContract;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_warehouseStorageContract = new Mock<IWarehouseStorageContract>();
|
||||
_warehouseBusinessLogicContract = new WarehouseBusinessLogicContract(_warehouseStorageContract.Object, new Mock<ILogger>().Object);
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
_warehouseStorageContract.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWarehouses_ReturnListOfRecords_Test()
|
||||
{
|
||||
// Arrange
|
||||
var listOriginal = new List<WarehouseDataModel>()
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), "aba", []),
|
||||
new(Guid.NewGuid().ToString(), "aaa", []),
|
||||
new(Guid.NewGuid().ToString(), "aaa", []),
|
||||
};
|
||||
_warehouseStorageContract.Setup(x => x.GetList()).Returns(listOriginal);
|
||||
// Act
|
||||
var list = _warehouseBusinessLogicContract.GetAllWarehouses();
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(listOriginal));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWarehouses_ReturnEmptyList_Test()
|
||||
{
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.GetList()).Returns([]);
|
||||
// Act
|
||||
var list = _warehouseBusinessLogicContract.GetAllWarehouses();
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_warehouseStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWarehouses_ReturnNull_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.GetList()).Returns((List<WarehouseDataModel>)null);
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.GetAllWarehouses(), Throws.TypeOf<NullListException>());
|
||||
_warehouseStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWarehouses_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.GetAllWarehouses(), Throws.TypeOf<StorageException>());
|
||||
_warehouseStorageContract.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllWarehousesByData_GetById_ReturnRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var record = new WarehouseDataModel(id, "aba", []);
|
||||
_warehouseStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
|
||||
// Act
|
||||
var element = _warehouseBusinessLogicContract.GetWarehouseByData(id);
|
||||
// Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
_warehouseStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetCocktailByData_GetByName_ReturnRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var name = "name";
|
||||
var record = new WarehouseDataModel(Guid.NewGuid().ToString(), name, []);
|
||||
_warehouseStorageContract.Setup(x => x.GetElementByName(name)).Returns(record);
|
||||
//Act
|
||||
var element = _warehouseBusinessLogicContract.GetWarehouseByData(name);
|
||||
//Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Name, Is.EqualTo(name));
|
||||
_warehouseStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWarehouseByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.GetWarehouseByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _warehouseBusinessLogicContract.GetWarehouseByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_warehouseStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
||||
_warehouseStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWarehouseByData_GetById_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new ElementNotFoundException(""));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.GetWarehouseByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
_warehouseStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWarehouseByData_GetByName_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.GetWarehouseByData("name"), Throws.TypeOf<ElementNotFoundException>());
|
||||
_warehouseStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetWarehouseByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_warehouseStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_warehouseStorageContract.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.GetWarehouseByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _warehouseBusinessLogicContract.GetWarehouseByData("name"), Throws.TypeOf<StorageException>());
|
||||
_warehouseStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_warehouseStorageContract.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWarehouse_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var record = new WarehouseDataModel(Guid.NewGuid().ToString(), "aba",
|
||||
[new WarehouseCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_warehouseStorageContract.Setup(x => x.AddElement(It.IsAny<WarehouseDataModel>()));
|
||||
// Act
|
||||
_warehouseBusinessLogicContract.InsertWarehouse(record);
|
||||
// Assert
|
||||
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<WarehouseDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWarehouse_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.AddElement(It.IsAny<WarehouseDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertWarehouse(new(Guid.NewGuid().ToString(), "aba",
|
||||
[new WarehouseCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<WarehouseDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWarehouse_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertWarehouse(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<WarehouseDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWarehouse_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertWarehouse(new WarehouseDataModel("id", "aba", [])), Throws.TypeOf<ValidationException>());
|
||||
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<WarehouseDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertWarehouse_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.AddElement(It.IsAny<WarehouseDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.InsertWarehouse(new(Guid.NewGuid().ToString(), "aba",
|
||||
[new WarehouseCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<WarehouseDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWarehouse_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var record = new WarehouseDataModel(Guid.NewGuid().ToString(), "aba",
|
||||
[new WarehouseCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
|
||||
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<WarehouseDataModel>()));
|
||||
// Act
|
||||
_warehouseBusinessLogicContract.UpdateWarehouse(record);
|
||||
// Assert
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<WarehouseDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWarehouse_RecordWithIncorrectData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<WarehouseDataModel>())).Throws(new ElementNotFoundException(""));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateWarehouse(new(Guid.NewGuid().ToString(), "aba",
|
||||
[new WarehouseCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementNotFoundException>());
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<WarehouseDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWarehouse_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<WarehouseDataModel>())).Throws(new ElementExistsException("Data", "Data"));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateWarehouse(new(Guid.NewGuid().ToString(), "aba",
|
||||
[new WarehouseCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<WarehouseDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWarehouse_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateWarehouse(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<WarehouseDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWarehouse_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateWarehouse(new WarehouseDataModel(Guid.NewGuid().ToString(), "aba", [])), Throws.TypeOf<ValidationException>());
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<WarehouseDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateWarehouse_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<WarehouseDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
// Act & Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.UpdateWarehouse(new(Guid.NewGuid().ToString(), "aba",
|
||||
[new WarehouseCocktailDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
|
||||
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<WarehouseDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWarehouse_CorrectRecord_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
_warehouseStorageContract.Setup(x => x.DelElement(It.Is((string x) => x == id))).Callback(() => { flag = true; });
|
||||
//Act
|
||||
_warehouseBusinessLogicContract.DeleteWarehouse(id);
|
||||
//Assert
|
||||
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once); Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWarehouse_RecordWithIncorrectId_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_warehouseStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new ElementNotFoundException(id));
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.DeleteWarehouse(Guid.NewGuid().ToString()),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWarehouse_IdIsNullOrEmpty_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.DeleteWarehouse(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _warehouseBusinessLogicContract.DeleteWarehouse(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWarehouse_IdIsNotGuid_ThrowException_Test()
|
||||
{
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.DeleteWarehouse("id"),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteWarehouse_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
//Arrange
|
||||
_warehouseStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
//Act&Assert
|
||||
Assert.That(() => _warehouseBusinessLogicContract.DeleteWarehouse(Guid.NewGuid().ToString()),
|
||||
Throws.TypeOf<StorageException>());
|
||||
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
|
||||
namespace SquirrelTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplyCocktailDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void SupplyIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supplyCocktail = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNotGuidTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel("SupplyId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNotGuidTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), "ComponentId", 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var cocktailId = Guid.NewGuid().ToString();
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var count = 5;
|
||||
var supplyCocktail = CreateDataModel(supplyId, cocktailId, count);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supplyCocktail.SupplyId, Is.EqualTo(supplyId));
|
||||
Assert.That(supplyCocktail.CocktailId, Is.EqualTo(cocktailId));
|
||||
Assert.That(supplyCocktail.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyCocktailDataModel CreateDataModel(string? supplyId, string? cocktailId, int count) =>
|
||||
new(supplyId, cocktailId, count);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
|
||||
namespace SquirrelTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplyDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var supply = CreateDataModel(null, DateTime.Now, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supply = CreateDataModel(string.Empty, DateTime.Now, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var supply = CreateDataModel("id", DateTime.Now, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailsIsNullOrEmptyTest()
|
||||
{
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, null);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, []);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DateIsNotCorrectTest()
|
||||
{
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now.AddDays(5), CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var date = DateTime.Now;
|
||||
var cocktails = CreateSubDataModel();
|
||||
var supply = CreateDataModel(supplyId, date, cocktails);
|
||||
Assert.That(() => supply.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supply.Id, Is.EqualTo(supplyId));
|
||||
Assert.That(supply.SupplyDate, Is.EqualTo(date));
|
||||
Assert.That(supply.Cocktails, Is.EquivalentTo(cocktails));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyDataModel CreateDataModel(string? id, DateTime date, List<SupplyCocktailDataModel> cocktails) =>
|
||||
new(id, date, cocktails);
|
||||
|
||||
private static List<SupplyCocktailDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
|
||||
namespace SquirrelTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WarehouseCocktailDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WarehouseIdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseCocktail = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIdIsNotGuidTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel("id", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNotGuidTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), "id", 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var cocktailId = Guid.NewGuid().ToString();
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
var count = 5;
|
||||
var warehouseCocktail = CreateDataModel(warehouseId, cocktailId, count);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(warehouseCocktail.WarehouseId, Is.EqualTo(warehouseId));
|
||||
Assert.That(warehouseCocktail.CocktailId, Is.EqualTo(cocktailId));
|
||||
Assert.That(warehouseCocktail.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseCocktailDataModel CreateDataModel(string? storageId, string? cocktailId, int count) =>
|
||||
new(storageId, cocktailId, count);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
|
||||
namespace SquirrelTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WarehouseDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(null, "name", CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouse = CreateDataModel(string.Empty, "name", CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var warehouse = CreateDataModel("id", "name", CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseNameIsEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), null, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailsIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), "name", null);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), "name", []);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
var warehouseName = "name";
|
||||
var cocktails = CreateSubDataModel();
|
||||
var warehouse = CreateDataModel(warehouseId, warehouseName, cocktails);
|
||||
Assert.That(() => warehouse.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(warehouse.Id, Is.EqualTo(warehouseId));
|
||||
Assert.That(warehouse.Name, Is.EqualTo(warehouseName));
|
||||
Assert.That(warehouse.Cocktails, Is.EquivalentTo(cocktails));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseDataModel CreateDataModel(string? id, string? warehouseName, List<WarehouseCocktailDataModel> cocktails) =>
|
||||
new(id, warehouseName, cocktails);
|
||||
|
||||
private static List<WarehouseCocktailDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), "name", 1)];
|
||||
}
|
||||
Reference in New Issue
Block a user