diff --git a/MCTG/ConsoleApp/Program.cs b/MCTG/ConsoleApp/Program.cs index 604eea7..ead495b 100644 --- a/MCTG/ConsoleApp/Program.cs +++ b/MCTG/ConsoleApp/Program.cs @@ -1,62 +1,48 @@ -// See https://aka.ms/new-console-template for more information + using ConsoleApp; -<<<<<<< HEAD using Model; - -======= using ConsoleApp.Menu; using DataPersistence; -using Model; using System.Linq; using System.Text; ->>>>>>> origin/dev - -Console.WriteLine("Hello, World!\n\n"); -// TESTS: -<<<<<<< HEAD - -Stub stub = new Stub(); -PasswordManager passwordManager = new PasswordManager(); - -List recipes = stub.LoadRecipes(); -List recipeCollections = stub.LoadRecipeCollection(); -foreach (Recipe r in recipes) - Console.WriteLine(r); - -foreach (RecipeCollection r in recipeCollections) - Console.WriteLine(r); +Console.WriteLine("Hello, World!\n\n"); -List users = stub.ConstrucList(); -foreach (User u in users) - Console.WriteLine(u); -bool isPassCorrect = stub.VerifPass(); -Console.WriteLine(isPassCorrect); -======= +// TESTS: DataManager dataMgr = new DataManager(new Stubs()); -//DataManager dataMgr = new DataManager(new DataContractXML(xmlFolderPath: "../../../../DataPersistence/data")); +//DataManager dataMgr = new DataManager(new DataContractXML()); //DataManager dataMgr = new DataManager(new DataContractJSON()); -//dataMgr.Serializer = new DataContractXML(xmlFolderPath: "../../../../DataPersistence/data"); -dataMgr.Serializer = new DataContractJSON(); - +dataMgr.Serializer = new DataContractXML(); +//dataMgr.Serializer = new DataContractJSON(); // /!\ here is an absolute path I put for testing purpose. It will only work on my computer so don't forget to change it whene you test. //dataMgr.Export(rc[2], "C:\\Users\\alex6\\Downloads\\recipe2.json"); //dataMgr.Import("C:\\Users\\alex6\\Downloads\\recipe2.json"); +PasswordManager passwordManager = new PasswordManager(); RecipeCollection rc = new RecipeCollection("All recipes", dataMgr.Data[nameof(Recipe)].Cast().ToArray()); +User user = dataMgr.Data[nameof(User)].Cast().Last(); + +//rc[0].AddReview(new Review(user, 1, "bonne recette !1")); +//rc[0].AddReview(new Review(user, 1, "bonne recette !2")); +//rc[0].AddReview(new Review(user, 4, "bonne recette !3")); +//rc[0].AddReview(new Review(user, 5, "bonne recette !4")); +//rc[0].AddReview(new Review(user, 3, "bonne recette !5")); +//rc[0].AddReview(new Review(user, 2, "bonne recette !6")); +//rc[0].AddReview(new Review(user, 2, "peut etre pas ducoup !")); +//rc[1].AddReview(new Review(user, 2, "Mais celle-ci oui !")); + dataMgr.Save(); MenuManager menuMgr = new MenuManager(dataMgr); menuMgr.Loop(); -// press any key to quit -//Console.ReadKey(); ->>>>>>> origin/dev +Console.WriteLine(passwordManager.VerifyPassword(user.Password, "pamigos")); +Console.ReadKey(); \ No newline at end of file diff --git a/MCTG/ConsoleApp/Stub.cs b/MCTG/ConsoleApp/Stub.cs deleted file mode 100644 index 7bbf872..0000000 --- a/MCTG/ConsoleApp/Stub.cs +++ /dev/null @@ -1,79 +0,0 @@ -using Model; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace ConsoleApp -{ - - internal struct Stub - { - private IPasswordManager passwordManager = new PasswordManager(); - - public List LoadRecipes() - { - List stub = new List(); - stub.AddRange(new[] - { - new Recipe(), - new Recipe("Cookies"), - new Recipe("Cookies", 23), - new Recipe("Cookies", null), - new Recipe("", null), - new Recipe("", 24), - new Recipe("Cookies", 24, - new PreparationStep(1)), - new Recipe("Cookies", 26, - new PreparationStep(1), - new PreparationStep(2, "Faire cuire.")) - }); - 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",passwordManager.HashPassword("password")); - User Dylan = new User("d", "r", "dr@mail.fr", passwordManager.HashPassword("dede")); - User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin")); - - Users.Add(Roger); - Users.Add(Dylan); - Users.Add(Val); - return Users; - } - - public bool VerifPass() - { - User John = new User("John", "Doe", "JD@gmail.com", passwordManager.HashPassword("GIJD")); - string entryPass = "GIJD"; - - User Val = new User("V", "entin", "Valentin@mail.fr", passwordManager.HashPassword("valentin")); - Val.Password = passwordManager.HashPassword("jeChange"); - - bool isPasswordCorrect = passwordManager.VerifyPassword(John.Password, entryPass); - - return isPasswordCorrect; - } - public Stub() - { - - } - } -} diff --git a/MCTG/DataPersistence/DataContractJSON.cs b/MCTG/DataPersistence/DataContractJSON.cs index 382a4eb..05db57e 100644 --- a/MCTG/DataPersistence/DataContractJSON.cs +++ b/MCTG/DataPersistence/DataContractJSON.cs @@ -34,7 +34,12 @@ namespace DataPersistence if (dataContractJsonSerializerSettings is null) _dataContractJsonSerializerSettings = new DataContractJsonSerializerSettings() { - KnownTypes = new[] { typeof(Recipe) } + KnownTypes = new[] + { + typeof(Recipe), + typeof(Review), + typeof(User) + } }; else _dataContractJsonSerializerSettings = dataContractJsonSerializerSettings; diff --git a/MCTG/DataPersistence/DataContractXML.cs b/MCTG/DataPersistence/DataContractXML.cs index 3944c85..92f4baf 100644 --- a/MCTG/DataPersistence/DataContractXML.cs +++ b/MCTG/DataPersistence/DataContractXML.cs @@ -42,7 +42,12 @@ namespace DataPersistence if (dataContractSerializerSettings is null) _dataContractSerializerSettings = new DataContractSerializerSettings() { - KnownTypes = new Type[] { typeof(Recipe) }, + KnownTypes = new Type[] + { + typeof(Recipe), + typeof(Review), + typeof(User) + }, PreserveObjectReferences = true }; else diff --git a/MCTG/DataPersistence/DataPersistence.csproj b/MCTG/DataPersistence/DataPersistence.csproj index d5050a6..4b28c7b 100644 --- a/MCTG/DataPersistence/DataPersistence.csproj +++ b/MCTG/DataPersistence/DataPersistence.csproj @@ -10,8 +10,4 @@ - - - - diff --git a/MCTG/DataPersistence/Stubs.cs b/MCTG/DataPersistence/Stubs.cs index cc09f39..1539bc5 100644 --- a/MCTG/DataPersistence/Stubs.cs +++ b/MCTG/DataPersistence/Stubs.cs @@ -14,6 +14,8 @@ namespace DataPersistence { public Dictionary> Load() { + PasswordManager passwordManager = new PasswordManager(); + Dictionary> data = new Dictionary> { { @@ -86,6 +88,24 @@ namespace DataPersistence }) }) #endregion + }, + { + #region Data: User + nameof(User), + new List(new[] + { + new User( + name: "Admin", + surname: "Admin", + mail: "admin@mctg.fr", + password: passwordManager.HashPassword("admin")), + new User( + name: "Pedros", + surname: "Amigos", + mail: "pedrosamigos@hotmail.com", + password: passwordManager.HashPassword("pamigos")) + }) + #endregion } }; diff --git a/MCTG/DataPersistence/data/data.json b/MCTG/DataPersistence/data/data.json deleted file mode 100644 index 8d25dfd..0000000 --- a/MCTG/DataPersistence/data/data.json +++ /dev/null @@ -1,168 +0,0 @@ -[ - { - "Key": "Recipe", - "Value": [ - { - "__type": "recipe:#Model", - "id": 26700, - "preparation-steps": [ - { - "description": "Faire cuire.", - "order": 1 - }, - { - "description": "Manger.", - "order": 2 - } - ], - "title": "Cookies classiques" - }, - { - "__type": "recipe:#Model", - "id": 16433, - "preparation-steps": [ - { - "description": "Moulinez la pâte.", - "order": 1 - }, - { - "description": "Faire cuire pendant une bonne heure.", - "order": 2 - }, - { - "description": "Sortir du four et mettre dans un plat.", - "order": 3 - } - ], - "title": "Cookies au chocolat" - }, - { - "__type": "recipe:#Model", - "id": 26093, - "preparation-steps": [ - { - "description": "Achetez les ingrédients.", - "order": 1 - }, - { - "description": "Préparez le matériel. Ustensiles et tout.", - "order": 2 - }, - { - "description": "Pleurez.", - "order": 3 - } - ], - "title": "Gateau nature" - }, - { - "__type": "recipe:#Model", - "id": 21481, - "preparation-steps": [ - { - "description": "Achetez les légumes.", - "order": 1 - }, - { - "description": "Préparez le plat. Ustensiles et préchauffez le four.", - "order": 2 - }, - { - "description": "Coupez les pommes en morceaux et disposez-les sur le plat.", - "order": 3 - }, - { - "description": "Mettez enfin le plat au four, puis une fois cuit, dégustez !", - "order": 4 - } - ], - "title": "Gateau au pommes" - }, - { - "__type": "recipe:#Model", - "id": 15049, - "preparation-steps": [ - { - "description": "Ajouter les oeufs.", - "order": 1 - }, - { - "description": "Ajouter la farine.", - "order": 2 - }, - { - "description": "Ajouter 100g de chocolat fondu.", - "order": 3 - }, - { - "description": "Mélanger le tout.", - "order": 4 - }, - { - "description": "Faire cuire 45h au four traditionnel.", - "order": 5 - } - ], - "title": "Gateau au chocolat" - }, - { - "__type": "recipe:#Model", - "id": 28153, - "preparation-steps": [ - { - "description": "Faire une cuisson bien sec de la dinde à la poêle", - "order": 1 - }, - { - "description": "Mettre la dinde au frigo.", - "order": 2 - }, - { - "description": "Mettre le jambon dans le micro-onde.", - "order": 3 - }, - { - "description": "Faire chauffer 3min.", - "order": 4 - }, - { - "description": "Présentez sur un plat la dinde et le jambon : Miam !", - "order": 5 - } - ], - "title": "Dinde au jambon" - }, - { - "__type": "recipe:#Model", - "id": 8053, - "preparation-steps": [ - { - "description": "Trouvez des épices de curry.", - "order": 1 - }, - { - "description": "Trouvez maintenant du poulet.", - "order": 2 - }, - { - "description": "Coupez la tête du poulet et posez-la dans un plat.", - "order": 3 - }, - { - "description": "Parsemez d'épices curry la tête de la poule.", - "order": 4 - }, - { - "description": "Mettre le tout au four traditionnel 30min.", - "order": 5 - }, - { - "description": "Dégustez en famille !", - "order": 6 - } - ], - "title": "Poulet au curry" - } - ] - } -] \ No newline at end of file diff --git a/MCTG/DataPersistence/data/data.xml b/MCTG/DataPersistence/data/data.xml deleted file mode 100644 index bc21b40..0000000 --- a/MCTG/DataPersistence/data/data.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - - Recipe - - - 9062 - - - Faire cuire. - 1 - - - Manger. - 2 - - - Cookies classiques - - - 27627 - - - Moulinez la pâte. - 1 - - - Faire cuire pendant une bonne heure. - 2 - - - Sortir du four et mettre dans un plat. - 3 - - - Cookies au chocolat - - - 8517 - - - Achetez les ingrédients. - 1 - - - Préparez le matériel. Ustensiles et tout. - 2 - - - Pleurez. - 3 - - - Gateau nature - - - 6161 - - - Achetez les légumes. - 1 - - - Préparez le plat. Ustensiles et préchauffez le four. - 2 - - - Coupez les pommes en morceaux et disposez-les sur le plat. - 3 - - - Mettez enfin le plat au four, puis une fois cuit, dégustez ! - 4 - - - Gateau au pommes - - - 17869 - - - Ajouter les oeufs. - 1 - - - Ajouter la farine. - 2 - - - Ajouter 100g de chocolat fondu. - 3 - - - Mélanger le tout. - 4 - - - Faire cuire 45h au four traditionnel. - 5 - - - Gateau au chocolat - - - 4810 - - - Faire une cuisson bien sec de la dinde à la poêle - 1 - - - Mettre la dinde au frigo. - 2 - - - Mettre le jambon dans le micro-onde. - 3 - - - Faire chauffer 3min. - 4 - - - Présentez sur un plat la dinde et le jambon : Miam ! - 5 - - - Dinde au jambon - - - 13570 - - - Trouvez des épices de curry. - 1 - - - Trouvez maintenant du poulet. - 2 - - - Coupez la tête du poulet et posez-la dans un plat. - 3 - - - Parsemez d'épices curry la tête de la poule. - 4 - - - Mettre le tout au four traditionnel 30min. - 5 - - - Dégustez en famille ! - 6 - - - Poulet au curry - - - 26918 - - - Achetez les ingrédients. - 1 - - - Préparez le matériel. Ustensiles et tout. - 2 - - - Pleurez. - 3 - - - Aprenez de vos echecs. - 4 - - - Gateau nature v2 - - - - \ No newline at end of file diff --git a/MCTG/Model/Recipes/Recipe.cs b/MCTG/Model/Recipes/Recipe.cs index fa80231..fe81d0a 100644 --- a/MCTG/Model/Recipes/Recipe.cs +++ b/MCTG/Model/Recipes/Recipe.cs @@ -1,106 +1,170 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Runtime.Serialization; -using System.Security.Cryptography; -using System.Text; - -namespace Model -{ - /// - /// Define a Recipe for the preparation of a meal. - /// - [DataContract(Name = "recipe")] - public class Recipe : IEquatable - { - #region Attributes - [DataMember(Name = "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. - /// - [DataMember(Name = "id")] - 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: . - /// - [DataMember(Name = "preparation-steps")] - 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 - } -} +using System; +using System.Collections.Generic; +using System.Runtime.CompilerServices; +using System.Runtime.Serialization; +using System.Security.Cryptography; +using System.Text; + +namespace Model +{ + /// + /// Define a Recipe for the preparation of a meal. + /// + [DataContract(Name = "recipe")] + public class Recipe : IEquatable + { + #region Attributes + [DataMember(Name = "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. + /// + [DataMember(Name = "id")] + public int Id { get; init; } + + /// + /// List of reviews of this recipe. + /// + [DataMember(Name = "reviews")] + public List Reviews { get; private set; } + + /// + /// 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: . + /// + [DataMember(Name = "preparation-steps")] + 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, + List reviews, + params PreparationStep[] preparationSteps) + { + Title = title; + PreparationSteps = new List(preparationSteps); + Reviews = reviews; + + 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; + } + + /// + /// + /// + /// The title of the recipe. + public Recipe(string title) + : this(title, null, new List()) + { + } + + /// + /// + /// + /// The title of the recipe. + /// The steps of the preparation of the meal. + public Recipe(string title, params PreparationStep[] preparationSteps) + : this(title, null, new List(), preparationSteps) + { + } + + /// + /// + /// + /// 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, params PreparationStep[] preparationSteps) + : this(title, id, new List(), preparationSteps) + { + } + #endregion + + #region Methods + /// + /// Add a review for the recipe. + /// + /// The new review to add. + public void AddReview(Review review) + => Reviews.Add(review); + + /// + /// Get a string representing all the reviews and their informations. + /// + /// + public string GetReviews() + { + StringBuilder sb = new StringBuilder("Reviews:\n------------------------------\n"); + foreach (Review review in Reviews) + { + sb.AppendLine(review.ToString()); + } + return sb.ToString(); + } + + 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()); + } + sb.AppendLine(); + foreach (Review review in Reviews) + { + sb.AppendLine(review.ToString()); + } + return sb.ToString(); + } + #endregion + } +} \ No newline at end of file diff --git a/MCTG/Model/Recipes/Review.cs b/MCTG/Model/Recipes/Review.cs new file mode 100644 index 0000000..b98d498 --- /dev/null +++ b/MCTG/Model/Recipes/Review.cs @@ -0,0 +1,99 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Security.Cryptography; +using System.Text; +using System.Threading.Tasks; +using System.Xml.Linq; + +namespace Model +{ + [DataContract(Name = "review")] + public class Review : IEquatable + { + [DataMember(Name = "stars")] + private int _stars; + + [DataMember(Name = "content")] + private string _content = ""; + + [DataMember(Name = "id")] + public int Id { get; init; } + + [DataMember(Name = "user")] + public User Author { get; private set; } + + public int Stars + { + get => _stars; + set + { + if (value < 0 || value > 5) throw new ArgumentException(nameof(Stars)); + else _stars = value; + } + } + + public string Content + { + get => _content; + set + { + if (string.IsNullOrEmpty(value)) _content = "No data..."; + else _content = value; + } + } + + public Review(User author, int? id, int stars, string content) + { + 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; + + Author = author; + Stars = stars; + Content = content; + } + + public Review(User author, int stars, string content) + : this(author, null, stars, content) + { + } + + public Review(int stars, string content) + : this(new User("admin", "admin", "admin@mctg.fr", new PasswordManager().HashPassword("admin")), + null, stars, content) + { + } + + public override string ToString() + { + return $"{Author.Name} {Author.Surname}: [ {Stars} stars ]\n{Content}"; + } + + public bool Equals(Review? other) + { + if (other is null) return false; + return Id.Equals(other.Id); + } + + public override bool Equals(object? obj) + { + if (ReferenceEquals(obj, null)) return false; + if (ReferenceEquals(obj, this)) return true; + if (GetType() != obj.GetType()) return false; + + return Equals(obj); + } + + public override int GetHashCode() + { + return Id.GetHashCode(); + } + } +} diff --git a/MCTG/Model/User/User.cs b/MCTG/Model/User/User.cs index 599d49f..013bbe1 100644 --- a/MCTG/Model/User/User.cs +++ b/MCTG/Model/User/User.cs @@ -7,23 +7,25 @@ using System.Threading.Tasks; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; using System.Text; +using System.Runtime.Serialization; 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 + /// This user can login with an Id and a password /// + [DataContract(Name = "user")] public class User : IEquatable { #region Private Attributes - private string name=""; - private string surname=""; - private string mail = ""; - private string picture = ""; - private int password ; - private List priorities; + [DataMember] private string name=""; + [DataMember] private string surname=""; + [DataMember] private string mail = ""; + [DataMember] private string picture = ""; + [DataMember] private int password ; + [DataMember] private List priorities; #endregion #region Properties @@ -123,7 +125,11 @@ namespace Model return Name.Equals(other.Name) && Surname.Equals(other.Surname) && Mail.Equals(other.Mail); } - + public override int GetHashCode() + { + throw new NotImplementedException(); + } + #endregion @@ -151,6 +157,8 @@ namespace Model } + + #endregion diff --git a/MCTG/Tests/Model_UnitTests/Model_UnitTests - Backup.csproj b/MCTG/Tests/Model_UnitTests/Model_UnitTests - Backup.csproj new file mode 100644 index 0000000..cbc7829 --- /dev/null +++ b/MCTG/Tests/Model_UnitTests/Model_UnitTests - Backup.csproj @@ -0,0 +1,31 @@ +<<<<<<< HEAD + +======= + + +>>>>>>> feature/18-model-user + + net7.0 + enable + enable + false + true + Debug;Release;CI + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + \ No newline at end of file diff --git a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj index a3649e1..ce77636 100644 --- a/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj +++ b/MCTG/Tests/Model_UnitTests/Model_UnitTests.csproj @@ -1,9 +1,4 @@ -<<<<<<< HEAD  - -======= - ->>>>>>> origin/dev net7.0 enable diff --git a/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs b/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs index 3f09b70..b79b884 100644 --- a/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs +++ b/MCTG/Tests/Model_UnitTests/RecipeCollection_UT.cs @@ -17,15 +17,14 @@ namespace Model_UnitTests 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) + new Recipe(title: "Gateau à la crème"), + new Recipe(title: "Gateau au chocolat"), + new Recipe(title: "Gateau aux cerises") }); - Recipe? recipe = recipes.ResearchByName("chocolat").FirstOrDefault(); - - Assert.NotNull(recipe); - Assert.Equal(2, recipe.Id); + Recipe? search_result = recipes.ResearchByName("chocolat").FirstOrDefault(); + Assert.NotNull(search_result); + Assert.Equal("Gateau au chocolat", search_result.Title); } } } diff --git a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs index 9655041..4fdce86 100644 --- a/MCTG/Tests/Model_UnitTests/Recipe_UT.cs +++ b/MCTG/Tests/Model_UnitTests/Recipe_UT.cs @@ -7,22 +7,8 @@ namespace Model_UnitTests [Fact] public void TestVoidConstructor() { - Recipe r = new Recipe(id: 999); // id is given to avoid tests errors with the static atrribute 'idCreator'. + Recipe r = new Recipe(""); // 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/test_unit_user.cs b/MCTG/Tests/Model_UnitTests/test_unit_user.cs index 001c228..5df6579 100644 --- a/MCTG/Tests/Model_UnitTests/test_unit_user.cs +++ b/MCTG/Tests/Model_UnitTests/test_unit_user.cs @@ -12,7 +12,6 @@ namespace Model_UnitTests [Fact] public void TestConstructUser() { -<<<<<<< HEAD PasswordManager passwordManager = new PasswordManager(); User user = new User("Bob", "Dylan", "bd@gmail.com", passwordManager.HashPassword("bobby")); Assert.Equal("Bob", user.Name); @@ -20,10 +19,6 @@ namespace Model_UnitTests Assert.Equal("bd@gmail.com", user.Mail); Assert.Equal(passwordManager.HashPassword("bobby"), user.Password); Assert.NotNull(user.Priorities); -======= - User? user = new User("Bob","Dylan", "bd@gmail.com"); - Assert.NotNull(user); ->>>>>>> origin/dev } } }