усложненка 1
This commit is contained in:
parent
e6a053624b
commit
1d4cc5bec0
@ -11,13 +11,16 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace PipingHotContrast.DataModels;
|
||||
|
||||
public class ProductDataModel(string id, string productName, ProductType productType,string restaurantId, double price, bool isDeleted): IValidation
|
||||
public class ProductDataModel(string id, string productName, ProductType productType,string restaurantId, double price, List<SupplyProductDataModel> supplies, List<WarehouseProductDataModel> warehouse, bool isDeleted): IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string ProductName { get; private set; } = productName;
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
public string RestaurantId { get; private set; } = restaurantId;
|
||||
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 void Validate()
|
||||
@ -36,5 +39,10 @@ public class ProductDataModel(string id, string productName, ProductType product
|
||||
throw new ValidationException("The value in the field RestaurantId is not a unique identifier");
|
||||
if(Price <= 0)
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
37
PipingHot/PipingHot/DataModels/SupplyDataModel.cs
Normal file
37
PipingHot/PipingHot/DataModels/SupplyDataModel.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using PipingHotContrast.Enums;
|
||||
using PipingHotContrast.Exceptions;
|
||||
using PipingHotContrast.Extensions;
|
||||
using PipingHotContrast.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PipingHotContrast.DataModels;
|
||||
|
||||
public class SupplyDataModel(string id, ProductType productType, DateTime deliveryDate, int count, List<SupplyProductDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
|
||||
public DateTime DeliveryDate { get; private set; } = deliveryDate;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public List<SupplyProductDataModel> 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 (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
}
|
||||
}
|
32
PipingHot/PipingHot/DataModels/SupplyProductDataModel.cs
Normal file
32
PipingHot/PipingHot/DataModels/SupplyProductDataModel.cs
Normal file
@ -0,0 +1,32 @@
|
||||
using PipingHotContrast.Exceptions;
|
||||
using PipingHotContrast.Extensions;
|
||||
using PipingHotContrast.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PipingHotContrast.DataModels;
|
||||
|
||||
public class SupplyProductDataModel(string supplyId, string productId, int count) : IValidation
|
||||
{
|
||||
public string SupplyId { get; private set; } = supplyId;
|
||||
public string ProductId { get; private set; } = productId;
|
||||
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 (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 (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
37
PipingHot/PipingHot/DataModels/WarehouseDataModel.cs
Normal file
37
PipingHot/PipingHot/DataModels/WarehouseDataModel.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using PipingHotContrast.Enums;
|
||||
using PipingHotContrast.Exceptions;
|
||||
using PipingHotContrast.Extensions;
|
||||
using PipingHotContrast.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PipingHotContrast.DataModels;
|
||||
|
||||
public class WarehouseDataModel(string id, ProductType productType, int count, List<WarehouseProductDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public List<WarehouseProductDataModel> 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 (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The warehouse must include products");
|
||||
}
|
||||
}
|
37
PipingHot/PipingHot/DataModels/WarehouseProductDataModel.cs
Normal file
37
PipingHot/PipingHot/DataModels/WarehouseProductDataModel.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using PipingHotContrast.Exceptions;
|
||||
using PipingHotContrast.Extensions;
|
||||
using PipingHotContrast.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PipingHotContrast.DataModels;
|
||||
|
||||
public class WarehouseProductDataModel(string warehouseId, string productId, int count) : IValidation
|
||||
{
|
||||
|
||||
public string WarehouseId { get; private set; } = warehouseId;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
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 (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field TourId is empty");
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -15,32 +15,32 @@ internal class ProductDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "name", ProductType.Pizza, Guid.NewGuid().ToString(),500, false);
|
||||
var product = CreateDataModel(null, "name", ProductType.Pizza, Guid.NewGuid().ToString(),500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||
product = CreateDataModel(string.Empty, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||
var product = CreateDataModel("id", "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductTypeIsNoneTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, Guid.NewGuid().ToString(), 500, false);
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@ -49,11 +49,11 @@ internal class ProductDataModelTests
|
||||
{
|
||||
|
||||
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>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.Pizza, string.Empty, 500, false);
|
||||
ProductType.Pizza, string.Empty, 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
@ -61,7 +61,7 @@ internal class ProductDataModelTests
|
||||
public void ReastaurantIdIsNotGuidTest()
|
||||
{
|
||||
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>());
|
||||
}
|
||||
@ -69,9 +69,26 @@ internal class ProductDataModelTests
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 0, false);
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 0, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), - 500, false);
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), - 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||
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>());
|
||||
}
|
||||
|
||||
@ -83,8 +100,10 @@ internal class ProductDataModelTests
|
||||
var productType = ProductType.Pizza;
|
||||
var productRestaurantId = Guid.NewGuid().ToString();
|
||||
var productPrice = 500;
|
||||
var supplies = CreateSuppliesDataModel();
|
||||
var warehouse = CreateWarehouseDataModel();
|
||||
var productIsDeleted = false;
|
||||
var product = CreateDataModel(productId, productName, productType, productRestaurantId,productPrice, productIsDeleted);
|
||||
var product = CreateDataModel(productId, productName, productType, productRestaurantId,productPrice, supplies, warehouse, productIsDeleted);
|
||||
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -93,10 +112,17 @@ internal class ProductDataModelTests
|
||||
Assert.That(product.ProductType, Is.EqualTo(productType));
|
||||
Assert.That(product.RestaurantId, Is.EqualTo(productRestaurantId));
|
||||
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));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? productRestaurantId,double price, bool isDeleted) =>
|
||||
new(id, productName, productType, productRestaurantId, price, isDeleted);
|
||||
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? productRestaurantId,double price, List<SupplyProductDataModel>? supplies, List<WarehouseProductDataModel>? warehouse, bool isDeleted) =>
|
||||
new(id, productName, productType, productRestaurantId, price, supplies, warehouse, 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)];
|
||||
}
|
||||
|
@ -0,0 +1,80 @@
|
||||
using PipingHotContrast.DataModels;
|
||||
using PipingHotContrast.Enums;
|
||||
using PipingHotContrast.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PipingHotTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplyDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var suppliesData = CreateDataModel(null, ProductType.Pizza, DateTime.Now, 1, CreateSubDataModel());
|
||||
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||
suppliesData = CreateDataModel(string.Empty, ProductType.Pizza, DateTime.Now, 1, CreateSubDataModel());
|
||||
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var suppliesData = CreateDataModel("id", ProductType.Pizza, DateTime.Now, 1, CreateSubDataModel());
|
||||
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductTypeIsNoneTest()
|
||||
{
|
||||
var suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.None, DateTime.Now, 1, CreateSubDataModel());
|
||||
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Pizza, DateTime.Now, 0, CreateSubDataModel());
|
||||
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Pizza, DateTime.Now, -1, CreateSubDataModel());
|
||||
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Pizza, DateTime.Now, 1, null);
|
||||
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||
suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Pizza, DateTime.Now, 1, []);
|
||||
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var productType = ProductType.Pizza;
|
||||
var deliveryDate = DateTime.Now;
|
||||
var count = 1;
|
||||
var products = CreateSubDataModel();
|
||||
var suppliesData = CreateDataModel(id, productType, deliveryDate, count, products);
|
||||
Assert.That(() => suppliesData.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(suppliesData.Id, Is.EqualTo(id));
|
||||
Assert.That(suppliesData.ProductType, Is.EqualTo(productType));
|
||||
Assert.That(suppliesData.DeliveryDate, Is.EqualTo(deliveryDate));
|
||||
Assert.That(suppliesData.Count, Is.EqualTo(count));
|
||||
Assert.That(suppliesData.Products, Is.EqualTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyDataModel CreateDataModel(string? id, ProductType productType, DateTime deliveryDate, int count, List<SupplyProductDataModel>? products)
|
||||
=> new(id, productType, deliveryDate, count, products);
|
||||
private static List<SupplyProductDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
using PipingHotContrast.DataModels;
|
||||
using PipingHotContrast.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PipingHotTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplyProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void SuppliesIdIsNullOrEmptyTest()
|
||||
{
|
||||
var productSupplies = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => productSupplies.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
productSupplies = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => productSupplies.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuppliesIdIsNotGuidTest()
|
||||
{
|
||||
var productSupplies = CreateDataModel("suppliesId", Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => productSupplies.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var productSupplies = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||
Assert.That(() => productSupplies.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
productSupplies = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||
Assert.That(() => productSupplies.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var productSupplies = CreateDataModel(Guid.NewGuid().ToString(), "productId", 1);
|
||||
Assert.That(() => productSupplies.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var productSupplies = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => productSupplies.Validate(), Throws.TypeOf<ValidationException>());
|
||||
productSupplies = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||
Assert.That(() => productSupplies.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var count = 1;
|
||||
var productSupplies = CreateDataModel(supplyId, productId, count);
|
||||
Assert.That(() => productSupplies.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(productSupplies.SupplyId, Is.EqualTo(supplyId));
|
||||
Assert.That(productSupplies.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(productSupplies.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyProductDataModel CreateDataModel(string? suppliesId, string? productId, int count)
|
||||
=> new(suppliesId, productId, count);
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
using PipingHotContrast.DataModels;
|
||||
using PipingHotContrast.Enums;
|
||||
using PipingHotContrast.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PipingHotTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WarehouseDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(null, ProductType.Pizza, 1, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouse = CreateDataModel(string.Empty, ProductType.Pizza, 1, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var warehouse = CreateDataModel("id", ProductType.Pizza, 1, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductTypeIsNoneTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), ProductType.None, 1, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Pizza, 0, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Pizza, -1, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Pizza, 1, null);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Pizza, 1, []);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var productType = ProductType.Pizza;
|
||||
var count = 1;
|
||||
var products = CreateSubDataModel();
|
||||
var model = CreateDataModel(id, productType, count, products);
|
||||
Assert.DoesNotThrow(() => model.Validate());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.Id, Is.EqualTo(id));
|
||||
Assert.That(model.ProductType, Is.EqualTo(productType));
|
||||
Assert.That(model.Count, Is.EqualTo(count));
|
||||
Assert.That(model.Products, Is.EqualTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseDataModel CreateDataModel(string? id, ProductType productType, int count, List<WarehouseProductDataModel>? products)
|
||||
=> new WarehouseDataModel(id, productType, count, products);
|
||||
|
||||
private static List<WarehouseProductDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
using PipingHotContrast.DataModels;
|
||||
using PipingHotContrast.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PipingHotTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WarehouseProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WarehouseIdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => warehouseProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
warehouseProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => warehouseProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIdIsNotGuidTest()
|
||||
{
|
||||
var warehouseProduct = CreateDataModel("warehouseId", Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => warehouseProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||
Assert.That(() => warehouseProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
warehouseProduct = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||
Assert.That(() => warehouseProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var warehouseProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 1);
|
||||
Assert.That(() => warehouseProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var warehouseProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => warehouseProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||
Assert.That(() => warehouseProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var count = 1;
|
||||
var warehouseProduct = CreateDataModel(warehouseId, productId, count);
|
||||
Assert.That(() => warehouseProduct.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(warehouseProduct.WarehouseId, Is.EqualTo(warehouseId));
|
||||
Assert.That(warehouseProduct.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(warehouseProduct.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseProductDataModel CreateDataModel(string? warehouseId, string? productId, int count)
|
||||
=> new(warehouseId, productId, count);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user