59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using System;
|
|
using NUnit.Framework;
|
|
using CandyHouseBase.DataModels;
|
|
using CandyHouseBase.Exceptions;
|
|
|
|
namespace CandyHouseTests.DataModelsTests
|
|
{
|
|
[TestFixture]
|
|
public class IngredientDataModelTests
|
|
{
|
|
[Test]
|
|
public void CreateIngredientDataModel_ValidData_ShouldCreateSuccessfully()
|
|
{
|
|
var id = Guid.NewGuid().ToString();
|
|
var name = "Sugar";
|
|
var unit = "kg";
|
|
var cost = 10.5m;
|
|
|
|
var ingredient = new IngredientDataModel(id, name, unit, cost);
|
|
|
|
Assert.AreEqual(id, ingredient.Id);
|
|
Assert.AreEqual(name, ingredient.Name);
|
|
Assert.AreEqual(unit, ingredient.Unit);
|
|
Assert.AreEqual(cost, ingredient.Cost);
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ValidData_ShouldNotThrowException()
|
|
{
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10);
|
|
|
|
Assert.DoesNotThrow(() => ingredient.Validate());
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_InvalidId_ShouldThrowValidationException()
|
|
{
|
|
var ingredient = new IngredientDataModel("", "Sugar", "kg", 10);
|
|
|
|
Assert.Throws<ValidationException>(() => ingredient.Validate());
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_InvalidName_ShouldThrowValidationException()
|
|
{
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "", "kg", 10);
|
|
|
|
Assert.Throws<ValidationException>(() => ingredient.Validate());
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_NegativeQuantity_ShouldThrowValidationException()
|
|
{
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", -5);
|
|
|
|
Assert.Throws<ValidationException>(() => ingredient.Validate());
|
|
}
|
|
}
|
|
} |