90 lines
3.5 KiB
C#
90 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
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";
|
|
var ingredients = new List<IngredientDataModel>()
|
|
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
|
var product = new ProductDataModel(id, name, description, ingredients);
|
|
|
|
Assert.AreEqual(id, product.Id);
|
|
Assert.AreEqual(name, product.Name);
|
|
Assert.AreEqual(description, product.Description);
|
|
Assert.AreEqual(ingredients, product.IngredientsItems);
|
|
}
|
|
|
|
[Test]
|
|
public void CreateProductDataModel_InvalidId_ShouldThrowArgumentException()
|
|
{
|
|
var invalidId = "";
|
|
var name = "Candy";
|
|
var description = "Delicious candy";
|
|
var ingredients = new List<IngredientDataModel>()
|
|
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
|
var product = new ProductDataModel(invalidId, name, description, ingredients);
|
|
|
|
Assert.Throws<ValidationException>(() => product.Validate());
|
|
}
|
|
|
|
[Test]
|
|
public void CreateProductDataModel_InvalidName_ShouldThrowArgumentException()
|
|
{
|
|
var id = Guid.NewGuid().ToString();
|
|
var invalidName = "";
|
|
var description = "Delicious candy";
|
|
var ingredients = new List<IngredientDataModel>()
|
|
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
|
var product = new ProductDataModel(id, invalidName, description, ingredients);
|
|
|
|
Assert.Throws<ValidationException>(() => product.Validate());
|
|
}
|
|
|
|
[Test]
|
|
public void CreateProductDataModel_InvalidDescription_ShouldThrowArgumentException()
|
|
{
|
|
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()
|
|
{
|
|
var id = Guid.NewGuid().ToString();
|
|
var name = "Candy";
|
|
var invalidDescription = "";
|
|
var ingredients = new List<IngredientDataModel>();
|
|
var product = new ProductDataModel(id, name, invalidDescription, ingredients);
|
|
|
|
Assert.Throws<ValidationException>(() => product.Validate());
|
|
}
|
|
|
|
[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());
|
|
}
|
|
}
|
|
} |