91 lines
3.9 KiB
C#
91 lines
3.9 KiB
C#
using NorthBridgeContract.DataModels;
|
|
using NorthBridgeContract.Enums;
|
|
using NorthBridgeContract.Exceptions;
|
|
|
|
namespace NorthBridgeTest.DataModelsTests;
|
|
|
|
[TestFixture]
|
|
internal class ComponentDataModelTests
|
|
{
|
|
[Test]
|
|
public void IdIsNullOrEmptyTest()
|
|
{
|
|
var component = CreateDataModel(null, "name", ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
component = CreateDataModel(string.Empty, "name", ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void IdIsNotGuidTest()
|
|
{
|
|
var component = CreateDataModel("id", "name", ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ComponentNameIsEmptyTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Processor, Guid.NewGuid().ToString(), 10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ComponentTypeIsNoneTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.None, Guid.NewGuid().ToString(), 10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ManufacturerIdIsNullOrEmptyTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, null, 10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, string.Empty, 10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ManufacturerIdIsNotGuidTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, "manufacturerId", 10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PriceIsLessOrZeroTest()
|
|
{
|
|
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, Guid.NewGuid().ToString(), 0, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Processor, Guid.NewGuid().ToString(), -10, false);
|
|
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsIsCorrectTest()
|
|
{
|
|
var componentId = Guid.NewGuid().ToString();
|
|
var componentName = "name";
|
|
var componentType = ComponentType.Processor;
|
|
var componentManufacturerId = Guid.NewGuid().ToString();
|
|
var componentPrice = 10;
|
|
var componentIsDelete = false;
|
|
var component = CreateDataModel(componentId, componentName, componentType, componentManufacturerId, componentPrice, componentIsDelete);
|
|
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(componentManufacturerId));
|
|
Assert.That(component.Price, Is.EqualTo(componentPrice));
|
|
Assert.That(component.IsDeleted, Is.EqualTo(componentIsDelete));
|
|
});
|
|
}
|
|
|
|
private static ComponentDataModel CreateDataModel(string? id, string? componentName, ComponentType componentType, string? manufacturerId, double price, bool isDeleted) =>
|
|
new(id, componentName, componentType, manufacturerId, price, isDeleted);
|
|
} |