From 41fd49d19a5c13ef7a011f180031902cc33c477e Mon Sep 17 00:00:00 2001 From: Matheo THIERRY Date: Tue, 16 May 2023 16:18:33 +0200 Subject: [PATCH 1/7] ADD basic files --- .drone.yml | 3 ++- notus/Notus_Persistence/IDataManager.cs | 7 +++++++ notus/Notus_Persistence/Notus_Persistance.csproj | 9 +++++++++ notus/Notus_Persistence/ToJSON.cs | 12 ++++++++++++ notus/Notus_Persistence/ToXML.cs | 12 ++++++++++++ notus/notus.sln | 12 +++++++++--- notus/notus_vue/notus_vue.csproj | 2 +- 7 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 notus/Notus_Persistence/IDataManager.cs create mode 100644 notus/Notus_Persistence/Notus_Persistance.csproj create mode 100644 notus/Notus_Persistence/ToJSON.cs create mode 100644 notus/Notus_Persistence/ToXML.cs diff --git a/.drone.yml b/.drone.yml index d373d05..63d2338 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,7 +4,8 @@ name: pipelinefordeveloppement trigger: branch: - - vSonar_test + - developpement + - master event: - push diff --git a/notus/Notus_Persistence/IDataManager.cs b/notus/Notus_Persistence/IDataManager.cs new file mode 100644 index 0000000..e330abe --- /dev/null +++ b/notus/Notus_Persistence/IDataManager.cs @@ -0,0 +1,7 @@ +namespace Notus_Persistance +{ + public class IDataManager + { + + } +} \ No newline at end of file diff --git a/notus/Notus_Persistence/Notus_Persistance.csproj b/notus/Notus_Persistence/Notus_Persistance.csproj new file mode 100644 index 0000000..4658cbf --- /dev/null +++ b/notus/Notus_Persistence/Notus_Persistance.csproj @@ -0,0 +1,9 @@ + + + + net7.0 + enable + enable + + + diff --git a/notus/Notus_Persistence/ToJSON.cs b/notus/Notus_Persistence/ToJSON.cs new file mode 100644 index 0000000..ec65800 --- /dev/null +++ b/notus/Notus_Persistence/ToJSON.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_Persistance +{ + internal class ToJSON + { + } +} diff --git a/notus/Notus_Persistence/ToXML.cs b/notus/Notus_Persistence/ToXML.cs new file mode 100644 index 0000000..29f400f --- /dev/null +++ b/notus/Notus_Persistence/ToXML.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_Persistance +{ + internal class ToXML + { + } +} diff --git a/notus/notus.sln b/notus/notus.sln index 84bd64d..e04e97e 100644 --- a/notus/notus.sln +++ b/notus/notus.sln @@ -3,11 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.0.31611.283 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "notus_vue", "notus_vue\notus_vue.csproj", "{561264A1-4611-40FB-A662-3EF65550CA71}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_Vue", "notus_vue\Notus_Vue.csproj", "{561264A1-4611-40FB-A662-3EF65550CA71}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Biblioteque_de_Class", "Biblioteque_de_Class\Biblioteque_de_Class.csproj", "{92DD50C5-EEAD-44ED-AEFF-E21935725477}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Biblioteque_de_Class", "Biblioteque_de_Class\Biblioteque_de_Class.csproj", "{92DD50C5-EEAD-44ED-AEFF-E21935725477}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_Console", "Notus_Console\Notus_Console.csproj", "{0A5E5F33-6B39-42BF-A46D-0752EDB666FB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_Console", "Notus_Console\Notus_Console.csproj", "{0A5E5F33-6B39-42BF-A46D-0752EDB666FB}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_Persistance", "Notus_Persistence\Notus_Persistance.csproj", "{184478A9-E14F-42E0-B963-B3A4474C9C1C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -29,6 +31,10 @@ Global {0A5E5F33-6B39-42BF-A46D-0752EDB666FB}.Debug|Any CPU.Build.0 = Debug|Any CPU {0A5E5F33-6B39-42BF-A46D-0752EDB666FB}.Release|Any CPU.ActiveCfg = Release|Any CPU {0A5E5F33-6B39-42BF-A46D-0752EDB666FB}.Release|Any CPU.Build.0 = Release|Any CPU + {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/notus/notus_vue/notus_vue.csproj b/notus/notus_vue/notus_vue.csproj index 64d92a7..0f358b2 100644 --- a/notus/notus_vue/notus_vue.csproj +++ b/notus/notus_vue/notus_vue.csproj @@ -6,7 +6,7 @@ Exe - notus + Notus_Vue true true enable From d6a319d600647af8186509817de4257f0e0acb48 Mon Sep 17 00:00:00 2001 From: Matheo THIERRY Date: Tue, 16 May 2023 17:26:26 +0200 Subject: [PATCH 2/7] ADD stub --- notus/Notus_Persistence/Stub.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 notus/Notus_Persistence/Stub.cs diff --git a/notus/Notus_Persistence/Stub.cs b/notus/Notus_Persistence/Stub.cs new file mode 100644 index 0000000..976d3de --- /dev/null +++ b/notus/Notus_Persistence/Stub.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_Persistance +{ + internal class Stub + { + } +} + From aff1a84ff1ede0f12e1af364b0afc4961198aac6 Mon Sep 17 00:00:00 2001 From: "matheo.thierry" Date: Thu, 18 May 2023 10:31:40 +0200 Subject: [PATCH 3/7] =?UTF-8?q?transfers=20francais=20=C3=A0=20englais?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- notus/Biblioteque_de_Class/Database.cs | 182 +++++++---------- notus/Biblioteque_de_Class/Logo.cs | 18 +- notus/Biblioteque_de_Class/Note.cs | 124 ++++++------ notus/Biblioteque_de_Class/NoteImage.cs | 17 +- notus/Biblioteque_de_Class/Tags.cs | 19 +- notus/Biblioteque_de_Class/Theme.cs | 28 +-- notus/Biblioteque_de_Class/User.cs | 230 ++++++++++++++++++++++ notus/Biblioteque_de_Class/Utilisateur.cs | 202 ------------------- notus/Notus_Console/Program.cs | 6 +- 9 files changed, 411 insertions(+), 415 deletions(-) create mode 100644 notus/Biblioteque_de_Class/User.cs delete mode 100644 notus/Biblioteque_de_Class/Utilisateur.cs diff --git a/notus/Biblioteque_de_Class/Database.cs b/notus/Biblioteque_de_Class/Database.cs index 44d7da1..488b487 100644 --- a/notus/Biblioteque_de_Class/Database.cs +++ b/notus/Biblioteque_de_Class/Database.cs @@ -10,89 +10,81 @@ namespace Biblioteque_de_Class { public class Database { - private List ListDefaultLogo; - private List ListTheme; - private List ListUtilisateur; + private List DefaultLogoList; + private List ThemeList; + private List UserList; - public Database() - { - ListDefaultLogo = new List(); - ListTheme = new List(); - ListUtilisateur = new List(); + public Database() + { + DefaultLogoList = new List(); + ThemeList = new List(); + UserList = new List(); } - public List GetListDefaultLogo() { return ListDefaultLogo; } - public List GetListTheme() { return ListTheme; } - public List GetListUtilisateur() { return ListUtilisateur; } + public List GetDefaultLogoList() { return DefaultLogoList; } + public List GetThemeList() { return ThemeList; } + public List GetUserList() { return UserList; } /// /// recherche un utilisateur dans la liste d'utilisateur /// - public List RechercherUtilisateur(string name) + public List SearchUser(string name) { - List ListUserSearch = new List(); + List searchedUsers = new List(); string search = name.ToLower(); - foreach (Utilisateur user in ListUtilisateur) + foreach (User user in UserList) { - if (user.GetPseudo().ToLower().Contains(search)) { ListUserSearch.Add(user); } + if (user.GetUsername().ToLower().Contains(search)) { searchedUsers.Add(user); } } - return ListUserSearch; + return searchedUsers; } /// /// récupérer le lien d'un logo /// - public string GetLinkLogo(string Name) + public string GetLogoLink(string name) { - foreach (Logo logo in ListDefaultLogo) + foreach (Logo logo in DefaultLogoList) { - if (logo.GetNom() == Name) { return logo.GetNom(); } - }throw new Exception("no logo link find"); + if (logo.GetName() == name) { return logo.GetLink(); } + } + throw new Exception("No logo link found."); } /// /// récupérer un utilisateur /// - public Utilisateur GetUtilisateur(string Name) - { - foreach(Utilisateur user in ListUtilisateur){ - if(user.GetPseudo() == Name) + public User GetUser(string name) + { + foreach (User user in UserList) + { + if (user.GetUsername() == name) { return user; } - }throw new Exception("no user find with this pseudo"); + } + throw new Exception("No user found with this username."); } /// /// comparer le mot de passe entré avec celui de l'utilisateur /// - public bool CorrespondPassword(Utilisateur user, string Psd) + public bool ComparePassword(User user, string password) { - if (user.GetPassword() == Psd) - { - return true; - } - else - { - return false; - } + return user.GetPassword() == password; } /// /// rechercher un mail dans la liste d'utilisateur /// - public bool TrouverMail(string mail) + public bool FindEmail(string email) { - foreach (Utilisateur Mail in ListUtilisateur) + foreach (User user in UserList) { - if (string.Equals(mail,Mail)) + if (string.Equals(user.GetEmail(), email)) { return true; } - else - { - return false; - } } return false; } @@ -100,137 +92,115 @@ namespace Biblioteque_de_Class /// /// ajouter un utilisateur dans la liste d'utilisateur /// - public void AjouterUtilisateur(Utilisateur user) + public void AddUser(User user) { - foreach (Utilisateur user1 in ListUtilisateur) + foreach (User existingUser in UserList) { - if (user1.GetPseudo() == user.GetPseudo()) - { - throw new Exception("Pseudo déjà utilisé"); - } - else if (user1.GetMail() == user.GetMail()) + if (existingUser.GetUsername() == user.GetUsername()) { - throw new Exception("Mail déjà utilisé"); + throw new Exception("Username already used."); } - else + else if (existingUser.GetEmail() == user.GetEmail()) { - ListUtilisateur.Add(user); + throw new Exception("Email already used."); } } + UserList.Add(user); } /// /// supprimer un utilisateur dans la liste d'utilisateur /// - public void SupUtilisateur(Utilisateur user) + public void RemoveUser(User user) { - foreach (Utilisateur user1 in ListUtilisateur) + if (UserList.Contains(user)) { - if (user1.GetPseudo() == user.GetPseudo()) - { - ListUtilisateur.Remove(user); - } - else - { - throw new Exception("Utilisateur non trouvé"); - } + UserList.Remove(user); + } + else + { + throw new Exception("User not found."); } } /// /// ajouter un theme dans la liste de theme /// - public void AjouterTheme(Theme stheme) + public void AddTheme(Theme theme) { - List ListTheme = GetListTheme(); - foreach (Theme theme in ListTheme) + foreach (Theme existingTheme in ThemeList) { - if (theme.GetNom() == stheme.GetNom()) - { - throw new Exception("Theme déjà utilisé"); - } - else + if (existingTheme.GetName() == theme.GetName()) { - ListTheme.Add(stheme); + throw new Exception("Theme already used."); } } + ThemeList.Add(theme); } /// /// supprimer un theme dans la liste de theme /// - public void SupTheme(Theme stheme) + public void RemoveTheme(Theme theme) { - List ListTheme = GetListTheme(); - foreach (Theme theme in ListTheme) + if (ThemeList.Contains(theme)) { - if (theme.GetNom() == stheme.GetNom()) - { - ListTheme.Remove(theme); - } - else - { - throw new Exception("Theme non trouvé"); - } + ThemeList.Remove(theme); + } + else + { + throw new Exception("Theme not found."); } } /// /// récupérer un theme /// - public Theme GetTheme(string Name) + public Theme GetTheme(string name) { - List ListTheme = GetListTheme(); - foreach (Theme theme in ListTheme) + foreach (Theme theme in ThemeList) { - if (theme.GetNom() == Name) + if (theme.GetName() == name) { return theme; } } - throw new Exception("no theme find with this name"); + throw new Exception("No theme found with this name."); } /// /// modifier le nom d'un theme /// - public void ModifierNomTheme( Theme stheme, string NewName) + public void ModifyThemeName(Theme theme, string newName) { - foreach (Theme theme1 in ListTheme) + foreach (Theme existingTheme in ThemeList) { - if (theme1.GetNom() == stheme.GetNom()) - { - theme1.SetNom(NewName); - } - else + if (existingTheme.GetName() == theme.GetName()) { - throw new Exception("Theme non trouvé"); + existingTheme.SetName(newName); + return; } } + throw new Exception("Theme not found."); } /// /// modifier la liste de couleur d'un theme /// - public void ModifierColorListTheme(Theme stheme, List NewColorList) + public void ModifyThemeColorList(Theme theme, List newColorList) { - foreach (Theme theme1 in ListTheme) + foreach (Theme existingTheme in ThemeList) { - if (theme1.GetNom() == stheme.GetNom()) + if (existingTheme.GetName() == theme.GetName()) { for (int i = 0; i < 3; i++) { - theme1.ChangeColor(theme1.GetColor(i), NewColorList[i]); + existingTheme.ChangeColor(existingTheme.GetColor(i), newColorList[i]); } - } - else - { - throw new Exception("Theme non trouvé"); + return; } } + throw new Exception("Theme not found."); } - - - } -} +} \ No newline at end of file diff --git a/notus/Biblioteque_de_Class/Logo.cs b/notus/Biblioteque_de_Class/Logo.cs index baee17b..4fdb203 100644 --- a/notus/Biblioteque_de_Class/Logo.cs +++ b/notus/Biblioteque_de_Class/Logo.cs @@ -8,18 +8,18 @@ namespace Biblioteque_de_Class { public class Logo { - private string Nom { get; set; } - private string LinkLogo { get; set; } - - public Logo(string nom, string linklogo) + private string Name { get; set; } + private string LogoLink { get; set; } + + public Logo(string name, string logoLink) { - Nom = nom; - LinkLogo = linklogo; + Name = name; + LogoLink = logoLink; } - public string GetNom() { return Nom; } - public string GetLinkLogo() { return LinkLogo; } + public string GetName() { return Name; } + public string GetLogoLink() { return LogoLink; } - public override string ToString() => $"logo -> nom : {Nom}\nlink : {LinkLogo}"; + public override string ToString() => $"Logo -> Name: {Name}\nLink: {LogoLink}"; } } diff --git a/notus/Biblioteque_de_Class/Note.cs b/notus/Biblioteque_de_Class/Note.cs index 16e384d..c33f949 100644 --- a/notus/Biblioteque_de_Class/Note.cs +++ b/notus/Biblioteque_de_Class/Note.cs @@ -8,130 +8,130 @@ namespace Biblioteque_de_Class { public class Note { - private string Nom + private string Name { - get { return Nom; } - set { if (value == null) { Nom = "Note sans nom"; } else { Nom = value; } } + get { return Name; } + set { if (value == null) { Name = "Unnamed Note"; } else { Name = value; } } } ///private string Text { get; set; } Attribut pour le texte de la note - private string LogoPATH + private string LogoPath { - get { return LogoPATH; } - set { if (value == null) { LogoPATH = "PATH TO DEFAULT LOGO"; } else { LogoPATH = value; } } + get { return LogoPath; } + set { if (value == null) { LogoPath = "PATH TO DEFAULT LOGO"; } else { LogoPath = value; } } } - private DateOnly DateCreation { get;} - private DateOnly DateModif { get; set; } - private List listeImage; - private List listeLigneTexte; - private List cooperateurs; - private List editeurs; - private Utilisateur owner; - - public Note(string nom, string logoPATH, Utilisateur uOwner) + + private DateOnly CreationDate { get; } + private DateOnly ModificationDate { get; set; } + private List ImageList; + private List TextLineList; + private List Collaborators; + private List Editors; + private User Owner; + + public Note(string name, string logoPath, User owner) { - Nom = nom; - LogoPATH = logoPATH; - DateCreation = DateOnly.FromDateTime(DateTime.Now); - DateModif = DateOnly.FromDateTime(DateTime.Now); - listeImage = new List(); - listeLigneTexte = new List(); - cooperateurs = new List(); - editeurs = new List(); - - owner = uOwner; + Name = name; + LogoPath = logoPath; + CreationDate = DateOnly.FromDateTime(DateTime.Now); + ModificationDate = DateOnly.FromDateTime(DateTime.Now); + ImageList = new List(); + TextLineList = new List(); + Collaborators = new List(); + Editors = new List(); + + Owner = owner; } - public string GetNom() { return Nom; } - public string GetLogoPATH() { return LogoPATH; } - public DateOnly GetDateCreation() { return DateCreation; } - public DateOnly GetDateModif() { return DateModif; } - public List GetListeImage() { return listeImage; } - public List GetListeLigneTexte() { return listeLigneTexte; } - public List GetCooperateurs() { return cooperateurs; } - public List GetEditeurs() { return editeurs; } - public Utilisateur GetOwner() { return owner; } + public string GetName() { return Name; } + public string GetLogoPath() { return LogoPath; } + public DateOnly GetCreationDate() { return CreationDate; } + public DateOnly GetModificationDate() { return ModificationDate; } + public List GetImageList() { return ImageList; } + public List GetTextLineList() { return TextLineList; } + public List GetCollaborators() { return Collaborators; } + public List GetEditors() { return Editors; } + public User GetOwner() { return Owner; } - public override string ToString() => $"note -> nom : {Nom}\nlogoPATH : {LogoPATH}\nhow many line : {listeLigneTexte.Count()}"; + public override string ToString() => $"Note -> Name: {Name}\nLogoPath: {LogoPath}\nNumber of lines: {TextLineList.Count()}"; - public void ModifNom(string nom) { Nom = nom; } - public void ModifLogoPATH(string logoPATH) { LogoPATH = logoPATH; } - public void ModifDateModif() { DateModif = DateOnly.FromDateTime(DateTime.Now); } + public void ModifyName(string name) { Name = name; } + public void ModifyLogoPath(string logoPath) { LogoPath = logoPath; } + public void ModifyModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); } /// /// vérifier si l'utilisateur est le propriétaire de la note /// - public bool VerifOwner(Utilisateur user) + public bool VerifyOwner(User user) { - if (user == owner) { return true; } - else { return false; } + return user == Owner; } - public void AjouterImage(string linkImage, string position) + public void AddImage(string imageLink, string position) { - foreach (NoteImage image in this.GetListeImage()) + foreach (NoteImage image in ImageList) { - if (image.GetLinkImage() == linkImage) + if (image.GetImageLink() == imageLink) { - + /// Do something } } } - public void SuppImage(string image) + public void RemoveImage(string image) { - /// il faut une nouvelle structure pour pouvoir stocker les images + /// Need a new data structure to store images } /// /// vérifier si l'utilisateur est un éditeur de la note /// - public bool VerifPriviledge(Utilisateur user) + public bool VerifyPrivilege(User user) { - if (editeurs.Contains(user)) + if (Editors.Contains(user)) { return true; } else { - throw new Exception("user is not editeur"); + throw new Exception("User is not an editor"); } } /// /// ajouter un utilisateur en tant que coopérateur /// - public void AjouterCoop(Utilisateur owner, Utilisateur user) + public void AddCollaborator(User owner, User user) { - if (VerifOwner(owner)) { cooperateurs.Add(user); } - else { throw new Exception("user is not owner"); } + if (VerifyOwner(owner)) { Collaborators.Add(user); } + else { throw new Exception("User is not the owner"); } } /// /// supprimer un utilisateur en tant que coopérateur /// - public void SupCoop(Utilisateur owner, Utilisateur user) + public void RemoveCollaborator(User owner, User user) { - if (VerifOwner(owner)) { cooperateurs.Remove(user); } - else { throw new Exception("user is not owner"); } + if (VerifyOwner(owner)) { Collaborators.Remove(user); } + else { throw new Exception("User is not the owner"); } } /// /// passer un coopérateur en tant qu'éditeur /// - public void AjouterEdit(Utilisateur owner, Utilisateur user) + public void AddEditor(User owner, User user) { - if (VerifOwner(owner)) { editeurs.Add(user); } - else { throw new Exception("user is not owner"); } + if (VerifyOwner(owner)) { Editors.Add(user); } + else { throw new Exception("User is not the owner"); } } /// /// supprimer un coopérateur de la liste des éditeurs /// - public void SupEdit(Utilisateur owner, Utilisateur user) + public void RemoveEditor(User owner, User user) { - if (VerifOwner(owner)) { editeurs.Remove(user); } - else { throw new Exception("user is not owner"); } + if (VerifyOwner(owner)) { Editors.Remove(user); } + else { throw new Exception("User is not the owner"); } } } } diff --git a/notus/Biblioteque_de_Class/NoteImage.cs b/notus/Biblioteque_de_Class/NoteImage.cs index 1be20f7..db6f85d 100644 --- a/notus/Biblioteque_de_Class/NoteImage.cs +++ b/notus/Biblioteque_de_Class/NoteImage.cs @@ -8,22 +8,21 @@ namespace Biblioteque_de_Class { public class NoteImage { - private string Nom { get; set; } - private string LinkImage { get; set; } + private string Name { get; set; } + private string ImageLink { get; set; } private string Position { get; set; } - public NoteImage(string nom, string linkimage, string position) + public NoteImage(string name, string imageLink, string position) { - Nom = nom; - LinkImage = linkimage; + Name = name; + ImageLink = imageLink; Position = position; } - public string GetNom() { return Nom; } - public string GetLinkImage() { return LinkImage; } + public string GetName() { return Name; } + public string GetImageLink() { return ImageLink; } public string GetPosition() { return Position; } - public override string ToString() => $"image -> nom : {Nom}\nlink : {LinkImage}"; - + public override string ToString() => $"image -> name: {Name}\nlink: {ImageLink}"; } } diff --git a/notus/Biblioteque_de_Class/Tags.cs b/notus/Biblioteque_de_Class/Tags.cs index 991eab8..bf0181d 100644 --- a/notus/Biblioteque_de_Class/Tags.cs +++ b/notus/Biblioteque_de_Class/Tags.cs @@ -8,19 +8,18 @@ namespace Biblioteque_de_Class { public class Tags { - private string Nom { get; set; } - private string Couleur { get; set; } - - public Tags(string nom, string couleur) + private string Name { get; set; } + private string Color { get; set; } + + public Tags(string name, string color) { - Nom = nom; - Couleur = couleur; + Name = name; + Color = color; } - public string GetNom() { return Nom; } - public string GetCouleur() { return Couleur; } + public string GetName() { return Name; } + public string GetColor() { return Color; } - public override string ToString() => $"tag -> nom : {Nom}\ncouleur : {Couleur}"; - + public override string ToString() => $"tag -> name: {Name}\ncolor: {Color}"; } } diff --git a/notus/Biblioteque_de_Class/Theme.cs b/notus/Biblioteque_de_Class/Theme.cs index d19fc66..c4d2340 100644 --- a/notus/Biblioteque_de_Class/Theme.cs +++ b/notus/Biblioteque_de_Class/Theme.cs @@ -8,32 +8,32 @@ namespace Biblioteque_de_Class { public class Theme { - private string Nom { get; set; } - private List ListCouleur; + private string Name { get; set; } + private List ColorList; - public Theme(string nom, List listCouleur) + public Theme(string name, List colorList) { - Nom = nom; - ListCouleur = listCouleur; + Name = name; + ColorList = colorList; } - public string GetNom() { return Nom; } - public void SetNom(string nom) { Nom = nom; } - public List GetColorList() { return ListCouleur; } - public string GetColor(int code) { return ListCouleur[code]; } + public string GetName() { return Name; } + public void SetName(string name) { Name = name; } + public List GetColorList() { return ColorList; } + public string GetColor(int index) { return ColorList[index]; } - public override string ToString() => $"nom : {Nom} color 1: {ListCouleur[0]}\ncolor 2: {ListCouleur[1]}\ncolor 3: {ListCouleur[2]}\n"; + public override string ToString() => $"name: {Name}\ncolor 1: {ColorList[0]}\ncolor 2: {ColorList[1]}\ncolor 3: {ColorList[2]}\n"; /// - /// changer la couleur spécifique d'un theme + /// Change a specific color of the theme. /// public void ChangeColor(string color, string newColor) { - for (int i = 0; i < ListCouleur.Count; i++) + for (int i = 0; i < ColorList.Count; i++) { - if (ListCouleur[i] == color) + if (ColorList[i] == color) { - ListCouleur[i] = newColor; + ColorList[i] = newColor; } } } diff --git a/notus/Biblioteque_de_Class/User.cs b/notus/Biblioteque_de_Class/User.cs new file mode 100644 index 0000000..0a7cf80 --- /dev/null +++ b/notus/Biblioteque_de_Class/User.cs @@ -0,0 +1,230 @@ +using Microsoft.VisualBasic.FileIO; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations.Schema; + +namespace Biblioteque_de_Class +{ + public class User + { + private string Username { get; set; } + private string Email { get; set; } + private string Password { get; set; } + private List NoteList; + private List TagList; + private List FavList; + private bool IsConnected { get; set; } + 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 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; + } + + /// + /// ajouter une note dans la liste de note favorite de l'utilisateur + /// + public void AddFavorite(Note note) + { + if (FavList.Contains(note)) + { + throw new Exception("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 Exception("Note not found"); + } + } + + /// + ///creer une note + /// + public void CreateNote(string name, string imagePath) + { + foreach (Note existingNote in NoteList) + { + if (existingNote.GetName() == name) + { + throw new Exception("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 Exception("Note not found"); + } + } + + /// + /// creer un tag + /// + public void CreateTag(string name, string color) + { + foreach (Tags tag in TagList) + { + if (tag.GetName() == name) + { + throw new Exception("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 Exception("Tag not found"); + } + if (!NoteList.Contains(note)) + { + throw new Exception("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 Exception("Tag not found"); + } + if (!NoteList.Contains(note)) + { + throw new Exception("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/Biblioteque_de_Class/Utilisateur.cs b/notus/Biblioteque_de_Class/Utilisateur.cs deleted file mode 100644 index 2d76578..0000000 --- a/notus/Biblioteque_de_Class/Utilisateur.cs +++ /dev/null @@ -1,202 +0,0 @@ -using Microsoft.VisualBasic.FileIO; -using System.ComponentModel; -using System.ComponentModel.DataAnnotations.Schema; - -namespace Biblioteque_de_Class -{ - public class Utilisateur - { - private string Pseudo { get; set; } - private string Mail { get; set; } - private string Password { get; set; } - private List NoteList; - private List TagList; - private List FavList; - private bool connecte { get; set; } - private Dictionary> NoteTaged; - - public Utilisateur(string Upseudo, string Umail, string Upassword) - { - Pseudo = Upseudo; - Mail = Umail; - Password = Upassword; - NoteList = new List(); - TagList = new List(); - FavList = new List(); - NoteTaged = new Dictionary>(); - } - - public string GetPseudo() { return Pseudo; } - public string GetMail() { return Mail; } - public string GetPassword() { return Password; } - public List GetNoteList() { return NoteList; } - public List GetTagList() { return TagList; } - public List GetFavList() { return FavList; } - public bool GetConnecte() { return connecte; } - public Dictionary> GetNoteTaged() { return NoteTaged; } - - public override string ToString() => $"pseudo : {Pseudo}\nmail : {Mail}\npassword : {Password}\nNote possédé : {NoteList.Count}"; - - /// - /// rechercher une note dans la liste de note de l'utilisateur - /// - public List RechercherNote(string name) - { - List ListNotesearch = new List(); - string search = name.ToLower(); - foreach(Note note in NoteList){ - if(note.GetNom().ToLower().Contains(search)) { ListNotesearch.Add(note); } - }return ListNotesearch; - } - - /// - /// rechercher une note dans la liste de note favoris de l'utilisateur - /// - public List RechercherNoteFav(string name) - { - List ListNotesearch = new List(); - string search = name.ToLower(); - foreach(Note note in FavList){ - if(note.GetNom().ToLower().Contains(search)) { ListNotesearch.Add(note); } - }return ListNotesearch; - } - - /// - /// rechercher un tag dans la liste de tag de l'utilisateur - /// - public List RechercherTags(string name) - { - List ListTagssearch = new List(); - string search = name.ToLower(); - foreach(Tags tag in TagList){ - if(tag.GetNom().ToLower().Contains(search)) { ListTagssearch.Add(tag); } - } - return ListTagssearch; - } - - /// - /// ajouter une note dans la liste de note favorite de l'utilisateur - /// - public void AddFav(Note note) - { - foreach(Note notefav in FavList) - { - if (notefav.Equals(note)) - { - throw new Exception("Note already in favorite"); - } - } - FavList.Add(note); - } - - /// - /// supprimer une note dans la liste de note favorite de l'utilisateur - /// - public void SupFav(Note note) - { - foreach(Note notefav in FavList) - { - if (notefav.Equals(note)) - { - FavList.Remove(note); - } - } - throw new Exception("Note not found"); - } - - /// - ///creer une note - /// - public void CreateNote(string nom, string LogoPath) - { - foreach (Note eachnote in NoteList) - { - if (eachnote.GetNom() == nom) - { - throw new Exception("Note already exist"); - } - } - Note note = new Note(nom, LogoPath,this); - NoteList.Add(note); - NoteTaged.Add(note, new List()); - } - - /// - /// supprimer une note - /// - public void DeleteNote(Note note) - { - if (NoteList.Contains(note)) - { - NoteList.Remove(note); - NoteTaged.Remove(note); - } - else - throw new Exception("Note not found"); - } - - /// - /// creer un tag - /// - public void CreateTag(string name, string color) - { - foreach(Tags tag in TagList){ - if(tag.GetNom() == name) { throw new Exception("Tag already exist"); } - } - TagList.Add(new Tags(name, color)); - } - - /// - /// supprimer un tag - /// - public void DeleteTag(string name) - { - foreach(Tags tag in TagList){ - if(tag.GetNom() == name) { TagList.Remove(tag); } - } - } - - /// - /// ajouter un tag a une note - /// - public void AddOneTagToNoteList(Note note, Tags tagtoadd) - { - if (TagList.Contains(tagtoadd) == false) { throw new Exception("Tag not found"); } - if(NoteList.Contains(note) == false) { throw new Exception("Note not found"); } - else - { - NoteTaged[note].Add(tagtoadd); - } - } - - /// - /// supprimer un tag a une note - /// - public void SupOneTagToNoteList(Note note, Tags tagtosup) - { - if (TagList.Contains(tagtosup) == false) { throw new Exception("Tag not found"); } - if(NoteList.Contains(note) == false) { throw new Exception("Note not found"); } - else - { - NoteTaged[note].Remove(tagtosup); - } - } - - /// - /// ajouter plusieur tag a une note - /// - public void AddTagToNoteList(Note note, List listTags) - { - NoteTaged.Add(note, listTags); - } - - /// - ///supprimer tout les tags d'une note - /// - public void SupTagToNoteList(Note note) - { - NoteTaged.Remove(note); - } - - } -} \ No newline at end of file diff --git a/notus/Notus_Console/Program.cs b/notus/Notus_Console/Program.cs index 5451fbf..b90abfe 100644 --- a/notus/Notus_Console/Program.cs +++ b/notus/Notus_Console/Program.cs @@ -25,10 +25,10 @@ string linkimage = "u"; List NewColorList; List listCouleurs; -Utilisateur user = new Utilisateur(Upseudo, Umail, Upassword); +User user = new User(Upseudo, Umail, Upassword); NoteImage image = new NoteImage(nom2, linkimage, position); Database db= new Database(); -Utilisateur u = new Utilisateur(Upseudo, Umail, Upassword); +User u = new User(Upseudo, Umail, Upassword); Note n = new Note(nom, logoPath, u); Tags t = new Tags(name, couleur); @@ -100,7 +100,7 @@ while (boucle == 0){ Umail = Console.ReadLine(); Console.WriteLine("Saisissez un mot de passe"); Upassword = Console.ReadLine(); - Utilisateur u1 = new Utilisateur(Upseudo, Umail, Upassword); + User u1 = new User(Upseudo, Umail, Upassword); db.AjouterUtilisateur(u1); break; From bca8018f0b82dbdb444d15c6063065068c65a50a Mon Sep 17 00:00:00 2001 From: "matheo.thierry" Date: Thu, 18 May 2023 16:55:43 +0200 Subject: [PATCH 4/7] persistance en place - attente pour test --- notus/Biblioteque_de_Class/Database.cs | 7 +- notus/Biblioteque_de_Class/Manager.cs | 13 +++ notus/Biblioteque_de_Class/User.cs | 10 ++ notus/Notus_Persistence/IDataManager.cs | 7 -- .../Notus_Persistance.csproj | 4 + notus/Notus_Persistence/PersistenceManager.cs | 33 +++++++ notus/Notus_Persistence/Stub.cs | 23 ++++- notus/Notus_Persistence/ToJSON.cs | 91 ++++++++++++++++++- notus/Notus_Persistence/ToXML.cs | 30 +++++- .../{UnitTest1.cs => UserSearchTests.cs} | 28 +++--- 10 files changed, 219 insertions(+), 27 deletions(-) create mode 100644 notus/Biblioteque_de_Class/Manager.cs delete mode 100644 notus/Notus_Persistence/IDataManager.cs create mode 100644 notus/Notus_Persistence/PersistenceManager.cs rename notus/Notus_UnitTest/{UnitTest1.cs => UserSearchTests.cs} (94%) diff --git a/notus/Biblioteque_de_Class/Database.cs b/notus/Biblioteque_de_Class/Database.cs index 488b487..a7ae603 100644 --- a/notus/Biblioteque_de_Class/Database.cs +++ b/notus/Biblioteque_de_Class/Database.cs @@ -3,15 +3,20 @@ using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; namespace Biblioteque_de_Class { + [DataContract] public class Database { + [DataMember] private List DefaultLogoList; + [DataMember] private List ThemeList; + [DataMember] private List UserList; public Database() @@ -46,7 +51,7 @@ namespace Biblioteque_de_Class { foreach (Logo logo in DefaultLogoList) { - if (logo.GetName() == name) { return logo.GetLink(); } + if (logo.GetName() == name) { return logo.GetLogoLink(); } } throw new Exception("No logo link found."); } diff --git a/notus/Biblioteque_de_Class/Manager.cs b/notus/Biblioteque_de_Class/Manager.cs new file mode 100644 index 0000000..5699a42 --- /dev/null +++ b/notus/Biblioteque_de_Class/Manager.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Biblioteque_de_Class +{ + public class Manager + { + private PersistenceManager persistence { set; get; } + } +} diff --git a/notus/Biblioteque_de_Class/User.cs b/notus/Biblioteque_de_Class/User.cs index 0a7cf80..c602590 100644 --- a/notus/Biblioteque_de_Class/User.cs +++ b/notus/Biblioteque_de_Class/User.cs @@ -1,18 +1,28 @@ 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) diff --git a/notus/Notus_Persistence/IDataManager.cs b/notus/Notus_Persistence/IDataManager.cs deleted file mode 100644 index e330abe..0000000 --- a/notus/Notus_Persistence/IDataManager.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Notus_Persistance -{ - public class IDataManager - { - - } -} \ No newline at end of file diff --git a/notus/Notus_Persistence/Notus_Persistance.csproj b/notus/Notus_Persistence/Notus_Persistance.csproj index 4658cbf..bec8016 100644 --- a/notus/Notus_Persistence/Notus_Persistance.csproj +++ b/notus/Notus_Persistence/Notus_Persistance.csproj @@ -6,4 +6,8 @@ enable + + + + diff --git a/notus/Notus_Persistence/PersistenceManager.cs b/notus/Notus_Persistence/PersistenceManager.cs new file mode 100644 index 0000000..4828a29 --- /dev/null +++ b/notus/Notus_Persistence/PersistenceManager.cs @@ -0,0 +1,33 @@ +using Biblioteque_de_Class; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.Xml; +using System; +using System.Collections.Generic; +using System.Diagnostics; + +namespace Notus_Persistance +{ + public static class PersistenceManager + { + public static void SaveDatabaseData(Database database) + { + ToJSON.SaveDatabaseData(database); + } + + public static Database LoadDatabaseData() + { + return ToJSON.LoadDatabaseData(); + } + + public static void SaveUserData(User user) + { + ToJSON.SaveUserData(user); + } + + public static User LoadUserData() + { + return ToJSON.LoadUserData(); + } + } +} \ No newline at end of file diff --git a/notus/Notus_Persistence/Stub.cs b/notus/Notus_Persistence/Stub.cs index 976d3de..8056488 100644 --- a/notus/Notus_Persistence/Stub.cs +++ b/notus/Notus_Persistence/Stub.cs @@ -1,6 +1,8 @@ -using System; +using Biblioteque_de_Class; +using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization.Json; using System.Text; using System.Threading.Tasks; @@ -8,6 +10,25 @@ namespace Notus_Persistance { internal class Stub { + public static void SaveDatabaseData(Database database) + { + + } + + public static Database LoadDatabaseData() + { + + } + + public static void SaveUserData(User user) + { + + } + + public static User LoadUserData() + { + + } } } diff --git a/notus/Notus_Persistence/ToJSON.cs b/notus/Notus_Persistence/ToJSON.cs index ec65800..5f10a96 100644 --- a/notus/Notus_Persistence/ToJSON.cs +++ b/notus/Notus_Persistence/ToJSON.cs @@ -1,12 +1,99 @@ -using System; +using Biblioteque_de_Class; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.Xml; +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.IO; +using System.Text.Json; namespace Notus_Persistance { - internal class ToJSON + public static class ToJSON { + private const string DatabaseDataFilePath = "data.json"; + private const string UserDataFilePath = "userdata.json"; + private static DataContractJsonSerializer DatabasejsonSerializer = new DataContractJsonSerializer(typeof(Database)); + private static DataContractJsonSerializer UserjsonSerializer = new DataContractJsonSerializer(typeof(User)); + public static void SaveDatabaseData(Database database) + { + using (FileStream fileStream = File.Create(DatabaseDataFilePath)) + { + using (var writer = JsonReaderWriterFactory.CreateJsonWriter( + fileStream, + System.Text.Encoding.UTF8, + false, + true))//<- this boolean says that we sant indentation + { + DatabasejsonSerializer.WriteObject(writer, database); + } + } + } + + public static Database LoadDatabaseData() + { + if (File.Exists(DatabaseDataFilePath)) + { + Database database1; + using (FileStream fileStream = File.OpenRead(DatabaseDataFilePath)) + { + Database? database = (Database?)DatabasejsonSerializer.ReadObject(fileStream); + if (database == null) + { + throw new Exception("Failed to load database. The loaded object is null."); + } + else + { + return database1 = database; + } + } + } + else + { + throw new Exception("No data file found."); + } + } + + public static void SaveUserData(User user) + { + using (FileStream fileStream = File.Create(UserDataFilePath)) + { + using (var writer = JsonReaderWriterFactory.CreateJsonWriter( + fileStream, + System.Text.Encoding.UTF8, + false, + true))//<- this boolean says that we sant indentation + { + UserjsonSerializer.WriteObject(writer, user); + } + } + } + + public static User LoadUserData() + { + if (File.Exists(UserDataFilePath)) + { + User user1; + using (FileStream fileStream = File.OpenRead(UserDataFilePath)) + { + User? user = (User?)UserjsonSerializer.ReadObject(fileStream); + if (user == null) + { + throw new Exception("Failed to load database. The loaded object is null."); + } + else + { + return user1 = user; + } + } + } + else + { + throw new Exception("No userfile find"); + } + } } } diff --git a/notus/Notus_Persistence/ToXML.cs b/notus/Notus_Persistence/ToXML.cs index 29f400f..f813109 100644 --- a/notus/Notus_Persistence/ToXML.cs +++ b/notus/Notus_Persistence/ToXML.cs @@ -1,4 +1,8 @@ -using System; +using Biblioteque_de_Class; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Json; +using System.Xml; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +10,29 @@ using System.Threading.Tasks; namespace Notus_Persistance { - internal class ToXML + public static class ToXML { + private const string DataFilePath = "data.xml"; + private const string XmlDataFilePath = "userdata.xml"; + + public static void SaveDatabaseData(Database database) + { + + } + + public static Database LoadDatabaseData() + { + + } + + public static void SaveUserData(User user) + { + + } + + public static User LoadUserData() + { + + } } } diff --git a/notus/Notus_UnitTest/UnitTest1.cs b/notus/Notus_UnitTest/UserSearchTests.cs similarity index 94% rename from notus/Notus_UnitTest/UnitTest1.cs rename to notus/Notus_UnitTest/UserSearchTests.cs index 1b47d45..336b1bf 100644 --- a/notus/Notus_UnitTest/UnitTest1.cs +++ b/notus/Notus_UnitTest/UserSearchTests.cs @@ -1,14 +1,14 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; - -namespace Notus_UnitTest -{ - [TestClass] - public class UnitTest1 - { - [TestMethod] - public void TestMethod1() - { - } - } -} +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace Notus_UnitTest +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} From 1e0cb17daffe47c3102d0ff75a44e8896a79fe81 Mon Sep 17 00:00:00 2001 From: "matheo.thierry" Date: Thu, 18 May 2023 18:21:13 +0200 Subject: [PATCH 5/7] debut structure UnitTest --- notus/Biblioteque_de_Class/Manager.cs | 1 - notus/Notus_UnitTest/Notus_UnitTest.csproj | 68 ------------------- .../Notus_UnitTest/Properties/AssemblyInfo.cs | 20 ------ notus/Notus_UnitTest/UserSearchTests.cs | 14 ---- notus/Notus_UnitTest/packages.config | 5 -- .../GetLogoLinkTests.cs | 42 ++++++++++++ .../Notus_UnitTest_Database.csproj | 20 ++++++ .../SearchUserTests.cs | 54 +++++++++++++++ notus/Tests/Notus_UnitTest_Database/Usings.cs | 1 + notus/notus.sln | 8 ++- 10 files changed, 124 insertions(+), 109 deletions(-) delete mode 100644 notus/Notus_UnitTest/Notus_UnitTest.csproj delete mode 100644 notus/Notus_UnitTest/Properties/AssemblyInfo.cs delete mode 100644 notus/Notus_UnitTest/UserSearchTests.cs delete mode 100644 notus/Notus_UnitTest/packages.config create mode 100644 notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/Notus_UnitTest_Database.csproj create mode 100644 notus/Tests/Notus_UnitTest_Database/SearchUserTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/Usings.cs diff --git a/notus/Biblioteque_de_Class/Manager.cs b/notus/Biblioteque_de_Class/Manager.cs index 5699a42..64c3eed 100644 --- a/notus/Biblioteque_de_Class/Manager.cs +++ b/notus/Biblioteque_de_Class/Manager.cs @@ -8,6 +8,5 @@ namespace Biblioteque_de_Class { public class Manager { - private PersistenceManager persistence { set; get; } } } diff --git a/notus/Notus_UnitTest/Notus_UnitTest.csproj b/notus/Notus_UnitTest/Notus_UnitTest.csproj deleted file mode 100644 index 5da3cd5..0000000 --- a/notus/Notus_UnitTest/Notus_UnitTest.csproj +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - Debug - AnyCPU - {8DCE500B-E01F-44CA-933E-DDE95111899B} - Library - Properties - Notus_UnitTest - Notus_UnitTest - v4.7.2 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - 15.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages - False - UnitTest - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - ..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll - - - ..\packages\MSTest.TestFramework.2.2.10\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll - - - - - - - - - - - - - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - \ No newline at end of file diff --git a/notus/Notus_UnitTest/Properties/AssemblyInfo.cs b/notus/Notus_UnitTest/Properties/AssemblyInfo.cs deleted file mode 100644 index 13b22e5..0000000 --- a/notus/Notus_UnitTest/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -[assembly: AssemblyTitle("Notus_UnitTest")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("workgroup")] -[assembly: AssemblyProduct("Notus_UnitTest")] -[assembly: AssemblyCopyright("Copyright © workgroup 2023")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -[assembly: ComVisible(false)] - -[assembly: Guid("8dce500b-e01f-44ca-933e-dde95111899b")] - -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/notus/Notus_UnitTest/UserSearchTests.cs b/notus/Notus_UnitTest/UserSearchTests.cs deleted file mode 100644 index 336b1bf..0000000 --- a/notus/Notus_UnitTest/UserSearchTests.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; - -namespace Notus_UnitTest -{ - [TestClass] - public class UnitTest1 - { - [TestMethod] - public void TestMethod1() - { - } - } -} diff --git a/notus/Notus_UnitTest/packages.config b/notus/Notus_UnitTest/packages.config deleted file mode 100644 index 4ea5008..0000000 --- a/notus/Notus_UnitTest/packages.config +++ /dev/null @@ -1,5 +0,0 @@ - - - - - \ No newline at end of file diff --git a/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs b/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs new file mode 100644 index 0000000..2ecf99d --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs @@ -0,0 +1,42 @@ +using Biblioteque_de_Class; + +namespace Notus_UnitTest_Database +{ + [TestFixture] + public class GetLogoLinkTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + } + + // ... Existing tests for other methods ... + + // GetLogoLink + [Test] + public void GetLogoLink_ExistingLogoName_ReturnsLogoLink() + { + // Arrange + Logo logo1 = new Logo("Logo1", "logo1.png"); + Logo logo2 = new Logo("Logo2", "logo2.png"); + database.GetDefaultLogoList().Add(logo1); + database.GetDefaultLogoList().Add(logo2); + + // Act + string result = database.GetLogoLink("Logo1"); + + // Assert + Assert.AreEqual("logo1.png", result); + } + + [Test] + public void GetLogoLink_NonExistingLogoName_ThrowsException() + { + // Act & Assert + Assert.Throws(() => database.GetLogoLink("Logo3")); + } + } +} \ No newline at end of file diff --git a/notus/Tests/Notus_UnitTest_Database/Notus_UnitTest_Database.csproj b/notus/Tests/Notus_UnitTest_Database/Notus_UnitTest_Database.csproj new file mode 100644 index 0000000..8d82d90 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/Notus_UnitTest_Database.csproj @@ -0,0 +1,20 @@ + + + + net7.0 + enable + enable + + false + true + + + + + + + + + + + diff --git a/notus/Tests/Notus_UnitTest_Database/SearchUserTests.cs b/notus/Tests/Notus_UnitTest_Database/SearchUserTests.cs new file mode 100644 index 0000000..06799b7 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/SearchUserTests.cs @@ -0,0 +1,54 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_UnitTest_Database +{ + [TestFixture] + public class DatabaseTests + { + private Database database; + + [SetUp] + public void Setup() + { + // Create an instance of the Database class + database = new Database(); + + // Add some dummy users for testing + database.GetUserList().Add(new User("John", "john@example.com", "choco")); + database.GetUserList().Add(new User("Jane", "jane@example.com", "choco")); + database.GetUserList().Add(new User("Alice", "alice@example.com", "choco")); + } + + [Test] + public void SearchUser_UserExists_ReturnsMatchingUsers() + { + // Arrange + string searchName = "Jo"; + + // Act + List searchedUsers = database.SearchUser(searchName); + + // Assert + Assert.That(searchedUsers.Count, Is.EqualTo(1)); + Assert.That(searchedUsers[0].GetUsername(), Is.EqualTo("John")); + } + + [Test] + public void SearchUser_UserDoesNotExist_ReturnsEmptyList() + { + // Arrange + string searchName = "Bob"; + + // Act + List searchedUsers = database.SearchUser(searchName); + + // Assert + Assert.IsEmpty(searchedUsers); + } + } +} diff --git a/notus/Tests/Notus_UnitTest_Database/Usings.cs b/notus/Tests/Notus_UnitTest_Database/Usings.cs new file mode 100644 index 0000000..cefced4 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/Usings.cs @@ -0,0 +1 @@ +global using NUnit.Framework; \ No newline at end of file diff --git a/notus/notus.sln b/notus/notus.sln index e04e97e..7c16614 100644 --- a/notus/notus.sln +++ b/notus/notus.sln @@ -9,7 +9,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Biblioteque_de_Class", "Bib EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_Console", "Notus_Console\Notus_Console.csproj", "{0A5E5F33-6B39-42BF-A46D-0752EDB666FB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_Persistance", "Notus_Persistence\Notus_Persistance.csproj", "{184478A9-E14F-42E0-B963-B3A4474C9C1C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_Persistance", "Notus_Persistence\Notus_Persistance.csproj", "{184478A9-E14F-42E0-B963-B3A4474C9C1C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest", "Notus_UnitTest\Notus_UnitTest.csproj", "{8DCE500B-E01F-44CA-933E-DDE95111899B}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -35,6 +37,10 @@ Global {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Debug|Any CPU.Build.0 = Debug|Any CPU {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.ActiveCfg = Release|Any CPU {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.Build.0 = Release|Any CPU + {8DCE500B-E01F-44CA-933E-DDE95111899B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8DCE500B-E01F-44CA-933E-DDE95111899B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8DCE500B-E01F-44CA-933E-DDE95111899B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8DCE500B-E01F-44CA-933E-DDE95111899B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From 55a4f3da5c634f4e1c5f060de9ea84ebe7b334ac Mon Sep 17 00:00:00 2001 From: "matheo.thierry" Date: Fri, 19 May 2023 11:05:33 +0200 Subject: [PATCH 6/7] ADD unitTest for Database and fix class missing methodes --- notus/Biblioteque_de_Class/Logo.cs | 3 ++ notus/Biblioteque_de_Class/Manager.cs | 12 ----- notus/Biblioteque_de_Class/Note.cs | 6 +-- notus/Biblioteque_de_Class/NoteImage.cs | 4 ++ notus/Biblioteque_de_Class/Tags.cs | 2 + notus/Biblioteque_de_Class/User.cs | 5 ++ notus/Notus_Console/Manager.cs | 18 +++++++ notus/Notus_Persistence/Manager.cs | 14 +++++ notus/Notus_Persistence/Stub.cs | 2 +- .../Notus_UnitTest_Database/AddThemeTests.cs | 39 ++++++++++++++ .../Notus_UnitTest_Database/AddUserTests.cs | 51 +++++++++++++++++++ .../ComparePasswordTests.cs | 42 +++++++++++++++ .../Notus_UnitTest_Database/FindMailTests.cs | 39 ++++++++++++++ .../GetLogoLinkTests.cs | 30 ++++------- .../Notus_UnitTest_Database/GetThemeTests.cs | 36 +++++++++++++ .../Notus_UnitTest_Database/GetUserTests.cs | 36 +++++++++++++ .../ModifyThemeColorListTests.cs | 43 ++++++++++++++++ .../ModifyThemeNameTests.cs | 36 +++++++++++++ .../Notus_UnitTest_Database.csproj | 4 ++ .../RemoveUserTests.cs | 38 ++++++++++++++ .../SearchUserTests.cs | 38 +++++++------- notus/notus.sln | 10 ++-- 22 files changed, 449 insertions(+), 59 deletions(-) delete mode 100644 notus/Biblioteque_de_Class/Manager.cs create mode 100644 notus/Notus_Console/Manager.cs create mode 100644 notus/Notus_Persistence/Manager.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/AddThemeTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/AddUserTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/ComparePasswordTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/FindMailTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/GetThemeTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/GetUserTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/ModifyThemeColorListTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/ModifyThemeNameTests.cs create mode 100644 notus/Tests/Notus_UnitTest_Database/RemoveUserTests.cs diff --git a/notus/Biblioteque_de_Class/Logo.cs b/notus/Biblioteque_de_Class/Logo.cs index 4fdb203..7baf505 100644 --- a/notus/Biblioteque_de_Class/Logo.cs +++ b/notus/Biblioteque_de_Class/Logo.cs @@ -20,6 +20,9 @@ namespace Biblioteque_de_Class public string GetName() { return Name; } public string GetLogoLink() { return LogoLink; } + public void SetName(string name) { Name = name; } + public void SetLogoLink(string logoLink) { LogoLink = logoLink; } + public override string ToString() => $"Logo -> Name: {Name}\nLink: {LogoLink}"; } } diff --git a/notus/Biblioteque_de_Class/Manager.cs b/notus/Biblioteque_de_Class/Manager.cs deleted file mode 100644 index 64c3eed..0000000 --- a/notus/Biblioteque_de_Class/Manager.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Biblioteque_de_Class -{ - public class Manager - { - } -} diff --git a/notus/Biblioteque_de_Class/Note.cs b/notus/Biblioteque_de_Class/Note.cs index c33f949..f8724a9 100644 --- a/notus/Biblioteque_de_Class/Note.cs +++ b/notus/Biblioteque_de_Class/Note.cs @@ -55,9 +55,9 @@ namespace Biblioteque_de_Class public override string ToString() => $"Note -> Name: {Name}\nLogoPath: {LogoPath}\nNumber of lines: {TextLineList.Count()}"; - public void ModifyName(string name) { Name = name; } - public void ModifyLogoPath(string logoPath) { LogoPath = logoPath; } - public void ModifyModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); } + public void SetName(string name) { Name = name; } + public void SetLogoPath(string logoPath) { LogoPath = logoPath; } + public void SetModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); } /// /// vérifier si l'utilisateur est le propriétaire de la note diff --git a/notus/Biblioteque_de_Class/NoteImage.cs b/notus/Biblioteque_de_Class/NoteImage.cs index db6f85d..c141096 100644 --- a/notus/Biblioteque_de_Class/NoteImage.cs +++ b/notus/Biblioteque_de_Class/NoteImage.cs @@ -23,6 +23,10 @@ namespace Biblioteque_de_Class public string GetImageLink() { return ImageLink; } public string GetPosition() { return Position; } + public void SetName(string name) { Name = name; } + public void SetImageLink(string imageLink) { ImageLink = imageLink; } + public void SetPosition(string position) { Position = position; } + public override string ToString() => $"image -> name: {Name}\nlink: {ImageLink}"; } } diff --git a/notus/Biblioteque_de_Class/Tags.cs b/notus/Biblioteque_de_Class/Tags.cs index bf0181d..dbba2b4 100644 --- a/notus/Biblioteque_de_Class/Tags.cs +++ b/notus/Biblioteque_de_Class/Tags.cs @@ -19,6 +19,8 @@ namespace Biblioteque_de_Class public string GetName() { return Name; } public string GetColor() { return Color; } + public void SetName(string name) { Name = name; } + public void SetColor(string color) { Color = color; } public override string ToString() => $"tag -> name: {Name}\ncolor: {Color}"; } diff --git a/notus/Biblioteque_de_Class/User.cs b/notus/Biblioteque_de_Class/User.cs index c602590..ac9627d 100644 --- a/notus/Biblioteque_de_Class/User.cs +++ b/notus/Biblioteque_de_Class/User.cs @@ -45,6 +45,11 @@ namespace Biblioteque_de_Class 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}"; /// diff --git a/notus/Notus_Console/Manager.cs b/notus/Notus_Console/Manager.cs new file mode 100644 index 0000000..ad95038 --- /dev/null +++ b/notus/Notus_Console/Manager.cs @@ -0,0 +1,18 @@ +using Notus_Persistance; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_Console +{ + public class Manager + { + PersistenceManager pers { get; set; } + public Manager(PersistenceManager pers) + { + this.pers = pers; + } + } +} diff --git a/notus/Notus_Persistence/Manager.cs b/notus/Notus_Persistence/Manager.cs new file mode 100644 index 0000000..291cf69 --- /dev/null +++ b/notus/Notus_Persistence/Manager.cs @@ -0,0 +1,14 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_Persistance +{ + public class Manager : PersistenceManager + { + PersistenceManager pers { get; set; } + } +} diff --git a/notus/Notus_Persistence/Stub.cs b/notus/Notus_Persistence/Stub.cs index 8056488..c00b816 100644 --- a/notus/Notus_Persistence/Stub.cs +++ b/notus/Notus_Persistence/Stub.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; namespace Notus_Persistance { - internal class Stub + public class Stub { public static void SaveDatabaseData(Database database) { diff --git a/notus/Tests/Notus_UnitTest_Database/AddThemeTests.cs b/notus/Tests/Notus_UnitTest_Database/AddThemeTests.cs new file mode 100644 index 0000000..339eddb --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/AddThemeTests.cs @@ -0,0 +1,39 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Security.Cryptography.X509Certificates; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_UnitTest_Database +{ + public class AddThemeTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + } + + [Test] + public void AddTheme_NewTheme_ThemeAddedToList() + { + List listcolor = new List() { "Blue", "Dark", "Grey" }; + Theme theme = new Theme("ocean", listcolor); + database.AddTheme(theme); + CollectionAssert.Contains(database.GetThemeList(), theme); + } + + [Test] + public void AddTheme_ExistingTheme_ThrowsException() + { + List listcolor = new(); + Theme theme = new Theme("ocean", listcolor); + database.GetThemeList().Add(theme); + Assert.Throws(() => database.AddTheme(theme), "Theme already used."); + } + } +} diff --git a/notus/Tests/Notus_UnitTest_Database/AddUserTests.cs b/notus/Tests/Notus_UnitTest_Database/AddUserTests.cs new file mode 100644 index 0000000..e5fc44b --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/AddUserTests.cs @@ -0,0 +1,51 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_UnitTest_Database +{ + public class AddUserTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + } + + [Test] + public void AddUser_ValidUser_UserAddedToList() + { + User user = new User("John", "rien", "choco") ; + user.SetEmail("john@example.com"); + database.AddUser(user); + CollectionAssert.Contains(database.GetUserList(), user); + } + + [Test] + public void AddUser_DuplicateUsername_ThrowsException() + { + User existingUser = new User("John1", "rien", "choco"); + existingUser.SetEmail("john1@example.com"); + database.GetUserList().Add(existingUser); + User newUser = new User("John1", "rien", "choco"); + newUser.SetEmail("Jane@example.com"); + Assert.Throws(() => database.AddUser(newUser), "Username already used."); + } + + [Test] + public void AddUser_DuplicateEmail_ThrowsException() + { + User existingUser = new User("John2", "rien", "choco"); + existingUser.SetEmail("john2@example.com"); + database.GetUserList().Add(existingUser); + User newUser = new User("Jane", "rien", "choco"); + newUser.SetEmail("john2@example.com"); + Assert.Throws(() => database.AddUser(newUser), "Email already used."); + } + } +} diff --git a/notus/Tests/Notus_UnitTest_Database/ComparePasswordTests.cs b/notus/Tests/Notus_UnitTest_Database/ComparePasswordTests.cs new file mode 100644 index 0000000..7f02e56 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/ComparePasswordTests.cs @@ -0,0 +1,42 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_UnitTest_Database +{ + [TestFixture] + public class ComparePasswordTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + User user = new User("John","rien","choco"); + user.SetPassword("password123"); + database.GetUserList().Add(user); + } + + [Test] + public void ComparePassword_CorrectPassword_ReturnsTrue() + { + User user = database.GetUserList()[0]; + string password = "password123"; + bool result = database.ComparePassword(user, password); + Assert.IsTrue(result); + } + + [Test] + public void ComparePassword_IncorrectPassword_ReturnsFalse() + { + User user = database.GetUserList()[0]; + string password = "incorrectPassword"; + bool result = database.ComparePassword(user, password); + Assert.IsFalse(result); + } + } +} diff --git a/notus/Tests/Notus_UnitTest_Database/FindMailTests.cs b/notus/Tests/Notus_UnitTest_Database/FindMailTests.cs new file mode 100644 index 0000000..8639be1 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/FindMailTests.cs @@ -0,0 +1,39 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_UnitTest_Database +{ + public class FindMailTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + User user = new User("John"); + user.SetEmail("john@example.com"); + database.GetUserList().Add(user); + } + + [Test] + public void FindEmail_ExistingEmail_ReturnsTrue() + { + string email = "john@example.com"; + bool result = database.FindEmail(email); + Assert.IsTrue(result); + } + + [Test] + public void FindEmail_NonExistingEmail_ReturnsFalse() + { + string email = "jane@example.com"; + bool result = database.FindEmail(email); + Assert.IsFalse(result); + } + } +} diff --git a/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs b/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs index 2ecf99d..1b65d38 100644 --- a/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs +++ b/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs @@ -3,7 +3,7 @@ using Biblioteque_de_Class; namespace Notus_UnitTest_Database { [TestFixture] - public class GetLogoLinkTests + public class GetLogoLinksTests { private Database database; @@ -11,32 +11,24 @@ namespace Notus_UnitTest_Database public void Setup() { database = new Database(); + database.GetDefaultLogoList().Add(new Logo("Logo1", "link1")); + database.GetDefaultLogoList().Add(new Logo("Logo2", "link2")); + database.GetDefaultLogoList().Add(new Logo("Logo3", "link3")); } - // ... Existing tests for other methods ... - - // GetLogoLink [Test] - public void GetLogoLink_ExistingLogoName_ReturnsLogoLink() + public void GetLogoLink_LogoExists_ReturnsLogoLink() { - // Arrange - Logo logo1 = new Logo("Logo1", "logo1.png"); - Logo logo2 = new Logo("Logo2", "logo2.png"); - database.GetDefaultLogoList().Add(logo1); - database.GetDefaultLogoList().Add(logo2); - - // Act - string result = database.GetLogoLink("Logo1"); - - // Assert - Assert.AreEqual("logo1.png", result); + string logoName = "Logo2"; + string logoLink = database.GetLogoLink(logoName); + Assert.That(logoLink, Is.EqualTo("link2")); } [Test] - public void GetLogoLink_NonExistingLogoName_ThrowsException() + public void GetLogoLink_LogoDoesNotExist_ThrowsException() { - // Act & Assert - Assert.Throws(() => database.GetLogoLink("Logo3")); + string logoName = "Logo4"; + Assert.Throws(() => database.GetLogoLink(logoName)); } } } \ No newline at end of file diff --git a/notus/Tests/Notus_UnitTest_Database/GetThemeTests.cs b/notus/Tests/Notus_UnitTest_Database/GetThemeTests.cs new file mode 100644 index 0000000..1786528 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/GetThemeTests.cs @@ -0,0 +1,36 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_UnitTest_Database +{ + public class GetThemeTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + } + + [Test] + public void GetTheme_ExistingTheme_ReturnsTheme() + { + List listcolor = new List() { "Blue", "Dark", "Grey" }; + Theme theme = new Theme("ocean", listcolor); + database.GetThemeList().Add(theme); + Theme retrievedTheme = database.GetTheme("Dark"); + Assert.That(retrievedTheme, Is.EqualTo(theme)); + } + + [Test] + public void GetTheme_NonExistingTheme_ThrowsException() + { + Assert.Throws(() => database.GetTheme("NonExistingTheme"), "No theme found with this name."); + } + } +} diff --git a/notus/Tests/Notus_UnitTest_Database/GetUserTests.cs b/notus/Tests/Notus_UnitTest_Database/GetUserTests.cs new file mode 100644 index 0000000..d06ea0b --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/GetUserTests.cs @@ -0,0 +1,36 @@ +using Biblioteque_de_Class; + +namespace Notus_UnitTest_Database +{ + + [TestFixture] + public class GetUserTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + database.GetUserList().Add(new User("John","rien","choco")); + database.GetUserList().Add(new User("Alice", "rien", "choco")); + database.GetUserList().Add(new User("Bob", "rien", "choco")); + } + + [Test] + public void GetUser_UserExists_ReturnsUser() + { + string userName = "Alice"; + User user = database.GetUser(userName); + Assert.IsNotNull(user); + Assert.That(user.GetUsername(), Is.EqualTo(userName)); + } + + [Test] + public void GetUser_UserDoesNotExist_ThrowsException() + { + string userName = "Eve"; + Assert.Throws(() => database.GetUser(userName)); + } + } +} diff --git a/notus/Tests/Notus_UnitTest_Database/ModifyThemeColorListTests.cs b/notus/Tests/Notus_UnitTest_Database/ModifyThemeColorListTests.cs new file mode 100644 index 0000000..96c1d4a --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/ModifyThemeColorListTests.cs @@ -0,0 +1,43 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_UnitTest_Database +{ + public class ModifyThemeColorListTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + } + + [Test] + public void ModifyThemeColorList_ExistingTheme_ModifiesColors() + { + List listcolor = new List() { "Blue", "Dark", "Grey" }; + Theme theme = new Theme("ocean", listcolor); + database.GetThemeList().Add(theme); + List newColorList = new List { "Red", "Green", "Blue" }; + database.ModifyThemeColorList(theme, newColorList); + Assert.That(theme.GetColor(0), Is.EqualTo(newColorList[0])); + 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_Database/ModifyThemeNameTests.cs b/notus/Tests/Notus_UnitTest_Database/ModifyThemeNameTests.cs new file mode 100644 index 0000000..4f57537 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/ModifyThemeNameTests.cs @@ -0,0 +1,36 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_UnitTest_Database +{ + public class ModifyThemeNameTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + } + + [Test] + public void GetTheme_ExistingTheme_ReturnsTheme() + { + List listcolor = new List() { "Blue", "Dark", "Grey" }; + Theme theme = new Theme("ocean", listcolor); + database.GetThemeList().Add(theme); + Theme retrievedTheme = database.GetTheme("Dark"); + Assert.That(retrievedTheme, Is.EqualTo(theme)); + } + + [Test] + public void GetTheme_NonExistingTheme_ThrowsException() + { + Assert.Throws(() => database.GetTheme("NonExistingTheme"), "No theme found with this name."); + } + } +} diff --git a/notus/Tests/Notus_UnitTest_Database/Notus_UnitTest_Database.csproj b/notus/Tests/Notus_UnitTest_Database/Notus_UnitTest_Database.csproj index 8d82d90..3f9f74f 100644 --- a/notus/Tests/Notus_UnitTest_Database/Notus_UnitTest_Database.csproj +++ b/notus/Tests/Notus_UnitTest_Database/Notus_UnitTest_Database.csproj @@ -17,4 +17,8 @@ + + + + diff --git a/notus/Tests/Notus_UnitTest_Database/RemoveUserTests.cs b/notus/Tests/Notus_UnitTest_Database/RemoveUserTests.cs new file mode 100644 index 0000000..abec9e5 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/RemoveUserTests.cs @@ -0,0 +1,38 @@ +using Biblioteque_de_Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Notus_UnitTest_Database +{ + public class RemoveUserTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + } + + [Test] + public void RemoveUser_ExistingUser_UserRemovedFromList() + { + User user = new User("John","rien","choco"); + user.SetEmail("john@example.com"); + database.GetUserList().Add(user); + database.RemoveUser(user); + CollectionAssert.DoesNotContain(database.GetUserList(), user); + } + + [Test] + public void RemoveUser_NonExistingUser_ThrowsException() + { + User user = new User("John", "rien", "choco"); + user.SetEmail("john@example.com"); + Assert.Throws(() => database.RemoveUser(user), "User not found."); + } + } +} diff --git a/notus/Tests/Notus_UnitTest_Database/SearchUserTests.cs b/notus/Tests/Notus_UnitTest_Database/SearchUserTests.cs index 06799b7..3c25715 100644 --- a/notus/Tests/Notus_UnitTest_Database/SearchUserTests.cs +++ b/notus/Tests/Notus_UnitTest_Database/SearchUserTests.cs @@ -1,24 +1,16 @@ using Biblioteque_de_Class; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Notus_UnitTest_Database { [TestFixture] - public class DatabaseTests + public class SearchUserTests { private Database database; [SetUp] public void Setup() { - // Create an instance of the Database class database = new Database(); - - // Add some dummy users for testing database.GetUserList().Add(new User("John", "john@example.com", "choco")); database.GetUserList().Add(new User("Jane", "jane@example.com", "choco")); database.GetUserList().Add(new User("Alice", "alice@example.com", "choco")); @@ -27,13 +19,8 @@ namespace Notus_UnitTest_Database [Test] public void SearchUser_UserExists_ReturnsMatchingUsers() { - // Arrange string searchName = "Jo"; - - // Act List searchedUsers = database.SearchUser(searchName); - - // Assert Assert.That(searchedUsers.Count, Is.EqualTo(1)); Assert.That(searchedUsers[0].GetUsername(), Is.EqualTo("John")); } @@ -41,14 +28,27 @@ namespace Notus_UnitTest_Database [Test] public void SearchUser_UserDoesNotExist_ReturnsEmptyList() { - // Arrange string searchName = "Bob"; + List searchedUsers = database.SearchUser(searchName); + Assert.IsEmpty(searchedUsers); + } - // Act + [Test] + public void SearchUser_CaseInsensitiveSearch_ReturnsMatchingUsers() + { + string searchName = "ALICE"; List searchedUsers = database.SearchUser(searchName); + Assert.That(searchedUsers.Count, Is.EqualTo(1)); + Assert.That(searchedUsers[0].GetUsername(), Is.EqualTo("Alice")); + } - // Assert - Assert.IsEmpty(searchedUsers); + [Test] + public void SearchUser_PartialMatch_ReturnsMatchingUsers() + { + string searchName = "ane"; + List searchedUsers = database.SearchUser(searchName); + Assert.That(searchedUsers.Count, Is.EqualTo(1)); + Assert.That(searchedUsers[0].GetUsername(), Is.EqualTo("Jane")); } } -} +} \ No newline at end of file diff --git a/notus/notus.sln b/notus/notus.sln index 7c16614..6c35a63 100644 --- a/notus/notus.sln +++ b/notus/notus.sln @@ -11,7 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_Console", "Notus_Cons EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_Persistance", "Notus_Persistence\Notus_Persistance.csproj", "{184478A9-E14F-42E0-B963-B3A4474C9C1C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest", "Notus_UnitTest\Notus_UnitTest.csproj", "{8DCE500B-E01F-44CA-933E-DDE95111899B}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest_Database", "Tests\Notus_UnitTest_Database\Notus_UnitTest_Database.csproj", "{EE443C17-B31D-4AD0-9141-920876E7DF79}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,10 +37,10 @@ Global {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Debug|Any CPU.Build.0 = Debug|Any CPU {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.ActiveCfg = Release|Any CPU {184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.Build.0 = Release|Any CPU - {8DCE500B-E01F-44CA-933E-DDE95111899B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8DCE500B-E01F-44CA-933E-DDE95111899B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8DCE500B-E01F-44CA-933E-DDE95111899B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8DCE500B-E01F-44CA-933E-DDE95111899B}.Release|Any CPU.Build.0 = Release|Any CPU + {EE443C17-B31D-4AD0-9141-920876E7DF79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EE443C17-B31D-4AD0-9141-920876E7DF79}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EE443C17-B31D-4AD0-9141-920876E7DF79}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EE443C17-B31D-4AD0-9141-920876E7DF79}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE From cb2cd438f124182a6cce2f9965af747fa47ba698 Mon Sep 17 00:00:00 2001 From: "matheo.thierry" Date: Sat, 20 May 2023 08:40:47 +0200 Subject: [PATCH 7/7] tempo - pour merge --- notus/Biblioteque_de_Class/Manager.cs | 13 +++ notus/Notus_Console/Notus_Console.csproj | 1 + notus/Notus_UnitTest/UserSearchTests.cs | 96 +++++++++++++++++++ .../Notus_UnitTest_Database/AddThemeTests.cs | 2 +- 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 notus/Biblioteque_de_Class/Manager.cs create mode 100644 notus/Notus_UnitTest/UserSearchTests.cs diff --git a/notus/Biblioteque_de_Class/Manager.cs b/notus/Biblioteque_de_Class/Manager.cs new file mode 100644 index 0000000..10adb96 --- /dev/null +++ b/notus/Biblioteque_de_Class/Manager.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Biblioteque_de_Class +{ + public class Manager + { + public Manager(Persistence + } +} diff --git a/notus/Notus_Console/Notus_Console.csproj b/notus/Notus_Console/Notus_Console.csproj index 75d1b7d..047b5cb 100644 --- a/notus/Notus_Console/Notus_Console.csproj +++ b/notus/Notus_Console/Notus_Console.csproj @@ -9,6 +9,7 @@ + diff --git a/notus/Notus_UnitTest/UserSearchTests.cs b/notus/Notus_UnitTest/UserSearchTests.cs new file mode 100644 index 0000000..39933a4 --- /dev/null +++ b/notus/Notus_UnitTest/UserSearchTests.cs @@ -0,0 +1,96 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; + +namespace Notus_UnitTest +{ + [TestFixture] + public class UserSearchTests + { + private UserSearch userSearch; + + [SetUp] + public void Setup() + { + // Initialize the class under test + userSearch = new UserSearch(); + } + + [Test] + public void SearchUser_EmptyUserList_ReturnsEmptyList() + { + // Arrange + List userList = new List(); + userSearch.SetUserList(userList); + string searchName = "John"; + + // Act + List result = userSearch.SearchUser(searchName); + + // Assert + Assert.IsEmpty(result); + } + + [Test] + public void SearchUser_MatchingUsername_ReturnsMatchingUser() + { + // Arrange + List userList = new List() + { + new User("John"), + new User("Jane"), + new User("Robert") + }; + userSearch.SetUserList(userList); + string searchName = "Jane"; + + // Act + List result = userSearch.SearchUser(searchName); + + // Assert + Assert.AreEqual(1, result.Count); + Assert.AreEqual("Jane", result[0].GetUsername()); + } + + [Test] + public void SearchUser_NoMatchingUsername_ReturnsEmptyList() + { + // Arrange + List userList = new List() + { + new User("John"), + new User("Jane"), + new User("Robert") + }; + userSearch.SetUserList(userList); + string searchName = "Alice"; + + // Act + List result = userSearch.SearchUser(searchName); + + // Assert + Assert.IsEmpty(result); + } + + [Test] + public void SearchUser_PartiallyMatchingUsername_ReturnsMatchingUsers() + { + // Arrange + List userList = new List() + { + new User("John Doe"), + new User("Jane Smith"), + new User("Robert Johnson") + }; + userSearch.SetUserList(userList); + string searchName = "Jo"; + + // Act + List result = userSearch.SearchUser(searchName); + + // Assert + Assert.AreEqual(2, result.Count); + Assert.AreEqual("John Doe", result[0].GetUsername()); + Assert.AreEqual("Robert Johnson", result[1].GetUsername()); + } + } +} \ No newline at end of file diff --git a/notus/Tests/Notus_UnitTest_Database/AddThemeTests.cs b/notus/Tests/Notus_UnitTest_Database/AddThemeTests.cs index 339eddb..0d0ba83 100644 --- a/notus/Tests/Notus_UnitTest_Database/AddThemeTests.cs +++ b/notus/Tests/Notus_UnitTest_Database/AddThemeTests.cs @@ -32,7 +32,7 @@ namespace Notus_UnitTest_Database { List listcolor = new(); Theme theme = new Theme("ocean", listcolor); - database.GetThemeList().Add(theme); + database.AddTheme(theme); Assert.Throws(() => database.AddTheme(theme), "Theme already used."); } }