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