98 lines
4.3 KiB
C#
98 lines
4.3 KiB
C#
using NorthBridgeContracts.DataModels;
|
|
using NorthBridgeContracts.Enums;
|
|
using NorthBridgeContracts.Exceptions;
|
|
|
|
namespace NorthBridgeTests.DataModelsTests;
|
|
|
|
[TestFixture]
|
|
internal class ComponentDataModelTests
|
|
{
|
|
[Test]
|
|
public void IdIsNullOrEmptyTest()
|
|
{
|
|
var component = CreateDataModel(null, "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
component = CreateDataModel(string.Empty, "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void IdIsNotGuidTest()
|
|
{
|
|
var component = CreateDataModel("not-a-guid", "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ComponentNameIsNullOrEmptyTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Motherboard, Guid.NewGuid().ToString(), 100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ComponentTypeIsNoneTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.None, Guid.NewGuid().ToString(), 100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ManufacturerIdIsNullOrEmptyTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, null, 100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, string.Empty, 100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ManufacturerIdIsNotGuidTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, "not-a-guid", 100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PriceIsLessOrEqualToZeroTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), 0, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
component = CreateDataModel(Guid.NewGuid().ToString(), "ComponentName", ComponentType.Motherboard, Guid.NewGuid().ToString(), -100, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsAreCorrectTest()
|
|
{
|
|
var componentId = Guid.NewGuid().ToString();
|
|
var componentName = "ComponentName";
|
|
var componentType = ComponentType.Motherboard;
|
|
var manufacturerId = Guid.NewGuid().ToString();
|
|
var price = 100.0;
|
|
var isDeleted = false;
|
|
|
|
var component = CreateDataModel(componentId, componentName, componentType, manufacturerId, price, isDeleted);
|
|
|
|
Assert.That(() => component.Validate(), Throws.Nothing);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(component.Id, Is.EqualTo(componentId));
|
|
Assert.That(component.ComponentName, Is.EqualTo(componentName));
|
|
Assert.That(component.ComponentType, Is.EqualTo(componentType));
|
|
Assert.That(component.ManufacturerId, Is.EqualTo(manufacturerId));
|
|
Assert.That(component.Price, Is.EqualTo(price));
|
|
Assert.That(component.IsDeleted, Is.EqualTo(isDeleted));
|
|
});
|
|
}
|
|
|
|
private static ComponentDataModel CreateDataModel(string? id, string? componentName, ComponentType componentType, string? manufacturerId, double price, bool isDeleted) =>
|
|
new(id, componentName, componentType, manufacturerId, price, isDeleted);
|
|
}
|