71 lines
2.9 KiB
C#
71 lines
2.9 KiB
C#
|
using NorthBridgeContract.DataModels;
|
|||
|
using NorthBridgeContract.Exceptions;
|
|||
|
|
|||
|
namespace NorthBridgeTest.DataModelsTests
|
|||
|
{
|
|||
|
[TestFixture]
|
|||
|
internal class ComponentInSupplyDataModelTests
|
|||
|
{
|
|||
|
[Test]
|
|||
|
public void SupplyIdIsNullOrEmptyTest()
|
|||
|
{
|
|||
|
var componentSupply = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
|||
|
Assert.That(() => componentSupply.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
componentSupply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
|||
|
Assert.That(() => componentSupply.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void SupplyIdIsNotGuidTest()
|
|||
|
{
|
|||
|
var componentSupply = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
|
|||
|
Assert.That(() => componentSupply.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void ProductIdIsNullOrEmptyTest()
|
|||
|
{
|
|||
|
var componentSupply = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
|||
|
Assert.That(() => componentSupply.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
componentSupply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
|||
|
Assert.That(() => componentSupply.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void ProductIdIsNotGuidTest()
|
|||
|
{
|
|||
|
var componentSupply = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
|
|||
|
Assert.That(() => componentSupply.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void CountIsLessThanOrEqualToZeroTest()
|
|||
|
{
|
|||
|
var componentSupply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
|||
|
Assert.That(() => componentSupply.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
componentSupply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
|||
|
Assert.That(() => componentSupply.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void AllFieldsAreCorrectTest()
|
|||
|
{
|
|||
|
var supplyId = Guid.NewGuid().ToString();
|
|||
|
var componentId = Guid.NewGuid().ToString();
|
|||
|
var count = 5;
|
|||
|
var componentSupply = CreateDataModel(supplyId, componentId, count);
|
|||
|
Assert.That(() => componentSupply.Validate(), Throws.Nothing);
|
|||
|
Assert.Multiple(() =>
|
|||
|
{
|
|||
|
Assert.That(componentSupply.SupplyId, Is.EqualTo(supplyId));
|
|||
|
Assert.That(componentSupply.ComponentId, Is.EqualTo(componentId));
|
|||
|
Assert.That(componentSupply.Count, Is.EqualTo(count));
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
private static ComponentInSupplyDataModel CreateDataModel(string? supplyId, string? componentId, int count) =>
|
|||
|
new(supplyId, componentId, count);
|
|||
|
}
|
|||
|
|
|||
|
}
|