2025-02-07 23:50:56 +04:00
|
|
|
|
using NorthBridgeContract.DataModels;
|
|
|
|
|
using NorthBridgeContract.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace NorthBridgeTest.DataModelsTests
|
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
|
|
|
|
internal class SupplyDataModelTests
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void IdIsNullOrEmptyTest()
|
|
|
|
|
{
|
2025-02-18 22:17:03 +04:00
|
|
|
|
var components = CreateComponents();
|
|
|
|
|
var supply = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.Now, components);
|
2025-02-07 23:50:56 +04:00
|
|
|
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
2025-02-18 22:17:03 +04:00
|
|
|
|
|
|
|
|
|
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.Now, components);
|
2025-02-07 23:50:56 +04:00
|
|
|
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IdIsNotGuidTest()
|
|
|
|
|
{
|
2025-02-18 22:17:03 +04:00
|
|
|
|
var supply = CreateDataModel("id", Guid.NewGuid().ToString(), DateTime.Now, CreateComponents());
|
2025-02-07 23:50:56 +04:00
|
|
|
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void StorageIdIsNullOrEmptyTest()
|
|
|
|
|
{
|
2025-02-18 22:17:03 +04:00
|
|
|
|
var components = CreateComponents();
|
|
|
|
|
var supply = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.Now, components);
|
2025-02-07 23:50:56 +04:00
|
|
|
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
2025-02-18 22:17:03 +04:00
|
|
|
|
|
|
|
|
|
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.Now, components);
|
2025-02-07 23:50:56 +04:00
|
|
|
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void StorageIdIsNotGuidTest()
|
|
|
|
|
{
|
2025-02-18 22:17:03 +04:00
|
|
|
|
var supply = CreateDataModel(Guid.NewGuid().ToString(), "id", DateTime.Now, CreateComponents());
|
|
|
|
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void ComponentsListIsEmptyTest()
|
|
|
|
|
{
|
|
|
|
|
var supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now, new List<ComponentInSupplyDataModel>());
|
2025-02-07 23:50:56 +04:00
|
|
|
|
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AllFieldsAreCorrectTest()
|
|
|
|
|
{
|
|
|
|
|
var supplyId = Guid.NewGuid().ToString();
|
|
|
|
|
var storageId = Guid.NewGuid().ToString();
|
|
|
|
|
var date = DateTime.Now;
|
2025-02-18 22:17:03 +04:00
|
|
|
|
var components = CreateComponents();
|
|
|
|
|
|
|
|
|
|
var supply = CreateDataModel(supplyId, storageId, date, components);
|
2025-02-07 23:50:56 +04:00
|
|
|
|
Assert.That(() => supply.Validate(), Throws.Nothing);
|
2025-02-18 22:17:03 +04:00
|
|
|
|
|
2025-02-07 23:50:56 +04:00
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(supply.Id, Is.EqualTo(supplyId));
|
|
|
|
|
Assert.That(supply.StorageId, Is.EqualTo(storageId));
|
|
|
|
|
Assert.That(supply.Date, Is.EqualTo(date));
|
2025-02-18 22:17:03 +04:00
|
|
|
|
Assert.That(supply.Components, Is.EquivalentTo(components));
|
2025-02-07 23:50:56 +04:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-18 22:17:03 +04:00
|
|
|
|
private static SupplyDataModel CreateDataModel(string? id, string? storageId, DateTime date, List<ComponentInSupplyDataModel> components) =>
|
|
|
|
|
new(id, storageId, date, components);
|
|
|
|
|
|
|
|
|
|
private static List<ComponentInSupplyDataModel> CreateComponents() =>
|
|
|
|
|
new()
|
|
|
|
|
{
|
|
|
|
|
new ComponentInSupplyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5),
|
|
|
|
|
new ComponentInSupplyDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10)
|
|
|
|
|
};
|
|
|
|
|
|
2025-02-07 23:50:56 +04:00
|
|
|
|
}
|
|
|
|
|
}
|