add hard data models and tests
This commit is contained in:
parent
a7358fb837
commit
5995caa131
@ -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");
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
using TheCyclopsContracts.Exceptions;
|
||||
using TheCyclopsContracts.Extensions;
|
||||
using TheCyclopsContracts.Infrastructure;
|
||||
|
||||
namespace TheCyclopsContracts.DataModels;
|
||||
|
||||
public class StorageDataModel(string id, string address, List<StorageComponentDataModel> components) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string Address { get; private set; } = address;
|
||||
|
||||
public List<StorageComponentDataModel> 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");
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using TheCyclopsContracts.Exceptions;
|
||||
using TheCyclopsContracts.Extensions;
|
||||
using TheCyclopsContracts.Infrastructure;
|
||||
|
||||
namespace TheCyclopsContracts.DataModels;
|
||||
|
||||
public class SupplyDataModel(string id, DateTime supplyDate,
|
||||
List<SupplyComponentDataModel> components) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public DateTime SupplyDate { get; private set; } = supplyDate;
|
||||
|
||||
public List<SupplyComponentDataModel> 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");
|
||||
}
|
||||
}
|
@ -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<ValidationException>());
|
||||
|
||||
storageComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => storageComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StorageIdIsNotGuidTest()
|
||||
{
|
||||
var storageComponent = CreateDataModel("storageId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => storageComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNullOrEmptyTest()
|
||||
{
|
||||
var storageComponent = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => storageComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
storageComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => storageComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNotGuidTest()
|
||||
{
|
||||
var storageComponent = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 10);
|
||||
Assert.That(() => storageComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var storageComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => storageComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
storageComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => storageComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
@ -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<ValidationException>());
|
||||
|
||||
storage = CreateDataModel(string.Empty, "123", CreateSubDataModel());
|
||||
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var storage = CreateDataModel("id", "123", CreateSubDataModel());
|
||||
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentsIsNullOrEmptyTest()
|
||||
{
|
||||
var storage = CreateDataModel(Guid.NewGuid().ToString(), "123", null);
|
||||
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
storage = CreateDataModel(Guid.NewGuid().ToString(), "123", []);
|
||||
Assert.That(() => storage.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[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<StorageComponentDataModel> components) =>
|
||||
new(id, address, components);
|
||||
|
||||
private static List<StorageComponentDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10)];
|
||||
}
|
@ -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<ValidationException>());
|
||||
|
||||
supplyComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNotGuidTest()
|
||||
{
|
||||
var supplyComponent = CreateDataModel("supplyId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyComponent = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => supplyComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplyComponent = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNotGuidTest()
|
||||
{
|
||||
var supplyComponent = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 10);
|
||||
Assert.That(() => supplyComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var supplyComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => supplyComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplyComponent = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => supplyComponent.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[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);
|
||||
}
|
@ -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<ValidationException>());
|
||||
|
||||
supply = CreateDataModel(string.Empty, DateTime.UtcNow, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var supply = CreateDataModel("id", DateTime.UtcNow, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentsIsNullOrEmptyTest()
|
||||
{
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.UtcNow, null);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.UtcNow, []);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[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<SupplyComponentDataModel> components) =>
|
||||
new(id, date, components);
|
||||
|
||||
private static List<SupplyComponentDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10)];
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user