diff --git a/MCTG/ConsoleApp/Stub.cs b/MCTG/ConsoleApp/Stub.cs index 87c5a72..a6fc02a 100644 --- a/MCTG/ConsoleApp/Stub.cs +++ b/MCTG/ConsoleApp/Stub.cs @@ -18,12 +18,12 @@ namespace ConsoleApp new Recipe("Cookies"), new Recipe("Cookies", 23), new Recipe("Cookies", null), - new Recipe(null, null), - new Recipe(null, 24), + new Recipe("", null), + new Recipe("", 24), new Recipe("Cookies", 24, - new PreparationStep(1, null)), + new PreparationStep(1)), new Recipe("Cookies", 26, - new PreparationStep(1, null), + new PreparationStep(1), new PreparationStep(2, "Faire cuire.")) }); return stub; diff --git a/MCTG/Model/PreparationStep.cs b/MCTG/Model/PreparationStep.cs index 54a9f14..55336d2 100644 --- a/MCTG/Model/PreparationStep.cs +++ b/MCTG/Model/PreparationStep.cs @@ -12,7 +12,7 @@ namespace Model public class PreparationStep : IEquatable { #region Attributes - private string? _description; + private string _description = ""; #endregion #region Properties @@ -25,7 +25,7 @@ namespace Model /// The description of the task the user need to do for this step of the preparation.
/// Set to "No description." when the value passed is null, empty or contain white spaces. /// - public string? Description + public string Description { get => _description; private set @@ -44,7 +44,7 @@ namespace Model /// /// The number of the order in preparation /// The description of the task - public PreparationStep(int order, string? description) + public PreparationStep(int order, string description = "") { Order = order; Description = description; @@ -52,8 +52,10 @@ namespace Model #endregion #region Methods - public bool Equals(PreparationStep? other) + public virtual bool Equals(PreparationStep? other) { + if (other == null) return false; + if (other == this) return true; return Order.Equals(other.Order) && Description.Equals(other.Description); } diff --git a/MCTG/Model/Recipe.cs b/MCTG/Model/Recipe.cs index d99da31..8f69fb9 100644 --- a/MCTG/Model/Recipe.cs +++ b/MCTG/Model/Recipe.cs @@ -11,9 +11,9 @@ namespace Model public class Recipe : IEquatable { #region Attributes - private string? _title; + private string _title = ""; #endregion - + #region Properties /// /// The ID of the recipe - allows you to compare and/or get this item in an easier way. @@ -24,7 +24,7 @@ namespace Model /// The Title of the recipe.
/// Set to "No title." when the value passed is null, empty or contain white spaces. ///
- public string? Title + public string Title { get => _title; set @@ -39,7 +39,7 @@ namespace Model /// /// The steps of the preparation. See: . /// - public List? PreparationSteps { get; private set; } + public List PreparationSteps { get; set; } #endregion #region Constructors @@ -49,7 +49,7 @@ namespace Model /// The title of the recipe /// The id of the recipe. If not given, get a new id. /// The steps of the preparation of the meal - public Recipe(string? title = null, int? id = null, + public Recipe(string title = "", int? id = null, params PreparationStep[] preparationSteps) { Title = title; diff --git a/MCTG/Model/RecipeCollection.cs b/MCTG/Model/RecipeCollection.cs index 546d2aa..6575729 100644 --- a/MCTG/Model/RecipeCollection.cs +++ b/MCTG/Model/RecipeCollection.cs @@ -13,8 +13,8 @@ namespace Model public class RecipeCollection : IList, IEquatable { #region Attributes - private readonly List recipes; - private string? _description; + private readonly List _recipes; + private string _description = ""; #endregion #region Properties @@ -22,7 +22,7 @@ namespace Model /// A short description of what this collection contain.
/// Set to "No description." when the value passed is null, empty or contain white spaces. /// - public string? Description + public string Description { get => _description; set @@ -35,21 +35,21 @@ namespace Model } #region IList Prperties - public int Count => recipes.Count; + public int Count => _recipes.Count; public bool IsReadOnly => false; - public Recipe this[int index] { get => recipes[index]; set => recipes[index] = value; } + public Recipe this[int index] { get => _recipes[index]; set => _recipes[index] = value; } #endregion #endregion #region Constructors /// - /// Construct a new collection of recipes. + /// Construct a new collection of _recipes. /// /// A short description of what this list will contain /// Recipes to add in this new collection - public RecipeCollection(string? description = null, params Recipe[] recipes) + public RecipeCollection(string description, params Recipe[] recipes) { - this.recipes = new List(recipes); + _recipes = new List(recipes); Description = description; } #endregion @@ -63,79 +63,80 @@ namespace Model /// public Recipe? GetRecipeById(int id) { - Recipe? recipe = recipes.Find(r => r.Id == id); - if (recipe == null) throw new ArgumentException("No recipes match the given id."); + Recipe? recipe = _recipes.Find(r => r.Id == id); + if (recipe == null) throw new ArgumentException("No _recipes match the given id."); return recipe; } #region IList Methods public int IndexOf(Recipe item) { - return recipes.IndexOf(item); + return _recipes.IndexOf(item); } public void Insert(int index, Recipe item) { - recipes.Insert(index, item); + _recipes.Insert(index, item); } public void RemoveAt(int index) { - recipes.RemoveAt(index); + _recipes.RemoveAt(index); } public void Add(Recipe item) { - recipes.Add(item); + _recipes.Add(item); } public void Clear() { - recipes.Clear(); + _recipes.Clear(); } public bool Contains(Recipe item) { - return recipes.Contains(item); + return _recipes.Contains(item); } public void CopyTo(Recipe[] array, int arrayIndex) { - recipes.CopyTo(array, arrayIndex); + _recipes.CopyTo(array, arrayIndex); } public bool Remove(Recipe item) { - return recipes.Remove(item); + return _recipes.Remove(item); } public IEnumerator GetEnumerator() { - return recipes.GetEnumerator(); + return _recipes.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { - return recipes.GetEnumerator(); + return _recipes.GetEnumerator(); } #endregion public virtual bool Equals(RecipeCollection? other) { + if (other == null) return false; if (other == this) return true; - return Description.Equals(other.Description) && recipes.Equals(other.recipes); + return _description.Equals(other.Description) && _recipes.Equals(other._recipes); } public override int GetHashCode() { - return recipes.GetHashCode(); + return _recipes.GetHashCode(); } public override string ToString() { StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n"); - foreach (Recipe r in recipes) + foreach (Recipe r in _recipes) { sb.AppendFormat("\t - {0}\n", r.ToString()); } diff --git a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs index 55df465..e8593a5 100644 --- a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs +++ b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs @@ -15,7 +15,6 @@ namespace Model_UnitTests [InlineData("Cookies", 23, "Cookies", 23)] [InlineData("Cookies", 1, "Cookies", 1)] [InlineData("No title.", 1, "", 1)] - [InlineData("No title.", 1, null, 1)] public void TestConstructor(string expectedTitle, int expectedId, string title, int? id) { Recipe r = new Recipe(title, id);