90 lines
3.5 KiB
C#
Raw Normal View History

2025-02-13 16:13:21 +04:00
using System;
2025-02-13 16:25:09 +04:00
using System.Collections.Generic;
2025-02-13 16:13:21 +04:00
using NUnit.Framework;
using CandyHouseBase.DataModels;
using CandyHouseBase.Exceptions;
namespace CandyHouseTests.DataModelsTests
{
[TestFixture]
public class ProductDataModelTests
{
[Test]
public void CreateProductDataModel_ValidData_ShouldCreateSuccessfully()
{
var id = Guid.NewGuid().ToString();
var name = "Candy";
var description = "Delicious candy";
2025-02-13 16:28:13 +04:00
var ingredients = new List<IngredientDataModel>()
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
2025-02-13 16:25:09 +04:00
var product = new ProductDataModel(id, name, description, ingredients);
2025-02-13 16:13:21 +04:00
Assert.AreEqual(id, product.Id);
Assert.AreEqual(name, product.Name);
Assert.AreEqual(description, product.Description);
2025-02-13 16:25:09 +04:00
Assert.AreEqual(ingredients, product.IngredientsItems);
2025-02-13 16:13:21 +04:00
}
[Test]
public void CreateProductDataModel_InvalidId_ShouldThrowArgumentException()
{
var invalidId = "";
var name = "Candy";
var description = "Delicious candy";
2025-02-13 16:28:13 +04:00
var ingredients = new List<IngredientDataModel>()
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
2025-02-13 16:25:09 +04:00
var product = new ProductDataModel(invalidId, name, description, ingredients);
2025-02-13 16:13:21 +04:00
Assert.Throws<ValidationException>(() => product.Validate());
}
[Test]
public void CreateProductDataModel_InvalidName_ShouldThrowArgumentException()
{
var id = Guid.NewGuid().ToString();
var invalidName = "";
var description = "Delicious candy";
2025-02-13 16:28:13 +04:00
var ingredients = new List<IngredientDataModel>()
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
2025-02-13 16:25:09 +04:00
var product = new ProductDataModel(id, invalidName, description, ingredients);
2025-02-13 16:13:21 +04:00
Assert.Throws<ValidationException>(() => product.Validate());
}
[Test]
public void CreateProductDataModel_InvalidDescription_ShouldThrowArgumentException()
2025-02-13 16:28:13 +04:00
{
var id = Guid.NewGuid().ToString();
var name = "Candy";
var invalidDescription = "";
var ingredients = new List<IngredientDataModel>()
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
var product = new ProductDataModel(id, name, invalidDescription, ingredients);
Assert.Throws<ValidationException>(() => product.Validate());
}
[Test]
public void CreateProductDataModel_InvalidIngredients_ShouldThrowArgumentException()
2025-02-13 16:13:21 +04:00
{
var id = Guid.NewGuid().ToString();
var name = "Candy";
var invalidDescription = "";
2025-02-13 16:25:09 +04:00
var ingredients = new List<IngredientDataModel>();
var product = new ProductDataModel(id, name, invalidDescription, ingredients);
2025-02-13 16:13:21 +04:00
Assert.Throws<ValidationException>(() => product.Validate());
}
2025-02-25 15:42:57 +04:00
[Test]
public void CreateProductDataModel_InvalidIngredientsNull_ShouldThrowArgumentException()
{
var id = Guid.NewGuid().ToString();
var name = "Candy";
var invalidDescription = "";
var product = new ProductDataModel(id, name, invalidDescription, null);
Assert.Throws<ValidationException>(() => product.Validate());
}
2025-02-13 16:13:21 +04:00
}
}