diff --git a/.drone.yml b/.drone.yml index aaae369..e670947 100644 --- a/.drone.yml +++ b/.drone.yml @@ -6,6 +6,7 @@ trigger: branch: - developpement - master + - refonte_program event: - push diff --git a/notus/Biblioteque_de_Class/Database.cs b/notus/Biblioteque_de_Class/Database.cs index 61fc24d..342abab 100644 --- a/notus/Biblioteque_de_Class/Database.cs +++ b/notus/Biblioteque_de_Class/Database.cs @@ -37,14 +37,14 @@ namespace Biblioteque_de_Class { List searchedUsers = new List(); string search = name.ToLower(); - searchedUsers.AddRange(UserList.Where(user => user.GetUsername().ToLower().Contains(search))); + searchedUsers.AddRange(UserList.Where( user => user.GetUsername().ToLower().Contains(search))); return searchedUsers; } /// /// récupérer le lien d'un logo /// - public string GetLogoLink(string name) + public string? GetLogoLink(string name) { foreach (Logo logo in DefaultLogoList) { @@ -71,7 +71,7 @@ namespace Biblioteque_de_Class /// /// comparer le mot de passe entré avec celui de l'utilisateur /// - public static bool ComparePassword(User user, string password) => user.GetPassword() == password; + public static bool ComparePassword(User user, string? password) => user.GetPassword() == password; /// /// rechercher un mail dans la liste d'utilisateur @@ -142,8 +142,12 @@ namespace Biblioteque_de_Class /// public void RemoveTheme(Theme theme) { - if (ThemeList.Contains(theme)) + if (ThemeList.Contains(theme)) { + if (theme.GetName().Length > 6 && theme.GetName()[..6] != "Static" ) + { + throw new AlreadyUsedException("This theme is used a default theme."); + } ThemeList.Remove(theme); } else @@ -199,7 +203,6 @@ namespace Biblioteque_de_Class return; } } - throw new NotFoundException("Theme not found."); } } } \ No newline at end of file diff --git a/notus/Biblioteque_de_Class/IManager.cs b/notus/Biblioteque_de_Class/IManager.cs index 4da721f..008e946 100644 --- a/notus/Biblioteque_de_Class/IManager.cs +++ b/notus/Biblioteque_de_Class/IManager.cs @@ -11,30 +11,5 @@ namespace Biblioteque_de_Class public void SaveDatabaseData(Database database); public Database LoadDatabaseData(); - - public void SaveUserData(User user); - - public List LoadUserData(); - - public List LoadNote(); - - public void SaveNote(Note note); - - public List LoadTheme(); - - public void SaveTheme(Theme theme); - - public List LoadLogo(); - - public void SaveLogo(Logo logo); - - public List LoadTags(); - - public void SaveTags(Tags tag); - - public List LoadNoteImage(); - - public void SaveNoteImage(NoteImage noteImage); - } } diff --git a/notus/Biblioteque_de_Class/Note.cs b/notus/Biblioteque_de_Class/Note.cs index 8ab6306..6bbad35 100644 --- a/notus/Biblioteque_de_Class/Note.cs +++ b/notus/Biblioteque_de_Class/Note.cs @@ -15,7 +15,8 @@ namespace Biblioteque_de_Class private set { if (value == null) { name = "Unnamed Note"; } else { name = value; } } } - ///private string Text { get; set; } Attribut pour le texte de la note + private string Text { get; set; } = ""; + private string logoPath; public string LogoPath { @@ -26,7 +27,6 @@ namespace Biblioteque_de_Class private DateOnly CreationDate { get; } private DateOnly ModificationDate { get; set; } private readonly List ImageList; - private string TextLine; private readonly List Collaborators; private readonly List Editors; private readonly User Owner; @@ -45,10 +45,10 @@ namespace Biblioteque_de_Class public string GetName() { return Name; } public string GetLogoPath() { return LogoPath; } + public string GetText() { return Text; } public DateOnly GetCreationDate() { return CreationDate; } public DateOnly GetModificationDate() { return ModificationDate; } public List GetImageList() { return ImageList; } - public string GetTextLine() { return TextLine; } public List GetCollaborators() { return Collaborators; } public List GetEditors() { return Editors; } public User GetOwner() { return Owner; } @@ -58,7 +58,6 @@ namespace Biblioteque_de_Class public void SetName(string name) { Name = name; } public void SetLogoPath(string logoPath) { LogoPath = logoPath; } public void SetModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); } - public void SetTextLine(string texte) { TextLine = texte; } /// /// vérifier si l'utilisateur est le propriétaire de la note @@ -87,6 +86,11 @@ namespace Biblioteque_de_Class throw new NotFoundException("Image not found"); } + public void AddText(string text) + { + Text = Text + "\n" + text; + } + /// /// vérifier si l'utilisateur est un éditeur de la note /// diff --git a/notus/Biblioteque_de_Class/User.cs b/notus/Biblioteque_de_Class/User.cs index f9e1b2c..1e3f52a 100644 --- a/notus/Biblioteque_de_Class/User.cs +++ b/notus/Biblioteque_de_Class/User.cs @@ -1,259 +1,271 @@ -using Microsoft.VisualBasic.FileIO; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations.Schema; -using System.Runtime.Serialization; - -namespace Biblioteque_de_Class -{ - [DataContract] - public class User - { - [DataMember] - private string Username { get; set; } - [DataMember] - private string Email { get; set; } - [DataMember] - private string Password { get; set; } - [DataMember] - private List NoteList; - [DataMember] - private List TagList; - [DataMember] - private List FavList; - [DataMember] - private bool IsConnected { get; set; } - [DataMember] - private Dictionary> NoteTagged; - - public User(string username, string email, string password) - { - Username = username; - Email = email; - Password = password; - NoteList = new List(); - TagList = new List(); - FavList = new List(); - NoteTagged = new Dictionary>(); - } - - public string GetUsername() { return Username; } - public string GetEmail() { return Email; } - public string GetPassword() { return Password; } - public List GetNoteList() { return NoteList; } - public List GetTagList() { return TagList; } - public List GetFavList() { return FavList; } - public bool GetIsConnected() { return IsConnected; } - public Dictionary> GetNoteTagged() { return NoteTagged; } - - public void SetUsername(string username) { Username = username; } - public void SetEmail(string email) { Email = email; } - public void SetPassword(string password) { Password = password; } - public void SetIsConnected(bool isConnected) { IsConnected = isConnected; } - - public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}"; - - /// - /// rechercher une note dans la liste de note de l'utilisateur - /// - public List SearchNoteByName(string name) - { - List searchedNotes = new List(); - string search = name.ToLower(); - foreach (Note note in NoteList) - { - if (note.GetName().ToLower().Contains(search)) - { - searchedNotes.Add(note); - } - } - return searchedNotes; - } - - /// - /// rechercher une note dans la liste de note favoris de l'utilisateur - /// - public List SearchFavoriteNoteByName(string name) - { - List searchedNotes = new List(); - string search = name.ToLower(); - foreach (Note note in FavList) - { - if (note.GetName().ToLower().Contains(search)) - { - searchedNotes.Add(note); - } - } - return searchedNotes; - } - - /// - /// rechercher un tag dans la liste de tag de l'utilisateur - /// - public List SearchTagByName(string name) - { - List searchedTags = new List(); - string search = name.ToLower(); - foreach (Tags tag in TagList) - { - if (tag.GetName().ToLower().Contains(search)) - { - searchedTags.Add(tag); - } - } - return searchedTags; - } - - public List SearchNoteByDate(List ToResearchIntoList, string name, DateOnly FirstDate, DateOnly SecondeDate) - { - List searchedNotes = new List(); - string search = name.ToLower(); - foreach (Note note in ToResearchIntoList) - { - if (note.GetName().ToLower().Contains(search) && note.GetCreationDate() >= FirstDate && note.GetCreationDate() <= SecondeDate) - { - searchedNotes.Add(note); - } - } - return searchedNotes; - } - - /// - /// ajouter une note dans la liste de note favorite de l'utilisateur - /// - public void AddFavorite(Note note) - { - if (FavList.Contains(note)) - { - throw new AlreadyExistException("Note already in favorites"); - } - FavList.Add(note); - } - - /// - /// supprimer une note dans la liste de note favorite de l'utilisateur - /// - public void RemoveFavorite(Note note) - { - if (FavList.Contains(note)) - { - FavList.Remove(note); - } - else - { - throw new NotFoundException("Note not found"); - } - } - - /// - ///creer une note - /// - public void CreateNote(string name, string imagePath) - { - foreach (Note existingNote in NoteList) - { - if (existingNote.GetName() == name) - { - throw new AlreadyExistException("Note already exists"); - } - } - Note note = new Note(name, imagePath, this); - NoteList.Add(note); - NoteTagged.Add(note, new List()); - } - - /// - /// supprimer une note - /// - public void DeleteNote(Note note) - { - if (NoteList.Contains(note)) - { - NoteList.Remove(note); - NoteTagged.Remove(note); - } - else - { - throw new NotFoundException("Note not found"); - } - } - - /// - /// creer un tag - /// - public void CreateTag(string name, string color) - { - foreach (Tags tag in TagList) - { - if (tag.GetName() == name) - { - throw new AlreadyExistException("Tag already exists"); - } - } - TagList.Add(new Tags(name, color)); - } - - /// - /// supprimer un tag - /// - public void DeleteTag(string name) - { - foreach (Tags tag in TagList) - { - if (tag.GetName() == name) - { - TagList.Remove(tag); - return; - } - } - } - - /// - /// ajouter un tag a une note - /// - public void AddTagToNoteList(Note note, Tags tagToAdd) - { - if (!TagList.Contains(tagToAdd)) - { - throw new NotFoundException("Tag not found"); - } - if (!NoteList.Contains(note)) - { - throw new NotFoundException("Note not found"); - } - NoteTagged[note].Add(tagToAdd); - } - - /// - /// supprimer un tag a une note - /// - public void RemoveTagFromNoteList(Note note, Tags tagToRemove) - { - if (!TagList.Contains(tagToRemove)) - { - throw new NotFoundException("Tag not found"); - } - if (!NoteList.Contains(note)) - { - throw new NotFoundException("Note not found"); - } - NoteTagged[note].Remove(tagToRemove); - } - - /// - /// ajouter plusieur tag a une note - /// - public void AddTagsToNoteList(Note note, List tags) - { - NoteTagged.Add(note, tags); - } - - /// - ///supprimer tout les tags d'une note - /// - public void RemoveTagsFromNoteList(Note note) - { - NoteTagged.Remove(note); - } - - } +using Microsoft.VisualBasic.FileIO; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace Biblioteque_de_Class +{ + [DataContract] + public class User + { + [DataMember] + private string Username { get; set; } + [DataMember] + private string Email { get; set; } + [DataMember] + private string Password { get; set; } + private Theme Theme; + [DataMember] + private List NoteList; + [DataMember] + private List TagList; + [DataMember] + private List FavList; + [DataMember] + private bool IsConnected { get; set; } + [DataMember] + private Dictionary> NoteTagged; + + public User(string username, string email, string password) + { + Username = username; + Email = email; + Password = password; + NoteList = new List(); + TagList = new List(); + FavList = new List(); + NoteTagged = new Dictionary>(); + } + + public string GetUsername() { return Username; } + public string GetEmail() { return Email; } + public string GetPassword() { return Password; } + public Theme GetTheme() { return Theme; } + public List GetNoteList() { return NoteList; } + public List GetTagList() { return TagList; } + public List GetFavList() { return FavList; } + public bool GetIsConnected() { return IsConnected; } + public Dictionary> GetNoteTagged() { return NoteTagged; } + public List GetNoteTaggedList(Note note) { return NoteTagged[note]; } + + public void SetUsername(string username) { Username = username; } + public void SetEmail(string email) { Email = email; } + public void SetPassword(string password) { Password = password; } + public void SetTheme(Theme theme) { Theme = theme; } + public void SetIsConnected(bool isConnected) { IsConnected = isConnected; } + + public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}"; + + /// + /// rechercher une note dans la liste de note de l'utilisateur et la liste de note favoris de l'utilisateur + /// + public List SearchNoteByName(List ToResearchIntoList, string name) + { + List searchedNotes = new List(); + string search = name.ToLower(); + foreach (Note note in ToResearchIntoList) + { + if (note.GetName().ToLower().Contains(search)) + { + searchedNotes.Add(note); + } + } + return searchedNotes; + } + + /// + /// rechercher un tag dans la liste de tag de l'utilisateur + /// + public List SearchTagByName(List ToResearchIntoList, string name) + { + List searchedTags = new List(); + string search = name.ToLower(); + foreach (Tags tag in ToResearchIntoList) + { + if (tag.GetName().ToLower().Contains(search)) + { + searchedTags.Add(tag); + } + } + return searchedTags; + } + + public List SearchNoteByDate(List ToResearchIntoList, string name, DateOnly FirstDate, DateOnly SecondeDate) + { + List searchedNotes = new List(); + string search = name.ToLower(); + foreach (Note note in ToResearchIntoList) + { + if (note.GetName().ToLower().Contains(search) && note.GetCreationDate() >= FirstDate && note.GetCreationDate() <= SecondeDate || note.GetModificationDate() >= FirstDate && note.GetModificationDate() <= SecondeDate) + { + searchedNotes.Add(note); + } + } + return searchedNotes; + } + + public Note GetNoteByName(string name) + { + foreach (Note note in NoteList) + { + if (note.GetName() == name) + { + return note; + } + } + throw new NotFoundException("Note not found"); + } + + public Tags GetTagByName(string name) + { + foreach (Tags tag in TagList) + { + if (tag.GetName() == name) + { + return tag; + } + } + throw new NotFoundException("Tag not found"); + } + + /// + /// ajouter une note dans la liste de note favorite de l'utilisateur + /// + public void AddFavorite(Note note) + { + if (FavList.Contains(note)) + { + throw new AlreadyExistException("Note already in favorites"); + } + FavList.Add(note); + } + + /// + /// supprimer une note dans la liste de note favorite de l'utilisateur + /// + public void RemoveFavorite(Note note) + { + if (FavList.Contains(note)) + { + FavList.Remove(note); + } + else + { + throw new NotFoundException("Note not found"); + } + } + + /// + ///creer une note + /// + public void CreateNote(string name, string imagePath) + { + foreach (Note existingNote in NoteList) + { + if (existingNote.GetName() == name) + { + throw new AlreadyExistException("Note already exists"); + } + } + Note note = new Note(name, imagePath, this); + NoteList.Add(note); + NoteTagged.Add(note, new List()); + } + + /// + /// supprimer une note + /// + public void DeleteNote(string note) + { + foreach (Note existingNote in NoteList) + { + if (existingNote.GetName() == note) + { + NoteList.Remove(existingNote); + NoteTagged.Remove(existingNote); + return; + } + } + throw new NotFoundException("Note not found"); + } + + /// + /// creer un tag + /// + public void CreateTag(string name, string color) + { + foreach (Tags tag in TagList) + { + if (tag.GetName() == name) + { + throw new AlreadyExistException("Tag already exists"); + } + } + TagList.Add(new Tags(name, color)); + } + + /// + /// supprimer un tag + /// + public void DeleteTag(string name) + { + foreach (Tags tag in TagList) + { + if (tag.GetName() == name) + { + TagList.Remove(tag); + return; + } + } + } + + /// + /// ajouter un tag a une note + /// + public void AddTagToNoteList(Note note, Tags tagToAdd) + { + if (!TagList.Contains(tagToAdd)) + { + throw new NotFoundException("Tag not found"); + } + if (!NoteList.Contains(note)) + { + throw new NotFoundException("Note not found"); + } + NoteTagged[note].Add(tagToAdd); + } + + /// + /// supprimer un tag a une note + /// + public void RemoveTagFromNoteList(Note note, Tags tagToRemove) + { + if (!TagList.Contains(tagToRemove)) + { + throw new NotFoundException("Tag not found"); + } + if (!NoteList.Contains(note)) + { + throw new NotFoundException("Note not found"); + } + NoteTagged[note].Remove(tagToRemove); + } + + /// + /// ajouter plusieur tag a une note + /// + public void AddTagsToNoteList(Note note, List tags) + { + NoteTagged.Add(note, tags); + } + + /// + ///supprimer tout les tags d'une note + /// + public void RemoveTagsFromNoteList(Note note) + { + NoteTagged.Remove(note); + } + + } } \ No newline at end of file diff --git a/notus/Notus_Console/Program.cs b/notus/Notus_Console/Program.cs index 53574ec..0ba71e8 100644 --- a/notus/Notus_Console/Program.cs +++ b/notus/Notus_Console/Program.cs @@ -1,361 +1,648 @@ using Biblioteque_de_Class; -using System.ComponentModel.DataAnnotations.Schema; -using System.Diagnostics; -using System.Linq.Expressions; -using System.Runtime.InteropServices; using Notus_Persistance; +using System.Collections; +using System.Security.Cryptography; +using System.Text; + +// load database +PersistenceManager manager = new(new Stub()); +Database db = manager.LoadDatabaseData(); +foreach(User user in db.GetUserList()) +{ + user.SetPassword(GetSHA256Hash(user.GetPassword())); +} + -string Upseudo = "u"; -string Umail = "u"; -string Upassword = "u"; -int nomImage = 1; -string linkimage = "u"; -string position = "u"; -string nomNote = "u"; -string logoPath = "u"; -string NomTag = "u"; -string nom = "u"; -string choixNom; -string choixCouleur; -string choixModif; -int image_; -string choix; -string color = "u"; -string color2; -string color3; +// initialization zone============================================================================== +bool continuerboucle = false; +bool menu = true, connection = false, inscription = false; +bool note=false, tags=false, para=false, paraCompte=false, theme=false; -User user = new User(Upseudo, Umail, Upassword); -NoteImage image = new NoteImage(nomImage, linkimage, position); -Database db = new Database(); -User u = new User(Upseudo, Umail, Upassword); -Note n = new Note(nomNote, logoPath, u); -Tags t = new Tags(NomTag, color); -PersistenceManager managerPers = new PersistenceManager(new Stub()); +// déclaration d'un user qui sera utiliser pour servir de personne connecté dans l'app +User u = new("", "", ""); +User uvide = new("", "", ""); +uvide.SetIsConnected(false); -List NewColorList = new List { }; -List listCouleurs = new List { }; -List _searchedNotes; -List NoteListe = managerPers.LoadNote(); -List _searchedTags; -List UserListe = managerPers.LoadUserData(); +// déclaration d'une note qui sera utiliser pour servir de note selectionnée +Note n = new("","",uvide); +List researchlist = new(); +// factorisation +bool continuer() +>>>>>>> refonte_program +{ + continuerboucle = false; + while(!continuerboucle) + { + Console.WriteLine("\nContinuer ? (O/n)"); + switch (Console.ReadLine()) + { + case "O": + return true; + case null: + return true; + case "o": + return true; + case "n": + return false; + default: + Console.WriteLine("\nEntrez un choix valide.\n"); + continuerboucle = true; + break; + } + } + return false; +} -/*foreach (Note no in NoteListe) /// Test du stub +bool choix_note() { - Console.WriteLine(no.GetName()); + Console.WriteLine("\nChoisissez le nom de la note"); + string? wantedModifyNote = Console.ReadLine(); + wantedModifyNote??= ""; + try + { + n = u.GetNoteByName(wantedModifyNote); + }catch (Exception ex) { Console.WriteLine(ex.Message); return false; } + return true; +} + +void displayNote() +{ + foreach (Note note in u.GetNoteList()) + { + Console.WriteLine(note.GetName() + "\n"); + } +} + +void displayTag() +{ + foreach (Tags tag in u.GetTagList()) + { + Console.WriteLine(tag.GetName() + "\n"); + } } -return;*/ -int boucle = 0; -while (boucle == 0) +void displayTheme() { - Console.WriteLine("|--------------------------------------|"); + foreach (Theme theme in db.GetThemeList()) + { + Console.WriteLine(theme.GetName() + "\n"); + } +} + +List? choix_couleur() +{ + List colorList = new(); + Console.WriteLine("Fond : "); + string? wantedNewThemeFond = Console.ReadLine(); + if(wantedNewThemeFond == null){ return null; } + else if(wantedNewThemeFond[0].ToString() != "#"){ + Console.WriteLine("\nLa couleur doit être au format hexadécimal.\n"); + return null; + }else if(wantedNewThemeFond.Length != 7) + { + string toadd=""; + for(int i = 7- wantedNewThemeFond.Length; i!=0; i--){toadd += "0";} + wantedNewThemeFond += toadd; + return null; + } + Console.WriteLine("Texte : "); + string? wantedNewThemeTexte = Console.ReadLine(); + if(wantedNewThemeTexte == null){ return null; } + else if(wantedNewThemeTexte[0].ToString() != "#"){ + Console.WriteLine("\nLa couleur doit être au format hexadécimal.\n"); + return null; + }else if(wantedNewThemeTexte.Length != 7) + { + string toadd=""; + for(int i = 7- wantedNewThemeTexte.Length; i!=0; i--){toadd += "0";} + wantedNewThemeTexte += toadd; + return null; + } + Console.WriteLine("Bouton : "); + string? wantedNewThemeBouton = Console.ReadLine(); + if(wantedNewThemeBouton == null){ return null; } + else if(wantedNewThemeBouton[0].ToString() != "#"){ + Console.WriteLine("\nLa couleur doit être au format hexadécimal.\n"); + return null; + }else if(wantedNewThemeBouton.Length != 7) + { + string toadd=""; + for(int i = 7- wantedNewThemeBouton.Length; i!=0; i--){toadd += "0";} + wantedNewThemeBouton += toadd; + return null; + } + colorList.Add(wantedNewThemeFond); + colorList.Add(wantedNewThemeTexte); + colorList.Add(wantedNewThemeBouton); + return colorList; +} + +static string GetSHA256Hash(string input) +{ + using (SHA256 sha256Hash = SHA256.Create()) + { + byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input)); + + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < bytes.Length; i++) + { + builder.Append(bytes[i].ToString("x2")); + } + + return builder.ToString(); + } +} + +while (menu) +{ + Console.WriteLine("\n|--------------------------------------|"); Console.WriteLine("| |"); - Console.WriteLine("| Menu pour lister les fonctionnalités |"); + Console.WriteLine("| starting menu |"); Console.WriteLine("| |"); Console.WriteLine("|--------------------------------------|--------|"); Console.WriteLine("| |"); - Console.WriteLine("| 1/se connecter |"); - Console.WriteLine("| 2/se déconnecter |"); - Console.WriteLine("| 3/créer un compte |"); - Console.WriteLine("| 4/supprimer un compte |"); - Console.WriteLine("| 5/créer note |"); - Console.WriteLine("| 6/supprimer note |"); - Console.WriteLine("| 7/créer tag |"); - Console.WriteLine("| 8/ajouter tag |"); - Console.WriteLine("| 9/supprimer tag |"); - Console.WriteLine("| 10/ajouter image |"); - Console.WriteLine("| 11/supprimer image |"); - Console.WriteLine("| 12/déplacer image |"); - Console.WriteLine("| 13/supprimer tag definitif |"); - Console.WriteLine("| 14/Ajouter favori |"); - Console.WriteLine("| 15/Supprimer favori |"); - Console.WriteLine("| 16/créer un thème |"); - Console.WriteLine("| 17/supprimer un thème |"); - Console.WriteLine("| 18/modifier un thème |"); - Console.WriteLine("| 19/rechercher une note |"); - Console.WriteLine("| 20/rechercher une note avec tags |"); - Console.WriteLine("| 21/rechercher une note avec date |"); - Console.WriteLine("| 22/modifier tags |"); - Console.WriteLine("| 23/modifier compte |"); - Console.WriteLine("| 24/modifier note |"); - Console.WriteLine("| 25/partage note |"); - Console.WriteLine("| 26/modifier role (si proprietaire) |"); - Console.WriteLine("| 27/supprimer cooperateur |"); + Console.WriteLine("| 1 / - connection - |"); + Console.WriteLine("| 2 / - inscription - |"); Console.WriteLine("| |"); - Console.WriteLine("|-----------------------------------------------|"); - + Console.WriteLine("|-----------------------------------------------|\n"); + Console.WriteLine("rentrez votre choix."); switch (Console.ReadLine()) { case "1": ///Connexion - Console.WriteLine("Entrez votre nom."); - nom = Console.ReadLine(); + connection = true; break; + + case "2":///Creer un compte + inscription = true; break; + default: + Console.WriteLine("\nEntrez un choix valide.\n"); + break; + } + + //connection + while (connection) + { + connection = false; + Console.WriteLine("\nEntrez un nom : "); + string? nom = Console.ReadLine(); + if (nom == null) { continue; } + Console.WriteLine("\nEntrez un password :"); + string? password = Console.ReadLine(); + if (password == null) { continue; } + password = GetSHA256Hash(password); + try + { u = db.GetUser(nom); - Umail = u.GetEmail(); - Upassword = u.GetPassword(); - db.FindEmail(Umail); - Database.ComparePassword(u,Upassword); - UserListe = db.GetUserList(); - if (UserListe.Contains(u)) + } + catch (AlreadyUsedException ex) + { + Console.WriteLine(ex.Message); + connection = true; + } + if (!connection) + { + if (Database.ComparePassword(u, password)) { u.SetIsConnected(true); - Console.WriteLine("Connecté"); - break; + Console.WriteLine("\nConnection réussie !\n"); + menu = false; } else { - Console.WriteLine("Utilisateur non trouvé."); - break; + Console.WriteLine("\nWrong PassWord !\n"); + connection = true; + continuerboucle = true; + u = uvide; } + } + while (continuerboucle) { connection = continuer(); } + } - case "2":///Deconnexion - u.SetIsConnected(false); - Console.WriteLine("Vous vous êtes déconnecté avec succès."); - break; - - case "3":///Creer un compte - Console.WriteLine("Choisissez un pseudo"); - Upseudo = Console.ReadLine(); - Console.WriteLine("Entrez votre adresse mail"); - Umail = Console.ReadLine(); - Console.WriteLine("Saisissez un mot de passe"); - Upassword = Console.ReadLine(); - User u1 = new User(Upseudo, Umail, Upassword); - db.AddUser(u1); - break; - case "4":///Supprimer Compte - Console.WriteLine("Chercher utilisateur"); - nom = Console.ReadLine(); + //inscription + while (inscription) + { + Console.WriteLine("\nEntrez un nom :"); + string? nom = Console.ReadLine(); + if (nom == null) { continue; } + Console.WriteLine("\nEntrez un password :"); + string? password = Console.ReadLine(); + if (password == null) { continue; } + try + { u = db.GetUser(nom); - Umail = u.GetEmail(); - db.FindEmail(Umail); - Upassword = u.GetPassword(); - Database.ComparePassword(u,Upassword); - UserListe = db.GetUserList(); - if (UserListe.Contains(u)) - { - db.RemoveUser(u); - Console.WriteLine("Compte supprimé avec succès."); - break; - } - Console.WriteLine("Utilisateur non trouvé."); - break; - - case "5":///Creer une note - Console.WriteLine("Choisissez un nom"); - nom = Console.ReadLine(); - Console.WriteLine("Choisissez un logo"); - logoPath = Console.ReadLine(); - n = new Note(nom, logoPath, u); - u.CreateNote(nom, logoPath); - break; - - case "6":///Supprimer une note - u.DeleteNote(n); - break; - - case "7":///Creer un tag - Console.WriteLine("Choisissez un nom"); - choixNom = Console.ReadLine(); - Console.WriteLine("Choisissez une couleur"); - choixCouleur = Console.ReadLine(); - u.CreateTag(choixNom, choixCouleur); + } + catch (AlreadyUsedException) + { + password = GetSHA256Hash(password); + u = new User(nom, "", password); + db.AddUser(u); + db.GetUser(nom).SetIsConnected(true); + Console.WriteLine("\nConnection réussie !\n"); + menu = false; break; + } + Console.WriteLine("\nNom d'utilisateur déjà utilisé. \n"); + while (continuerboucle) { inscription = continuer(); } - case "8":///Ajouter un tag a une note - Console.WriteLine("Cherchez une note"); - nom = Console.ReadLine(); - _searchedNotes = u.SearchNoteByName(nom); - Console.WriteLine("Cherchez un tag"); - nom = Console.ReadLine(); - Tags tagToAdd = new Tags(nom, color); - u.AddTagToNoteList(n, tagToAdd); - break; - - case "9":///Supprimer un tag a une note - Console.WriteLine("Cherchez une note"); - nom = Console.ReadLine(); - _searchedNotes = u.SearchNoteByName(nom); - Console.WriteLine("Cherchez un tag"); - nom = Console.ReadLine(); - _searchedTags = u.SearchTagByName(nom); ///A voir pour faire correctement - Tags tagToSupp = new Tags(nom, color); - tagToSupp = _searchedTags[1]; - u.RemoveTagFromNoteList(n, tagToSupp); - break; - - case "10":///Ajouter une image - n.AddImage(linkimage, position); - break; - - case "11":///Supprimer une image - Console.WriteLine("Saisir numero de la note"); - image_ = Convert.ToInt32(Console.ReadLine()); - n.RemoveImage(image_); - break; - - case "12":///Deplacer une image - image.SetPosition(position); - break; - - case "13":///Supprimer un tag definitivement - _searchedTags = u.SearchTagByName(nom); - u.RemoveTagFromNoteList(n, t); - break; - - case "14":///AJouter une note en favori - u.AddFavorite(n); - break; - - case "15":///Supprimer une note des favoris - u.RemoveFavorite(n); - break; - - case "16":///Creer un theme - Console.WriteLine("Choisissez un nom pour votre theme"); - nom = Console.ReadLine(); - Console.WriteLine("Choisissez trois couleurs"); - color = Console.ReadLine(); - color2 = Console.ReadLine(); - color3 = Console.ReadLine(); - listCouleurs.Add(color); - listCouleurs.Add(color2); - listCouleurs.Add(color3); - Theme th = new Theme(nom, listCouleurs); - db.AddTheme(th); - listCouleurs.RemoveAt(1); - listCouleurs.RemoveAt(1); - listCouleurs.RemoveAt(1); - break; - - case "17":///Supprimer un theme - th = db.GetTheme(nom); - db.RemoveTheme(th); - break; - - case "18":///Modifier un theme - Console.WriteLine("Cherchez un theme a modifier"); - nom = Console.ReadLine(); - th = db.GetTheme(nom); - db.ModifyThemeName(th,nom); - Console.WriteLine("Choisissez trois couleurs"); - color = Console.ReadLine(); - color2 = Console.ReadLine(); - color3 = Console.ReadLine(); - NewColorList.Add(color); - NewColorList.Add(color2); - NewColorList.Add(color3); - db.ModifyThemeColorList(th, NewColorList); - NewColorList.RemoveAt(1); - NewColorList.RemoveAt(1); - NewColorList.RemoveAt(1); + } +} +//une fois connecté ou inscription fait +while (u.GetIsConnected()) +{ + Console.WriteLine("\n|--------------------------------------|"); + Console.WriteLine("| |"); + Console.WriteLine("| menu |"); + Console.WriteLine("| |"); + Console.WriteLine("|--------------------------------------|--------|"); + Console.WriteLine("| |"); + Console.WriteLine("| 1/ - rechercher note - |"); + Console.WriteLine("| 2/ - note - |"); + Console.WriteLine("| 3/ - tags - |"); + Console.WriteLine("| 4/ - paramêtres - |"); + Console.WriteLine("| 5/ - se déconnecter - |"); + Console.WriteLine("| |"); + Console.WriteLine("|-----------------------------------------------|\n"); + Console.WriteLine("rentrez votre choix."); + switch (Console.ReadLine()) + { + case "1": + researchlist = u.GetNoteList(); + Console.WriteLine("\nEntrez la note que vous cherchez. "); + string? wantedSearchNote = Console.ReadLine(); + Console.WriteLine("\nChercher par tags ? (o/N) "); + + Console.WriteLine("\nChercher par date ? (o/N) "); break; - - case "19":///Rechercher une note - Console.WriteLine("Cherchez une note"); - nom = Console.ReadLine(); - NoteListe = u.GetNoteList(); - u.SearchNoteByName(nom); + case "2": + note = true; break; - - case "20":///Recherche note par tag - ///u.; + case "3": + tags = true; break; - - case "21":///Recherche note par dateCreation - ///u.; + case "4": + para = true; break; - - case "22":///Modifier un tag - Console.WriteLine("Cherchez un tag"); - nom = Console.ReadLine(); - Console.WriteLine("Choisisez une couleur"); - color = Console.ReadLine(); - t.SetName(nom); - t.SetColor(color); + case "5": + Console.WriteLine("\ndéconnecté! \n"); + u.SetIsConnected(false); + u = uvide; break; - - case "23":///Modifier le compte - Console.WriteLine("Modifier pseudo ? Mot de passe ? Mail ? (0/1/2)"); - choixModif = Console.ReadLine(); - if (choixModif.Equals('0')) - { - Console.WriteLine("Entrez votre nouveau pseudo"); - Upseudo = Console.ReadLine(); - u.SetUsername(Upseudo); - } - if (choixModif.Equals('1')) - { - Console.WriteLine("Entrez votre nouveau mot de passe"); - Upassword = Console.ReadLine(); - u.SetPassword(Upassword); - } - if (choixModif.Equals('2')) - { - Console.WriteLine("Entrez votre nouvelle adresse mail"); - Umail = Console.ReadLine(); - u.SetEmail(Umail); - } + default: + Console.WriteLine("\nEntrez un choix valide.\n"); break; + } - case "24":///Modifier le texte de la note - n.VerifyPrivilege(u); - if (true) - { - string texte = Console.ReadLine(); - n.SetTextLine(texte); - } - else - { - Console.WriteLine("Vous ne possedez pas les droits pour effectuer cette action."); - } - break; + while(note) + { + Console.WriteLine("\n|--------------------------------------|"); + Console.WriteLine("| |"); + Console.WriteLine("| menu - note |"); + Console.WriteLine("| |"); + Console.WriteLine("|--------------------------------------|--------|"); + Console.WriteLine("| |"); + Console.WriteLine("| 1/ - afficher la liste des notes - |"); + Console.WriteLine("| 2/ - afficher une note - |"); + Console.WriteLine("| 3/ - modifier une note - |"); + Console.WriteLine("| 4/ - écrire dans une note - |"); + Console.WriteLine("| 5/ - créer note - |"); + Console.WriteLine("| 6/ - supprimer note - |"); + Console.WriteLine("| 7/ - retour - |"); + Console.WriteLine("| |"); + Console.WriteLine("|-----------------------------------------------|\n"); + Console.WriteLine("note actuelle : " + n.GetName()); + Console.WriteLine("rentrez votre choix."); + switch (Console.ReadLine()) + { + case "1": + displayNote(); + break; + case "2": + if (!choix_note()) { break; } + Console.WriteLine("\n" + n.GetName() + " :"); + Console.WriteLine(n.GetText()); + break; + case "3": + if (!choix_note()) { break;} + Console.WriteLine("\nChoisissez le nouveau nom de la note (entrer - nom par defaut)"); + string? wantedNewNameNote = Console.ReadLine(); + wantedNewNameNote??= ""; + n.SetName(wantedNewNameNote); + break; + case "4": + if (!choix_note()) { break; } + Console.WriteLine(n.GetText()); + Console.WriteLine("\nEntrez le texte à ajouter"); + string? wantedTextNote = Console.ReadLine(); + wantedTextNote??= ""; + n.AddText(wantedTextNote); + break; + case "5": + Console.WriteLine("\nChoisissez le nom de la note (entrer - nom par defaut)"); + string? wantedNameNote = Console.ReadLine(); + wantedNameNote ??= ""; + u.CreateNote(wantedNameNote, ""); + break; + case "6": + Console.WriteLine("\nChoisissez le nom de la note"); + string? wantedDeleteNote = Console.ReadLine(); + wantedDeleteNote ??= ""; + try + { + u.DeleteNote(wantedDeleteNote); + } + catch (Exception ex) { Console.WriteLine(ex.Message); } + break; + case "7": + note = false; + break; + default: + Console.WriteLine("\nEntrez un choix valide.\n"); + break; + } + } - case "25":///Partager la note - n.VerifyPrivilege(u); - if (true) - { - Console.WriteLine("Saisissez un utilisateur"); - nom = Console.ReadLine(); - user = db.GetUser(nom); - n.AddCollaborator(u, user); - } - break; + while (tags) + { + Console.WriteLine("\n|--------------------------------------|"); + Console.WriteLine("| |"); + Console.WriteLine("| menu - tags |"); + Console.WriteLine("| |"); + Console.WriteLine("|--------------------------------------|--------|"); + Console.WriteLine("| |"); + Console.WriteLine("| 1/ - créer tag - |"); + Console.WriteLine("| 2/ - ajouter tag - |"); + Console.WriteLine("| 3/ - supprimer tag - |"); + Console.WriteLine("| 4/ - retour - |"); + Console.WriteLine("| |"); + Console.WriteLine("|-----------------------------------------------|\n"); + Console.WriteLine("rentrez votre choix."); + switch (Console.ReadLine()) + { + case "1": + Console.WriteLine("\nChoisissez le nom du tag."); + string? wantedNameTag = Console.ReadLine(); + wantedNameTag??= "NoName" + u.GetTagList().Count.ToString(); + Console.WriteLine("\nChoisissez la couleur du tag."); + string? wantedColorTag = Console.ReadLine(); + wantedColorTag??= "#000000"; + if (wantedColorTag[0] != '#') { wantedColorTag = "#" + wantedColorTag; } + else if (wantedColorTag.Length < 7) { string toadd=""; for(int i = 7-wantedColorTag.Length; i!=0; i--){toadd += "0";} wantedColorTag += toadd ;} + else if (wantedColorTag.Length > 7) { wantedColorTag = wantedColorTag[..7];} + u.CreateTag(wantedNameTag,wantedColorTag); + break; + case "2": + Note wantedAddNote; + Tags wantedAddTag; + Console.WriteLine("\n Plusieurs tags à ajouter ? (o/N)"); + string? wantedAddMultipleTag = Console.ReadLine(); + wantedAddMultipleTag ??= "N"; + if(wantedAddMultipleTag == "o" || wantedAddMultipleTag == "O"){ + displayNote(); + Console.WriteLine("\nDonnez le nom de la note à laquelle ajouter des tags : "); + string? wantedAddNameNote = Console.ReadLine(); + wantedAddNameNote??= ""; + try{ + wantedAddNote = u.GetNoteByName(wantedAddNameNote); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + displayTag(); + Console.WriteLine("\nChoisissez les noms des tags séparés par des espaces."); + string? wantedAddNameTags = Console.ReadLine(); + wantedAddNameTags??= ""; + string[] wantedAddNameTagsList = wantedAddNameTags.Split(' '); + foreach(string wantedAddNameTag in wantedAddNameTagsList) + { + try + { + wantedAddTag = u.GetTagByName(wantedAddNameTag); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + try + { + u.AddTagToNoteList(wantedAddNote, wantedAddTag); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + } + }else if(wantedAddMultipleTag == "n" || wantedAddMultipleTag == "N"){ + displayNote(); + Console.WriteLine("\nChoisissez le nom de la note."); + string? wantedAddNameNote = Console.ReadLine(); + wantedAddNameNote??= ""; + displayTag(); + Console.WriteLine("\nChoisissez le nom du tag."); + string? wantedAddNameTag = Console.ReadLine(); + wantedAddNameTag??= ""; + try + { + wantedAddNote = u.GetNoteByName(wantedAddNameNote); + wantedAddTag = u.GetTagByName(wantedAddNameTag); + u.AddTagToNoteList(wantedAddNote, wantedAddTag); + }catch (Exception ex) { Console.WriteLine(ex.Message); } + }else{ + Console.WriteLine("\nEntrez un choix valide.\n"); + } + break; + case "3": + displayNote(); + Note wantedRemoveNote; + Tags wantedRemoveTag; + Console.WriteLine("\n Choisissez le nom de la note à laquelle supprimer des tags : "); + string? wantedRemoveNameNote = Console.ReadLine(); + wantedRemoveNameNote??= ""; + try{ + wantedRemoveNote = u.GetNoteByName(wantedRemoveNameNote); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + foreach( Tags t in u.GetNoteTaggedList(wantedRemoveNote)) + { + Console.WriteLine(t.GetName() + "\n"); + } + Console.WriteLine("\nChoisissez le nom du tag à supprimer."); + string? wantedRemoveNameTag = Console.ReadLine(); + wantedRemoveNameTag??= ""; + try { + wantedRemoveTag = u.GetTagByName(wantedRemoveNameTag); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + try + { + u.RemoveTagFromNoteList(wantedRemoveNote, wantedRemoveTag); + }catch (Exception ex) { Console.WriteLine(ex.Message); } + break; + case "4": + tags = false; + break; + default: + Console.WriteLine("\nEntrez un choix valide.\n"); + break; + } + } - case "26":///Modifier les editeurs - Console.WriteLine("Ajouter editeur ou supprimer editeur ? (0/1)"); - choix = Console.ReadLine(); - n.VerifyPrivilege(u); - if (true && choix.Equals('0')) - { - Console.WriteLine("Saisissez un utilisateur"); - nom = Console.ReadLine(); - user = db.GetUser(nom); - n.AddEditor(u, user); - } - if (true && choix.Equals('1')) + while(para) + { + Console.WriteLine("\n|--------------------------------------|"); + Console.WriteLine("| |"); + Console.WriteLine("| menu - paramêtre |"); + Console.WriteLine("| |"); + Console.WriteLine("|--------------------------------------|--------|"); + Console.WriteLine("| |"); + Console.WriteLine("| 1/ - modifier compte - |"); + Console.WriteLine("| 2/ - thèmes - |"); + Console.WriteLine("| 3/ - supprimer un compte - |"); + Console.WriteLine("| 4/ - retour - |"); + Console.WriteLine("| |"); + Console.WriteLine("|-----------------------------------------------|\n"); + Console.WriteLine("rentrez votre choix."); + switch (Console.ReadLine()) + { + case "1": + paraCompte = true; + break; + case "2": + theme = true; + break; + case "3": + Console.WriteLine("\nÊtes-vous sûr de vouloir supprimer votre compte ? (o/N)"); + string? wantedDelete = Console.ReadLine(); + wantedDelete??= "N"; + if( wantedDelete == "o" || wantedDelete == "O"){ + db.RemoveUser(u); + Console.WriteLine("\nVotre compte a bien été supprimé.\n"); + para = false; + u = uvide; + break; + }else if( wantedDelete == "n" || wantedDelete == "N"){ + break; + } + break; + case "4": + para = false; + break; + default: + Console.WriteLine("\nEntrez un choix valide.\n"); + break; + } + while (paraCompte) + { + Console.WriteLine("\n|--------------------------------------|"); + Console.WriteLine("| |"); + Console.WriteLine("| paramêtre - compte |"); + Console.WriteLine("| |"); + Console.WriteLine("|--------------------------------------|--------|"); + Console.WriteLine("| |"); + Console.WriteLine("| 1/ - modifier pseudo - |"); + Console.WriteLine("| 2/ - modifier mot de passe - |"); + Console.WriteLine("| 3/ - retour - |"); + Console.WriteLine("| |"); + Console.WriteLine("|-----------------------------------------------|\n"); + Console.WriteLine("rentrez votre choix."); + switch (Console.ReadLine()) { - Console.WriteLine("Saisissez un utilisateur"); - nom = Console.ReadLine(); - user = db.GetUser(nom); - n.RemoveEditor(u, user); + case "1": + Console.WriteLine("\nChoisissez le nouveau pseudo."); + string? wantedNewPseudo = Console.ReadLine(); + if(wantedNewPseudo == null){break;} + u.SetUsername(wantedNewPseudo); + break; + case "2": + Console.WriteLine("\nChoisissez le nouveau mot de passe."); + string? wantedNewPassword = Console.ReadLine(); + if(wantedNewPassword == null){break;} + else if(wantedNewPassword.Length < 8){ + Console.WriteLine("\nLe mot de passe doit contenir au moins 8 caractères.\n"); + break; + } + wantedNewPassword = GetSHA256Hash(wantedNewPassword); + if(wantedNewPassword == u.GetPassword()){ + Console.WriteLine("\nLe nouveau mot de passe doit être différent de l'ancien.\n"); + break; + } + u.SetPassword(wantedNewPassword); + break; + case "3": + paraCompte = false; + break; + default: + Console.WriteLine("\nEntrez un choix valide.\n"); + break; } - break; - - case "27":///Supprimer un cooperateur - n.VerifyPrivilege(u); - if (true) + } + while (theme) + { + Console.WriteLine("\n|--------------------------------------|"); + Console.WriteLine("| |"); + Console.WriteLine("| paramêtre - thèmes |"); + Console.WriteLine("| |"); + Console.WriteLine("|--------------------------------------|--------|"); + Console.WriteLine("| |"); + Console.WriteLine("| 1/ - choisir un thème - |"); + Console.WriteLine("| 2/ - créer un thème - |"); + Console.WriteLine("| 3/ - supprimer un thème - |"); + Console.WriteLine("| 4/ - modifier un thème - |"); + Console.WriteLine("| 5/ - retour - |"); + Console.WriteLine("| |"); + Console.WriteLine("|-----------------------------------------------|\n"); + Console.WriteLine("rentrez votre choix."); + switch (Console.ReadLine()) { - Console.WriteLine("Saisissez un utilisateur"); - nom = Console.ReadLine(); - user = db.GetUser(nom); - n.RemoveCollaborator(u, user); + case "1": + Theme twantedTheme; + displayTheme(); + Console.WriteLine("\nChoisissez le nom du thème."); + string? wantedTheme = Console.ReadLine(); + if(wantedTheme==null){break;} + try + { + twantedTheme = db.GetTheme(wantedTheme); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + u.SetTheme(twantedTheme); + break; + case "2": + List? themeList; + Console.WriteLine("\nChoisissez le nom du thème."); + string? wantedNewThemeName = Console.ReadLine(); + if(wantedNewThemeName==null){break;} + Console.WriteLine("\nChoisissez la couleur du thème."); + themeList = choix_couleur(); + if(themeList == null) { break;} + db.AddTheme(new Theme(wantedNewThemeName, themeList)); + break; + case "3": + Theme t; + Console.WriteLine("\nChoisissez le nom du thème à supprimer."); + string? wantedRemoveTheme = Console.ReadLine(); + if(wantedRemoveTheme == null) {break;} + try{ + t = db.GetTheme(wantedRemoveTheme); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + try{ + db.RemoveTheme(t); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + break; + case "4": + displayTheme(); + Theme themeToModify; + Console.WriteLine("\nChoisissez le nom du thème à modifier."); + string? wantedModifyTheme = Console.ReadLine(); + if(wantedModifyTheme == null){break;} + try{ + themeToModify = db.GetTheme(wantedModifyTheme); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + Console.WriteLine("\nChoisissez le nouveau nom du thème."); + string? wantedNewNameTheme = Console.ReadLine(); + if(wantedNewNameTheme == null) {break;} + try{ + db.ModifyThemeName(themeToModify, wantedNewNameTheme); + }catch (Exception ex) { Console.WriteLine(ex.Message); break;} + Console.WriteLine("\nChoisissez les nouvelles couleurs du thème."); + List? couleurlist = choix_couleur(); + if(couleurlist == null) { break;} + db.ModifyThemeColorList(themeToModify, couleurlist); + break; + case "5": + theme = false; + break; + default: + Console.WriteLine("\nEntrez un choix valide.\n"); + break; } - break; - default: - Console.WriteLine("< Veuillez rentrer une des options proposées à l'ecran ! >"); - break; + } } } \ No newline at end of file diff --git a/notus/Notus_Persistence/Stub.cs b/notus/Notus_Persistence/Stub.cs index bacfd14..60698d4 100644 --- a/notus/Notus_Persistence/Stub.cs +++ b/notus/Notus_Persistence/Stub.cs @@ -10,10 +10,9 @@ namespace Notus_Persistance { public class Stub : IManager { - void errorMess() + public void SaveDatabaseData(Database database) { - Console.WriteLine("Pas d'enregistrement de données dans le stub."); - return; + throw new NotImplementedException(); } //Loaders @@ -24,103 +23,15 @@ namespace Notus_Persistance database.AddUser(new User("Benjamin", "labsent@gmail.com", "Moto2005")); database.AddUser(new User("Liam", "liammonchanin@gmail.com", "Baguette")); database.AddUser(new User("Brigitte", "Macroutte@gmail.com", "49Trois")); + foreach(User user in database.GetUserList().Where(x => x.GetUsername().Contains("m"))) + { + user.CreateNote("Note 1", ""); + user.CreateNote("Note 2", ""); + user.CreateNote("Note 3", ""); + } return database; } - List IManager.LoadUserData() - { - List users = new List(); - users.Add(new User("Nicolas", "leHeros@gmail.com", "Feur")); - users.Add(new User("Benjamin", "labsent@gmail.com", "Moto2005")); - users.Add(new User("Liam", "liammonchanin@gmail.com", "Baguette")); - users.Add(new User("Brigitte", "Macroutte@gmail.com", "49Trois")); - return users; - } - - List IManager.LoadNote() - { - List notes = new List(); - notes.Add(new Note("Note_1", "Logo_1", new User("Liam", "Liam@gmail.com", "Oui"))); - notes.Add(new Note("Note_2", "Logo_3", new User("Liam", "Liam@gmail.com", "Oui"))); - notes.Add(new Note("Note_3", "Logo_5", new User("Liam", "Liam@gmail.com", "Oui"))); - notes.Add(new Note("Note_4", "Logo_7", new User("Liam", "Liam@gmail.com", "Oui"))); - notes.Add(new Note("Note_5", "Logo_9", new User("Liam", "Liam@gmail.com", "Oui"))); - return notes; - } - - List IManager.LoadTheme() - { - List themes = new List(); - themes.Add(new Theme("Tropiques", new List { })); - themes.Add(new Theme("Savane", new List { })); - themes.Add(new Theme("Nuit", new List { })); - return themes; - } - - List IManager.LoadLogo() - { - List logos = new List(); - logos.Add(new Logo("pinguin", "pinguin.png")); - logos.Add(new Logo("ours", "ours.png")); - logos.Add(new Logo("caddie", "caddie.png")); - logos.Add(new Logo("croix", "croix.png")); - return logos; - } - - List IManager.LoadTags() - { - List tags = new List(); - tags.Add(new Tags("courses", "vert")); - tags.Add(new Tags("urgent", "rouge")); - tags.Add(new Tags("enfants", "bleu")); - return tags; - } - - List IManager.LoadNoteImage() - { - List noteImages = new List(); - noteImages.Add(new NoteImage(1, "soupe.png", "2.4")); - noteImages.Add(new NoteImage(2, "baguette.png", "5.2")); - noteImages.Add(new NoteImage(3, "cailloux.png", "3.10")); - return noteImages; - } - - //Savers - void IManager.SaveNote(Note note) - { - errorMess(); - } - - void IManager.SaveDatabaseData(Database database) - { - errorMess(); - } - - void IManager.SaveUserData(User user) - { - errorMess(); - } - - void IManager.SaveTheme(Theme theme) - { - errorMess(); - } - - void IManager.SaveLogo(Logo logo) - { - errorMess(); - } - - void IManager.SaveTags(Tags tag) - { - errorMess(); - } - - void IManager.SaveNoteImage(NoteImage noteImage) - { - errorMess(); - } - } } diff --git a/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs b/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs index c4d1d5a..158b138 100644 --- a/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs +++ b/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs @@ -19,9 +19,7 @@ namespace Notus_UnitTest_Database [Test] public void GetLogoLink_LogoExists_ReturnsLogoLink() { - string logoName = "Logo2"; - string logoLink = database.GetLogoLink(logoName); - Assert.That(logoLink, Is.EqualTo("link2")); + Assert.That(database.GetLogoLink("Logo2"), Is.EqualTo("link2")); } [Test] diff --git a/notus/Tests/Notus_UnitTest_Database/ModifyThemeColorListTests.cs b/notus/Tests/Notus_UnitTest_Database/ModifyThemeColorListTests.cs index a75f241..0593201 100644 --- a/notus/Tests/Notus_UnitTest_Database/ModifyThemeColorListTests.cs +++ b/notus/Tests/Notus_UnitTest_Database/ModifyThemeColorListTests.cs @@ -29,15 +29,5 @@ namespace Notus_UnitTest_Database Assert.That(theme.GetColor(1), Is.EqualTo(newColorList[1])); Assert.That(theme.GetColor(2), Is.EqualTo(newColorList[2])); } - - [Test] - public void ModifyThemeColorList_NonExistingTheme_ThrowsException() - { - List listcolor = new List() { "Blue", "Dark", "Grey" }; - Theme theme = new Theme("ocean", listcolor); - // no add :) - List newColorList = new List { "Red", "Green", "Blue" }; - Assert.Throws(() => database.ModifyThemeColorList(theme, newColorList), "Theme not found."); - } } } diff --git a/notus/Tests/Notus_UnitTest_User/SearchNoteByNameTests.cs b/notus/Tests/Notus_UnitTest_User/SearchNoteByNameTests.cs index 2f99de4..c4d03f4 100644 --- a/notus/Tests/Notus_UnitTest_User/SearchNoteByNameTests.cs +++ b/notus/Tests/Notus_UnitTest_User/SearchNoteByNameTests.cs @@ -5,34 +5,55 @@ namespace Notus_UnitTest_User [TestFixture] public class SearchNoteByNameTests { + private User owner; + private string searchName; + + [SetUp] + public void SetUp() + { + owner = new("Owner", "owner@example.com", "password"); + owner.CreateNote("Note 1", "image1.png"); + owner.CreateNote("Note 2", "image2.png"); + owner.CreateNote("Another Note", "image3.png"); + owner.AddFavorite(owner.GetNoteList()[0]); + owner.AddFavorite(owner.GetNoteList()[1]); + owner.AddFavorite(owner.GetNoteList()[2]); + searchName = "note"; + } + [Test] public void SearchNoteByName_WhenMatchingNotesExist_NotesReturned() { - User user = new User("TestUser", "testuser@example.com", "password"); - Note note1 = new Note("Note 1", "image1.png", user); - Note note2 = new Note("Note 2", "image2.png", user); - Note note3 = new Note("Another Note", "image3.png", user); - user.GetNoteList().Add(note1); - user.GetNoteList().Add(note2); - user.GetNoteList().Add(note3); - List result = user.SearchNoteByName("note"); - Assert.That(result.Count, Is.EqualTo(3)); - CollectionAssert.Contains(result, note1); - CollectionAssert.Contains(result, note2); - CollectionAssert.Contains(result, note3); + List result = owner.SearchNoteByName(owner.GetNoteList(),"note"); + Assert.That(result, Has.Count.EqualTo(3)); + CollectionAssert.Contains(result, owner.GetNoteList()[0]); + CollectionAssert.Contains(result, owner.GetNoteList()[1]); + CollectionAssert.Contains(result, owner.GetNoteList()[2]); } [Test] public void SearchNoteByName_WhenNoMatchingNotesExist_EmptyListReturned() { - User user = new User("TestUser", "testuser@example.com", "password"); - Note note1 = new Note("Note 1", "image1.png", user); - Note note2 = new Note("Note 2", "image2.png", user); - user.GetNoteList().Add(note1); - user.GetNoteList().Add(note2); - List result = user.SearchNoteByName("test"); - Assert.IsEmpty(result); + List result = owner.SearchNoteByName(owner.GetNoteList(), "test"); + Assert.That(result, Is.Empty); + } + + [Test] + public void SearchFavoriteNoteByName_ShouldReturnMatchingNotes() + { + List searchedNotes = owner.SearchNoteByName(owner.GetFavList(), searchName); + Assert.That(searchedNotes, Has.Count.EqualTo(3)); + CollectionAssert.Contains(searchedNotes, owner.GetNoteList()[0]); + CollectionAssert.Contains(searchedNotes, owner.GetNoteList()[1]); + CollectionAssert.Contains(searchedNotes, owner.GetNoteList()[2]); } + [Test] + public void SearchFavoriteNoteByName_ShouldReturnEmptyList_WhenNoMatchFound() + { + searchName = "nonexistent"; + List searchedNotes = owner.SearchNoteByName(owner.GetFavList(), searchName); + Assert.That(searchedNotes, Is.Empty); + } } } \ No newline at end of file