This commit is contained in:
2025-04-15 01:47:02 +04:00
parent 4518d36016
commit d51c616862
19 changed files with 443 additions and 40 deletions

View File

@@ -0,0 +1,72 @@
using CandyHouseContracts.BusinessLogicContracts;
using CandyHouseContracts.DataModels;
using CandyHouseContracts.Enums;
using CandyHouseContracts.Exceptions;
using CandyHouseContracts.Extensions;
using CandyHouseContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
namespace CandyHouseBusinessLogic.Implementations;
public class StorageBusinessLogicContract(IStorageStorageContract agencyStorageContract, ILogger logger) : IStorageBusinessLogicContract
{
private readonly IStorageStorageContract _agencyStorageContract = agencyStorageContract;
private readonly ILogger _logger = logger;
public List<StorageDataModel> GetAllComponents()
{
_logger.LogInformation("GetAllComponents");
return _agencyStorageContract.GetList() ?? throw new NullListException();
return [];
}
public StorageDataModel GetComponentByData(string data)
{
_logger.LogInformation("Get element by data: {data}", data);
if (data.IsEmpty())
{
throw new ArgumentNullException(nameof(data));
}
if (!data.IsGuid())
{
throw new ElementNotFoundException(data);
}
return _agencyStorageContract.GetElementById(data) ?? throw new ElementNotFoundException(data);
}
public void InsertComponent(StorageDataModel storageDataModel)
{
_logger.LogInformation("New data: {json}", JsonSerializer.Serialize(storageDataModel));
ArgumentNullException.ThrowIfNull(storageDataModel);
storageDataModel.Validate();
_agencyStorageContract.AddElement(storageDataModel);
}
public void UpdateComponent(StorageDataModel storageDataModel)
{
_logger.LogInformation("Update data: {json}", JsonSerializer.Serialize(storageDataModel));
ArgumentNullException.ThrowIfNull(storageDataModel);
storageDataModel.Validate();
_agencyStorageContract.UpdElement(storageDataModel);
}
public void DeleteComponent(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");
}
_agencyStorageContract.DelElement(id);
}
}

View File

@@ -0,0 +1,17 @@
using CandyHouseContracts.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CandyHouseContracts.BusinessLogicContracts;
public interface IStorageBusinessLogicContract
{
List<StorageDataModel> GetAllComponents();
StorageDataModel GetComponentByData(string data);
void InsertComponent(StorageDataModel storageDataModel);
void UpdateComponent(StorageDataModel storageDataModel);
void DeleteComponent(string id);
}

View File

@@ -13,7 +13,7 @@ using System.Xml.Linq;
namespace CandyHouseContracts.DataModels;
public class ProductDataModel(string id, string productName, string productDescription, double price, ProductType productType,
List<ProductSuppliesDataModel> supplies, List<ProductAgencyDataModel> agency) : IValidation
List<ProductSuppliesDataModel> supplies, List<ProductStorageDataModel> agency) : IValidation
{
public string Id { get; private set; } = id;
public string ProductName { get; private set; } = productName;
@@ -21,7 +21,7 @@ public class ProductDataModel(string id, string productName, string productDescr
public double Price { get; private set; } = price;
public ProductType Type { get; private set; } = productType;
public List<ProductSuppliesDataModel> Supplies { get; private set; } = supplies;
public List<ProductAgencyDataModel> Agency { get; private set; } = agency;
public List<ProductStorageDataModel> Storage { get; private set; } = agency;
public void Validate()
{
@@ -39,7 +39,7 @@ public class ProductDataModel(string id, string productName, string productDescr
throw new ValidationException("Field Type is empty");
if ((Supplies?.Count ?? 0) == 0)
throw new ValidationException("The product must include supplies");
if ((Agency?.Count ?? 0) == 0)
if ((Storage?.Count ?? 0) == 0)
throw new ValidationException("The product must include agency");
}
}

View File

@@ -10,18 +10,18 @@ using System.Threading.Tasks;
namespace CandyHouseContracts.DataModels;
public class ProductAgencyDataModel(string agencyId, string productId, int count) : IValidation
public class ProductStorageDataModel(string agencyId, string productId, int count) : IValidation
{
public string AgencyId { get; private set; } = agencyId;
public string StorageId { get; private set; } = agencyId;
public string ProductId { get; private set; } = productId;
public int Count { get; private set; } = count;
public void Validate()
{
if (AgencyId.IsEmpty())
throw new ValidationException("Field AgencyId is empty");
if (!AgencyId.IsGuid())
throw new ValidationException("The value in the field AgencyId is not a unique identifier");
if (StorageId.IsEmpty())
throw new ValidationException("Field StorageId is empty");
if (!StorageId.IsGuid())
throw new ValidationException("The value in the field StorageId is not a unique identifier");
if (ProductId.IsEmpty())
throw new ValidationException("Field ProductId is empty");
if (!ProductId.IsGuid())

View File

@@ -10,12 +10,12 @@ using System.Threading.Tasks;
namespace CandyHouseContracts.DataModels;
public class AgencyDataModel(string id, ProductType productType, int count, List<ProductAgencyDataModel> products) : IValidation
public class StorageDataModel(string id, ProductType productType, int count, List<ProductStorageDataModel> products) : IValidation
{
public string Id { get; private set; } = id;
public ProductType Type { get; private set; } = productType;
public int Count { get; private set; } = count;
public List<ProductAgencyDataModel> Products { get; private set; } = products;
public List<ProductStorageDataModel> Products { get; private set; } = products;
public void Validate()
{

View File

@@ -15,7 +15,7 @@ public class SuppliesDataModel(string id, ProductType productType, DateTime date
{
public string Id { get; private set; } = id;
public ProductType Type { get; private set; } = productType;
public DateTime ProductuionDate { get; private set; } = date;
public DateTime OrderDate { get; private set; } = date;
public int Count { get; private set; } = count;
public List<ProductSuppliesDataModel> Products { get; private set; } = products;

View File

@@ -0,0 +1,18 @@
using CandyHouseContracts.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CandyHouseContracts.StoragesContracts;
public interface IStorageStorageContract
{
List<StorageDataModel> GetList();
StorageDataModel GetElementById(string id);
void AddElement(StorageDataModel storageDataModel);
void UpdElement(StorageDataModel storageDataModel);
void DelElement(string id);
bool CheckComponents(SaleDataModel saleDataModel);
}

View File

@@ -291,7 +291,7 @@ internal class ProductBusinessLogicContractTests
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new ProductDataModel("id", "name", "country", 10,
ProductType.Chocolate,
[new ProductSuppliesDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)],
[new ProductAgencyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])),
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])),
Throws.TypeOf<ValidationException>());
_productStorageContract.Verify(x => x.UpdElement(It.IsAny<ProductDataModel>()), Times.Never);
}

View File

@@ -0,0 +1,296 @@
using CandyHouseBusinessLogic.Implementations;
using CandyHouseContracts.BusinessLogicContracts;
using CandyHouseContracts.DataModels;
using CandyHouseContracts.Enums;
using CandyHouseContracts.Exceptions;
using CandyHouseContracts.StoragesContracts;
using Microsoft.Extensions.Logging;
using Moq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CandyHouseTests.BusinessLogicContractsTests;
[TestFixture]
internal class StorageBusinessLogicContractTests
{
private IStorageBusinessLogicContract _warehouseBusinessLogicContract;
private Mock<IStorageStorageContract> _warehouseStorageContract;
[OneTimeSetUp]
public void OneTimeSetUp()
{
_warehouseStorageContract = new Mock<IStorageStorageContract>();
_warehouseBusinessLogicContract = new StorageBusinessLogicContract(_warehouseStorageContract.Object, new Mock<ILogger>().Object);
}
[TearDown]
public void TearDown()
{
_warehouseStorageContract.Reset();
}
public void GetAllSupplies_ReturnListOfRecords_Test()
{
// Arrange
var listOriginal = new List<StorageDataModel>()
{
new(Guid.NewGuid().ToString(), ProductType.Cake, 1, []),
new(Guid.NewGuid().ToString(), ProductType.Cake, 1, []),
new(Guid.NewGuid().ToString(), ProductType.Cake, 1, []),
};
_warehouseStorageContract.Setup(x => x.GetList()).Returns(listOriginal);
// Act
var list = _warehouseBusinessLogicContract.GetAllComponents();
// Assert
Assert.That(list, Is.Not.Null);
Assert.That(list, Is.EquivalentTo(listOriginal));
}
[Test]
public void GetAllSupplies_ReturnEmptyList_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.GetList()).Returns([]);
// Act
var list = _warehouseBusinessLogicContract.GetAllComponents();
// Assert
Assert.That(list, Is.Not.Null);
Assert.That(list, Has.Count.EqualTo(0));
_warehouseStorageContract.Verify(x => x.GetList(), Times.Once);
}
[Test]
public void GetAllSupplies_ReturnNull_ThrowException_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.GetList()).Returns((List<StorageDataModel>)null);
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.GetAllComponents(), Throws.TypeOf<NullListException>());
_warehouseStorageContract.Verify(x => x.GetList(), Times.Once);
}
[Test]
public void GetAllSupplies_StorageThrowError_ThrowException_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.GetAllComponents(), Throws.TypeOf<StorageException>());
_warehouseStorageContract.Verify(x => x.GetList(), Times.Once);
}
[Test]
public void GetSuppliesByData_GetById_ReturnRecord_Test()
{
// Arrange
var id = Guid.NewGuid().ToString();
var record = new StorageDataModel(id, ProductType.Cake, 1, []);
_warehouseStorageContract.Setup(x => x.GetElementById(id)).Returns(record);
// Act
var element = _warehouseBusinessLogicContract.GetComponentByData(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 GetComponentsByData_EmptyData_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _warehouseBusinessLogicContract.GetComponentByData(null), Throws.TypeOf<ArgumentNullException>());
Assert.That(() => _warehouseBusinessLogicContract.GetComponentByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
_warehouseStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
}
[Test]
public void GetSuppliesByData_GetById_NotFoundRecord_ThrowException_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new ElementNotFoundException(""));
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.GetComponentByData(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
_warehouseStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
}
[Test]
public void GetSuppliesByData_StorageThrowError_ThrowException_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.GetComponentByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
_warehouseStorageContract.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
}
[Test]
public void InsertSupplies_CorrectRecord_Test()
{
// Arrange
var record = new StorageDataModel(Guid.NewGuid().ToString(), ProductType.Cake, 1,
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
_warehouseStorageContract.Setup(x => x.AddElement(It.IsAny<StorageDataModel>()));
// Act
_warehouseBusinessLogicContract.InsertComponent(record);
// Assert
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<StorageDataModel>()), Times.Once);
}
[Test]
public void InsertSupplies_RecordWithExistsData_ThrowException_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.AddElement(It.IsAny<StorageDataModel>())).Throws(new ElementExistsException("Data", "Data"));
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<StorageDataModel>()), Times.Once);
}
[Test]
public void InsertSupplies_NullRecord_ThrowException_Test()
{
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(null), Throws.TypeOf<ArgumentNullException>());
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<StorageDataModel>()), Times.Never);
}
[Test]
public void InsertComponents_InvalidRecord_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(new StorageDataModel("id", ProductType.Cake, 1, [])), Throws.TypeOf<ValidationException>());
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<StorageDataModel>()), Times.Never);
}
[Test]
public void InsertSupplies_StorageThrowError_ThrowException_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.AddElement(It.IsAny<StorageDataModel>())).Throws(new StorageException(new InvalidOperationException()));
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.InsertComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
_warehouseStorageContract.Verify(x => x.AddElement(It.IsAny<StorageDataModel>()), Times.Once);
}
[Test]
public void UpdateSupplies_CorrectRecord_Test()
{
// Arrange
var record = new StorageDataModel(Guid.NewGuid().ToString(), ProductType.Cake, 1,
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)]);
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<StorageDataModel>()));
// Act
_warehouseBusinessLogicContract.UpdateComponent(record);
// Assert
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Once);
}
[Test]
public void UpdateSupplies_RecordWithIncorrectData_ThrowException_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<StorageDataModel>())).Throws(new ElementNotFoundException(""));
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementNotFoundException>());
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Once);
}
[Test]
public void UpdateSupplies_RecordWithExistsData_ThrowException_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<StorageDataModel>())).Throws(new ElementExistsException("Data", "Data"));
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<ElementExistsException>());
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Once);
}
[Test]
public void UpdateSupplies_NullRecord_ThrowException_Test()
{
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(null), Throws.TypeOf<ArgumentNullException>());
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Never);
}
[Test]
public void UpdateComponents_InvalidRecord_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new StorageDataModel(Guid.NewGuid().ToString(), ProductType.Cake, 1, [])), Throws.TypeOf<ValidationException>());
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Never);
}
[Test]
public void UpdateSupplies_StorageThrowError_ThrowException_Test()
{
// Arrange
_warehouseStorageContract.Setup(x => x.UpdElement(It.IsAny<StorageDataModel>())).Throws(new StorageException(new InvalidOperationException()));
// Act & Assert
Assert.That(() => _warehouseBusinessLogicContract.UpdateComponent(new(Guid.NewGuid().ToString(), ProductType.Cake, 1,
[new ProductStorageDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)])), Throws.TypeOf<StorageException>());
_warehouseStorageContract.Verify(x => x.UpdElement(It.IsAny<StorageDataModel>()), Times.Once);
}
[Test]
public void DeleteComponents_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.DeleteComponent(id);
//Assert
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once); Assert.That(flag);
}
[Test]
public void DeleteComponents_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.DeleteComponent(Guid.NewGuid().ToString()),
Throws.TypeOf<ElementNotFoundException>());
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
}
[Test]
public void DeleteComponents_IdIsNullOrEmpty_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _warehouseBusinessLogicContract.DeleteComponent(null), Throws.TypeOf<ArgumentNullException>());
Assert.That(() => _warehouseBusinessLogicContract.DeleteComponent(string.Empty), Throws.TypeOf<ArgumentNullException>());
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
}
[Test]
public void DeleteComponents_IdIsNotGuid_ThrowException_Test()
{
//Act&Assert
Assert.That(() => _warehouseBusinessLogicContract.DeleteComponent("id"),
Throws.TypeOf<ValidationException>());
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
}
[Test]
public void DeleteComponents_StorageThrowError_ThrowException_Test()
{
//Arrange
_warehouseStorageContract.Setup(x => x.DelElement(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
//Act&Assert
Assert.That(() => _warehouseBusinessLogicContract.DeleteComponent(Guid.NewGuid().ToString()),
Throws.TypeOf<StorageException>());
_warehouseStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Once);
}
}

View File

@@ -16,10 +16,10 @@ internal class ProductDataModelTests
public void IdIsNullOrEmptyTest()
{
var cocktail = CreateDataModel(null, "name", "country", 10.5, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
cocktail = CreateDataModel(string.Empty, "name", "country", 10.5, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
@@ -27,7 +27,7 @@ internal class ProductDataModelTests
public void IdIsNotGuidTest()
{
var cocktail = CreateDataModel("id", "name", "country", 10.5, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
@@ -35,19 +35,19 @@ internal class ProductDataModelTests
public void ProductNameIsNullOrEmptyTest()
{
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, "country", 10.5, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "country", 10.5, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
public void ProductDescriptionIsNullOrEmptyTest()
{
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", null, 10.5, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", string.Empty, 10.5, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
@@ -55,10 +55,10 @@ internal class ProductDataModelTests
public void PriceIsLessOrZeroTest()
{
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, string.Empty, -10.5, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
@@ -66,21 +66,21 @@ internal class ProductDataModelTests
public void ProductTypeIsNoneTest()
{
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, ProductType.Cake,
CreateSuppliesDataModel(), CreateAgencyDataModel());
CreateSuppliesDataModel(), CreateStorageDataModel());
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SuppliesIsEmptyOrNullTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), "name", "country", 10.5, ProductType.Cake, [], CreateAgencyDataModel());
var model = CreateDataModel(Guid.NewGuid().ToString(), "name", "country", 10.5, ProductType.Cake, [], CreateStorageDataModel());
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
model = CreateDataModel(Guid.NewGuid().ToString(), "name", "country", 10.5, ProductType.Cake, null, CreateAgencyDataModel());
model = CreateDataModel(Guid.NewGuid().ToString(), "name", "country", 10.5, ProductType.Cake, null, CreateStorageDataModel());
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AgencyIsEmptyOrNullTest()
public void StorageIsEmptyOrNullTest()
{
var model = CreateDataModel(Guid.NewGuid().ToString(), "name", "country", 10.5, ProductType.Cake, CreateSuppliesDataModel(), []);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
@@ -98,7 +98,7 @@ internal class ProductDataModelTests
var price = 10.5;
var productType = ProductType.Chocolate;
var supplies = CreateSuppliesDataModel();
var agency = CreateAgencyDataModel();
var agency = CreateStorageDataModel();
var product = CreateDataModel(productId, productName, productDescription, price, productType, supplies, agency);
Assert.That(() => product.Validate(), Throws.Nothing);
Assert.Multiple(() =>
@@ -109,16 +109,16 @@ internal class ProductDataModelTests
Assert.That(product.Price, Is.EqualTo(price));
Assert.That(product.Type, Is.EqualTo(productType));
Assert.That(product.Supplies, Is.EqualTo(supplies));
Assert.That(product.Agency, Is.EqualTo(agency));
Assert.That(product.Storage, Is.EqualTo(agency));
});
}
private static ProductDataModel CreateDataModel(string? id, string? productName, string? countryName, double price, ProductType productType,
List<ProductSuppliesDataModel> supplies, List<ProductAgencyDataModel> agency) =>
List<ProductSuppliesDataModel> supplies, List<ProductStorageDataModel> agency) =>
new(id, productName, countryName,price, productType, supplies, agency);
private static List<ProductSuppliesDataModel> CreateSuppliesDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
private static List<ProductAgencyDataModel> CreateAgencyDataModel()
private static List<ProductStorageDataModel> CreateStorageDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

View File

@@ -9,10 +9,10 @@ using System.Threading.Tasks;
namespace CandyHouseTests.DataModelTests;
[TestFixture]
internal class ProductAgencyDataModelTests
internal class ProductStorageDataModelTests
{
[Test]
public void AgencyIdIsNullOrEmptyTest()
public void StorageIdIsNullOrEmptyTest()
{
var model = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
@@ -22,7 +22,7 @@ internal class ProductAgencyDataModelTests
}
[Test]
public void AgencyIdIsNotGuidTest()
public void StorageIdIsNotGuidTest()
{
var model = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
@@ -64,12 +64,12 @@ internal class ProductAgencyDataModelTests
Assert.That(() => model.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(model.AgencyId, Is.EqualTo(agencyId));
Assert.That(model.StorageId, Is.EqualTo(agencyId));
Assert.That(model.ProductId, Is.EqualTo(productId));
Assert.That(model.Count, Is.EqualTo(count));
});
}
private static ProductAgencyDataModel CreateDataModel(string? agencyId, string? productId, int count)
private static ProductStorageDataModel CreateDataModel(string? agencyId, string? productId, int count)
=> new(agencyId, productId, count);
}

View File

@@ -10,7 +10,7 @@ using System.Threading.Tasks;
namespace CandyHouseTests.DataModelTests;
[TestFixture]
internal class AgencyDataModelTests
internal class StorageDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
@@ -72,8 +72,8 @@ internal class AgencyDataModelTests
});
}
private static AgencyDataModel CreateDataModel(string? id, ProductType type, int count, List<ProductAgencyDataModel> products)
=> new AgencyDataModel(id, type, count, products);
private static List<ProductAgencyDataModel> CreateSubDataModel()
private static StorageDataModel CreateDataModel(string? id, ProductType type, int count, List<ProductStorageDataModel> products)
=> new StorageDataModel(id, type, count, products);
private static List<ProductStorageDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

View File

@@ -67,7 +67,7 @@ internal class SuppliesDataModelTests
{
Assert.That(model.Id, Is.EqualTo(id));
Assert.That(model.Type, Is.EqualTo(type));
Assert.That(model.ProductuionDate, Is.EqualTo(date));
Assert.That(model.OrderDate, Is.EqualTo(date));
Assert.That(model.Count, Is.EqualTo(count));
Assert.That(model.Products, Is.EqualTo(products));
});