103 lines
4.3 KiB
C#
103 lines
4.3 KiB
C#
using PipingHotContrast.DataModels;
|
|
using PipingHotContrast.Enums;
|
|
using PipingHotContrast.Exceptions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace PipingHotTests.DataModelsTests;
|
|
|
|
[TestFixture]
|
|
internal class ProductDataModelTests
|
|
{
|
|
[Test]
|
|
public void IdIsNullOrEmptyTest()
|
|
{
|
|
var product = CreateDataModel(null, "name", ProductType.Pizza, Guid.NewGuid().ToString(),500, false);
|
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
product = CreateDataModel(string.Empty, "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void IdIsNotGuidTest()
|
|
{
|
|
var product = CreateDataModel("id", "name", ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ProductNameIsNullOrEmptyTest()
|
|
{
|
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), 500, false);
|
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ProductTypeIsNoneTest()
|
|
{
|
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, Guid.NewGuid().ToString(), 500, false);
|
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void ReastaurantIdIsNullOrEmptyTest()
|
|
{
|
|
|
|
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
|
ProductType.Pizza, null, 500, false);
|
|
Assert.That(() => product.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
|
ProductType.Pizza, string.Empty, 500, false);
|
|
Assert.That(() => product.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
[Test]
|
|
public void ReastaurantIdIsNotGuidTest()
|
|
{
|
|
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
|
ProductType.Pizza, "restaurantId", 500, false);
|
|
Assert.That(() => product.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PriceIsLessOrZeroTest()
|
|
{
|
|
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Pizza, Guid.NewGuid().ToString(), 0, false);
|
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Pizza, Guid.NewGuid().ToString(), - 500, false);
|
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsIsCorrectTest()
|
|
{
|
|
var productId = Guid.NewGuid().ToString();
|
|
var productName = "name";
|
|
var productType = ProductType.Pizza;
|
|
var productRestaurantId = Guid.NewGuid().ToString();
|
|
var productPrice = 500;
|
|
var productIsDeleted = false;
|
|
var product = CreateDataModel(productId, productName, productType, productRestaurantId,productPrice, 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(productIsDeleted));
|
|
});
|
|
}
|
|
|
|
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? productRestaurantId,double price, bool isDeleted) =>
|
|
new(id, productName, productType, productRestaurantId, price, isDeleted);
|
|
}
|