Конец
This commit is contained in:
parent
1d4cc5bec0
commit
b79a18a401
@ -11,16 +11,13 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace PipingHotContrast.DataModels;
|
namespace PipingHotContrast.DataModels;
|
||||||
|
|
||||||
public class ProductDataModel(string id, string productName, ProductType productType,string restaurantId, double price, List<SupplyProductDataModel> supplies, List<WarehouseProductDataModel> warehouse, bool isDeleted): IValidation
|
public class ProductDataModel(string id, string productName, ProductType productType,string restaurantId, double price, bool isDeleted): IValidation
|
||||||
{
|
{
|
||||||
public string Id { get; private set; } = id;
|
public string Id { get; private set; } = id;
|
||||||
public string ProductName { get; private set; } = productName;
|
public string ProductName { get; private set; } = productName;
|
||||||
public ProductType ProductType { get; private set; } = productType;
|
public ProductType ProductType { get; private set; } = productType;
|
||||||
public string RestaurantId { get; private set; } = restaurantId;
|
public string RestaurantId { get; private set; } = restaurantId;
|
||||||
public double Price { get; private set; } = price;
|
public double Price { get; private set; } = price;
|
||||||
public List<SupplyProductDataModel> Supplies { get; private set; } = supplies;
|
|
||||||
|
|
||||||
public List<WarehouseProductDataModel> Warehouse { get; private set; } = warehouse;
|
|
||||||
public bool IsDeleted { get; private set; } = isDeleted;
|
public bool IsDeleted { get; private set; } = isDeleted;
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
@ -39,10 +36,5 @@ public class ProductDataModel(string id, string productName, ProductType product
|
|||||||
throw new ValidationException("The value in the field RestaurantId is not a unique identifier");
|
throw new ValidationException("The value in the field RestaurantId is not a unique identifier");
|
||||||
if(Price <= 0)
|
if(Price <= 0)
|
||||||
throw new ValidationException("Field Price is empty");
|
throw new ValidationException("Field Price is empty");
|
||||||
if ((Supplies?.Count ?? 0) == 0)
|
|
||||||
throw new ValidationException("The product must include supplies");
|
|
||||||
|
|
||||||
if ((Warehouse?.Count ?? 0) == 0)
|
|
||||||
throw new ValidationException("The product must include warehouse");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,32 +15,32 @@ internal class ProductDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel(null, "name", ProductType.Pizza, Guid.NewGuid().ToString(),500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
var product = CreateDataModel(null, "name", ProductType.Pizza, Guid.NewGuid().ToString(),500, false);
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
product = CreateDataModel(string.Empty, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
product = CreateDataModel(string.Empty, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IdIsNotGuidTest()
|
public void IdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel("id", "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
var product = CreateDataModel("id", "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ProductNameIsNullOrEmptyTest()
|
public void ProductNameIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ProductTypeIsNoneTest()
|
public void ProductTypeIsNoneTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, Guid.NewGuid().ToString(), 500, false);
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,50 +48,26 @@ internal class ProductDataModelTests
|
|||||||
public void ReastaurantIdIsNullOrEmptyTest()
|
public void ReastaurantIdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
|
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Pizza, null, 500, false);
|
||||||
ProductType.Pizza, null, 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
Assert.That(() => product.Validate(),Throws.TypeOf<ValidationException>());
|
||||||
Assert.That(() => product.Validate(),
|
product = CreateDataModel(Guid.NewGuid().ToString(), "name",ProductType.Pizza, string.Empty, 500, false);
|
||||||
Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
|
||||||
ProductType.Pizza, string.Empty, 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
|
||||||
Assert.That(() => product.Validate(),
|
|
||||||
Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
}
|
||||||
[Test]
|
[Test]
|
||||||
public void ReastaurantIdIsNotGuidTest()
|
public void ReastaurantIdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Pizza, "restaurantId", 500, false);
|
||||||
ProductType.Pizza, "restaurantId", 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
Assert.That(() => product.Validate(),
|
|
||||||
Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void PriceIsLessOrZeroTest()
|
public void PriceIsLessOrZeroTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 0, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 0, false);
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), - 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), - 500,false);
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
[Test]
|
|
||||||
public void SuppliesIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Pizza, Guid.NewGuid().ToString(), 0, null, CreateWarehouseDataModel(), false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Pizza, Guid.NewGuid().ToString(), 0, [], CreateWarehouseDataModel(), false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void WarehouseIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Pizza, Guid.NewGuid().ToString(), 0, CreateSuppliesDataModel(), null, false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Pizza, Guid.NewGuid().ToString(), 0, CreateSuppliesDataModel(), [], false);
|
|
||||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void AllFieldsIsCorrectTest()
|
public void AllFieldsIsCorrectTest()
|
||||||
{
|
{
|
||||||
@ -100,10 +76,8 @@ internal class ProductDataModelTests
|
|||||||
var productType = ProductType.Pizza;
|
var productType = ProductType.Pizza;
|
||||||
var productRestaurantId = Guid.NewGuid().ToString();
|
var productRestaurantId = Guid.NewGuid().ToString();
|
||||||
var productPrice = 500;
|
var productPrice = 500;
|
||||||
var supplies = CreateSuppliesDataModel();
|
|
||||||
var warehouse = CreateWarehouseDataModel();
|
|
||||||
var productIsDeleted = false;
|
var productIsDeleted = false;
|
||||||
var product = CreateDataModel(productId, productName, productType, productRestaurantId,productPrice, supplies, warehouse, productIsDeleted);
|
var product = CreateDataModel(productId, productName, productType, productRestaurantId,productPrice, productIsDeleted);
|
||||||
Assert.That(() => product.Validate(), Throws.Nothing);
|
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
{
|
{
|
||||||
@ -112,17 +86,10 @@ internal class ProductDataModelTests
|
|||||||
Assert.That(product.ProductType, Is.EqualTo(productType));
|
Assert.That(product.ProductType, Is.EqualTo(productType));
|
||||||
Assert.That(product.RestaurantId, Is.EqualTo(productRestaurantId));
|
Assert.That(product.RestaurantId, Is.EqualTo(productRestaurantId));
|
||||||
Assert.That(product.Price, Is.EqualTo(productPrice));
|
Assert.That(product.Price, Is.EqualTo(productPrice));
|
||||||
Assert.That(product.Supplies, Is.EqualTo(supplies));
|
|
||||||
Assert.That(product.Warehouse, Is.EqualTo(warehouse));
|
|
||||||
Assert.That(product.IsDeleted, Is.EqualTo(productIsDeleted));
|
Assert.That(product.IsDeleted, Is.EqualTo(productIsDeleted));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? productRestaurantId,double price, List<SupplyProductDataModel>? supplies, List<WarehouseProductDataModel>? warehouse, bool isDeleted) =>
|
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? productRestaurantId,double price, bool isDeleted) =>
|
||||||
new(id, productName, productType, productRestaurantId, price, supplies, warehouse, isDeleted);
|
new(id, productName, productType, productRestaurantId, price, isDeleted);
|
||||||
private static List<SupplyProductDataModel> CreateSuppliesDataModel()
|
|
||||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
|
||||||
|
|
||||||
private static List<WarehouseProductDataModel> CreateWarehouseDataModel()
|
|
||||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user