В процессе
This commit is contained in:
parent
72b36bf3f0
commit
6e499a37d1
@ -11,12 +11,14 @@ using PuferFishContracts.Infrastructure;
|
|||||||
|
|
||||||
namespace PuferFishContracts.DataModels;
|
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<SupplyProductDataModel> supplies, List<ShopProductDataModel> shop, 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 double Price { get; private set; } = price;
|
public double Price { get; private set; } = price;
|
||||||
|
public List<SupplyProductDataModel> Supplies { get; private set; } = supplies;
|
||||||
|
public List<ShopProductDataModel> Shop { get; private set; } = shop;
|
||||||
public bool IsDeleted { get; private set; } = isDeleted;
|
public bool IsDeleted { get; private set; } = isDeleted;
|
||||||
public void Validate()
|
public void Validate()
|
||||||
{
|
{
|
||||||
|
@ -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<ShopProductDataModel> 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<ShopProductDataModel> 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");
|
||||||
|
}
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
@ -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<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");
|
||||||
|
}
|
||||||
|
}
|
@ -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");
|
||||||
|
}
|
||||||
|
}
|
@ -16,73 +16,114 @@ internal class ProductDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel(null, "name", ProductType.Sushi, 10, false);
|
var product = CreateDataModel(null, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||||
Assert.That(() => product.Validate(),
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
Throws.TypeOf<ValidationException>());
|
product = CreateDataModel(string.Empty, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||||
product = CreateDataModel(string.Empty, "name",
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
ProductType.Sushi, 10, false);
|
|
||||||
Assert.That(() => product.Validate(),
|
|
||||||
Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IdIsNotGuidTest()
|
public void IdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel("id", "name", ProductType.Sushi, 10, false);
|
var product = CreateDataModel("id", "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||||
Assert.That(() => product.Validate(),
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ProductNameIsEmptyTest()
|
public void ProductNameIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null,
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||||
ProductType.Sushi, 10, false);
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
Assert.That(() => product.Validate(),
|
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||||
Throws.TypeOf<ValidationException>());
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
|
||||||
ProductType.Sushi, 10, false);
|
|
||||||
Assert.That(() => product.Validate(),
|
|
||||||
Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void ProductTypeIsNoneTest()
|
public void ProductTypeIsNoneTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null,
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, Guid.NewGuid().ToString(), 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||||
ProductType.None, 10, false);
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ReastaurantIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||||
|
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, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||||
Assert.That(() => product.Validate(),
|
Assert.That(() => product.Validate(),
|
||||||
Throws.TypeOf<ValidationException>());
|
Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
[Test]
|
[Test]
|
||||||
public void PriceIsLessOrZeroTest()
|
public void ReastaurantIdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||||
ProductType.Sushi, 0, false);
|
ProductType.Pizza, "restaurantId", 500, CreateSuppliesDataModel(), CreateWarehouseDataModel(), false);
|
||||||
Assert.That(() => product.Validate(),
|
|
||||||
Throws.TypeOf<ValidationException>());
|
|
||||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
|
||||||
ProductType.Sushi, -10, false);
|
|
||||||
Assert.That(() => product.Validate(),
|
Assert.That(() => product.Validate(),
|
||||||
Throws.TypeOf<ValidationException>());
|
Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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<ValidationException>());
|
||||||
|
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>());
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void AllFieldsIsCorrectTest()
|
public void AllFieldsIsCorrectTest()
|
||||||
{
|
{
|
||||||
var productId = Guid.NewGuid().ToString();
|
var productId = Guid.NewGuid().ToString();
|
||||||
var productName = "name";
|
var productName = "name";
|
||||||
var productType = ProductType.Sushi;
|
var productType = ProductType.Pizza;
|
||||||
var productPrice = 10;
|
var productRestaurantId = Guid.NewGuid().ToString();
|
||||||
var productIsDelete = false;
|
var productPrice = 500;
|
||||||
var product = CreateDataModel(productId, productName, productType, productPrice, productIsDelete);
|
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.That(() => product.Validate(), Throws.Nothing);
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
{
|
{
|
||||||
Assert.That(product.Id, Is.EqualTo(productId));
|
Assert.That(product.Id, Is.EqualTo(productId));
|
||||||
Assert.That(product.ProductName, Is.EqualTo(productName));
|
Assert.That(product.ProductName, Is.EqualTo(productName));
|
||||||
Assert.That(product.ProductType, Is.EqualTo(productType));
|
Assert.That(product.ProductType, Is.EqualTo(productType));
|
||||||
|
Assert.That(product.RestaurantId, Is.EqualTo(productRestaurantId));
|
||||||
Assert.That(product.Price, Is.EqualTo(productPrice));
|
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
|
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? productRestaurantId, double price, List<SupplyProductDataModel>? supplies, List<WarehouseProductDataModel>? warehouse, bool isDeleted) =>
|
||||||
isDeleted) => new(id, productName, productType, price, 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,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<ValidationException>());
|
||||||
|
shop = CreateDataModel(string.Empty, ProductType.Rolls, 1, CreateSubDataModel());
|
||||||
|
Assert.That(() => shop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var shop = CreateDataModel("id", ProductType.Rolls, 1, CreateSubDataModel());
|
||||||
|
Assert.That(() => shop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
var shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.None, 1, CreateSubDataModel());
|
||||||
|
Assert.That(() => shop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, 0, CreateSubDataModel());
|
||||||
|
Assert.That(() => shop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, -1, CreateSubDataModel());
|
||||||
|
Assert.That(() => shop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductsIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, 1, null);
|
||||||
|
Assert.That(() => shop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
shop = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, 1, []);
|
||||||
|
Assert.That(() => shop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[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<ShopProductDataModel>? products)
|
||||||
|
=> new ShopDataModel(id, productType, count, products);
|
||||||
|
|
||||||
|
private static List<ShopProductDataModel> CreateSubDataModel()
|
||||||
|
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||||
|
}
|
@ -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<ValidationException>());
|
||||||
|
|
||||||
|
shopProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => shopProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ShopIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var shopProduct = CreateDataModel("shopId", Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => shopProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var shopProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||||
|
Assert.That(() => shopProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
shopProduct = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||||
|
Assert.That(() => shopProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ProductIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var shopProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 1);
|
||||||
|
Assert.That(() => shopProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsLessOrZeroTest()
|
||||||
|
{
|
||||||
|
var shopProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => shopProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
shopProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||||
|
Assert.That(() => shopProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[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);
|
||||||
|
}
|
||||||
|
|
@ -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<ValidationException>());
|
||||||
|
suppliesData = CreateDataModel(string.Empty, ProductType.Rolls, DateTime.Now, 1, CreateSubDataModel());
|
||||||
|
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var suppliesData = CreateDataModel("id", ProductType.Rolls, 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.Rolls, DateTime.Now, 0, CreateSubDataModel());
|
||||||
|
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, DateTime.Now, -1, CreateSubDataModel());
|
||||||
|
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void ProductsIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, DateTime.Now, 1, null);
|
||||||
|
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
suppliesData = CreateDataModel(Guid.NewGuid().ToString(), ProductType.Rolls, DateTime.Now, 1, []);
|
||||||
|
Assert.That(() => suppliesData.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[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<SupplyProductDataModel>? products)
|
||||||
|
=> new(id, productType, deliveryDate, count, products);
|
||||||
|
private static List<SupplyProductDataModel> CreateSubDataModel()
|
||||||
|
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||||
|
}
|
||||||
|
|
@ -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<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);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user