84 lines
3.3 KiB
C#
Raw Normal View History

using NorthBridgeContract.DataModels;
using NorthBridgeContract.Exceptions;
namespace NorthBridgeTest.DataModelsTests
{
[TestFixture]
internal class SupplyDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var components = CreateComponents();
var supply = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.Now, components);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.Now, components);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var supply = CreateDataModel("id", Guid.NewGuid().ToString(), DateTime.Now, CreateComponents());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StorageIdIsNullOrEmptyTest()
{
var components = CreateComponents();
var supply = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.Now, components);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.Now, components);
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StorageIdIsNotGuidTest()
{
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>());
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;
var components = CreateComponents();
var supply = CreateDataModel(supplyId, storageId, date, components);
Assert.That(() => supply.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(supply.Id, Is.EqualTo(supplyId));
Assert.That(supply.StorageId, Is.EqualTo(storageId));
Assert.That(supply.Date, Is.EqualTo(date));
Assert.That(supply.Components, Is.EquivalentTo(components));
});
}
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)
};
}
}