diff --git a/MCTG/Model/Ingredient.cs b/MCTG/Model/Ingredient.cs index cc3303c..a63a2ec 100644 --- a/MCTG/Model/Ingredient.cs +++ b/MCTG/Model/Ingredient.cs @@ -9,38 +9,55 @@ namespace Model internal class Ingredient { #region Attributes - /// - /// Name of the ingredient - /// - private string name; - /// - /// get the quatity of ingredient - /// - private Quantity quantity; + + private string name = ""; + private Quantity quantity = new Quantity(1, Unit.unit) ; #endregion #region + /// + /// Property of the Ingredient's attribute name. It raises an ArgumentNullException to prevent a nullable field. + /// public string Name { get => name; - set + set { - if (value == null) + if (value == null) { throw new ArgumentNullException("Impossible de ne pas avoir de nom pour l'ingrédient"); } } } - public Quantity QuantityP + /// + /// Property of the Ingredient's attribute Quantity. + /// + public Quantity QuantityI { get => quantity; set => quantity = value; + } + + public bool Equals(Ingredient? other) + { + if (other == null) { return false; } + if (this == other) { return true; } + return Name.Equals(other.Name); + } #endregion + #region Constructor + + public Ingredient(string name, Quantity quantity) + { + Name = name; + QuantityI = quantity; + } + #endregion } } diff --git a/MCTG/Model/Quantity.cs b/MCTG/Model/Quantity.cs index ccaf89d..7378634 100644 --- a/MCTG/Model/Quantity.cs +++ b/MCTG/Model/Quantity.cs @@ -6,6 +6,10 @@ using System.Threading.Tasks; namespace Model { + /// + /// Quantity is a class which is associate to Ingedients. It represents the quantity of every ingredient with an enum + /// to indicate the unit of the quantity. + /// public class Quantity { #region Attributes @@ -17,20 +21,41 @@ namespace Model /// have the Unit enum of the quantity of ingredient /// private Unit unit; - - #endregion + #endregion + /// + /// Represents the quantity in digits. The null value raise an argumentException. + /// public int Number { get { return number; } set { - if (value <0 ) + if (value < 0) { throw new ArgumentException("Si la quantité est inférieur à 0, enlever l'ingrédient!"); } number = value; } } + public Unit UnitQ + { + get => unit; + set => unit = value; + } + + + #region Constructor + /// + /// Constructor of Quantity + /// + /// + /// + public Quantity(int number, Unit unit) + { + Number = number; + UnitQ = unit; + } + #endregion } } diff --git a/MCTG/Model/Recipe.cs b/MCTG/Model/Recipe.cs index b43440b..eefb84a 100644 --- a/MCTG/Model/Recipe.cs +++ b/MCTG/Model/Recipe.cs @@ -32,7 +32,7 @@ namespace Model { StringBuilder sb = new StringBuilder(); foreach (string str in Ingredients) sb.Append("\t- " + str + "\n"); - + return sb.ToString(); } diff --git a/MCTG/Model/Unit.cs b/MCTG/Model/Unit.cs index 297c633..5e7d38c 100644 --- a/MCTG/Model/Unit.cs +++ b/MCTG/Model/Unit.cs @@ -6,6 +6,10 @@ using System.Threading.Tasks; namespace Model { - public enum Unit + /// + /// Unit is an Enum that represents the units of quantities + /// + /// + public enum Unit { Unit, kG, mG, G, L, cL, mL }; } diff --git a/MCTG/Tests/Model_UnitTests/Ingredient_UT.cs b/MCTG/Tests/Model_UnitTests/Ingredient_UT.cs new file mode 100644 index 0000000..35a6e2c --- /dev/null +++ b/MCTG/Tests/Model_UnitTests/Ingredient_UT.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model_UnitTests +{ + public class Ingredient_UT + { + public void TestConstructIngredient() + { + Quantity quantity = new Quantity(200, Unit.mL); + Ingredient patate = new Ingredient("Patate", quantity); + Assert.Equal("Patate", patate.Nom); + } + } +}