diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/StorageComponentDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/StorageComponentDataModel.cs new file mode 100644 index 0000000..144aaef --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/StorageComponentDataModel.cs @@ -0,0 +1,32 @@ +using TheCyclopsContracts.Exceptions; +using TheCyclopsContracts.Extensions; +using TheCyclopsContracts.Infrastructure; + +namespace TheCyclopsContracts.DataModels; + +public class StorageComponentDataModel(string storageId, string componentId, int count) : IValidation +{ + public string StorageId { get; private set; } = storageId; + + public string ComponentId { get; private set; } = componentId; + + public int Count { get; private set; } = count; + + public void Validate() + { + 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 (ComponentId.IsEmpty()) + throw new ValidationException("Field ComponentId is empty"); + + if (!ComponentId.IsGuid()) + throw new ValidationException("The value in the field ComponentId is not a unique identifier"); + + if (Count <= 0) + throw new ValidationException("Field Count is less than or equal to 0"); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/StorageDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/StorageDataModel.cs new file mode 100644 index 0000000..a60069b --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/StorageDataModel.cs @@ -0,0 +1,29 @@ +using TheCyclopsContracts.Exceptions; +using TheCyclopsContracts.Extensions; +using TheCyclopsContracts.Infrastructure; + +namespace TheCyclopsContracts.DataModels; + +public class StorageDataModel(string id, string address, List components) : IValidation +{ + public string Id { get; private set; } = id; + + public string Address { get; private set; } = address; + + public List Components { get; private set; } = components; + + 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 (Address.IsEmpty()) + throw new ValidationException("Field Address is empty"); + + if ((Components?.Count ?? 0) == 0) + throw new ValidationException("The supply must include components"); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/SupplyComponentDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/SupplyComponentDataModel.cs new file mode 100644 index 0000000..84b1328 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/SupplyComponentDataModel.cs @@ -0,0 +1,32 @@ +using TheCyclopsContracts.Exceptions; +using TheCyclopsContracts.Extensions; +using TheCyclopsContracts.Infrastructure; + +namespace TheCyclopsContracts.DataModels; + +public class SupplyComponentDataModel(string supplyId, string componentId, int count) : IValidation +{ + public string SupplyId { get; private set; } = supplyId; + + public string ComponentId { get; private set; } = componentId; + + 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 (ComponentId.IsEmpty()) + throw new ValidationException("Field ComponentId is empty"); + + if (!ComponentId.IsGuid()) + throw new ValidationException("The value in the field ComponentId is not a unique identifier"); + + if (Count <= 0) + throw new ValidationException("Field Count is less than or equal to 0"); + } +} diff --git a/TheCyclopsProject/TheCyclopsContracts/DataModels/SupplyDataModel.cs b/TheCyclopsProject/TheCyclopsContracts/DataModels/SupplyDataModel.cs new file mode 100644 index 0000000..791a59e --- /dev/null +++ b/TheCyclopsProject/TheCyclopsContracts/DataModels/SupplyDataModel.cs @@ -0,0 +1,27 @@ +using TheCyclopsContracts.Exceptions; +using TheCyclopsContracts.Extensions; +using TheCyclopsContracts.Infrastructure; + +namespace TheCyclopsContracts.DataModels; + +public class SupplyDataModel(string id, DateTime supplyDate, + List components) : IValidation +{ + public string Id { get; private set; } = id; + + public DateTime SupplyDate { get; private set; } = supplyDate; + + public List Components { get; private set; } = components; + + 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 ((Components?.Count ?? 0) == 0) + throw new ValidationException("The supply must include components"); + } +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/StorageComponentDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/StorageComponentDataModelTests.cs new file mode 100644 index 0000000..2645d2d --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/StorageComponentDataModelTests.cs @@ -0,0 +1,73 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class StorageComponentDataModelTests +{ + [Test] + public void StorageIdIsNullOrEmptyTest() + { + var storageComponent = CreateDataModel(null, Guid.NewGuid().ToString(), 10); + Assert.That(() => storageComponent.Validate(), Throws.TypeOf()); + + storageComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => storageComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void StorageIdIsNotGuidTest() + { + var storageComponent = CreateDataModel("storageId", Guid.NewGuid().ToString(), 10); + Assert.That(() => storageComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentIdIsNullOrEmptyTest() + { + var storageComponent = CreateDataModel(Guid.NewGuid().ToString(), null, 10); + Assert.That(() => storageComponent.Validate(), Throws.TypeOf()); + + storageComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => storageComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentIdIsNotGuidTest() + { + var storageComponent = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 10); + Assert.That(() => storageComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var storageComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => storageComponent.Validate(), Throws.TypeOf()); + + storageComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10); + Assert.That(() => storageComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var storageId = Guid.NewGuid().ToString(); + var componentId = Guid.NewGuid().ToString(); + var count = 10; + var storageComponent = CreateDataModel(storageId, componentId, count); + + Assert.That(() => storageComponent.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(storageComponent.StorageId, Is.EqualTo(storageId)); + Assert.That(storageComponent.ComponentId, Is.EqualTo(componentId)); + Assert.That(storageComponent.Count, Is.EqualTo(count)); + }); + } + + private static StorageComponentDataModel CreateDataModel(string? storageId, string? componentId, int count) => + new(storageId, componentId, count); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/StorageDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/StorageDataModelTests.cs new file mode 100644 index 0000000..ad584b2 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/StorageDataModelTests.cs @@ -0,0 +1,58 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class StorageDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var storage = CreateDataModel(null, "123", CreateSubDataModel()); + Assert.That(() => storage.Validate(), Throws.TypeOf()); + + storage = CreateDataModel(string.Empty, "123", CreateSubDataModel()); + Assert.That(() => storage.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var storage = CreateDataModel("id", "123", CreateSubDataModel()); + Assert.That(() => storage.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentsIsNullOrEmptyTest() + { + var storage = CreateDataModel(Guid.NewGuid().ToString(), "123", null); + Assert.That(() => storage.Validate(), Throws.TypeOf()); + + storage = CreateDataModel(Guid.NewGuid().ToString(), "123", []); + Assert.That(() => storage.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var storageId = Guid.NewGuid().ToString(); + var components = CreateSubDataModel(); + var storage = CreateDataModel(storageId, "123", components); + + Assert.That(() => storage.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(storage.Id, Is.EqualTo(storageId)); + Assert.That(storage.Components, Is.EquivalentTo(components)); + }); + } + + private static StorageDataModel CreateDataModel(string id, string address, + List components) => + new(id, address, components); + + private static List CreateSubDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10)]; +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SupplyComponentDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SupplyComponentDataModelTests.cs new file mode 100644 index 0000000..7065192 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SupplyComponentDataModelTests.cs @@ -0,0 +1,73 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class SupplyComponentDataModelTests +{ + [Test] + public void SupplyIdIsNullOrEmptyTest() + { + var supplyComponent = CreateDataModel(null, Guid.NewGuid().ToString(), 10); + Assert.That(() => supplyComponent.Validate(), Throws.TypeOf()); + + supplyComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => supplyComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void SupplyIdIsNotGuidTest() + { + var supplyComponent = CreateDataModel("supplyId", Guid.NewGuid().ToString(), 10); + Assert.That(() => supplyComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentIdIsNullOrEmptyTest() + { + var supplyComponent = CreateDataModel(Guid.NewGuid().ToString(), null, 10); + Assert.That(() => supplyComponent.Validate(), Throws.TypeOf()); + + supplyComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10); + Assert.That(() => supplyComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentIdIsNotGuidTest() + { + var supplyComponent = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 10); + Assert.That(() => supplyComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var supplyComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => supplyComponent.Validate(), Throws.TypeOf()); + + supplyComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10); + Assert.That(() => supplyComponent.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var supplyId = Guid.NewGuid().ToString(); + var componentId = Guid.NewGuid().ToString(); + var count = 10; + var supplyComponent = CreateDataModel(supplyId, componentId, count); + + Assert.That(() => supplyComponent.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(supplyComponent.SupplyId, Is.EqualTo(supplyId)); + Assert.That(supplyComponent.ComponentId, Is.EqualTo(componentId)); + Assert.That(supplyComponent.Count, Is.EqualTo(count)); + }); + } + + private static SupplyComponentDataModel CreateDataModel(string? supplyId, string? componentId, int count) => + new(supplyId, componentId, count); +} diff --git a/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SupplyDataModelTests.cs b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SupplyDataModelTests.cs new file mode 100644 index 0000000..4bbb5d0 --- /dev/null +++ b/TheCyclopsProject/TheCyclopsTests/DataModelsTests/SupplyDataModelTests.cs @@ -0,0 +1,58 @@ +using TheCyclopsContracts.DataModels; +using TheCyclopsContracts.Exceptions; + +namespace TheCyclopsTests.DataModelsTests; + +[TestFixture] +internal class SupplyDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var supply = CreateDataModel(null, DateTime.UtcNow, CreateSubDataModel()); + Assert.That(() => supply.Validate(), Throws.TypeOf()); + + supply = CreateDataModel(string.Empty, DateTime.UtcNow, CreateSubDataModel()); + Assert.That(() => supply.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var supply = CreateDataModel("id", DateTime.UtcNow, CreateSubDataModel()); + Assert.That(() => supply.Validate(), Throws.TypeOf()); + } + + [Test] + public void ComponentsIsNullOrEmptyTest() + { + var supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.UtcNow, null); + Assert.That(() => supply.Validate(), Throws.TypeOf()); + + supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.UtcNow, []); + Assert.That(() => supply.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var supplyId = Guid.NewGuid().ToString(); + var components = CreateSubDataModel(); + var supply = CreateDataModel(supplyId, DateTime.UtcNow, components); + + Assert.That(() => supply.Validate(), Throws.Nothing); + + Assert.Multiple(() => + { + Assert.That(supply.Id, Is.EqualTo(supplyId)); + Assert.That(supply.Components, Is.EquivalentTo(components)); + }); + } + + private static SupplyDataModel CreateDataModel(string id, DateTime date, + List components) => + new(id, date, components); + + private static List CreateSubDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10)]; +}