Добавил склад (сделал 1 усложненку)
This commit is contained in:
@@ -3,13 +3,15 @@ using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class ComplitedWorkDataModel(string id, string workId, string roomId, List<WorkerComplitedWorkDataModel> workers ) :IValidation
|
||||
public class ComplitedWorkDataModel(string id, string workId, string roomId, List<WorkerComplitedWorkDataModel> workers,
|
||||
List<ComplitedWorkProductDataModel> usedProducts) :IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string WorkId { get; private set; } = workId;
|
||||
public string RoomId { get; private set; } = roomId;
|
||||
public DateTime Date { get; private set; } = DateTime.Now;
|
||||
public List<WorkerComplitedWorkDataModel> Workers { get; private set; } = workers;
|
||||
public List<ComplitedWorkProductDataModel> UsedProducts { get; private set; } = usedProducts;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
@@ -27,6 +29,8 @@ public class ComplitedWorkDataModel(string id, string workId, string roomId, Lis
|
||||
throw new ValidationException("The value in the field RoomId is not a unique identifier");
|
||||
if((Workers?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The value in the Workers must include workers");
|
||||
if ((UsedProducts?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The value in the UsedProducts must include usedProducts");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class ComplitedWorkProductDataModel(string complitedWorkId, string productId, double quantity) : IValidation
|
||||
{
|
||||
public string ComplitedWorkId { get; private set; } = complitedWorkId;
|
||||
public string ProductId { get; private set; } = productId;
|
||||
public double Quantity { get; private set; } = quantity;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ComplitedWorkId.IsEmpty()) throw new ValidationException("Field ComplitedWorkId is empty");
|
||||
if (!ComplitedWorkId.IsGuid()) throw new ValidationException("The value in the field ComplitedWorkId is not a unique identifier");
|
||||
if (ProductId.IsEmpty()) throw new ValidationException("Field ProductId is empty");
|
||||
if (!ProductId.IsGuid()) throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
if (Quantity <= 0) throw new ValidationException("Field Quantity must be greater than zero");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Xml.Linq;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class ProductDataModel(string id, string name, string unit) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string Name { get; private set; } = name;
|
||||
public string Unit { get; private set; } = unit;
|
||||
|
||||
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 (Unit.IsEmpty()) throw new ValidationException("Field Unit is empty");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class ProductSupplyDataModel(string productId, string supplyId, double quantity) : IValidation
|
||||
{
|
||||
public string ProductId { get; private set; } = productId;
|
||||
public string SupplyId { get; private set; } = supplyId;
|
||||
public double Quantity { get; private set; } = quantity;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ProductId.IsEmpty()) throw new ValidationException("Field ProductId is empty");
|
||||
if (!ProductId.IsGuid()) throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
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 (Quantity <= 0) throw new ValidationException("Field Quantity must be greater than zero");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class SupplyDataModel(string id, string warehouseId, DateTime supplyDate, List<ProductSupplyDataModel> products): IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string WarehouseId { get; private set; } = warehouseId;
|
||||
public DateTime SupplyDate { get; private set; } = supplyDate;
|
||||
public List<ProductSupplyDataModel> Products { get; private set; } = products;
|
||||
|
||||
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 (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 ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The value in the Product must include Product");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
using TwoFromTheCasketContracts.Extensions;
|
||||
using TwoFromTheCasketContracts.Infastructure;
|
||||
|
||||
namespace TwoFromTheCasketContracts.DataModels;
|
||||
|
||||
public class WarehouseDataModel(string id, string name, string location) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string Name { get; private set; } = name;
|
||||
public string Location { get; private set; } = location;
|
||||
|
||||
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 (Location.IsEmpty()) throw new ValidationException("Field Location is empty");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,12 @@ internal class ComplitedWorkDataModelTests
|
||||
{
|
||||
List<WorkerComplitedWorkDataModel> workers = new List<WorkerComplitedWorkDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel(null, "1", "2", workers);
|
||||
List<ComplitedWorkProductDataModel> products = new List<ComplitedWorkProductDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel(null, "1", "2", workers, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
complitedWork = CreateDataModel(string.Empty, "1", "2", workers);
|
||||
complitedWork = CreateDataModel(string.Empty, "1", "2", workers, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -23,7 +25,9 @@ internal class ComplitedWorkDataModelTests
|
||||
{
|
||||
List<WorkerComplitedWorkDataModel> workers = new List<WorkerComplitedWorkDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("not-a-guid", "1", "2", workers);
|
||||
List<ComplitedWorkProductDataModel> products = new List<ComplitedWorkProductDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("not-a-guid", "1", "2", workers, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -32,10 +36,12 @@ internal class ComplitedWorkDataModelTests
|
||||
{
|
||||
List<WorkerComplitedWorkDataModel> workers = new List<WorkerComplitedWorkDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", null, "2", workers);
|
||||
List<ComplitedWorkProductDataModel> products = new List<ComplitedWorkProductDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", null, "2", workers, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
complitedWork = CreateDataModel("1", string.Empty, "2", workers);
|
||||
complitedWork = CreateDataModel("1", string.Empty, "2", workers, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -44,7 +50,9 @@ internal class ComplitedWorkDataModelTests
|
||||
{
|
||||
List<WorkerComplitedWorkDataModel> workers = new List<WorkerComplitedWorkDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", "not-a-guid", "2", workers);
|
||||
List<ComplitedWorkProductDataModel> products = new List<ComplitedWorkProductDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", "not-a-guid", "2", workers, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -53,10 +61,12 @@ internal class ComplitedWorkDataModelTests
|
||||
{
|
||||
List<WorkerComplitedWorkDataModel> workers = new List<WorkerComplitedWorkDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", "2", null, workers);
|
||||
List<ComplitedWorkProductDataModel> products = new List<ComplitedWorkProductDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", "2", null, workers, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
complitedWork = CreateDataModel("1", "2", string.Empty, workers);
|
||||
complitedWork = CreateDataModel("1", "2", string.Empty, workers, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -65,17 +75,35 @@ internal class ComplitedWorkDataModelTests
|
||||
{
|
||||
List<WorkerComplitedWorkDataModel> workers = new List<WorkerComplitedWorkDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", "2", "not-a-guid", workers);
|
||||
List<ComplitedWorkProductDataModel> products = new List<ComplitedWorkProductDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", "2", "not-a-guid", workers, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkersIsNullOrEmptyTest()
|
||||
{
|
||||
var complitedWork = CreateDataModel("1", "2", "3", null);
|
||||
|
||||
List<ComplitedWorkProductDataModel> products = new List<ComplitedWorkProductDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", "2", "3", null, products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
complitedWork = CreateDataModel("1", "2", "3", new List<WorkerComplitedWorkDataModel>());
|
||||
complitedWork = CreateDataModel("1", "2", "3", new List<WorkerComplitedWorkDataModel>(), products);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UsedProductsIsNullOrEmptyTest()
|
||||
{
|
||||
|
||||
List<WorkerComplitedWorkDataModel> workers = new List<WorkerComplitedWorkDataModel> { new("1", "2", 3) };
|
||||
|
||||
var complitedWork = CreateDataModel("1", "2", "3", workers, null);
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
complitedWork = CreateDataModel("1", "2", "3", workers, new List<ComplitedWorkProductDataModel>());
|
||||
Assert.That(() => complitedWork.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@@ -89,8 +117,12 @@ internal class ComplitedWorkDataModelTests
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)
|
||||
};
|
||||
var products = new List<ComplitedWorkProductDataModel>
|
||||
{
|
||||
new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 5)
|
||||
};
|
||||
|
||||
var complitedWork = CreateDataModel(id, workId, roomId, workers);
|
||||
var complitedWork = CreateDataModel(id, workId, roomId, workers, products);
|
||||
|
||||
Assert.That(() => complitedWork.Validate(), Throws.Nothing);
|
||||
|
||||
@@ -100,9 +132,10 @@ internal class ComplitedWorkDataModelTests
|
||||
Assert.That(complitedWork.WorkId, Is.EqualTo(workId));
|
||||
Assert.That(complitedWork.RoomId, Is.EqualTo(roomId));
|
||||
Assert.That(complitedWork.Workers, Is.EquivalentTo(workers));
|
||||
Assert.That(complitedWork.UsedProducts, Is.EquivalentTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static ComplitedWorkDataModel CreateDataModel(string? id, string? workId, string? roomId, List<WorkerComplitedWorkDataModel>? workers)
|
||||
=> new(id, workId, roomId, workers);
|
||||
private static ComplitedWorkDataModel CreateDataModel(string? id, string? workId, string? roomId, List<WorkerComplitedWorkDataModel>? workers, List<ComplitedWorkProductDataModel>? products)
|
||||
=> new(id, workId, roomId, workers, products);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
namespace TwoFromTheCasketTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class ComplitedWorkProductDataModelTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void ComplitedWorkIdIsNullOrEmptyTest()
|
||||
{
|
||||
var complitedWorkProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 5);
|
||||
Assert.That(() => complitedWorkProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
complitedWorkProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 5);
|
||||
Assert.That(() => complitedWorkProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComplitedWorkIdIsNotGuidTest()
|
||||
{
|
||||
var complitedWorkProduct = CreateDataModel("1", Guid.NewGuid().ToString(), 5);
|
||||
Assert.That(() => complitedWorkProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var complitedWorkProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 5);
|
||||
Assert.That(() => complitedWorkProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
complitedWorkProduct = CreateDataModel( Guid.NewGuid().ToString(), string.Empty, 5);
|
||||
Assert.That(() => complitedWorkProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var complitedWorkProduct = CreateDataModel(Guid.NewGuid().ToString(), "1", 5);
|
||||
Assert.That(() => complitedWorkProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QuantityIsInvalidTest()
|
||||
{
|
||||
var complitedWorkProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => complitedWorkProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var complitedWorkId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var quantity = 5;
|
||||
|
||||
var complitedWorkProduct = CreateDataModel(complitedWorkId, productId, quantity);
|
||||
Assert.That(() => complitedWorkProduct.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(complitedWorkProduct.ComplitedWorkId, Is.EqualTo(complitedWorkId));
|
||||
Assert.That(complitedWorkProduct.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(complitedWorkProduct.Quantity, Is.EqualTo(quantity));
|
||||
});
|
||||
}
|
||||
|
||||
private static ComplitedWorkProductDataModel CreateDataModel(string? complitedWorkId, string? productId, double quantity)
|
||||
=> new(complitedWorkId, productId, quantity);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
namespace TwoFromTheCasketTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class ProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "Paint", "L");
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
product = CreateDataModel(string.Empty, "Paint", "L");
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("1", "Paint", "L");
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "L");
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductUnitIsEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "Paint", string.Empty);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Paint";
|
||||
var unit = "L";
|
||||
|
||||
var product = CreateDataModel(id, name, unit);
|
||||
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(product.Id, Is.EqualTo(id));
|
||||
Assert.That(product.Name, Is.EqualTo(name));
|
||||
Assert.That(product.Unit, Is.EqualTo(unit));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductDataModel CreateDataModel(string? id, string name, string unit)
|
||||
=> new(id, name, unit);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
namespace TwoFromTheCasketTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class ProductSupplyDataModelTests
|
||||
{
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var productSupply = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
productSupply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var productSupply = CreateDataModel("1", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNullOrEmptyTest()
|
||||
{
|
||||
var productSupply = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
productSupply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNotGuidTest()
|
||||
{
|
||||
var productSupply = CreateDataModel(Guid.NewGuid().ToString(), "1", 10);
|
||||
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QuantityIsInvalidTest()
|
||||
{
|
||||
var productSupply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => productSupply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var quantity = 10;
|
||||
|
||||
var productSupply = CreateDataModel(productId, supplyId, quantity);
|
||||
Assert.That(() => productSupply.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(productSupply.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(productSupply.SupplyId, Is.EqualTo(supplyId));
|
||||
Assert.That(productSupply.Quantity, Is.EqualTo(quantity));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductSupplyDataModel CreateDataModel(string? productId, string? supplyId, double quantity)
|
||||
=> new(productId, supplyId, quantity);
|
||||
}
|
||||
@@ -33,6 +33,13 @@ internal class SalaryDataModelTests
|
||||
Assert.That(() => salaryHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var salaryHistory = CreateDataModel(Guid.NewGuid().ToString(), "1", 50000);
|
||||
Assert.That(() => salaryHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsNegativeOrZeroTest()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
namespace TwoFromTheCasketTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class SupplyDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void SupplyIdIsNullOrEmptyTest()
|
||||
{
|
||||
List<ProductSupplyDataModel> products = new List<ProductSupplyDataModel> { new("1", "2", 3) };
|
||||
|
||||
var supply = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.UtcNow, products);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.UtcNow, products);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNotGuidTest()
|
||||
{
|
||||
List<ProductSupplyDataModel> products = new List<ProductSupplyDataModel> { new("1", "2", 3) };
|
||||
|
||||
var supply = CreateDataModel("1", Guid.NewGuid().ToString(), DateTime.UtcNow, products);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIdIsNullOrEmptyTest()
|
||||
{
|
||||
List<ProductSupplyDataModel> products = new List<ProductSupplyDataModel> { new("1", "2", 3) };
|
||||
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.UtcNow, products);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.UtcNow, products);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIdIsNotGuidTest()
|
||||
{
|
||||
List<ProductSupplyDataModel> products = new List<ProductSupplyDataModel> { new("1", "2", 3) };
|
||||
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), "1", DateTime.UtcNow, products);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, new List<ProductSupplyDataModel>());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
var supplyDate = DateTime.UtcNow;
|
||||
List<ProductSupplyDataModel> products = new List<ProductSupplyDataModel> { new("1", "2", 3) };
|
||||
|
||||
var supply = CreateDataModel(id, warehouseId, supplyDate, products);
|
||||
Assert.That(() => supply.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supply.Id, Is.EqualTo(id));
|
||||
Assert.That(supply.WarehouseId, Is.EqualTo(warehouseId));
|
||||
Assert.That(supply.SupplyDate, Is.EqualTo(supplyDate));
|
||||
Assert.That(supply.Products, Is.EqualTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyDataModel CreateDataModel(string? id, string? warehouseId, DateTime supplyDate, List<ProductSupplyDataModel> product)
|
||||
=> new(id, warehouseId, supplyDate, product);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using TwoFromTheCasketContracts.DataModels;
|
||||
using TwoFromTheCasketContracts.Exceptions;
|
||||
|
||||
namespace TwoFromTheCasketTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class WarehouseDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WarehouseIdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(null, "Central Warehouse", "123 Main St");
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
warehouse = CreateDataModel(string.Empty, "Central Warehouse", "123 Main St");
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIdIsNotGuidTest()
|
||||
{
|
||||
var warehouse = CreateDataModel("1", "Central Warehouse", "123 Main St");
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseNameIsEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "123 Main St");
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseLocationIsEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), "Central Warehouse", string.Empty);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Central Warehouse";
|
||||
var location = "123 Main St";
|
||||
|
||||
var warehouse = CreateDataModel(id, name, location);
|
||||
Assert.That(() => warehouse.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(warehouse.Id, Is.EqualTo(id));
|
||||
Assert.That(warehouse.Name, Is.EqualTo(name));
|
||||
Assert.That(warehouse.Location, Is.EqualTo(location));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseDataModel CreateDataModel(string? id, string name, string location)
|
||||
=> new(id, name, location);
|
||||
}
|
||||
Reference in New Issue
Block a user