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

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