f 2
This commit is contained in:
parent
03057e83bd
commit
825133bed3
@ -52,6 +52,7 @@ namespace CandyHouseBase.DataModels
|
|||||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||||
if (Name.IsEmpty()) throw new ValidationException("Field Name is empty");
|
if (Name.IsEmpty()) throw new ValidationException("Field Name is empty");
|
||||||
if (Description.IsEmpty()) throw new ValidationException("Field Description is empty");
|
if (Description.IsEmpty()) throw new ValidationException("Field Description is empty");
|
||||||
|
if (IngredientsItems.Count == 0) throw new ValidationException("Field IngredientsItems is empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,7 +15,8 @@ namespace CandyHouseTests.DataModelsTests
|
|||||||
var id = Guid.NewGuid().ToString();
|
var id = Guid.NewGuid().ToString();
|
||||||
var name = "Candy";
|
var name = "Candy";
|
||||||
var description = "Delicious candy";
|
var description = "Delicious candy";
|
||||||
var ingredients = new List<IngredientDataModel>();
|
var ingredients = new List<IngredientDataModel>()
|
||||||
|
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
||||||
var product = new ProductDataModel(id, name, description, ingredients);
|
var product = new ProductDataModel(id, name, description, ingredients);
|
||||||
|
|
||||||
Assert.AreEqual(id, product.Id);
|
Assert.AreEqual(id, product.Id);
|
||||||
@ -30,7 +31,8 @@ namespace CandyHouseTests.DataModelsTests
|
|||||||
var invalidId = "";
|
var invalidId = "";
|
||||||
var name = "Candy";
|
var name = "Candy";
|
||||||
var description = "Delicious candy";
|
var description = "Delicious candy";
|
||||||
var ingredients = new List<IngredientDataModel>();
|
var ingredients = new List<IngredientDataModel>()
|
||||||
|
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
||||||
var product = new ProductDataModel(invalidId, name, description, ingredients);
|
var product = new ProductDataModel(invalidId, name, description, ingredients);
|
||||||
|
|
||||||
Assert.Throws<ValidationException>(() => product.Validate());
|
Assert.Throws<ValidationException>(() => product.Validate());
|
||||||
@ -42,7 +44,8 @@ namespace CandyHouseTests.DataModelsTests
|
|||||||
var id = Guid.NewGuid().ToString();
|
var id = Guid.NewGuid().ToString();
|
||||||
var invalidName = "";
|
var invalidName = "";
|
||||||
var description = "Delicious candy";
|
var description = "Delicious candy";
|
||||||
var ingredients = new List<IngredientDataModel>();
|
var ingredients = new List<IngredientDataModel>()
|
||||||
|
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
||||||
var product = new ProductDataModel(id, invalidName, description, ingredients);
|
var product = new ProductDataModel(id, invalidName, description, ingredients);
|
||||||
|
|
||||||
Assert.Throws<ValidationException>(() => product.Validate());
|
Assert.Throws<ValidationException>(() => product.Validate());
|
||||||
@ -50,6 +53,19 @@ namespace CandyHouseTests.DataModelsTests
|
|||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CreateProductDataModel_InvalidDescription_ShouldThrowArgumentException()
|
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 id = Guid.NewGuid().ToString();
|
||||||
var name = "Candy";
|
var name = "Candy";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user