diff --git a/.gitignore b/.gitignore index 4a3a6d3..07fac84 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,10 @@ ## ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore +# User-spacific editor config +.editorconfig +.vscode + # User-specific files *.rsuser *.suo diff --git a/MCTG/ConsoleApp/ConsoleApp.csproj b/MCTG/ConsoleApp/ConsoleApp.csproj index 62505b1..7e8ef62 100644 --- a/MCTG/ConsoleApp/ConsoleApp.csproj +++ b/MCTG/ConsoleApp/ConsoleApp.csproj @@ -5,11 +5,10 @@ net7.0 enable enable - Debug;Release;CI - - + + diff --git a/MCTG/ConsoleApp/Menu/IMenuDisplay.cs b/MCTG/ConsoleApp/Menu/IMenuDisplay.cs new file mode 100644 index 0000000..572082c --- /dev/null +++ b/MCTG/ConsoleApp/Menu/IMenuDisplay.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp.Menu +{ + internal interface IMenuDisplay + { + /// + /// Update the menu display in the Console. + /// + void UpdateDisplay(); + + /// + /// Select the next line in the menu + /// + /// The current number of the new selected line + int SelectNextLine(); + + /// + /// Select the previous line in the menu + /// + /// The current number of the new selected line + int SelectPrevioustLine(); + } +} diff --git a/MCTG/ConsoleApp/Menu/SearcherRecipe.cs b/MCTG/ConsoleApp/Menu/SearcherRecipe.cs new file mode 100644 index 0000000..4e17512 --- /dev/null +++ b/MCTG/ConsoleApp/Menu/SearcherRecipe.cs @@ -0,0 +1,125 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +using Model; + +namespace ConsoleApp.Menu +{ + /// + /// An utility to find a recipe. + /// + public class SearcherRecipe : SelectMenu + { + #region Attribute + private RecipeCollection _recipeOnSearch; + #endregion + + #region Properties + /// + /// A collection of recipe where the title contain the search string + /// + public RecipeCollection SearchResult { get; private set; } + + /// + /// The search string + /// + public string ResearchStr { get; set; } + #endregion + + /// + /// Constructor of the SearcherRecipe utility. + /// + /// The collection of recipe where to search + public SearcherRecipe(RecipeCollection recipeOnSearch) + { + _recipeOnSearch = recipeOnSearch; + SearchResult = _recipeOnSearch; + ResearchStr = ""; + } + + #region Methodes + /// + /// Launch a search by name request in the collection of Recipe with with a string. + /// + /// The string for search + /// True if the result of the search gave at least 1 element. False otherwise. + public bool ComputeSearch(string researchStr = "") + { + ResearchStr = researchStr; + SearchResult = _recipeOnSearch.ResearchByName(ResearchStr.ToLower()); + _maxLines = SearchResult.Count - 1; + + return SearchResult.Count > 0; + } + + public override void UpdateDisplay() + { + StringBuilder sb = new StringBuilder(); + sb.AppendLine("---------------------------------------------------------"); + sb.AppendLine($" Research: {ResearchStr}"); + sb.AppendLine("---------------------------------------------------------"); + for (int i = 0; i < SearchResult.Count; i++) + { + if (i == CurrentLine) + { + CurrentSelected = SearchResult[i]; + sb.Append($">"); + } + sb.AppendLine($" [ {SearchResult[i].Id} ]:\t{SearchResult[i].Title} "); + } + Console.Clear(); + Console.WriteLine(sb); + } + + /// + /// Launch and pilot the search menu. + /// + /// The collection of recipe where to search + /// The recipe selected + public static Recipe? ResearchOn(RecipeCollection recipeOnSearch) + { + SearcherRecipe sr = new SearcherRecipe(recipeOnSearch); + StringBuilder sb = new StringBuilder(); + sr.ComputeSearch(); + sr.UpdateDisplay(); + + ConsoleKeyInfo cki; + + do + { + cki = Console.ReadKey(true); + + switch (cki.Key) + { + case ConsoleKey.UpArrow: + sr.SelectPrevioustLine(); + break; + case ConsoleKey.DownArrow: + sr.SelectNextLine(); + break; + case ConsoleKey.Backspace: + if (sb.Length > 0) + { + sb.Remove(sb.Length - 1, 1); + sr.ComputeSearch(sb.ToString()); + } + break; + default: + sb.Append(cki.KeyChar); + sr.ComputeSearch(sb.ToString()); + break; + } + + sr.UpdateDisplay(); + + } while (cki.Key != ConsoleKey.Enter); + + return sr.CurrentSelected; + } + #endregion + } +} diff --git a/MCTG/ConsoleApp/Menu/SelectMenu.cs b/MCTG/ConsoleApp/Menu/SelectMenu.cs new file mode 100644 index 0000000..0e331c6 --- /dev/null +++ b/MCTG/ConsoleApp/Menu/SelectMenu.cs @@ -0,0 +1,52 @@ +using ConsoleApp; +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace ConsoleApp.Menu +{ + /// + /// An abstract class that define the components of a selection-type menu. + /// + /// The return type of the currently selected item + public abstract class SelectMenu : IMenuDisplay + { + protected int _currentLine = 0; + protected int _maxLines = 0; + + /// + /// The currently selected item. + /// + public T? CurrentSelected { get; protected set; } + + /// + /// The current line selected in the menu. + /// + public int CurrentLine + { + get => _currentLine; + protected set + { + _currentLine = value; + if (_currentLine > _maxLines) + { + _currentLine = _maxLines; + } + if (_currentLine < 0) + { + _currentLine = 0; + } + return; + } + } + + public int SelectNextLine() { return ++CurrentLine; } + public int SelectPrevioustLine() { return --CurrentLine; } + + public abstract void UpdateDisplay(); + } +} diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index c0760f0..ac9a1e9 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -1,32 +1,29 @@ -using System; +// See https://aka.ms/new-console-template for more information + +using ConsoleApp; +using ConsoleApp.Menu; using Model; +using System.Text; + +Console.WriteLine("Hello, World!\n\n"); + + +// TESTS: + +Stub stub = new Stub(); + +List recipes = stub.LoadRecipes(); +List recipeCollections = stub.LoadRecipeCollection(); + +RecipeCollection? allRecipe = recipeCollections.Find(x => x.Description.Equals("All")); +if (allRecipe == null) + throw new ArgumentException("Load AllRecipe in stub: can't find 'All'."); + +Manager manager = new Manager(allRecipe); -namespace Program; - -public static class Program -{ - public static void Main() - { - Console.WriteLine("Helle World!"); - - Recipe recipe = new Recipe( - 1, - "Cookies aux pépites de chocolat", - new List(new string[]{ - "2 pommes", - "3L de vin", - "500g de farine" - }), - "Etape 1:\n" - + "\tCouper les pommes\n" - + "Etape 2:\n" - + "\tLes disposer sur le plat et mettre le vin dessus\n" - + "Etape 3:\n" - + "\tMettez toute la farine ensuite, puis 4h32 au four.\n" - + "\nDégustez c'est prêt !" - ); - - recipe.Display(); - } -} \ No newline at end of file +Recipe? ret = SearcherRecipe.ResearchOn(allRecipe); +Console.WriteLine(ret); + +// press any key to quit +Console.ReadKey(); diff --git a/MCTG/ConsoleApp/Stubs/Stub.cs b/MCTG/ConsoleApp/Stubs/Stub.cs new file mode 100644 index 0000000..f116321 --- /dev/null +++ b/MCTG/ConsoleApp/Stubs/Stub.cs @@ -0,0 +1,99 @@ +using Model; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ConsoleApp +{ + internal struct Stub + { + public List LoadRecipes() + { + List stub = new List(); + stub.AddRange(new[] + { + new Recipe(), + new Recipe( + title: "Cookies"), + new Recipe( + title: "Cookies", id: 23), + new Recipe( + title: "Cookies au chocolat", id: null), + new Recipe( + title: "", id: null), + new Recipe( + title: "", id: 24), + new Recipe( + title: "Cookies", id: 24, + preparationSteps: new[]{ + new PreparationStep(1) + }), + new Recipe( + title: "Cookies", id: 26, + preparationSteps: new[]{ + new PreparationStep(1), + new PreparationStep(2, "Faire cuire.") + }), + new Recipe( + title: "Gateau à la crème", + preparationSteps: new[]{ + new PreparationStep(1, "Ajouter les oeufs."), + new PreparationStep(2, "Ajouter la farine."), + new PreparationStep(3, "Mélanger le tout."), + new PreparationStep(4, "Faire cuire 1h10 au four traditionnel.") + }), + new Recipe( + title: "Gateau au chocolat", + preparationSteps: new[]{ + new PreparationStep(1, "Ajouter les oeufs."), + new PreparationStep(2, "Ajouter la farine."), + new PreparationStep(2, "Ajouter 100g de chocolat fondu."), + new PreparationStep(3, "Mélanger le tout."), + new PreparationStep(4, "Faire cuire 45h au four traditionnel.") + }), + new Recipe( + title: "Gateau aux cerises", + preparationSteps: new[]{ + new PreparationStep(1, "Ajouter les oeufs."), + new PreparationStep(2, "Ajouter la farine."), + new PreparationStep(2, "Ajouter des morceaux de fraises découpées en petits carré"), + new PreparationStep(3, "Mélanger le tout."), + new PreparationStep(4, "Faire cuire 30min au four traditionnel.") + }), + }); + return stub; + } + + public List LoadRecipeCollection() + { + List stub = new List(); + stub.AddRange(new[] + { + new RecipeCollection("All", LoadRecipes().ToArray()), + new RecipeCollection("Starters", LoadRecipes().FindAll(x => x.Id.Equals(23)).ToArray()), + new RecipeCollection("Dishies", LoadRecipes().FindAll(x => x.Id.Equals(24)).ToArray()), + new RecipeCollection("Desserts", LoadRecipes().FindAll(x => x.Id.Equals(26)).ToArray()), + }); + return stub; + } + + + public List ConstrucList() + { + List Users = new List(); + + User Roger = new User("Roger", "Rabbit", "carotte@mail.fr"); + User Dylan = new User("d", "r", "dr@mail.fr"); + User Val = new User("V", "entin", "Valentin@mail.fr"); + + Users.Add(Roger); + Users.Add(Dylan); + Users.Add(Val); + + return Users; + } + } +} diff --git a/MCTG/Model/Manager/Manager.cs b/MCTG/Model/Manager/Manager.cs new file mode 100644 index 0000000..5c4a6a7 --- /dev/null +++ b/MCTG/Model/Manager/Manager.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + /// + /// Manager of the model. Here is stoked all the recipes, the users, etc... + /// + public class Manager + { + /// + /// A collection of all the recipe loaded in the app. + /// + public RecipeCollection AllRecipes { get; protected set; } + + /// + /// The constructor of the manager. + /// + public Manager() + { + AllRecipes = new RecipeCollection(description: "All Recipes"); + } + + /// + /// The constructor of the manager. + /// + /// A list of loaded recipes + public Manager(RecipeCollection allRecipes) + { + AllRecipes = new RecipeCollection( + description: "All Recipes", + recipes: allRecipes.ToArray()); + } + } +} diff --git a/MCTG/Model/Model.csproj b/MCTG/Model/Model.csproj index fd3452d..97854fe 100644 --- a/MCTG/Model/Model.csproj +++ b/MCTG/Model/Model.csproj @@ -1,4 +1,4 @@ - + net7.0 diff --git a/MCTG/Model/Recipe.cs b/MCTG/Model/Recipe.cs deleted file mode 100644 index b43440b..0000000 --- a/MCTG/Model/Recipe.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Text; - -namespace Model -{ - public class Recipe - { - public uint Id { get; set; } - public string Title { get; set; } - public List Ingredients { get; set; } - public string Preparation { get; set; } - - /// - /// Constructor of a Recipe. - /// - /// Identificator - /// The name of the recipe - /// A list of ingredient needed by the preparation - /// The text that explain the preparation of the recipe - public Recipe(uint id, string title, List ingredients, string preparation) - { - Id = id; - Title = title; - Ingredients = ingredients; - Preparation = preparation; - } - - /// - /// Concatenate the list of ingredients in a single string - /// - /// The list of ingredients in string format - private string ConcatIngredients() - { - StringBuilder sb = new StringBuilder(); - foreach (string str in Ingredients) sb.Append("\t- " + str + "\n"); - - return sb.ToString(); - } - - /// - /// Build a string with all elements (title, ingredients, preparation, ...) - /// - /// A string that represent the recipe - public override string ToString() - { - return $"{Title} -- id:{Id}\n\n" - + "List of ingredient:\n" - + ConcatIngredients() + "\n\n" - + "Preparation:\n" - + $"{Preparation}\n"; - } - - /// - /// Display the recipe in the console - /// - public void Display() - { - Console.WriteLine(this.ToString()); - } - } -} \ No newline at end of file diff --git a/MCTG/Model/Recipes/PreparationStep.cs b/MCTG/Model/Recipes/PreparationStep.cs new file mode 100644 index 0000000..95d15ca --- /dev/null +++ b/MCTG/Model/Recipes/PreparationStep.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + /// + /// Define a step of the preparation of a recipe. + /// + public class PreparationStep : IEquatable + { + #region Attributes + private string _description = ""; + #endregion + + #region Properties + /// + /// The order of this step in the preparation of the meal. + /// + public int Order { get; init; } + + /// + /// 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 + { + get => _description; + private set + { + if (string.IsNullOrWhiteSpace(value)) + _description = "No description."; + else + _description = value; + } + } + #endregion + + #region Constructors + /// + /// Construct a new step of preparation. + /// + /// The number of the order in preparation + /// The description of the task + public PreparationStep(int order, string description = "") + { + Order = order; + Description = description; + } + #endregion + + #region Methods + 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); + } + + public override bool Equals(object? obj) + { + var item = obj as PreparationStep; + if (item == null) return false; + return Equals(obj); + } + + public override int GetHashCode() + { + return Order.GetHashCode() + Description.GetHashCode(); + } + + public override string ToString() + { + return $"{Order}- {Description}"; + } + #endregion + } +} diff --git a/MCTG/Model/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs new file mode 100644 index 0000000..6048fdf --- /dev/null +++ b/MCTG/Model/Recipes/Recipe.cs @@ -0,0 +1,101 @@ +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Security.Cryptography; +using System.Text; + +namespace Model +{ + /// + /// Define a Recipe for the preparation of a meal. + /// + public class Recipe : IEquatable + { + #region Attributes + private string _title = ""; + #endregion + + #region Properties + /// + /// The ID of the recipe - allows you to compare and/or get this item in an easier way. + /// + public int Id { get; init; } + + /// + /// The Title of the recipe.
+ /// Set to "No title." when the value passed is null, empty or contain white spaces. + ///
+ public string Title + { + get => _title; + set + { + if (string.IsNullOrWhiteSpace(value)) + _title = "No title."; + else + _title = value; + } + } + + /// + /// The steps of the preparation. See: . + /// + public List PreparationSteps { get; set; } + #endregion + + #region Constructors + /// + /// Construct a new recipe. + /// + /// 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 = "", int? id = null, + params PreparationStep[] preparationSteps) + { + Title = title; + PreparationSteps = new List(preparationSteps); + + if (id == null) + { + var randomGenerator = RandomNumberGenerator.Create(); + byte[] data = new byte[16]; + randomGenerator.GetBytes(data); + Id = Math.Abs(BitConverter.ToInt16(data)); + } + else Id = (int)id; + } + #endregion + + #region Methods + public virtual bool Equals(Recipe? other) + { + if (other == null) return false; + if (other == this) return true; + return Title.Equals(other.Title) && PreparationSteps.Equals(other.PreparationSteps); + } + + public override bool Equals(object? obj) + { + var item = obj as Recipe; + if (item == null) return false; + return Equals(obj); + } + + public override int GetHashCode() + { + return Id.GetHashCode(); + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder($"[Recipe n°{Id}] - {Title}\n"); + foreach (PreparationStep ps in PreparationSteps) + { + sb.AppendFormat("\t* {0}\n", ps.ToString()); + } + return sb.ToString(); + } + #endregion + } +} diff --git a/MCTG/Model/Recipes/RecipeCollection.cs b/MCTG/Model/Recipes/RecipeCollection.cs new file mode 100644 index 0000000..d439c76 --- /dev/null +++ b/MCTG/Model/Recipes/RecipeCollection.cs @@ -0,0 +1,165 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Text; + +namespace Model +{ + /// + /// Define a collection of . + ///
This class implement and . + ///
+ public class RecipeCollection : IList, IEquatable + { + #region Attributes + private readonly List _recipes; + private string _description = ""; + #endregion + + #region Properties + /// + /// 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 + { + get => _description; + set + { + if (string.IsNullOrWhiteSpace(value)) + _description = "No description."; + else + _description = value; + } + } + + #region IList Prperties + public int Count => _recipes.Count; + public bool IsReadOnly => false; + public Recipe this[int index] { get => _recipes[index]; set => _recipes[index] = value; } + #endregion + #endregion + + #region Constructors + /// + /// 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, params Recipe[] recipes) + { + _recipes = new List(recipes); + Description = description; + } + #endregion + + #region Methods + /// + /// Find a recipe in this list by giving the id. + /// + /// The id of the list we are looking for + /// The recipe of the id given + /// + 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."); + return recipe; + } + + /// + /// Utility to find a recipe by his name. + /// + /// The string for the search + /// A collection of Recipe where their Title contain the string. + public RecipeCollection ResearchByName(string str) + { + return new RecipeCollection( + description: $"Results of the research: {str}", + recipes: _recipes.FindAll(x => x.Title.ToLower().Contains(str.ToLower())).ToArray()); + } + + #region IList Methods + public int IndexOf(Recipe item) + { + return _recipes.IndexOf(item); + } + + public void Insert(int index, Recipe item) + { + _recipes.Insert(index, item); + } + + public void RemoveAt(int index) + { + _recipes.RemoveAt(index); + } + + public void Add(Recipe item) + { + _recipes.Add(item); + } + + public void Clear() + { + _recipes.Clear(); + } + + public bool Contains(Recipe item) + { + return _recipes.Contains(item); + } + + public void CopyTo(Recipe[] array, int arrayIndex) + { + _recipes.CopyTo(array, arrayIndex); + } + + public bool Remove(Recipe item) + { + return _recipes.Remove(item); + } + + public IEnumerator GetEnumerator() + { + return _recipes.GetEnumerator(); + } + + IEnumerator IEnumerable.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); + } + + public override bool Equals(object? obj) + { + var item = obj as RecipeCollection; + if (item == null) return false; + return Equals(obj); + } + + public override int GetHashCode() + { + return _recipes.GetHashCode(); + } + + public override string ToString() + { + StringBuilder sb = new StringBuilder($"[RecipeCollection] - {Description}:\n"); + foreach (Recipe r in _recipes) + { + sb.AppendFormat("\t - {0}\n", r.ToString()); + } + return sb.ToString(); + } + #endregion + } +} diff --git a/MCTG/Model/User/IPasswordManager.cs b/MCTG/Model/User/IPasswordManager.cs new file mode 100644 index 0000000..12f0e0a --- /dev/null +++ b/MCTG/Model/User/IPasswordManager.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + public interface IPasswordManager + { + public void changePassword(User user, string newPassword); + public string HashPassword(User user); + public bool VerifyPassword(string hashedPassword); + + } +} diff --git a/MCTG/Model/User/PasswordManager.cs b/MCTG/Model/User/PasswordManager.cs new file mode 100644 index 0000000..59bc784 --- /dev/null +++ b/MCTG/Model/User/PasswordManager.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + public class PasswordManager : IPasswordManager + { + public void changePassword(User user, string newPassword) + { + throw new NotImplementedException(); + } + + public string HashPassword(User user) + { + throw new NotImplementedException(); + } + + public bool VerifyPassword(string hashedPassword) + { + throw new NotImplementedException(); + } + } +} diff --git a/MCTG/Model/User/Priority.cs b/MCTG/Model/User/Priority.cs new file mode 100644 index 0000000..d851823 --- /dev/null +++ b/MCTG/Model/User/Priority.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model +{ + /// + /// This is the list of priorities that user can define in his profil. Priorities + /// are also present in recipes to match the first user's priority with the recipe's priority. + /// + public enum Priority + { Economic, Fast, Easy, Light, Gourmet }; + + +} + + diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs new file mode 100644 index 0000000..3c6bf73 --- /dev/null +++ b/MCTG/Model/User/User.cs @@ -0,0 +1,150 @@ +using System; +using System.Collections.Generic; +using System.Collections; +using System.Collections.ObjectModel; +using System.Threading.Tasks; +using System.Runtime.CompilerServices; +using System.Text.RegularExpressions; + +namespace Model +{ + /// + /// A user is an entity with a name, a surname, mail, profilePict and a list of priority. + /// This user can login with a Id and password + /// + public class User : IEquatable + { + #region Private Attributes + + private string name=""; + private string surname=""; + private string mail = ""; + private string picture = ""; + private string password = ""; + //private string defaultUserSavePath = ""; + private List priorities; + #endregion + + #region Properties + + /// + /// Property to get Name of users and a setter + /// + /// Setter have Exception which is trigger when Name is null + public string Name + { + get { return name; } + private set + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Nom vide!"); + } + name = value; + } + } + + /// + /// Property to get Surname of users and a setter + /// + /// Setter have Exception which is trigger when Surname is null + public string Surname + { + get { return surname; } + private set + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Prénom vide!"); + } + surname = value; + } + } + + /// + /// Property to get mail of users and a setter + /// + /// User's mail will serve to log the user. So there's no setter, just an init. User will enter one time his email at his + /// account creation. + public string Mail + { + get { return mail; } + private init + { + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Impossible d'avoir un champ Email vide!"); + } + mail = value; + } + } + + /// + /// Property to initiate password, change it, and + /// + public string Password + { + get { return password; } + + set { password = value; } + } + + /// + /// For now, we define the ProfilPict as a string which is "PhotoParDefaut" + /// when the value is null. + /// + public string ProfilPict + { + get => picture; + set => picture = value; + + } + + /// + /// This is the list of priorities specific tu the user. This list is initiate + /// by default. User could change it at will. + /// + + public List Priorities + { + get => priorities; + set=> priorities = value; + } + + public bool Equals(User other) + { + return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); + } + + + #endregion + + + #region Constructors + + /// + /// Construtors of user. + /// + /// The name of the user + /// The surname of the user + /// The user needs an email to login. + public User(string name, string surname, string mail) + { + Name = name; + Surname = surname; + Mail = mail; + priorities = new List { + Priority.Gourmet, + Priority.Economic, + Priority.Fast, + Priority.Light, + Priority.Easy}; + ProfilPict = picture; + + } + + #endregion + + + } +} diff --git a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj index 423f4e0..318f712 100644 --- a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj +++ b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj @@ -1,15 +1,12 @@ - net7.0 enable enable - false true Debug;Release;CI - @@ -22,5 +19,7 @@ all - - + + + +
\ No newline at end of file diff --git a/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs b/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs new file mode 100644 index 0000000..36008b1 --- /dev/null +++ b/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Model; + +namespace Model_UnitTests +{ + public class RecipeCollection_UT + { + [Fact] + public void TestResearchByName() + { + RecipeCollection recipes = new RecipeCollection( + description: "test recipe", + recipes: new[] + { + new Recipe(title: "Gateau à la crème", id: 1), + new Recipe(title: "Gateau au chocolat", id: 2), + new Recipe(title: "Gateau aux cerises", id: 3) + }); + + Assert.Equal(2, recipes.ResearchByName("chocolat").FirstOrDefault().Id); + } + } +} diff --git a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs new file mode 100644 index 0000000..e8593a5 --- /dev/null +++ b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs @@ -0,0 +1,26 @@ +using Model; + +namespace Model_UnitTests +{ + public class Recipe_UT + { + [Fact] + public void TestVoidConstructor() + { + Recipe r = new Recipe(id: 999); // id is given to avoid tests errors with the static atrribute 'idCreator'. + Assert.NotNull(r.Title); + } + + [Theory] + [InlineData("Cookies", 23, "Cookies", 23)] + [InlineData("Cookies", 1, "Cookies", 1)] + [InlineData("No title.", 1, "", 1)] + public void TestConstructor(string expectedTitle, int expectedId, string title, int? id) + { + Recipe r = new Recipe(title, id); + Assert.NotNull(r.Title); + Assert.Equal(expectedId, r.Id); + Assert.Equal(expectedTitle, r.Title); + } + } +} diff --git a/MCTG/Tests/Model_UnitTests/UnitTest1.cs b/MCTG/Tests/Model_UnitTests/UnitTest1.cs deleted file mode 100644 index 4d22b68..0000000 --- a/MCTG/Tests/Model_UnitTests/UnitTest1.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace MCTGLib_UnitTests -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - - } - } -} \ No newline at end of file diff --git a/MCTG/Tests/Model_UnitTests/test_unit_user.cs b/MCTG/Tests/Model_UnitTests/test_unit_user.cs new file mode 100644 index 0000000..943afa0 --- /dev/null +++ b/MCTG/Tests/Model_UnitTests/test_unit_user.cs @@ -0,0 +1,19 @@ +using Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Model_UnitTests +{ + public class test_unit_user + { + [Fact] + public void TestConstructUser() + { + User user = new User("Bob","Dylan", "bd@gmail.com"); + //Assert. + } + } +} diff --git a/MCTG/Views/App.xaml b/MCTG/Views/App.xaml deleted file mode 100644 index beb7cff..0000000 --- a/MCTG/Views/App.xaml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - diff --git a/MCTG/Views/App.xaml.cs b/MCTG/Views/App.xaml.cs deleted file mode 100644 index 40c0c3f..0000000 --- a/MCTG/Views/App.xaml.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Views -{ - public partial class App : Application - { - public App() - { - InitializeComponent(); - - MainPage = new AppShell(); - } - } -} \ No newline at end of file diff --git a/MCTG/Views/AppShell.xaml b/MCTG/Views/AppShell.xaml deleted file mode 100644 index 54e7dbe..0000000 --- a/MCTG/Views/AppShell.xaml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - diff --git a/MCTG/Views/AppShell.xaml.cs b/MCTG/Views/AppShell.xaml.cs deleted file mode 100644 index 15833b6..0000000 --- a/MCTG/Views/AppShell.xaml.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Views -{ - public partial class AppShell : Shell - { - public AppShell() - { - InitializeComponent(); - } - } -} \ No newline at end of file diff --git a/MCTG/Views/MainPage.xaml b/MCTG/Views/MainPage.xaml deleted file mode 100644 index a1864aa..0000000 --- a/MCTG/Views/MainPage.xaml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - - -