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/Biblioteque_de_Class/Database.cs b/notus/Biblioteque_de_Class/Database.cs index 44d7da1..a7ae603 100644 --- a/notus/Biblioteque_de_Class/Database.cs +++ b/notus/Biblioteque_de_Class/Database.cs @@ -3,96 +3,93 @@ 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 { - private List ListDefaultLogo; - private List ListTheme; - private List ListUtilisateur; - - public Database() - { - ListDefaultLogo = new List(); - ListTheme = new List(); - ListUtilisateur = new List(); + [DataMember] + private List DefaultLogoList; + [DataMember] + private List ThemeList; + [DataMember] + private List UserList; + + 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.GetLogoLink(); } + } + 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 +97,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()) + if (existingUser.GetUsername() == user.GetUsername()) { - throw new Exception("Pseudo déjà utilisé"); + throw new Exception("Username already used."); } - else if (user1.GetMail() == user.GetMail()) + else if (existingUser.GetEmail() == user.GetEmail()) { - throw new Exception("Mail déjà utilisé"); - } - else - { - 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()) + if (existingTheme.GetName() == theme.GetName()) { - throw new Exception("Theme déjà utilisé"); - } - else - { - 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()) + if (existingTheme.GetName() == theme.GetName()) { - theme1.SetNom(NewName); - } - else - { - 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..7baf505 100644 --- a/notus/Biblioteque_de_Class/Logo.cs +++ b/notus/Biblioteque_de_Class/Logo.cs @@ -8,18 +8,21 @@ 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 void SetName(string name) { Name = name; } + public void SetLogoLink(string logoLink) { LogoLink = 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/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/Biblioteque_de_Class/Note.cs b/notus/Biblioteque_de_Class/Note.cs index 16e384d..f8724a9 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 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 /// - 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..c141096 100644 --- a/notus/Biblioteque_de_Class/NoteImage.cs +++ b/notus/Biblioteque_de_Class/NoteImage.cs @@ -8,22 +8,25 @@ 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 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 991eab8..dbba2b4 100644 --- a/notus/Biblioteque_de_Class/Tags.cs +++ b/notus/Biblioteque_de_Class/Tags.cs @@ -8,19 +8,20 @@ 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 void SetName(string name) { Name = name; } + public void SetColor(string color) { Color = 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..ac9627d --- /dev/null +++ b/notus/Biblioteque_de_Class/User.cs @@ -0,0 +1,245 @@ +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; + } + + /// + /// 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/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_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_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; 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/Notus_Persistance.csproj b/notus/Notus_Persistence/Notus_Persistance.csproj new file mode 100644 index 0000000..bec8016 --- /dev/null +++ b/notus/Notus_Persistence/Notus_Persistance.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + 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 new file mode 100644 index 0000000..c00b816 --- /dev/null +++ b/notus/Notus_Persistence/Stub.cs @@ -0,0 +1,34 @@ +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; + +namespace Notus_Persistance +{ + public 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 new file mode 100644 index 0000000..5f10a96 --- /dev/null +++ b/notus/Notus_Persistence/ToJSON.cs @@ -0,0 +1,99 @@ +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 +{ + 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 new file mode 100644 index 0000000..f813109 --- /dev/null +++ b/notus/Notus_Persistence/ToXML.cs @@ -0,0 +1,38 @@ +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; + +namespace Notus_Persistance +{ + 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/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/UnitTest1.cs b/notus/Notus_UnitTest/UnitTest1.cs deleted file mode 100644 index 1b47d45..0000000 --- a/notus/Notus_UnitTest/UnitTest1.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/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/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/AddThemeTests.cs b/notus/Tests/Notus_UnitTest_Database/AddThemeTests.cs new file mode 100644 index 0000000..0d0ba83 --- /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.AddTheme(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 new file mode 100644 index 0000000..1b65d38 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/GetLogoLinkTests.cs @@ -0,0 +1,34 @@ +using Biblioteque_de_Class; + +namespace Notus_UnitTest_Database +{ + [TestFixture] + public class GetLogoLinksTests + { + private Database database; + + [SetUp] + 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")); + } + + [Test] + public void GetLogoLink_LogoExists_ReturnsLogoLink() + { + string logoName = "Logo2"; + string logoLink = database.GetLogoLink(logoName); + Assert.That(logoLink, Is.EqualTo("link2")); + } + + [Test] + public void GetLogoLink_LogoDoesNotExist_ThrowsException() + { + 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 new file mode 100644 index 0000000..3f9f74f --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/Notus_UnitTest_Database.csproj @@ -0,0 +1,24 @@ + + + + net7.0 + enable + enable + + false + true + + + + + + + + + + + + + + + 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 new file mode 100644 index 0000000..3c25715 --- /dev/null +++ b/notus/Tests/Notus_UnitTest_Database/SearchUserTests.cs @@ -0,0 +1,54 @@ +using Biblioteque_de_Class; + +namespace Notus_UnitTest_Database +{ + [TestFixture] + public class SearchUserTests + { + private Database database; + + [SetUp] + public void Setup() + { + database = new Database(); + 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() + { + string searchName = "Jo"; + List searchedUsers = database.SearchUser(searchName); + Assert.That(searchedUsers.Count, Is.EqualTo(1)); + Assert.That(searchedUsers[0].GetUsername(), Is.EqualTo("John")); + } + + [Test] + public void SearchUser_UserDoesNotExist_ReturnsEmptyList() + { + string searchName = "Bob"; + List searchedUsers = database.SearchUser(searchName); + Assert.IsEmpty(searchedUsers); + } + + [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")); + } + + [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/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 84bd64d..6c35a63 100644 --- a/notus/notus.sln +++ b/notus/notus.sln @@ -3,11 +3,15 @@ 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("{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_Database", "Tests\Notus_UnitTest_Database\Notus_UnitTest_Database.csproj", "{EE443C17-B31D-4AD0-9141-920876E7DF79}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -29,6 +33,14 @@ 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 + {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 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