public void OverrideEuals() { var ingredient1 = new Ingredient(1, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(1, "1", 0)); var ingredient2 = new Ingredient(1, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(1, "1", 0)); Assert.AreEqual(ingredient1, ingredient2); }
public void TryUpdateIngredientWorks() { DTOIngredient dtoIngredient = new DTOIngredient(1, 0, new Size(1, "size1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(1, "water", 0)); Ingredient ingredient = new Ingredient(1, new Model.Size(1, new PositionStub(1, "1", "1")), new Model.Consumable(1)); var result = ingredient.TryUpdateIngredient(dtoIngredient, out var error); Assert.IsTrue(result); Assert.IsTrue(string.IsNullOrWhiteSpace(error)); Assert.AreEqual(0, ingredient.Amount); }
public void CantAddIngredientToNonExistingSize() { var position = new DTOPosition(1, "1", "1"); var ingredient = new DTOIngredient(1, 1, new DTOSize(2, "1", new Money(1), position), new DTOConsumable(1, "water", 1)); var ingredientListStub = new IngredientListStub(); var ingredientListValidator = new IngredientListValidator(ingredientListStub); string error = null; EventHandler<IngredientListChangedEventArgs> handler = (sender, e) => error = e.Error; ingredientListValidator.IngredientListChanged += handler; ingredientListValidator.AddIngredient(ingredient); }
public void UpdateIngredientMethod_InvokesDependencyAddIngredientMethod_IfIngredientPassesValidation() { var position = new DTOPosition(1, "1", "1"); var ingredient = new DTOIngredient(1, 1, new DTOSize(1, "1", new Money(1), position), new DTOConsumable(1, "1", 1)); var ingredientListStub = new IngredientListStub(); bool invoked = false; EventHandler<IngredientListChangedEventArgs> handler = (sender, e) => invoked = true; ingredientListStub.IngredientListChanged += handler; var ingredientListValidator = new IngredientListValidator(ingredientListStub); ingredientListValidator.UpdateIngredient(ingredient); Assert.IsTrue(invoked); }
public void CantRepeatConsumable_withAddMethod() { var position = new DTOPosition(1, "1", "1"); var ingredient = new DTOIngredient(3, 1, new DTOSize(1, "1", new Money(1), position), new DTOConsumable(1, "water", 1)); var ingredientListStub = new IngredientListStub(); var ingredientListValidator = new IngredientListValidator(ingredientListStub); string error = null; EventHandler<IngredientListChangedEventArgs> handler = (sender, e) => error = e.Error; ingredientListValidator.IngredientListChanged += handler; ingredientListValidator.AddIngredient(ingredient); Assert.AreEqual("Ingredient water already exists", error); }
public void DTOworks() { DTOIngredient dtoIngredient = new DTOIngredient(1, 0, new Size(1, "size1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(1, "water", 0)); Ingredient ingredient = new Ingredient(1, new Model.Size(1, new PositionStub(1, "1", "1")), new Model.Consumable(1)); ingredient.TryUpdateIngredient(dtoIngredient, out _); DTOIngredient testIngredient = ingredient.DTO; Assert.AreEqual(1, testIngredient.Id); Assert.AreEqual(0, testIngredient.Amount); Assert.AreEqual(1, testIngredient.Position.Id); Assert.AreEqual(1, testIngredient.Size.Id); }
public void ReraiseEventOfDependency() { var position = new DTOPosition(1, "1", "1"); var ingredient = new DTOIngredient(3, 1, new DTOSize(1, "1", new Money(1), position), new DTOConsumable(1, "1", 1)); var ingredientListStub = new IngredientListStub(); var ingredientListValidator = new IngredientListValidator(ingredientListStub); bool invoked = false; EventHandler<IngredientListChangedEventArgs> handler = (sender, e) => invoked = true; ingredientListValidator.IngredientListChanged += handler; ingredientListValidator.AddIngredient(ingredient); Assert.IsTrue(invoked); }
public void CanUpdateAmountOnly() { var position = new DTOPosition(1, "1", "1"); var ingredient = new DTOIngredient(1, 2, new DTOSize(1, "1", new Money(1), position), new DTOConsumable(1, "water", 1)); var ingredientListStub = new IngredientListStub(); var ingredientListValidator = new IngredientListValidator(ingredientListStub); string error = null; EventHandler<IngredientListChangedEventArgs> handler = (sender, e) => error = e.Error; ingredientListValidator.IngredientListChanged += handler; ingredientListValidator.UpdateIngredient(ingredient); Assert.IsNull(error); }
public void CantUpdateNonExistingIngredient() { var position = new DTOPosition(1, "1", "1"); var ingredient = new DTOIngredient(3, 1, new DTOSize(1, "1", new Money(1), position), new DTOConsumable(1, "water", 1)); var ingredientListStub = new IngredientListStub(); var ingredientListValidator = new IngredientListValidator(ingredientListStub); string error = null; EventHandler<IngredientListChangedEventArgs> handler = (sender, e) => error = e.Error; ingredientListValidator.IngredientListChanged += handler; ingredientListValidator.UpdateIngredient(ingredient); Assert.AreEqual("Ingredient water cannot be found", error); }
public void ValidateIngredientsReturnsError_IfSizeId_DoesntMach() { var size = new Size(1, Position.Create(new DTO.Position(1, "1", "1"))); var ingredient = new DTOIngredient(1, 1, new DTOSize(2, "1", new Money(), new DTO.Position(1, "1", "1")), new DTO.Consumable(1, "1", 0)); var ingredients = new List <DTOIngredient>() { ingredient }; var list = size.ValidateIngredients(ingredients, out var error); Assert.AreEqual("Ingredient 1 corresponds to another size /n", error); Assert.AreEqual(0, list.Count); }
public void AddIngredientWorks() { var size = new Size(1, Position.Create(new DTO.Position(1, "1", "1"))); var consumables = new List <Model.Consumable>() { new Model.Consumable(1) }; var dtoIngredient = new DTOIngredient(1, 1, new DTOSize(1, "1", new Money(1), new DTO.Position(1, "1", "1")), new DTO.Consumable(1, "1", 1)); var ingredient = new Ingredient(1, size, new Model.Consumable(1)); size.AddIngredient(dtoIngredient, consumables); Assert.AreEqual(ingredient, size.Ingredients[0]); }
public void DoesConsumableExist_DTOList() { var ingredient1 = new DTOIngredient(1, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(1, "1", 1)); var ingredient2 = new DTOIngredient(2, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(2, "2", 1)); var ingredient3 = new DTOIngredient(3, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(1, "1", 1)); var ingredients = new List <DTOIngredient>() { ingredient1, ingredient2 }; var result = Ingredient.DoesConsumableExist(ingredient3, ingredients, out var error); Assert.IsTrue(result); Assert.AreEqual($"Ingredient {ingredient3.Consumable.Name} is already present", error); }
public void DoesIngredientExistFail_DTOList() { var ingredient1 = new DTOIngredient(1, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(1, "1", 1)); var ingredient2 = new DTOIngredient(2, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(2, "2", 1)); var ingredient3 = new DTOIngredient(3, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(3, "3", 1)); var ingredients = new List <DTOIngredient>() { ingredient1, ingredient2 }; var result = Ingredient.DoesIngredientExist(ingredient3, ingredients, out var error); Assert.IsFalse(result); Assert.AreEqual($"Ingredient {ingredient3.Consumable.Name} cannot be found", error); }
public void ValidateIngredientsReturnsError_IfConsumableRepeat() { var size = new Size(1, Position.Create(new DTO.Position(1, "1", "1"))); var ingredient1 = new DTOIngredient(1, 1, new DTOSize(1, "1", new Money(), new DTO.Position(1, "1", "1")), new DTO.Consumable(1, "1", 0)); var ingredient2 = new DTOIngredient(2, 1, new DTOSize(1, "1", new Money(), new DTO.Position(1, "1", "1")), new DTO.Consumable(1, "1", 0)); var ingredients = new List <DTOIngredient>() { ingredient1, ingredient2 }; var list = size.ValidateIngredients(ingredients, out string error); Assert.AreEqual("Ingredient 1 is already present /n", error); Assert.AreEqual(1, list.Count); }
public void OverrideEualsOperator() { var ingredient1 = new Ingredient(1, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(1, "1", 0)); var ingredient2 = new Ingredient(1, 1, new Size(1, "1", new Money(1), new Position(1, "1", "1")), new DTO.Consumable(1, "1", 0)); var ingredient3 = new Ingredient(2, 2, new Size(2, "2", new Money(1), new Position(2, "2", "2")), new DTO.Consumable(2, "2", 0)); Ingredient ingredient4 = null; Assert.IsTrue(ingredient1 == ingredient2); Assert.IsFalse(ingredient1 == ingredient3); Assert.IsTrue(ingredient1 != ingredient3); Assert.IsFalse(ingredient1 == ingredient3); Assert.IsTrue(ingredient1 != null); Assert.IsFalse(ingredient1 == null); Assert.IsTrue(ingredient4 == null); Assert.IsFalse(ingredient4 != null); }
public void UpdateIngredientsTest() { var consumables = new List <Model.Consumable>() { new Model.Consumable(1) }; var size = new Size(1, new PositionStub(1, "1", "1")); var dtoIngredient = new DTOIngredient(1, 0, new DTO.Size(1, "size1", new Money(1), new DTO.Position(1, "1", "1")), new DTO.Consumable(1, "water", 0)); var ingredients = new List <DTOIngredient> { dtoIngredient }; var domainIngredient = new Ingredient(1, size, consumables[0]); size.UpdateIngredients(ingredients, consumables); Assert.AreEqual(domainIngredient, size.Ingredients[0]); Assert.AreEqual(ingredients.Count, size.Ingredients.Count); }
public void DeleteIngredient(DTOIngredient ingredient) { IngredientListChanged?.Invoke(this, new IngredientListChangedEventArgs(Ingredients)); }
public void DeleteIngredient(DTOIngredient ingredient) { IngredientListChanged?.Invoke(this, new IngredientListChangedEventArgs(GetIngredientList(ingredient.Size), null)); }
public List <Ingredient> AddIngredient(Ingredient ingredient) { ingredientList.AddIngredient(ingredient); return(ingredients); }
public List <Ingredient> DeleteIngredient(Ingredient ingredient) { ingredientList.DeleteIngredient(ingredient); return(ingredients); }
public List <Ingredient> UpdateIngredient(Ingredient ingredient) { ingredientList.UpdateIngredient(ingredient); return(ingredients); }