74 lines
2.7 KiB
C#

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);
}