Compare commits
2 Commits
LabWork04_
...
LabWorks01
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b10b08b94 | ||
|
|
21e7134953 |
@@ -5,7 +5,7 @@ using FurnitureAssemblyContracts.Infrastructure;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DataModels;
|
||||
|
||||
public class ComponentDataModel(string id, string name, string? prevName, string? prevPrevName, ComponentType componentType) : IValidation
|
||||
public class ComponentDataModel(string id, string name, ComponentType componentType, string? prevName, string? prevPrevName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string Name { get; private set; } = name;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Extentions;
|
||||
using FurnitureAssemblyContracts.Infrastructure;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DataModels;
|
||||
|
||||
public class ComponentSuppliesDataModel(string suppliesId, string componentId, int count) : IValidation
|
||||
{
|
||||
public string SuppliesId { get; private set; } = suppliesId;
|
||||
public string ComponentId { get; private set; } = componentId;
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SuppliesId.IsEmpty())
|
||||
throw new ValidationException("Field FurnitureId is empty");
|
||||
if (!SuppliesId.IsGuid())
|
||||
throw new ValidationException("The value in the field FurnitureId is not a unique identifier");
|
||||
if (ComponentId.IsEmpty())
|
||||
throw new ValidationException("Field ComponentId is empty");
|
||||
if (!ComponentId.IsGuid())
|
||||
throw new ValidationException("The value in the field BlandId is not a unique identifier");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Extentions;
|
||||
using FurnitureAssemblyContracts.Infrastructure;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DataModels;
|
||||
|
||||
public class ComponentWarehouseDataModel(string warehouseId, string componentId, int count) : IValidation
|
||||
{
|
||||
public string WarehouseId { get; private set; } = warehouseId;
|
||||
public string ComponentId { get; private set; } = componentId;
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (WarehouseId.IsEmpty())
|
||||
throw new ValidationException("Field WarehouseId is empty");
|
||||
if (!WarehouseId.IsGuid())
|
||||
throw new ValidationException("The value in the field WarehouseId is not a unique identifier");
|
||||
if (ComponentId.IsEmpty())
|
||||
throw new ValidationException("Field ComponentId is empty");
|
||||
if (!ComponentId.IsGuid())
|
||||
throw new ValidationException("The value in the field ComponentId is not a unique identifier");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class FurnitureComponentDataModel(string furnitureId, string componentId,
|
||||
if (ComponentId.IsEmpty())
|
||||
throw new ValidationException("Field ComponentId is empty");
|
||||
if (!ComponentId.IsGuid())
|
||||
throw new ValidationException("The value in the field BlandId is not a unique identifier");
|
||||
throw new ValidationException("The value in the field ComponentId is not a unique identifier");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
|
||||
@@ -18,10 +18,10 @@ public class FurnitureDataModel(string id, string name, int weight, List<Compone
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (Name.IsEmpty())
|
||||
throw new ValidationException("Field FurnitureId is empty");
|
||||
throw new ValidationException("Field Name is empty");
|
||||
if (Weight <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
throw new ValidationException("Field Weight is less than or equal to 0");
|
||||
if ((Components?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
throw new ValidationException("The furniture must include Components");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using FurnitureAssemblyContracts.Enums;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Extentions;
|
||||
using FurnitureAssemblyContracts.Infrastructure;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DataModels;
|
||||
|
||||
public class SuppliesDataModel(string id, ComponentType componentType, DateTime date, int count, List<ComponentSuppliesDataModel> components) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public ComponentType Type { get; private set; } = componentType;
|
||||
public DateTime ProductuionDate { get; private set; } = date;
|
||||
public int Count { get; private set; } = count;
|
||||
public List<ComponentSuppliesDataModel> Components { get; private set; } = components;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (Type == ComponentType.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
if ((Components?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The component must include supplies");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using FurnitureAssemblyContracts.Enums;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
using FurnitureAssemblyContracts.Extentions;
|
||||
using FurnitureAssemblyContracts.Infrastructure;
|
||||
|
||||
namespace FurnitureAssemblyContracts.DataModels;
|
||||
|
||||
public class WarehouseDataModel(string id, ComponentType componentType, int count, List<ComponentWarehouseDataModel> components) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public ComponentType Type { get; private set; } = componentType;
|
||||
public int Count { get; private set; } = count;
|
||||
public List<ComponentWarehouseDataModel> Components { get; private set; } = components;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (Type == ComponentType.None)
|
||||
throw new ValidationException("Field Type is empty");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
if ((Components?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The component must include supplies");
|
||||
}
|
||||
}
|
||||
@@ -10,9 +10,9 @@ internal class ComponentDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(null, "name", null, null, ComponentType.Box);
|
||||
var component = CreateDataModel(null, "name", ComponentType.Box);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
component = CreateDataModel(string.Empty, "name", null, null, ComponentType.Box);
|
||||
component = CreateDataModel(string.Empty, "name", ComponentType.Box);
|
||||
Assert.That(() => component.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
@@ -20,35 +20,34 @@ internal class ComponentDataModelTests
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var component = CreateDataModel("id", "name", null, null, ComponentType.Box);
|
||||
var component = CreateDataModel("id", "name", ComponentType.Box);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), null, null, null, ComponentType.Box);
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Box);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, null, null, ComponentType.Box);
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Box);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", null, null, ComponentType.None);
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.None);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var name = "name";
|
||||
var prevName = "prevName";
|
||||
var prevPrevName = "prevPrevName";
|
||||
var componentType = ComponentType.Box;
|
||||
var component = CreateDataModel(componentId, name, prevName, prevPrevName, componentType);
|
||||
var component = CreateDataModel(componentId, name, componentType);
|
||||
Assert.That(() => component.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@@ -58,5 +57,7 @@ internal class ComponentDataModelTests
|
||||
});
|
||||
}
|
||||
|
||||
private static ComponentDataModel CreateDataModel(string? id, string? name, string? prevName, string? prevPrevName, ComponentType componentType) => new(id, name, prevName, prevPrevName, componentType);
|
||||
private static ComponentDataModel CreateDataModel(string? id, string? name, ComponentType componentType, string? prevName = null, string? prevPrevName = null)
|
||||
=> new(id, name, componentType, prevName, prevPrevName);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
|
||||
namespace FurnitureAssemblyTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ComponentSuppliesDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void SuppliesIdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuppliesIdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var suppliesId = Guid.NewGuid().ToString();
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var count = 1;
|
||||
var model = CreateDataModel(suppliesId, componentId, count);
|
||||
Assert.That(() => model.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.SuppliesId, Is.EqualTo(suppliesId));
|
||||
Assert.That(model.ComponentId, Is.EqualTo(componentId));
|
||||
Assert.That(model.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static ComponentSuppliesDataModel CreateDataModel(string? suppliesId, string? componentId, int count)
|
||||
=> new(suppliesId, componentId, count);
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
|
||||
namespace FurnitureAssemblyTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ComponentWarehouseDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WarehouseIdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var count = 1;
|
||||
var model = CreateDataModel(componentId, componentId, count);
|
||||
Assert.That(() => model.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.WarehouseId, Is.EqualTo(componentId));
|
||||
Assert.That(model.ComponentId, Is.EqualTo(componentId));
|
||||
Assert.That(model.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static ComponentWarehouseDataModel CreateDataModel(string? warehouseId, string? componentId, int count)
|
||||
=> new(warehouseId, componentId, count);
|
||||
}
|
||||
@@ -11,47 +11,47 @@ internal class FurnitureDataModelTests
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, "name", 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>().With.Message.EqualTo("Field Id is empty"));
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(string.Empty, "name", 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>().With.Message.EqualTo("Field Id is empty"));
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel("id", "name", 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>().With.Message.EqualTo("The value in the field Id is not a unique identifier"));
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), null, 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>().With.Message.EqualTo("Field FurnitureId is empty"));
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>().With.Message.EqualTo("Field FurnitureId is empty"));
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WeightIsLessOrZeroTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "name", 0, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>().With.Message.EqualTo("Field Count is less than or equal to 0"));
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), "name", -1, CreateSubDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>().With.Message.EqualTo("Field Count is less than or equal to 0"));
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentsIsEmptyOrNullTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "name", 1, []);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>().With.Message.EqualTo("The sale must include products"));
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), "name", 1, null);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>().With.Message.EqualTo("The sale must include products"));
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@@ -77,5 +77,5 @@ internal class FurnitureDataModelTests
|
||||
=> new(id, name, weight, components);
|
||||
|
||||
private static List<ComponentDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), "componentName", "prevname", "prevprevname", ComponentType.Handle)];
|
||||
=> [new(Guid.NewGuid().ToString(), "componentName", ComponentType.Handle, "prevname", "prevPrevName")];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Enums;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
|
||||
namespace FurnitureAssemblyTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class SuppliesDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, ComponentType.Handle, DateTime.Now, 1, CreateSuppliesDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
model = CreateDataModel(string.Empty, ComponentType.Handle, DateTime.Now, 1, CreateSuppliesDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel("id", ComponentType.Handle, DateTime.Now, 1, CreateSuppliesDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TypeIsNoneTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, DateTime.Now, 1, CreateSuppliesDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, DateTime.Now, 0, CreateSuppliesDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, DateTime.Now, -1, CreateSuppliesDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuppliesIsEmptyOrNullTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, DateTime.Now, 0, []);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, DateTime.Now, 0, null);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var type = ComponentType.Handle;
|
||||
var date = DateTime.Now;
|
||||
var count = 1;
|
||||
var supplies = CreateSuppliesDataModel();
|
||||
var model = CreateDataModel(id, type, date, count, supplies);
|
||||
Assert.DoesNotThrow(() => model.Validate());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.Id, Is.EqualTo(id));
|
||||
Assert.That(model.Type, Is.EqualTo(type));
|
||||
Assert.That(model.ProductuionDate, Is.EqualTo(date));
|
||||
Assert.That(model.Count, Is.EqualTo(count));
|
||||
Assert.That(model.Components, Is.EqualTo(supplies));
|
||||
});
|
||||
}
|
||||
|
||||
private static SuppliesDataModel CreateDataModel(string? id, ComponentType type, DateTime date, int count, List<ComponentSuppliesDataModel> supplies)
|
||||
=> new(id, type, date, count, supplies);
|
||||
private static List<ComponentSuppliesDataModel> CreateSuppliesDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using FurnitureAssemblyContracts.DataModels;
|
||||
using FurnitureAssemblyContracts.Enums;
|
||||
using FurnitureAssemblyContracts.Exceptions;
|
||||
|
||||
namespace FurnitureAssemblyTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WorkhouseDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, ComponentType.Handle, 1, CreateWarehouseDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
model = CreateDataModel(string.Empty, ComponentType.Handle, 1, CreateWarehouseDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel("id", ComponentType.Handle, 1, CreateWarehouseDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TypeIsNoneTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, 1, CreateWarehouseDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, 0, CreateWarehouseDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, -1, CreateWarehouseDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkhouseIsEmptyOrNullTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, 0, []);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), ComponentType.None, 0, null);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var type = ComponentType.Handle;
|
||||
var count = 1;
|
||||
var warehouse = CreateWarehouseDataModel();
|
||||
var model = CreateDataModel(id, type, count, warehouse);
|
||||
Assert.DoesNotThrow(() => model.Validate());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.Id, Is.EqualTo(id));
|
||||
Assert.That(model.Type, Is.EqualTo(type));
|
||||
Assert.That(model.Count, Is.EqualTo(count));
|
||||
Assert.That(model.Components, Is.EqualTo(warehouse));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseDataModel CreateDataModel(string? id, ComponentType type, int count, List<ComponentWarehouseDataModel> warehouse)
|
||||
=> new WarehouseDataModel(id, type, count, warehouse);
|
||||
private static List<ComponentWarehouseDataModel> CreateWarehouseDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
Reference in New Issue
Block a user