2025-03-09 14:28:06 +04:00

82 lines
3.4 KiB
C#

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)];
}