From 6e499a37d13198d72776a36d17cc9474d8167606 Mon Sep 17 00:00:00 2001 From: Glliza Date: Sun, 9 Mar 2025 14:28:06 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=20=D0=BF=D1=80=D0=BE=D1=86=D0=B5=D1=81?= =?UTF-8?q?=D1=81=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataModels/ProductDataModel.cs | 4 +- .../DataModels/ShopDataModel.cs | 37 ++++++ .../DataModels/ShopProductDataModel.cs | 37 ++++++ .../DataModels/SupplyDataModel.cs | 37 ++++++ .../DataModels/SupplyProductDataModel.cs | 30 +++++ .../DataModelsTests/ProductDataModelTests.cs | 113 ++++++++++++------ .../DataModelsTests/ShopDataModelTests.cs | 81 +++++++++++++ .../ShopProductDataModelTests.cs | 75 ++++++++++++ .../DataModelsTests/SupplyDataModelTests.cs | 81 +++++++++++++ .../SupplyProductDataModelTests.cs | 74 ++++++++++++ 10 files changed, 532 insertions(+), 37 deletions(-) create mode 100644 PuferFishContracts/PuferFishContracts/DataModels/ShopDataModel.cs create mode 100644 PuferFishContracts/PuferFishContracts/DataModels/ShopProductDataModel.cs create mode 100644 PuferFishContracts/PuferFishContracts/DataModels/SupplyDataModel.cs create mode 100644 PuferFishContracts/PuferFishContracts/DataModels/SupplyProductDataModel.cs create mode 100644 PuferFishContracts/PuferFishTests/DataModelsTests/ShopDataModelTests.cs create mode 100644 PuferFishContracts/PuferFishTests/DataModelsTests/ShopProductDataModelTests.cs create mode 100644 PuferFishContracts/PuferFishTests/DataModelsTests/SupplyDataModelTests.cs create mode 100644 PuferFishContracts/PuferFishTests/DataModelsTests/SupplyProductDataModelTests.cs diff --git a/PuferFishContracts/PuferFishContracts/DataModels/ProductDataModel.cs b/PuferFishContracts/PuferFishContracts/DataModels/ProductDataModel.cs index 9c669cc..296ab0b 100644 --- a/PuferFishContracts/PuferFishContracts/DataModels/ProductDataModel.cs +++ b/PuferFishContracts/PuferFishContracts/DataModels/ProductDataModel.cs @@ -11,12 +11,14 @@ using PuferFishContracts.Infrastructure; namespace PuferFishContracts.DataModels; -public class ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted) : IValidation +public class ProductDataModel(string id, string productName, ProductType productType, double price, List supplies, List shop, 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 double Price { get; private set; } = price; + public List Supplies { get; private set; } = supplies; + public List Shop { get; private set; } = shop; public bool IsDeleted { get; private set; } = isDeleted; public void Validate() { diff --git a/PuferFishContracts/PuferFishContracts/DataModels/ShopDataModel.cs b/PuferFishContracts/PuferFishContracts/DataModels/ShopDataModel.cs new file mode 100644 index 0000000..0d3ab6a --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/DataModels/ShopDataModel.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.Extensions; +using PuferFishContracts.Exceptions; +using PuferFishContracts.Infrastructure; +using PuferFishContracts.Enums; + +namespace PuferFishContracts.DataModels; + +public class ShopDataModel(string id, ProductType productType, int count, List 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 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"); + } +} diff --git a/PuferFishContracts/PuferFishContracts/DataModels/ShopProductDataModel.cs b/PuferFishContracts/PuferFishContracts/DataModels/ShopProductDataModel.cs new file mode 100644 index 0000000..0ace296 --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/DataModels/ShopProductDataModel.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.Enums; +using PuferFishContracts.Extensions; +using PuferFishContracts.Exceptions; +using PuferFishContracts.Infrastructure; + +namespace PuferFishContracts.DataModels; + +public class ShopProductDataModel(string shopId, string productId, int count) : IValidation +{ + public string ShopId { get; private set; } = shopId; + + public string ProductId { get; private set; } = productId; + + public int Count { get; private set; } = count; + public void Validate() + { + if (ShopId.IsEmpty()) + throw new ValidationException("Field WarehouseId is empty"); + + if (!ShopId.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"); + } +} diff --git a/PuferFishContracts/PuferFishContracts/DataModels/SupplyDataModel.cs b/PuferFishContracts/PuferFishContracts/DataModels/SupplyDataModel.cs new file mode 100644 index 0000000..70770d3 --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/DataModels/SupplyDataModel.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.Enums; +using PuferFishContracts.Extensions; +using PuferFishContracts.Infrastructure; +using PuferFishContracts.Exceptions; + +namespace PuferFishContracts.DataModels; + +public class SupplyDataModel(string id, ProductType productType, DateTime deliveryDate, int count, List 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 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"); + } +} \ No newline at end of file diff --git a/PuferFishContracts/PuferFishContracts/DataModels/SupplyProductDataModel.cs b/PuferFishContracts/PuferFishContracts/DataModels/SupplyProductDataModel.cs new file mode 100644 index 0000000..d51304b --- /dev/null +++ b/PuferFishContracts/PuferFishContracts/DataModels/SupplyProductDataModel.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.Extensions; +using PuferFishContracts.Exceptions; +using PuferFishContracts.Infrastructure; + +namespace PuferFishContracts.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"); + } +} diff --git a/PuferFishContracts/PuferFishTests/DataModelsTests/ProductDataModelTests.cs b/PuferFishContracts/PuferFishTests/DataModelsTests/ProductDataModelTests.cs index 3b62232..3b90f12 100644 --- a/PuferFishContracts/PuferFishTests/DataModelsTests/ProductDataModelTests.cs +++ b/PuferFishContracts/PuferFishTests/DataModelsTests/ProductDataModelTests.cs @@ -16,73 +16,114 @@ internal class ProductDataModelTests [Test] public void IdIsNullOrEmptyTest() { - var product = CreateDataModel(null, "name", ProductType.Sushi, 10, false); - Assert.That(() => product.Validate(), - Throws.TypeOf()); - product = CreateDataModel(string.Empty, "name", - ProductType.Sushi, 10, false); - Assert.That(() => product.Validate(), - Throws.TypeOf()); + var product = CreateDataModel(null, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), Throws.TypeOf()); + product = CreateDataModel(string.Empty, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), Throws.TypeOf()); } + [Test] public void IdIsNotGuidTest() { - var product = CreateDataModel("id", "name", ProductType.Sushi, 10, false); - Assert.That(() => product.Validate(), - Throws.TypeOf()); + var product = CreateDataModel("id", "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), Throws.TypeOf()); } + [Test] - public void ProductNameIsEmptyTest() + public void ProductNameIsNullOrEmptyTest() { - var product = CreateDataModel(Guid.NewGuid().ToString(), null, - ProductType.Sushi, 10, false); - Assert.That(() => product.Validate(), - Throws.TypeOf()); - product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, - ProductType.Sushi, 10, false); - Assert.That(() => product.Validate(), - Throws.TypeOf()); + var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), Throws.TypeOf()); + product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), Throws.TypeOf()); } + [Test] public void ProductTypeIsNoneTest() { - var product = CreateDataModel(Guid.NewGuid().ToString(), null, - ProductType.None, 10, false); + var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [Test] + public void ReastaurantIdIsNullOrEmptyTest() + { + + var product = CreateDataModel(Guid.NewGuid().ToString(), "name", + ProductType.Pizza, null, 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), + Throws.TypeOf()); + product = CreateDataModel(Guid.NewGuid().ToString(), "name", + ProductType.Pizza, string.Empty, 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); Assert.That(() => product.Validate(), Throws.TypeOf()); } [Test] - public void PriceIsLessOrZeroTest() + public void ReastaurantIdIsNotGuidTest() { var product = CreateDataModel(Guid.NewGuid().ToString(), "name", - ProductType.Sushi, 0, false); - Assert.That(() => product.Validate(), - Throws.TypeOf()); - product = CreateDataModel(Guid.NewGuid().ToString(), "name", - ProductType.Sushi, -10, false); + ProductType.Pizza, "restaurantId", 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); Assert.That(() => product.Validate(), Throws.TypeOf()); } + + [Test] + public void PriceIsLessOrZeroTest() + { + var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 0, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), Throws.TypeOf()); + product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), -500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + [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()); + product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Pizza, Guid.NewGuid().ToString(), 0, [], CreateWarehouseDataModel(), false); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + + [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()); + product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Pizza, Guid.NewGuid().ToString(), 0, CreateSuppliesDataModel(), [], false); + Assert.That(() => product.Validate(), Throws.TypeOf()); + } + [Test] public void AllFieldsIsCorrectTest() { var productId = Guid.NewGuid().ToString(); var productName = "name"; - var productType = ProductType.Sushi; - var productPrice = 10; - var productIsDelete = false; - var product = CreateDataModel(productId, productName, productType, productPrice, productIsDelete); + 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, supplies, warehouse, productIsDeleted); Assert.That(() => product.Validate(), Throws.Nothing); Assert.Multiple(() => { Assert.That(product.Id, Is.EqualTo(productId)); Assert.That(product.ProductName, Is.EqualTo(productName)); Assert.That(product.ProductType, Is.EqualTo(productType)); + Assert.That(product.RestaurantId, Is.EqualTo(productRestaurantId)); Assert.That(product.Price, Is.EqualTo(productPrice)); - Assert.That(product.IsDeleted, Is.EqualTo(productIsDelete)); + 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, double price, bool - isDeleted) => new(id, productName, productType, price, isDeleted); -} + + private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? productRestaurantId, double price, List? supplies, List? warehouse, bool isDeleted) => + new(id, productName, productType, productRestaurantId, price, supplies, warehouse, isDeleted); + private static List CreateSuppliesDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; + + private static List CreateWarehouseDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; +} \ No newline at end of file diff --git a/PuferFishContracts/PuferFishTests/DataModelsTests/ShopDataModelTests.cs b/PuferFishContracts/PuferFishTests/DataModelsTests/ShopDataModelTests.cs new file mode 100644 index 0000000..66e56fd --- /dev/null +++ b/PuferFishContracts/PuferFishTests/DataModelsTests/ShopDataModelTests.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; +using PuferFishContracts.Enums; +using PuferFishContracts.Exceptions; + +namespace PuferFishTests.DataModelsTests; + +[TestFixture] +internal class ShopDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var shop = CreateDataModel(null, ProductType.Rolls, 1, CreateSubDataModel()); + Assert.That(() => shop.Validate(), Throws.TypeOf()); + shop = CreateDataModel(string.Empty, ProductType.Rolls, 1, CreateSubDataModel()); + Assert.That(() => shop.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var shop = CreateDataModel("id", ProductType.Rolls, 1, CreateSubDataModel()); + Assert.That(() => shop.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductTypeIsNoneTest() + { + var shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.None, 1, CreateSubDataModel()); + Assert.That(() => shop.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, 0, CreateSubDataModel()); + Assert.That(() => shop.Validate(), Throws.TypeOf()); + + shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, -1, CreateSubDataModel()); + Assert.That(() => shop.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductsIsNullOrEmptyTest() + { + var shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, 1, null); + Assert.That(() => shop.Validate(), Throws.TypeOf()); + + shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, 1, []); + Assert.That(() => shop.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var productType = ProductType.Rolls; + 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 ShopDataModel CreateDataModel(string? id, ProductType productType, int count, List? products) + => new ShopDataModel(id, productType, count, products); + + private static List CreateSubDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; +} diff --git a/PuferFishContracts/PuferFishTests/DataModelsTests/ShopProductDataModelTests.cs b/PuferFishContracts/PuferFishTests/DataModelsTests/ShopProductDataModelTests.cs new file mode 100644 index 0000000..5ad1611 --- /dev/null +++ b/PuferFishContracts/PuferFishTests/DataModelsTests/ShopProductDataModelTests.cs @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; +using PuferFishContracts.Exceptions; + +namespace PuferFishTests.DataModelsTests; + +[TestFixture] +internal class ShopProductDataModelTests +{ + [Test] + public void ShopIdIsNullOrEmptyTest() + { + var shopProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 1); + Assert.That(() => shopProduct.Validate(), Throws.TypeOf()); + + shopProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1); + Assert.That(() => shopProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ShopIdIsNotGuidTest() + { + var shopProduct = CreateDataModel("shopId", Guid.NewGuid().ToString(), 1); + Assert.That(() => shopProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductIdIsNullOrEmptyTest() + { + var shopProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 1); + Assert.That(() => shopProduct.Validate(), Throws.TypeOf()); + + shopProduct = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1); + Assert.That(() => shopProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductIdIsNotGuidTest() + { + var shopProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 1); + Assert.That(() => shopProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var shopProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => shopProduct.Validate(), Throws.TypeOf()); + shopProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1); + Assert.That(() => shopProduct.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var shopId = Guid.NewGuid().ToString(); + var productId = Guid.NewGuid().ToString(); + var count = 1; + var shopProduct = CreateDataModel(shopId, productId, count); + Assert.That(() => shopProduct.Validate(), Throws.Nothing); + Assert.Multiple(() => + { + Assert.That(shopProduct.shopId, Is.EqualTo(shopId)); + Assert.That(shopProduct.ProductId, Is.EqualTo(productId)); + Assert.That(shopProduct.Count, Is.EqualTo(count)); + }); + } + + private static ShopProductDataModel CreateDataModel(string? shopId, string? productId, int count) => new(shopId, productId, count); +} + diff --git a/PuferFishContracts/PuferFishTests/DataModelsTests/SupplyDataModelTests.cs b/PuferFishContracts/PuferFishTests/DataModelsTests/SupplyDataModelTests.cs new file mode 100644 index 0000000..8e57c92 --- /dev/null +++ b/PuferFishContracts/PuferFishTests/DataModelsTests/SupplyDataModelTests.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; +using PuferFishContracts.Enums; +using PuferFishContracts.Exceptions; + +namespace PuferFishTests.DataModelsTests; + +[TestFixture] +internal class SupplyDataModelTests +{ + [Test] + public void IdIsNullOrEmptyTest() + { + var suppliesData = CreateDataModel(null, ProductType.Rolls, DateTime.Now, 1, CreateSubDataModel()); + Assert.That(() => suppliesData.Validate(), Throws.TypeOf()); + suppliesData = CreateDataModel(string.Empty, ProductType.Rolls, DateTime.Now, 1, CreateSubDataModel()); + Assert.That(() => suppliesData.Validate(), Throws.TypeOf()); + } + + [Test] + public void IdIsNotGuidTest() + { + var suppliesData = CreateDataModel("id", ProductType.Rolls, DateTime.Now, 1, CreateSubDataModel()); + Assert.That(() => suppliesData.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductTypeIsNoneTest() + { + var suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.None, DateTime.Now, 1, CreateSubDataModel()); + Assert.That(() => suppliesData.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, DateTime.Now, 0, CreateSubDataModel()); + Assert.That(() => suppliesData.Validate(), Throws.TypeOf()); + + suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, DateTime.Now, -1, CreateSubDataModel()); + Assert.That(() => suppliesData.Validate(), Throws.TypeOf()); + } + [Test] + public void ProductsIsNullOrEmptyTest() + { + var suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, DateTime.Now, 1, null); + Assert.That(() => suppliesData.Validate(), Throws.TypeOf()); + suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, DateTime.Now, 1, []); + Assert.That(() => suppliesData.Validate(), Throws.TypeOf()); + } + + [Test] + public void AllFieldsIsCorrectTest() + { + var id = Guid.NewGuid().ToString(); + var productType = ProductType.Rolls; + 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? products) + => new(id, productType, deliveryDate, count, products); + private static List CreateSubDataModel() + => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; +} + diff --git a/PuferFishContracts/PuferFishTests/DataModelsTests/SupplyProductDataModelTests.cs b/PuferFishContracts/PuferFishTests/DataModelsTests/SupplyProductDataModelTests.cs new file mode 100644 index 0000000..4994936 --- /dev/null +++ b/PuferFishContracts/PuferFishTests/DataModelsTests/SupplyProductDataModelTests.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PuferFishContracts.DataModels; +using PuferFishContracts.Exceptions; + +namespace PuferFishTests.DataModelsTests; + +internal class SupplyProductDataModelTests +{ + [Test] + public void SuppliesIdIsNullOrEmptyTest() + { + var productSupplies = CreateDataModel(null, Guid.NewGuid().ToString(), 1); + Assert.That(() => productSupplies.Validate(), Throws.TypeOf()); + + productSupplies = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1); + Assert.That(() => productSupplies.Validate(), Throws.TypeOf()); + } + + [Test] + public void SuppliesIdIsNotGuidTest() + { + var productSupplies = CreateDataModel("suppliesId", Guid.NewGuid().ToString(), 1); + Assert.That(() => productSupplies.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductIdIsNullOrEmptyTest() + { + var productSupplies = CreateDataModel(Guid.NewGuid().ToString(), null, 1); + Assert.That(() => productSupplies.Validate(), Throws.TypeOf()); + + productSupplies = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1); + Assert.That(() => productSupplies.Validate(), Throws.TypeOf()); + } + + [Test] + public void ProductIdIsNotGuidTest() + { + var productSupplies = CreateDataModel(Guid.NewGuid().ToString(), "productId", 1); + Assert.That(() => productSupplies.Validate(), Throws.TypeOf()); + } + + [Test] + public void CountIsLessOrZeroTest() + { + var productSupplies = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0); + Assert.That(() => productSupplies.Validate(), Throws.TypeOf()); + productSupplies = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1); + Assert.That(() => productSupplies.Validate(), Throws.TypeOf()); + } + + [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); +}