Compare commits
3 Commits
Task_1_Mod
...
Task_1_Mod
| Author | SHA1 | Date | |
|---|---|---|---|
| b47e6a82ab | |||
| 6d0b535a23 | |||
| a4fe460401 |
@@ -16,10 +16,6 @@ public string OrderId { get; private set; } = orderid;
|
||||
public string DishId { get; private set; } = dishid;
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels
|
||||
{
|
||||
public class ProductDataModelHard(string id, string name, int quantity, string unit) : IValidation
|
||||
{
|
||||
public string ID { get; private set; } = id;
|
||||
public string Name { get; private set; } = name;
|
||||
public int Quantity { get; private set; } = quantity;
|
||||
public string Unit { get; private set; } = unit;
|
||||
|
||||
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ID.IsEmpty())
|
||||
throw new ValidationException("Field ID is empty");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
throw new ValidationException("Name cannot be empty.");
|
||||
|
||||
if (Quantity < 0)
|
||||
throw new ValidationException("Quantity cannot be negative.");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Unit))
|
||||
throw new ValidationException("Unit cannot be empty.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels
|
||||
{
|
||||
public class Product_SupplyDataModelHard(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 BlandId is not a unique identifier");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels
|
||||
{
|
||||
public class SupplyDataModelHard(string id, string supplierName, DateTime date, string warehouseID, List<Product_SupplyDataModelHard> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string SupplierName { get; private set; } = supplierName;
|
||||
public DateTime Date { get; private set; } = date;
|
||||
public string WarehouseID { get; private set; } = warehouseID;
|
||||
public List<Product_SupplyDataModelHard> Products { get; private set; } = products;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(SupplierName))
|
||||
throw new ValidationException("Field SupplierName is empty.");
|
||||
|
||||
if (Date == default)
|
||||
throw new ValidationException("Field Date is not set.");
|
||||
|
||||
if (WarehouseID.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (Products == null || Products.Count == 0)
|
||||
throw new ValidationException("Supply must contain at least one product.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels
|
||||
{
|
||||
public class WarehouseDataModel(string id, string name, string location, List<Warehouse_ProductDataModel> warehouse_Products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string Name { get; private set; } = name;
|
||||
public string Location { get; private set; } = location;
|
||||
public List<Warehouse_ProductDataModel> Warehouse_Products { get; private set; } = warehouse_Products;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Name))
|
||||
throw new ValidationException("Field Name is empty.");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Location))
|
||||
throw new ValidationException("Field Location is empty.");
|
||||
|
||||
if (Warehouse_Products == null || Warehouse_Products.Count == 0)
|
||||
throw new ValidationException("Warehouse must contain at least one product.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels
|
||||
{
|
||||
public class Warehouse_ProductDataModel : IValidation
|
||||
{
|
||||
public string WarehouseID { get; private set; }
|
||||
public string ProductID { get; private set; }
|
||||
public int Count { get; private set; }
|
||||
|
||||
public Warehouse_ProductDataModel(string warehouseID, string productID, int count)
|
||||
{
|
||||
WarehouseID = warehouseID;
|
||||
ProductID = productID;
|
||||
Count = count;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (WarehouseID.IsEmpty())
|
||||
throw new ValidationException("Field WarehouseID is empty");
|
||||
|
||||
if (!WarehouseID.IsGuid())
|
||||
throw new ValidationException("The value in field WarehouseID is not a unique identifier");
|
||||
|
||||
if (ProductID.IsEmpty())
|
||||
throw new ValidationException("Field ProductID is empty");
|
||||
|
||||
if (!ProductID.IsGuid())
|
||||
throw new ValidationException("The value in field ProductID is not a unique identifier");
|
||||
|
||||
if (Count < 0)
|
||||
throw new ValidationException("Count cannot be negative");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
internal class ProductDataModelHardTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, "Product 1", 10, "kg");
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(string.Empty, "Product 1", 10, "kg");
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameIsNullOrWhiteSpaceTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), null, 10, "kg");
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10, "kg");
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), " ", 10, "kg");
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void QuantityIsNegativeTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "Product 1", -1, "kg");
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UnitIsNullOrWhiteSpaceTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "Product 1", 10, null);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), "Product 1", 10, string.Empty);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), "Product 1", 10, " ");
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Product 1";
|
||||
var quantity = 10;
|
||||
var unit = "kg";
|
||||
|
||||
var model = CreateDataModel(id, name, quantity, unit);
|
||||
|
||||
Assert.DoesNotThrow(() => model.Validate());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.ID, Is.EqualTo(id));
|
||||
Assert.That(model.Name, Is.EqualTo(name));
|
||||
Assert.That(model.Quantity, Is.EqualTo(quantity));
|
||||
Assert.That(model.Unit, Is.EqualTo(unit));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductDataModelHard CreateDataModel(string id, string name, int quantity, string unit)
|
||||
=> new ProductDataModelHard(id, name, quantity, unit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
internal class ProductSupplyDataModelHardTests
|
||||
{
|
||||
[Test]
|
||||
public void SupplyIdIsNullOrEmptyTest()
|
||||
{
|
||||
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 SupplyIdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel("invalid-id", Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
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 ProductIdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "invalid-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 supplyId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var count = 5;
|
||||
|
||||
var model = CreateDataModel(supplyId, productId, count);
|
||||
|
||||
Assert.That(() => model.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.SupplyID, Is.EqualTo(supplyId));
|
||||
Assert.That(model.ProductID, Is.EqualTo(productId));
|
||||
Assert.That(model.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static Product_SupplyDataModelHard CreateDataModel(string supplyId, string productId, int count)
|
||||
=> new(supplyId, productId, count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class SupplyDataModelHardTest
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, "Supplier", DateTime.Now, "warehouse123", CreateProductsDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(string.Empty, "Supplier", DateTime.Now, "warehouse123", CreateProductsDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplierNameIsNullOrWhiteSpaceTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.Now, "warehouse123", CreateProductsDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.Now, "warehouse123", CreateProductsDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), " ", DateTime.Now, "warehouse123", CreateProductsDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DateIsDefaultTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "Supplier", default, "warehouse123", CreateProductsDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "Supplier", DateTime.Now, null, CreateProductsDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), "Supplier", DateTime.Now, string.Empty, CreateProductsDataModel());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsEmptyOrNullTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "Supplier", DateTime.Now, "warehouse123", []);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), "Supplier", DateTime.Now, "warehouse123", null);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var supplierName = "Test Supplier";
|
||||
var date = DateTime.Now;
|
||||
var warehouseId = "warehouse123";
|
||||
var products = CreateProductsDataModel();
|
||||
|
||||
var model = CreateDataModel(id, supplierName, date, warehouseId, products);
|
||||
|
||||
Assert.DoesNotThrow(() => model.Validate());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.Id, Is.EqualTo(id));
|
||||
Assert.That(model.SupplierName, Is.EqualTo(supplierName));
|
||||
Assert.That(model.Date, Is.EqualTo(date));
|
||||
Assert.That(model.WarehouseID, Is.EqualTo(warehouseId));
|
||||
Assert.That(model.Products, Is.EqualTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyDataModelHard CreateDataModel(string? id, string supplierName, DateTime date, string warehouseId, List<Product_SupplyDataModelHard> products)
|
||||
=> new(id, supplierName, date, warehouseId, products);
|
||||
|
||||
private static List<Product_SupplyDataModelHard> CreateProductsDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
internal class WarehouseDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, "Main Warehouse", "Moscow", CreateWarehouseProducts());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(string.Empty, "Main Warehouse", "Moscow", CreateWarehouseProducts());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameIsNullOrWhiteSpaceTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), null, "Moscow", CreateWarehouseProducts());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "Moscow", CreateWarehouseProducts());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), " ", "Moscow", CreateWarehouseProducts());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LocationIsNullOrWhiteSpaceTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "Main Warehouse", null, CreateWarehouseProducts());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), "Main Warehouse", string.Empty, CreateWarehouseProducts());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), "Main Warehouse", " ", CreateWarehouseProducts());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseProductsIsEmptyOrNullTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "Main Warehouse", "Moscow", new List<Warehouse_ProductDataModel>());
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), "Main Warehouse", "Moscow", null);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Main Warehouse";
|
||||
var location = "Moscow, Lenina st. 1";
|
||||
var products = CreateWarehouseProducts();
|
||||
|
||||
var model = CreateDataModel(id, name, location, products);
|
||||
|
||||
Assert.DoesNotThrow(() => model.Validate());
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.Id, Is.EqualTo(id));
|
||||
Assert.That(model.Name, Is.EqualTo(name));
|
||||
Assert.That(model.Location, Is.EqualTo(location));
|
||||
Assert.That(model.Warehouse_Products, Is.EqualTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseDataModel CreateDataModel(string id, string name, string location, List<Warehouse_ProductDataModel> products)
|
||||
=> new WarehouseDataModel(id, name, location, products);
|
||||
|
||||
private static List<Warehouse_ProductDataModel> CreateWarehouseProducts()
|
||||
=> [new Warehouse_ProductDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10)];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class Warehouse_ProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WarehouseIDIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
|
||||
warehouseProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIDIsNotGuidTest()
|
||||
{
|
||||
var warehouseProduct = CreateDataModel("not-a-guid", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIDIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => warehouseProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
|
||||
warehouseProduct = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => warehouseProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIDIsNotGuidTest()
|
||||
{
|
||||
var warehouseProduct = CreateDataModel(Guid.NewGuid().ToString(), "not-a-guid", 10);
|
||||
Assert.That(() => warehouseProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsNegativeTest()
|
||||
{
|
||||
var 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();
|
||||
const int count = 10;
|
||||
|
||||
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 Warehouse_ProductDataModel CreateDataModel(string? warehouseID, string? productID, int count) =>
|
||||
new(warehouseID ?? string.Empty, productID ?? string.Empty, count);
|
||||
}
|
||||
Reference in New Issue
Block a user