Модели и тесты
This commit is contained in:
parent
43e0e2afea
commit
bfcac4e4d9
@ -0,0 +1,24 @@
|
||||
using SoftBedContracts.Exceptions;
|
||||
using SoftBedContracts.Extensions;
|
||||
|
||||
namespace SoftBedContracts.DataModels;
|
||||
|
||||
public class SupplyDataModel(string id, DateTime date, List<SupplyWorkPieceDataModel> workPieces)
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public DateTime Date { get; private set; } = date;
|
||||
|
||||
public List<SupplyWorkPieceDataModel> WorkPieces { get; private set; } = workPieces;
|
||||
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 ((WorkPieces?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include Work Pieces");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using SoftBedContracts.Exceptions;
|
||||
using SoftBedContracts.Extensions;
|
||||
|
||||
namespace SoftBedContracts.DataModels;
|
||||
|
||||
public class SupplyWorkPieceDataModel(string supplyId, string workPieceId, int count)
|
||||
{
|
||||
public string SupplyId { get; private set; } = supplyId;
|
||||
|
||||
public string WorkPieceId { get; private set; } = workPieceId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SupplyId.IsEmpty())
|
||||
throw new ValidationException("Field SupplyId is empty");
|
||||
|
||||
if (!SupplyId.IsGuid())
|
||||
throw new ValidationException("The value in the field SupplyId is not a unique identifier");
|
||||
|
||||
if (WorkPieceId.IsEmpty())
|
||||
throw new ValidationException("Field WorkPieceId is empty");
|
||||
|
||||
if (!WorkPieceId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkPieceId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
using SoftBedContracts.Exceptions;
|
||||
using SoftBedContracts.Extensions;
|
||||
|
||||
namespace SoftBedContracts.DataModels;
|
||||
|
||||
public class WarehouseDataModel(string id, string name, List<WarehouseWorkPieceDataModel> workPieces)
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string Name { get; private set; } = name;
|
||||
|
||||
public List<WarehouseWorkPieceDataModel> WorkPieces { get; private set; } = workPieces;
|
||||
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 (Name.IsEmpty())
|
||||
throw new ValidationException("Field Name is empty");
|
||||
|
||||
if ((WorkPieces?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include Work Pieces");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using SoftBedContracts.Exceptions;
|
||||
using SoftBedContracts.Extensions;
|
||||
|
||||
namespace SoftBedContracts.DataModels;
|
||||
|
||||
public class WarehouseWorkPieceDataModel(string warehouseId, string workPieceId, int count)
|
||||
{
|
||||
public string WarehouseId { get; private set; } = warehouseId;
|
||||
|
||||
public string WorkPieceId { get; private set; } = workPieceId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (WarehouseId.IsEmpty())
|
||||
throw new ValidationException("Field FurnitureId is empty");
|
||||
|
||||
if (!WarehouseId.IsGuid())
|
||||
throw new ValidationException("The value in the field FurnitureId is not a unique identifier");
|
||||
|
||||
if (WorkPieceId.IsEmpty())
|
||||
throw new ValidationException("Field WorkPieceId is empty");
|
||||
|
||||
if (!WorkPieceId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkPieceId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftBedContracts.Enums
|
||||
{
|
||||
internal class MaterialType
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
using SoftBedContracts.DataModels;
|
||||
using SoftBedContracts.Exceptions;
|
||||
|
||||
namespace SoftBedTests.DataModelsTests;
|
||||
|
||||
internal class SuppluDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(null, DateTime.Now, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouse = CreateDataModel(string.Empty, DateTime.Now, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var warehouse = CreateDataModel("id", DateTime.Now, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkPiecesIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, null);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, []);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var date = DateTime.Now;
|
||||
var workPieces = CreateSubDataModel();
|
||||
var supply = CreateDataModel(supplyId, date, workPieces);
|
||||
Assert.That(() => supply.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supply.Id, Is.EqualTo(supplyId));
|
||||
Assert.That(supply.Date, Is.EqualTo(date));
|
||||
Assert.That(supply.WorkPieces, Is.EqualTo(workPieces));
|
||||
});
|
||||
}
|
||||
private static SupplyDataModel CreateDataModel(string? id, DateTime date, List<SupplyWorkPieceDataModel> workPieces) =>
|
||||
new(id, date, workPieces);
|
||||
private static List<SupplyWorkPieceDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
using SoftBedContracts.DataModels;
|
||||
using SoftBedContracts.Exceptions;
|
||||
|
||||
namespace SoftBedTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplyWorkPieceDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void SupplyIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyWorkPiece = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supplyWorkPiece = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNotGuidTest()
|
||||
{
|
||||
var supplyWorkPiece = CreateDataModel("supplyId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void WorkPieceIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => supplyWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supplyWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => supplyWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkPieceIdIsNotGuidTest()
|
||||
{
|
||||
var supplyWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), "workPieceId", 10);
|
||||
Assert.That(() => supplyWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var supplyWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => supplyWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supplyWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => supplyWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var workPieceId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var supplyWorkPiece = CreateDataModel(supplyId, workPieceId, count);
|
||||
Assert.That(() => supplyWorkPiece.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supplyWorkPiece.SupplyId, Is.EqualTo(supplyId));
|
||||
Assert.That(supplyWorkPiece.WorkPieceId, Is.EqualTo(workPieceId));
|
||||
Assert.That(supplyWorkPiece.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
public static SupplyWorkPieceDataModel CreateDataModel(string? supplyId, string? workPieceId, int count) =>
|
||||
new(supplyId, workPieceId, count);
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using SoftBedContracts.DataModels;
|
||||
using SoftBedContracts.Exceptions;
|
||||
|
||||
namespace SoftBedTests.DataModelsTests;
|
||||
|
||||
internal class WarehouseDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var workPiece = CreateDataModel(null, "name", CreateSubDataModel());
|
||||
Assert.That(() => workPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
workPiece = CreateDataModel(string.Empty, "name", CreateSubDataModel());
|
||||
Assert.That(() => workPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var workPiece = CreateDataModel("id", "name", CreateSubDataModel());
|
||||
Assert.That(() => workPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameIsNullOrEmptyTest()
|
||||
{
|
||||
var workPiece = CreateDataModel(Guid.NewGuid().ToString(), null, CreateSubDataModel());
|
||||
Assert.That(() => workPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
workPiece = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, CreateSubDataModel());
|
||||
Assert.That(() => workPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkPiecesIsNullOrEmptyTest()
|
||||
{
|
||||
var workPiece = CreateDataModel(Guid.NewGuid().ToString(), "name", null);
|
||||
Assert.That(() => workPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
workPiece = CreateDataModel(Guid.NewGuid().ToString(), "name", []);
|
||||
Assert.That(() => workPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
var name = "name";
|
||||
var workPieces = CreateSubDataModel();
|
||||
var warehouse = CreateDataModel(warehouseId, name, workPieces);
|
||||
Assert.That(() => warehouse.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(warehouse.Id, Is.EqualTo(warehouseId));
|
||||
Assert.That(warehouse.Name, Is.EqualTo(name));
|
||||
Assert.That(warehouse.WorkPieces, Is.EqualTo(workPieces));
|
||||
});
|
||||
}
|
||||
private static WarehouseDataModel CreateDataModel(string? id, string name, List<WarehouseWorkPieceDataModel> workPieces) =>
|
||||
new(id, name, workPieces);
|
||||
private static List<WarehouseWorkPieceDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
using SoftBedContracts.DataModels;
|
||||
using SoftBedContracts.Exceptions;
|
||||
|
||||
namespace SoftBedTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WarehouseWorkPieceDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WarehouseIdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseWorkPiece = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseWorkPiece = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIdIsNotGuidTest()
|
||||
{
|
||||
var warehouseWorkPiece = CreateDataModel("warehouseId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void WorkPieceIdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => warehouseWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => warehouseWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkPieceIdIsNotGuidTest()
|
||||
{
|
||||
var warehouseWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), "workPieceId", 10);
|
||||
Assert.That(() => warehouseWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var warehouseWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => warehouseWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseWorkPiece = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => warehouseWorkPiece.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
var workPieceId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var warehouseWorkPiece = CreateDataModel(warehouseId, workPieceId, count);
|
||||
Assert.That(() => warehouseWorkPiece.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(warehouseWorkPiece.WarehouseId, Is.EqualTo(warehouseId));
|
||||
Assert.That(warehouseWorkPiece.WorkPieceId, Is.EqualTo(workPieceId));
|
||||
Assert.That(warehouseWorkPiece.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
public static WarehouseWorkPieceDataModel CreateDataModel(string? warehouseId, string? workPieceId, int count) =>
|
||||
new(warehouseId, workPieceId, count);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user