示例#1
0
        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);
        }
示例#2
0
        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);
        }
示例#3
0
		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);
		}
示例#4
0
		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);
		}
示例#5
0
		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);
		}
示例#6
0
        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);
        }
示例#7
0
		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);
		}
示例#8
0
		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);
		}
示例#9
0
		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);
		}
示例#10
0
        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);
        }
示例#11
0
        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]);
        }
示例#12
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);
        }
示例#13
0
        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);
        }
示例#14
0
        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);
        }
示例#15
0
        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);
        }
示例#16
0
        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);
        }
示例#17
0
			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));
 }
示例#19
0
 public List <Ingredient> AddIngredient(Ingredient ingredient)
 {
     ingredientList.AddIngredient(ingredient);
     return(ingredients);
 }
示例#20
0
 public List <Ingredient> DeleteIngredient(Ingredient ingredient)
 {
     ingredientList.DeleteIngredient(ingredient);
     return(ingredients);
 }
示例#21
0
 public List <Ingredient> UpdateIngredient(Ingredient ingredient)
 {
     ingredientList.UpdateIngredient(ingredient);
     return(ingredients);
 }