setup to start upgrade persistance and adding correct stub
continuous-integration/drone/push Build is failing Details

pull/19/head
Matheo THIERRY 2 years ago
commit 9a79b6a8b2

@ -6,6 +6,7 @@ trigger:
branch: branch:
- developpement - developpement
- master - master
- refonte_program
event: event:
- push - push

@ -37,14 +37,14 @@ namespace Biblioteque_de_Class
{ {
List<User> searchedUsers = new List<User>(); List<User> searchedUsers = new List<User>();
string search = name.ToLower(); string search = name.ToLower();
searchedUsers.AddRange(UserList.Where(user => user.GetUsername().ToLower().Contains(search))); searchedUsers.AddRange(UserList.Where( user => user.GetUsername().ToLower().Contains(search)));
return searchedUsers; return searchedUsers;
} }
/// <summary> /// <summary>
/// récupérer le lien d'un logo /// récupérer le lien d'un logo
/// </summary> /// </summary>
public string GetLogoLink(string name) public string? GetLogoLink(string name)
{ {
foreach (Logo logo in DefaultLogoList) foreach (Logo logo in DefaultLogoList)
{ {
@ -71,7 +71,7 @@ namespace Biblioteque_de_Class
/// <summary> /// <summary>
/// comparer le mot de passe entré avec celui de l'utilisateur /// comparer le mot de passe entré avec celui de l'utilisateur
/// </summary> /// </summary>
public static bool ComparePassword(User user, string password) => user.GetPassword() == password; public static bool ComparePassword(User user, string? password) => user.GetPassword() == password;
/// <summary> /// <summary>
/// rechercher un mail dans la liste d'utilisateur /// rechercher un mail dans la liste d'utilisateur
@ -144,6 +144,10 @@ namespace Biblioteque_de_Class
{ {
if (ThemeList.Contains(theme)) if (ThemeList.Contains(theme))
{ {
if (theme.GetName().Length > 6 && theme.GetName()[..6] != "Static" )
{
throw new AlreadyUsedException("This theme is used a default theme.");
}
ThemeList.Remove(theme); ThemeList.Remove(theme);
} }
else else
@ -199,7 +203,6 @@ namespace Biblioteque_de_Class
return; return;
} }
} }
throw new NotFoundException("Theme not found.");
} }
} }
} }

@ -11,30 +11,5 @@ namespace Biblioteque_de_Class
public void SaveDatabaseData(Database database); public void SaveDatabaseData(Database database);
public Database LoadDatabaseData(); public Database LoadDatabaseData();
public void SaveUserData(User user);
public List<User> LoadUserData();
public List<Note> LoadNote();
public void SaveNote(Note note);
public List<Theme> LoadTheme();
public void SaveTheme(Theme theme);
public List<Logo> LoadLogo();
public void SaveLogo(Logo logo);
public List<Tags> LoadTags();
public void SaveTags(Tags tag);
public List<NoteImage> LoadNoteImage();
public void SaveNoteImage(NoteImage noteImage);
} }
} }

@ -15,7 +15,8 @@ namespace Biblioteque_de_Class
private set { if (value == null) { name = "Unnamed Note"; } else { name = value; } } private set { if (value == null) { name = "Unnamed Note"; } else { name = value; } }
} }
///private string Text { get; set; } Attribut pour le texte de la note <summary> private string Text { get; set; } = "";
private string logoPath; private string logoPath;
public string LogoPath public string LogoPath
{ {
@ -26,7 +27,6 @@ namespace Biblioteque_de_Class
private DateOnly CreationDate { get; } private DateOnly CreationDate { get; }
private DateOnly ModificationDate { get; set; } private DateOnly ModificationDate { get; set; }
private readonly List<NoteImage> ImageList; private readonly List<NoteImage> ImageList;
private string TextLine;
private readonly List<User> Collaborators; private readonly List<User> Collaborators;
private readonly List<User> Editors; private readonly List<User> Editors;
private readonly User Owner; private readonly User Owner;
@ -45,10 +45,10 @@ namespace Biblioteque_de_Class
public string GetName() { return Name; } public string GetName() { return Name; }
public string GetLogoPath() { return LogoPath; } public string GetLogoPath() { return LogoPath; }
public string GetText() { return Text; }
public DateOnly GetCreationDate() { return CreationDate; } public DateOnly GetCreationDate() { return CreationDate; }
public DateOnly GetModificationDate() { return ModificationDate; } public DateOnly GetModificationDate() { return ModificationDate; }
public List<NoteImage> GetImageList() { return ImageList; } public List<NoteImage> GetImageList() { return ImageList; }
public string GetTextLine() { return TextLine; }
public List<User> GetCollaborators() { return Collaborators; } public List<User> GetCollaborators() { return Collaborators; }
public List<User> GetEditors() { return Editors; } public List<User> GetEditors() { return Editors; }
public User GetOwner() { return Owner; } public User GetOwner() { return Owner; }
@ -58,7 +58,6 @@ namespace Biblioteque_de_Class
public void SetName(string name) { Name = name; } public void SetName(string name) { Name = name; }
public void SetLogoPath(string logoPath) { LogoPath = logoPath; } public void SetLogoPath(string logoPath) { LogoPath = logoPath; }
public void SetModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); } public void SetModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); }
public void SetTextLine(string texte) { TextLine = texte; }
/// <summary> /// <summary>
/// vérifier si l'utilisateur est le propriétaire de la note /// vérifier si l'utilisateur est le propriétaire de la note
@ -87,6 +86,11 @@ namespace Biblioteque_de_Class
throw new NotFoundException("Image not found"); throw new NotFoundException("Image not found");
} }
public void AddText(string text)
{
Text = Text + "\n" + text;
}
/// <summary> /// <summary>
/// vérifier si l'utilisateur est un éditeur de la note /// vérifier si l'utilisateur est un éditeur de la note
/// </summary> /// </summary>

@ -14,6 +14,7 @@ namespace Biblioteque_de_Class
private string Email { get; set; } private string Email { get; set; }
[DataMember] [DataMember]
private string Password { get; set; } private string Password { get; set; }
private Theme Theme;
[DataMember] [DataMember]
private List<Note> NoteList; private List<Note> NoteList;
[DataMember] [DataMember]
@ -39,44 +40,30 @@ namespace Biblioteque_de_Class
public string GetUsername() { return Username; } public string GetUsername() { return Username; }
public string GetEmail() { return Email; } public string GetEmail() { return Email; }
public string GetPassword() { return Password; } public string GetPassword() { return Password; }
public Theme GetTheme() { return Theme; }
public List<Note> GetNoteList() { return NoteList; } public List<Note> GetNoteList() { return NoteList; }
public List<Tags> GetTagList() { return TagList; } public List<Tags> GetTagList() { return TagList; }
public List<Note> GetFavList() { return FavList; } public List<Note> GetFavList() { return FavList; }
public bool GetIsConnected() { return IsConnected; } public bool GetIsConnected() { return IsConnected; }
public Dictionary<Note, List<Tags>> GetNoteTagged() { return NoteTagged; } public Dictionary<Note, List<Tags>> GetNoteTagged() { return NoteTagged; }
public List<Tags> GetNoteTaggedList(Note note) { return NoteTagged[note]; }
public void SetUsername(string username) { Username = username; } public void SetUsername(string username) { Username = username; }
public void SetEmail(string email) { Email = email; } public void SetEmail(string email) { Email = email; }
public void SetPassword(string password) { Password = password; } public void SetPassword(string password) { Password = password; }
public void SetTheme(Theme theme) { Theme = theme; }
public void SetIsConnected(bool isConnected) { IsConnected = isConnected; } public void SetIsConnected(bool isConnected) { IsConnected = isConnected; }
public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}"; public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}";
/// <summary> /// <summary>
/// rechercher une note dans la liste de note de l'utilisateur /// rechercher une note dans la liste de note de l'utilisateur et la liste de note favoris de l'utilisateur
/// </summary> /// </summary>
public List<Note> SearchNoteByName(string name) public List<Note> SearchNoteByName(List<Note> ToResearchIntoList, string name)
{ {
List<Note> searchedNotes = new List<Note>(); List<Note> searchedNotes = new List<Note>();
string search = name.ToLower(); string search = name.ToLower();
foreach (Note note in NoteList) foreach (Note note in ToResearchIntoList)
{
if (note.GetName().ToLower().Contains(search))
{
searchedNotes.Add(note);
}
}
return searchedNotes;
}
/// <summary>
/// rechercher une note dans la liste de note favoris de l'utilisateur
/// </summary>
public List<Note> SearchFavoriteNoteByName(string name)
{
List<Note> searchedNotes = new List<Note>();
string search = name.ToLower();
foreach (Note note in FavList)
{ {
if (note.GetName().ToLower().Contains(search)) if (note.GetName().ToLower().Contains(search))
{ {
@ -89,11 +76,11 @@ namespace Biblioteque_de_Class
/// <summary> /// <summary>
/// rechercher un tag dans la liste de tag de l'utilisateur /// rechercher un tag dans la liste de tag de l'utilisateur
/// </summary> /// </summary>
public List<Tags> SearchTagByName(string name) public List<Tags> SearchTagByName(List<Tags> ToResearchIntoList, string name)
{ {
List<Tags> searchedTags = new List<Tags>(); List<Tags> searchedTags = new List<Tags>();
string search = name.ToLower(); string search = name.ToLower();
foreach (Tags tag in TagList) foreach (Tags tag in ToResearchIntoList)
{ {
if (tag.GetName().ToLower().Contains(search)) if (tag.GetName().ToLower().Contains(search))
{ {
@ -109,7 +96,7 @@ namespace Biblioteque_de_Class
string search = name.ToLower(); string search = name.ToLower();
foreach (Note note in ToResearchIntoList) foreach (Note note in ToResearchIntoList)
{ {
if (note.GetName().ToLower().Contains(search) && note.GetCreationDate() >= FirstDate && note.GetCreationDate() <= SecondeDate) if (note.GetName().ToLower().Contains(search) && note.GetCreationDate() >= FirstDate && note.GetCreationDate() <= SecondeDate || note.GetModificationDate() >= FirstDate && note.GetModificationDate() <= SecondeDate)
{ {
searchedNotes.Add(note); searchedNotes.Add(note);
} }
@ -117,6 +104,30 @@ namespace Biblioteque_de_Class
return searchedNotes; return searchedNotes;
} }
public Note GetNoteByName(string name)
{
foreach (Note note in NoteList)
{
if (note.GetName() == name)
{
return note;
}
}
throw new NotFoundException("Note not found");
}
public Tags GetTagByName(string name)
{
foreach (Tags tag in TagList)
{
if (tag.GetName() == name)
{
return tag;
}
}
throw new NotFoundException("Tag not found");
}
/// <summary> /// <summary>
/// ajouter une note dans la liste de note favorite de l'utilisateur /// ajouter une note dans la liste de note favorite de l'utilisateur
/// </summary> /// </summary>
@ -164,17 +175,18 @@ namespace Biblioteque_de_Class
/// <summary> /// <summary>
/// supprimer une note /// supprimer une note
/// </summary> /// </summary>
public void DeleteNote(Note note) public void DeleteNote(string note)
{ {
if (NoteList.Contains(note)) foreach (Note existingNote in NoteList)
{
NoteList.Remove(note);
NoteTagged.Remove(note);
}
else
{ {
throw new NotFoundException("Note not found"); if (existingNote.GetName() == note)
{
NoteList.Remove(existingNote);
NoteTagged.Remove(existingNote);
return;
}
} }
throw new NotFoundException("Note not found");
} }
/// <summary> /// <summary>

@ -1,361 +1,648 @@
using Biblioteque_de_Class; using Biblioteque_de_Class;
using System.ComponentModel.DataAnnotations.Schema;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Runtime.InteropServices;
using Notus_Persistance; using Notus_Persistance;
using System.Collections;
using System.Security.Cryptography;
using System.Text;
// load database
PersistenceManager manager = new(new Stub());
Database db = manager.LoadDatabaseData();
foreach(User user in db.GetUserList())
{
user.SetPassword(GetSHA256Hash(user.GetPassword()));
}
string Upseudo = "u"; // initialization zone==============================================================================
string Umail = "u";
string Upassword = "u";
int nomImage = 1;
string linkimage = "u";
string position = "u";
string nomNote = "u";
string logoPath = "u";
string NomTag = "u";
string nom = "u";
string choixNom;
string choixCouleur;
string choixModif;
int image_;
string choix;
string color = "u";
string color2;
string color3;
bool continuerboucle = false;
bool menu = true, connection = false, inscription = false;
bool note=false, tags=false, para=false, paraCompte=false, theme=false;
User user = new User(Upseudo, Umail, Upassword); // déclaration d'un user qui sera utiliser pour servir de personne connecté dans l'app
NoteImage image = new NoteImage(nomImage, linkimage, position); User u = new("", "", "");
Database db = new Database(); User uvide = new("", "", "");
User u = new User(Upseudo, Umail, Upassword); uvide.SetIsConnected(false);
Note n = new Note(nomNote, logoPath, u);
Tags t = new Tags(NomTag, color);
PersistenceManager managerPers = new PersistenceManager(new Stub());
List<string> NewColorList = new List<string> { }; // déclaration d'une note qui sera utiliser pour servir de note selectionnée
List<string> listCouleurs = new List<string> { }; Note n = new("","",uvide);
List<Note> _searchedNotes;
List<Note> NoteListe = managerPers.LoadNote();
List<Tags> _searchedTags;
List<User> UserListe = managerPers.LoadUserData();
List<Note> researchlist = new();
// factorisation
bool continuer()
>>>>>>> refonte_program
{
continuerboucle = false;
while(!continuerboucle)
{
Console.WriteLine("\nContinuer ? (O/n)");
switch (Console.ReadLine())
{
case "O":
return true;
case null:
return true;
case "o":
return true;
case "n":
return false;
default:
Console.WriteLine("\nEntrez un choix valide.\n");
continuerboucle = true;
break;
}
}
return false;
}
/*foreach (Note no in NoteListe) /// Test du stub bool choix_note()
{ {
Console.WriteLine(no.GetName()); Console.WriteLine("\nChoisissez le nom de la note");
string? wantedModifyNote = Console.ReadLine();
wantedModifyNote??= "";
try
{
n = u.GetNoteByName(wantedModifyNote);
}catch (Exception ex) { Console.WriteLine(ex.Message); return false; }
return true;
}
void displayNote()
{
foreach (Note note in u.GetNoteList())
{
Console.WriteLine(note.GetName() + "\n");
}
}
void displayTag()
{
foreach (Tags tag in u.GetTagList())
{
Console.WriteLine(tag.GetName() + "\n");
}
} }
return;*/
int boucle = 0; void displayTheme()
while (boucle == 0)
{ {
Console.WriteLine("|--------------------------------------|"); foreach (Theme theme in db.GetThemeList())
{
Console.WriteLine(theme.GetName() + "\n");
}
}
List<string>? choix_couleur()
{
List<string> colorList = new();
Console.WriteLine("Fond : ");
string? wantedNewThemeFond = Console.ReadLine();
if(wantedNewThemeFond == null){ return null; }
else if(wantedNewThemeFond[0].ToString() != "#"){
Console.WriteLine("\nLa couleur doit être au format hexadécimal.\n");
return null;
}else if(wantedNewThemeFond.Length != 7)
{
string toadd="";
for(int i = 7- wantedNewThemeFond.Length; i!=0; i--){toadd += "0";}
wantedNewThemeFond += toadd;
return null;
}
Console.WriteLine("Texte : ");
string? wantedNewThemeTexte = Console.ReadLine();
if(wantedNewThemeTexte == null){ return null; }
else if(wantedNewThemeTexte[0].ToString() != "#"){
Console.WriteLine("\nLa couleur doit être au format hexadécimal.\n");
return null;
}else if(wantedNewThemeTexte.Length != 7)
{
string toadd="";
for(int i = 7- wantedNewThemeTexte.Length; i!=0; i--){toadd += "0";}
wantedNewThemeTexte += toadd;
return null;
}
Console.WriteLine("Bouton : ");
string? wantedNewThemeBouton = Console.ReadLine();
if(wantedNewThemeBouton == null){ return null; }
else if(wantedNewThemeBouton[0].ToString() != "#"){
Console.WriteLine("\nLa couleur doit être au format hexadécimal.\n");
return null;
}else if(wantedNewThemeBouton.Length != 7)
{
string toadd="";
for(int i = 7- wantedNewThemeBouton.Length; i!=0; i--){toadd += "0";}
wantedNewThemeBouton += toadd;
return null;
}
colorList.Add(wantedNewThemeFond);
colorList.Add(wantedNewThemeTexte);
colorList.Add(wantedNewThemeBouton);
return colorList;
}
static string GetSHA256Hash(string input)
{
using (SHA256 sha256Hash = SHA256.Create())
{
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}
while (menu)
{
Console.WriteLine("\n|--------------------------------------|");
Console.WriteLine("| |"); Console.WriteLine("| |");
Console.WriteLine("| Menu pour lister les fonctionnalités |"); Console.WriteLine("| starting menu |");
Console.WriteLine("| |"); Console.WriteLine("| |");
Console.WriteLine("|--------------------------------------|--------|"); Console.WriteLine("|--------------------------------------|--------|");
Console.WriteLine("| |"); Console.WriteLine("| |");
Console.WriteLine("| 1/se connecter |"); Console.WriteLine("| 1 / - connection - |");
Console.WriteLine("| 2/se déconnecter |"); Console.WriteLine("| 2 / - inscription - |");
Console.WriteLine("| 3/créer un compte |");
Console.WriteLine("| 4/supprimer un compte |");
Console.WriteLine("| 5/créer note |");
Console.WriteLine("| 6/supprimer note |");
Console.WriteLine("| 7/créer tag |");
Console.WriteLine("| 8/ajouter tag |");
Console.WriteLine("| 9/supprimer tag |");
Console.WriteLine("| 10/ajouter image |");
Console.WriteLine("| 11/supprimer image |");
Console.WriteLine("| 12/déplacer image |");
Console.WriteLine("| 13/supprimer tag definitif |");
Console.WriteLine("| 14/Ajouter favori |");
Console.WriteLine("| 15/Supprimer favori |");
Console.WriteLine("| 16/créer un thème |");
Console.WriteLine("| 17/supprimer un thème |");
Console.WriteLine("| 18/modifier un thème |");
Console.WriteLine("| 19/rechercher une note |");
Console.WriteLine("| 20/rechercher une note avec tags |");
Console.WriteLine("| 21/rechercher une note avec date |");
Console.WriteLine("| 22/modifier tags |");
Console.WriteLine("| 23/modifier compte |");
Console.WriteLine("| 24/modifier note |");
Console.WriteLine("| 25/partage note |");
Console.WriteLine("| 26/modifier role (si proprietaire) |");
Console.WriteLine("| 27/supprimer cooperateur |");
Console.WriteLine("| |"); Console.WriteLine("| |");
Console.WriteLine("|-----------------------------------------------|"); Console.WriteLine("|-----------------------------------------------|\n");
Console.WriteLine("rentrez votre choix.");
switch (Console.ReadLine()) switch (Console.ReadLine())
{ {
case "1": ///Connexion case "1": ///Connexion
Console.WriteLine("Entrez votre nom."); connection = true; break;
nom = Console.ReadLine();
case "2":///Creer un compte
inscription = true; break;
default:
Console.WriteLine("\nEntrez un choix valide.\n");
break;
}
//connection
while (connection)
{
connection = false;
Console.WriteLine("\nEntrez un nom : ");
string? nom = Console.ReadLine();
if (nom == null) { continue; }
Console.WriteLine("\nEntrez un password :");
string? password = Console.ReadLine();
if (password == null) { continue; }
password = GetSHA256Hash(password);
try
{
u = db.GetUser(nom); u = db.GetUser(nom);
Umail = u.GetEmail(); }
Upassword = u.GetPassword(); catch (AlreadyUsedException ex)
db.FindEmail(Umail); {
Database.ComparePassword(u,Upassword); Console.WriteLine(ex.Message);
UserListe = db.GetUserList(); connection = true;
if (UserListe.Contains(u)) }
if (!connection)
{
if (Database.ComparePassword(u, password))
{ {
u.SetIsConnected(true); u.SetIsConnected(true);
Console.WriteLine("Connecté"); Console.WriteLine("\nConnection réussie !\n");
break; menu = false;
} }
else else
{ {
Console.WriteLine("Utilisateur non trouvé."); Console.WriteLine("\nWrong PassWord !\n");
break; connection = true;
continuerboucle = true;
u = uvide;
} }
}
while (continuerboucle) { connection = continuer(); }
}
case "2":///Deconnexion //inscription
u.SetIsConnected(false); while (inscription)
Console.WriteLine("Vous vous êtes déconnecté avec succès."); {
break; Console.WriteLine("\nEntrez un nom :");
string? nom = Console.ReadLine();
case "3":///Creer un compte if (nom == null) { continue; }
Console.WriteLine("Choisissez un pseudo"); Console.WriteLine("\nEntrez un password :");
Upseudo = Console.ReadLine(); string? password = Console.ReadLine();
Console.WriteLine("Entrez votre adresse mail"); if (password == null) { continue; }
Umail = Console.ReadLine(); try
Console.WriteLine("Saisissez un mot de passe"); {
Upassword = Console.ReadLine();
User u1 = new User(Upseudo, Umail, Upassword);
db.AddUser(u1);
break;
case "4":///Supprimer Compte
Console.WriteLine("Chercher utilisateur");
nom = Console.ReadLine();
u = db.GetUser(nom); u = db.GetUser(nom);
Umail = u.GetEmail(); }
db.FindEmail(Umail); catch (AlreadyUsedException)
Upassword = u.GetPassword(); {
Database.ComparePassword(u,Upassword); password = GetSHA256Hash(password);
UserListe = db.GetUserList(); u = new User(nom, "", password);
if (UserListe.Contains(u)) db.AddUser(u);
{ db.GetUser(nom).SetIsConnected(true);
db.RemoveUser(u); Console.WriteLine("\nConnection réussie !\n");
Console.WriteLine("Compte supprimé avec succès."); menu = false;
break;
}
Console.WriteLine("Utilisateur non trouvé.");
break;
case "5":///Creer une note
Console.WriteLine("Choisissez un nom");
nom = Console.ReadLine();
Console.WriteLine("Choisissez un logo");
logoPath = Console.ReadLine();
n = new Note(nom, logoPath, u);
u.CreateNote(nom, logoPath);
break;
case "6":///Supprimer une note
u.DeleteNote(n);
break;
case "7":///Creer un tag
Console.WriteLine("Choisissez un nom");
choixNom = Console.ReadLine();
Console.WriteLine("Choisissez une couleur");
choixCouleur = Console.ReadLine();
u.CreateTag(choixNom, choixCouleur);
break;
case "8":///Ajouter un tag a une note
Console.WriteLine("Cherchez une note");
nom = Console.ReadLine();
_searchedNotes = u.SearchNoteByName(nom);
Console.WriteLine("Cherchez un tag");
nom = Console.ReadLine();
Tags tagToAdd = new Tags(nom, color);
u.AddTagToNoteList(n, tagToAdd);
break;
case "9":///Supprimer un tag a une note
Console.WriteLine("Cherchez une note");
nom = Console.ReadLine();
_searchedNotes = u.SearchNoteByName(nom);
Console.WriteLine("Cherchez un tag");
nom = Console.ReadLine();
_searchedTags = u.SearchTagByName(nom); ///A voir pour faire correctement
Tags tagToSupp = new Tags(nom, color);
tagToSupp = _searchedTags[1];
u.RemoveTagFromNoteList(n, tagToSupp);
break;
case "10":///Ajouter une image
n.AddImage(linkimage, position);
break;
case "11":///Supprimer une image
Console.WriteLine("Saisir numero de la note");
image_ = Convert.ToInt32(Console.ReadLine());
n.RemoveImage(image_);
break;
case "12":///Deplacer une image
image.SetPosition(position);
break;
case "13":///Supprimer un tag definitivement
_searchedTags = u.SearchTagByName(nom);
u.RemoveTagFromNoteList(n, t);
break;
case "14":///AJouter une note en favori
u.AddFavorite(n);
break; break;
}
Console.WriteLine("\nNom d'utilisateur déjà utilisé. \n");
while (continuerboucle) { inscription = continuer(); }
case "15":///Supprimer une note des favoris }
u.RemoveFavorite(n); }
break; //une fois connecté ou inscription fait
while (u.GetIsConnected())
case "16":///Creer un theme {
Console.WriteLine("Choisissez un nom pour votre theme"); Console.WriteLine("\n|--------------------------------------|");
nom = Console.ReadLine(); Console.WriteLine("| |");
Console.WriteLine("Choisissez trois couleurs"); Console.WriteLine("| menu |");
color = Console.ReadLine(); Console.WriteLine("| |");
color2 = Console.ReadLine(); Console.WriteLine("|--------------------------------------|--------|");
color3 = Console.ReadLine(); Console.WriteLine("| |");
listCouleurs.Add(color); Console.WriteLine("| 1/ - rechercher note - |");
listCouleurs.Add(color2); Console.WriteLine("| 2/ - note - |");
listCouleurs.Add(color3); Console.WriteLine("| 3/ - tags - |");
Theme th = new Theme(nom, listCouleurs); Console.WriteLine("| 4/ - paramêtres - |");
db.AddTheme(th); Console.WriteLine("| 5/ - se déconnecter - |");
listCouleurs.RemoveAt(1); Console.WriteLine("| |");
listCouleurs.RemoveAt(1); Console.WriteLine("|-----------------------------------------------|\n");
listCouleurs.RemoveAt(1); Console.WriteLine("rentrez votre choix.");
break; switch (Console.ReadLine())
{
case "17":///Supprimer un theme case "1":
th = db.GetTheme(nom); researchlist = u.GetNoteList();
db.RemoveTheme(th); Console.WriteLine("\nEntrez la note que vous cherchez. ");
break; string? wantedSearchNote = Console.ReadLine();
Console.WriteLine("\nChercher par tags ? (o/N) ");
case "18":///Modifier un theme Console.WriteLine("\nChercher par date ? (o/N) ");
Console.WriteLine("Cherchez un theme a modifier");
nom = Console.ReadLine();
th = db.GetTheme(nom);
db.ModifyThemeName(th,nom);
Console.WriteLine("Choisissez trois couleurs");
color = Console.ReadLine();
color2 = Console.ReadLine();
color3 = Console.ReadLine();
NewColorList.Add(color);
NewColorList.Add(color2);
NewColorList.Add(color3);
db.ModifyThemeColorList(th, NewColorList);
NewColorList.RemoveAt(1);
NewColorList.RemoveAt(1);
NewColorList.RemoveAt(1);
break; break;
case "2":
case "19":///Rechercher une note note = true;
Console.WriteLine("Cherchez une note");
nom = Console.ReadLine();
NoteListe = u.GetNoteList();
u.SearchNoteByName(nom);
break; break;
case "3":
case "20":///Recherche note par tag tags = true;
///u.;
break; break;
case "4":
case "21":///Recherche note par dateCreation para = true;
///u.;
break; break;
case "5":
case "22":///Modifier un tag Console.WriteLine("\ndéconnecté! \n");
Console.WriteLine("Cherchez un tag"); u.SetIsConnected(false);
nom = Console.ReadLine(); u = uvide;
Console.WriteLine("Choisisez une couleur");
color = Console.ReadLine();
t.SetName(nom);
t.SetColor(color);
break; break;
default:
case "23":///Modifier le compte Console.WriteLine("\nEntrez un choix valide.\n");
Console.WriteLine("Modifier pseudo ? Mot de passe ? Mail ? (0/1/2)");
choixModif = Console.ReadLine();
if (choixModif.Equals('0'))
{
Console.WriteLine("Entrez votre nouveau pseudo");
Upseudo = Console.ReadLine();
u.SetUsername(Upseudo);
}
if (choixModif.Equals('1'))
{
Console.WriteLine("Entrez votre nouveau mot de passe");
Upassword = Console.ReadLine();
u.SetPassword(Upassword);
}
if (choixModif.Equals('2'))
{
Console.WriteLine("Entrez votre nouvelle adresse mail");
Umail = Console.ReadLine();
u.SetEmail(Umail);
}
break; break;
}
case "24":///Modifier le texte de la note while(note)
n.VerifyPrivilege(u); {
if (true) Console.WriteLine("\n|--------------------------------------|");
{ Console.WriteLine("| |");
string texte = Console.ReadLine(); Console.WriteLine("| menu - note |");
n.SetTextLine(texte); Console.WriteLine("| |");
} Console.WriteLine("|--------------------------------------|--------|");
else Console.WriteLine("| |");
{ Console.WriteLine("| 1/ - afficher la liste des notes - |");
Console.WriteLine("Vous ne possedez pas les droits pour effectuer cette action."); Console.WriteLine("| 2/ - afficher une note - |");
} Console.WriteLine("| 3/ - modifier une note - |");
break; Console.WriteLine("| 4/ - écrire dans une note - |");
Console.WriteLine("| 5/ - créer note - |");
Console.WriteLine("| 6/ - supprimer note - |");
Console.WriteLine("| 7/ - retour - |");
Console.WriteLine("| |");
Console.WriteLine("|-----------------------------------------------|\n");
Console.WriteLine("note actuelle : " + n.GetName());
Console.WriteLine("rentrez votre choix.");
switch (Console.ReadLine())
{
case "1":
displayNote();
break;
case "2":
if (!choix_note()) { break; }
Console.WriteLine("\n" + n.GetName() + " :");
Console.WriteLine(n.GetText());
break;
case "3":
if (!choix_note()) { break;}
Console.WriteLine("\nChoisissez le nouveau nom de la note (entrer - nom par defaut)");
string? wantedNewNameNote = Console.ReadLine();
wantedNewNameNote??= "";
n.SetName(wantedNewNameNote);
break;
case "4":
if (!choix_note()) { break; }
Console.WriteLine(n.GetText());
Console.WriteLine("\nEntrez le texte à ajouter");
string? wantedTextNote = Console.ReadLine();
wantedTextNote??= "";
n.AddText(wantedTextNote);
break;
case "5":
Console.WriteLine("\nChoisissez le nom de la note (entrer - nom par defaut)");
string? wantedNameNote = Console.ReadLine();
wantedNameNote ??= "";
u.CreateNote(wantedNameNote, "");
break;
case "6":
Console.WriteLine("\nChoisissez le nom de la note");
string? wantedDeleteNote = Console.ReadLine();
wantedDeleteNote ??= "";
try
{
u.DeleteNote(wantedDeleteNote);
}
catch (Exception ex) { Console.WriteLine(ex.Message); }
break;
case "7":
note = false;
break;
default:
Console.WriteLine("\nEntrez un choix valide.\n");
break;
}
}
case "25":///Partager la note while (tags)
n.VerifyPrivilege(u); {
if (true) Console.WriteLine("\n|--------------------------------------|");
{ Console.WriteLine("| |");
Console.WriteLine("Saisissez un utilisateur"); Console.WriteLine("| menu - tags |");
nom = Console.ReadLine(); Console.WriteLine("| |");
user = db.GetUser(nom); Console.WriteLine("|--------------------------------------|--------|");
n.AddCollaborator(u, user); Console.WriteLine("| |");
} Console.WriteLine("| 1/ - créer tag - |");
break; Console.WriteLine("| 2/ - ajouter tag - |");
Console.WriteLine("| 3/ - supprimer tag - |");
Console.WriteLine("| 4/ - retour - |");
Console.WriteLine("| |");
Console.WriteLine("|-----------------------------------------------|\n");
Console.WriteLine("rentrez votre choix.");
switch (Console.ReadLine())
{
case "1":
Console.WriteLine("\nChoisissez le nom du tag.");
string? wantedNameTag = Console.ReadLine();
wantedNameTag??= "NoName" + u.GetTagList().Count.ToString();
Console.WriteLine("\nChoisissez la couleur du tag.");
string? wantedColorTag = Console.ReadLine();
wantedColorTag??= "#000000";
if (wantedColorTag[0] != '#') { wantedColorTag = "#" + wantedColorTag; }
else if (wantedColorTag.Length < 7) { string toadd=""; for(int i = 7-wantedColorTag.Length; i!=0; i--){toadd += "0";} wantedColorTag += toadd ;}
else if (wantedColorTag.Length > 7) { wantedColorTag = wantedColorTag[..7];}
u.CreateTag(wantedNameTag,wantedColorTag);
break;
case "2":
Note wantedAddNote;
Tags wantedAddTag;
Console.WriteLine("\n Plusieurs tags à ajouter ? (o/N)");
string? wantedAddMultipleTag = Console.ReadLine();
wantedAddMultipleTag ??= "N";
if(wantedAddMultipleTag == "o" || wantedAddMultipleTag == "O"){
displayNote();
Console.WriteLine("\nDonnez le nom de la note à laquelle ajouter des tags : ");
string? wantedAddNameNote = Console.ReadLine();
wantedAddNameNote??= "";
try{
wantedAddNote = u.GetNoteByName(wantedAddNameNote);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
displayTag();
Console.WriteLine("\nChoisissez les noms des tags séparés par des espaces.");
string? wantedAddNameTags = Console.ReadLine();
wantedAddNameTags??= "";
string[] wantedAddNameTagsList = wantedAddNameTags.Split(' ');
foreach(string wantedAddNameTag in wantedAddNameTagsList)
{
try
{
wantedAddTag = u.GetTagByName(wantedAddNameTag);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
try
{
u.AddTagToNoteList(wantedAddNote, wantedAddTag);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
}
}else if(wantedAddMultipleTag == "n" || wantedAddMultipleTag == "N"){
displayNote();
Console.WriteLine("\nChoisissez le nom de la note.");
string? wantedAddNameNote = Console.ReadLine();
wantedAddNameNote??= "";
displayTag();
Console.WriteLine("\nChoisissez le nom du tag.");
string? wantedAddNameTag = Console.ReadLine();
wantedAddNameTag??= "";
try
{
wantedAddNote = u.GetNoteByName(wantedAddNameNote);
wantedAddTag = u.GetTagByName(wantedAddNameTag);
u.AddTagToNoteList(wantedAddNote, wantedAddTag);
}catch (Exception ex) { Console.WriteLine(ex.Message); }
}else{
Console.WriteLine("\nEntrez un choix valide.\n");
}
break;
case "3":
displayNote();
Note wantedRemoveNote;
Tags wantedRemoveTag;
Console.WriteLine("\n Choisissez le nom de la note à laquelle supprimer des tags : ");
string? wantedRemoveNameNote = Console.ReadLine();
wantedRemoveNameNote??= "";
try{
wantedRemoveNote = u.GetNoteByName(wantedRemoveNameNote);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
foreach( Tags t in u.GetNoteTaggedList(wantedRemoveNote))
{
Console.WriteLine(t.GetName() + "\n");
}
Console.WriteLine("\nChoisissez le nom du tag à supprimer.");
string? wantedRemoveNameTag = Console.ReadLine();
wantedRemoveNameTag??= "";
try {
wantedRemoveTag = u.GetTagByName(wantedRemoveNameTag);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
try
{
u.RemoveTagFromNoteList(wantedRemoveNote, wantedRemoveTag);
}catch (Exception ex) { Console.WriteLine(ex.Message); }
break;
case "4":
tags = false;
break;
default:
Console.WriteLine("\nEntrez un choix valide.\n");
break;
}
}
case "26":///Modifier les editeurs while(para)
Console.WriteLine("Ajouter editeur ou supprimer editeur ? (0/1)"); {
choix = Console.ReadLine(); Console.WriteLine("\n|--------------------------------------|");
n.VerifyPrivilege(u); Console.WriteLine("| |");
if (true && choix.Equals('0')) Console.WriteLine("| menu - paramêtre |");
{ Console.WriteLine("| |");
Console.WriteLine("Saisissez un utilisateur"); Console.WriteLine("|--------------------------------------|--------|");
nom = Console.ReadLine(); Console.WriteLine("| |");
user = db.GetUser(nom); Console.WriteLine("| 1/ - modifier compte - |");
n.AddEditor(u, user); Console.WriteLine("| 2/ - thèmes - |");
} Console.WriteLine("| 3/ - supprimer un compte - |");
if (true && choix.Equals('1')) Console.WriteLine("| 4/ - retour - |");
Console.WriteLine("| |");
Console.WriteLine("|-----------------------------------------------|\n");
Console.WriteLine("rentrez votre choix.");
switch (Console.ReadLine())
{
case "1":
paraCompte = true;
break;
case "2":
theme = true;
break;
case "3":
Console.WriteLine("\nÊtes-vous sûr de vouloir supprimer votre compte ? (o/N)");
string? wantedDelete = Console.ReadLine();
wantedDelete??= "N";
if( wantedDelete == "o" || wantedDelete == "O"){
db.RemoveUser(u);
Console.WriteLine("\nVotre compte a bien été supprimé.\n");
para = false;
u = uvide;
break;
}else if( wantedDelete == "n" || wantedDelete == "N"){
break;
}
break;
case "4":
para = false;
break;
default:
Console.WriteLine("\nEntrez un choix valide.\n");
break;
}
while (paraCompte)
{
Console.WriteLine("\n|--------------------------------------|");
Console.WriteLine("| |");
Console.WriteLine("| paramêtre - compte |");
Console.WriteLine("| |");
Console.WriteLine("|--------------------------------------|--------|");
Console.WriteLine("| |");
Console.WriteLine("| 1/ - modifier pseudo - |");
Console.WriteLine("| 2/ - modifier mot de passe - |");
Console.WriteLine("| 3/ - retour - |");
Console.WriteLine("| |");
Console.WriteLine("|-----------------------------------------------|\n");
Console.WriteLine("rentrez votre choix.");
switch (Console.ReadLine())
{ {
Console.WriteLine("Saisissez un utilisateur"); case "1":
nom = Console.ReadLine(); Console.WriteLine("\nChoisissez le nouveau pseudo.");
user = db.GetUser(nom); string? wantedNewPseudo = Console.ReadLine();
n.RemoveEditor(u, user); if(wantedNewPseudo == null){break;}
u.SetUsername(wantedNewPseudo);
break;
case "2":
Console.WriteLine("\nChoisissez le nouveau mot de passe.");
string? wantedNewPassword = Console.ReadLine();
if(wantedNewPassword == null){break;}
else if(wantedNewPassword.Length < 8){
Console.WriteLine("\nLe mot de passe doit contenir au moins 8 caractères.\n");
break;
}
wantedNewPassword = GetSHA256Hash(wantedNewPassword);
if(wantedNewPassword == u.GetPassword()){
Console.WriteLine("\nLe nouveau mot de passe doit être différent de l'ancien.\n");
break;
}
u.SetPassword(wantedNewPassword);
break;
case "3":
paraCompte = false;
break;
default:
Console.WriteLine("\nEntrez un choix valide.\n");
break;
} }
break; }
while (theme)
case "27":///Supprimer un cooperateur {
n.VerifyPrivilege(u); Console.WriteLine("\n|--------------------------------------|");
if (true) Console.WriteLine("| |");
Console.WriteLine("| paramêtre - thèmes |");
Console.WriteLine("| |");
Console.WriteLine("|--------------------------------------|--------|");
Console.WriteLine("| |");
Console.WriteLine("| 1/ - choisir un thème - |");
Console.WriteLine("| 2/ - créer un thème - |");
Console.WriteLine("| 3/ - supprimer un thème - |");
Console.WriteLine("| 4/ - modifier un thème - |");
Console.WriteLine("| 5/ - retour - |");
Console.WriteLine("| |");
Console.WriteLine("|-----------------------------------------------|\n");
Console.WriteLine("rentrez votre choix.");
switch (Console.ReadLine())
{ {
Console.WriteLine("Saisissez un utilisateur"); case "1":
nom = Console.ReadLine(); Theme twantedTheme;
user = db.GetUser(nom); displayTheme();
n.RemoveCollaborator(u, user); Console.WriteLine("\nChoisissez le nom du thème.");
string? wantedTheme = Console.ReadLine();
if(wantedTheme==null){break;}
try
{
twantedTheme = db.GetTheme(wantedTheme);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
u.SetTheme(twantedTheme);
break;
case "2":
List<string>? themeList;
Console.WriteLine("\nChoisissez le nom du thème.");
string? wantedNewThemeName = Console.ReadLine();
if(wantedNewThemeName==null){break;}
Console.WriteLine("\nChoisissez la couleur du thème.");
themeList = choix_couleur();
if(themeList == null) { break;}
db.AddTheme(new Theme(wantedNewThemeName, themeList));
break;
case "3":
Theme t;
Console.WriteLine("\nChoisissez le nom du thème à supprimer.");
string? wantedRemoveTheme = Console.ReadLine();
if(wantedRemoveTheme == null) {break;}
try{
t = db.GetTheme(wantedRemoveTheme);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
try{
db.RemoveTheme(t);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
break;
case "4":
displayTheme();
Theme themeToModify;
Console.WriteLine("\nChoisissez le nom du thème à modifier.");
string? wantedModifyTheme = Console.ReadLine();
if(wantedModifyTheme == null){break;}
try{
themeToModify = db.GetTheme(wantedModifyTheme);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
Console.WriteLine("\nChoisissez le nouveau nom du thème.");
string? wantedNewNameTheme = Console.ReadLine();
if(wantedNewNameTheme == null) {break;}
try{
db.ModifyThemeName(themeToModify, wantedNewNameTheme);
}catch (Exception ex) { Console.WriteLine(ex.Message); break;}
Console.WriteLine("\nChoisissez les nouvelles couleurs du thème.");
List<string>? couleurlist = choix_couleur();
if(couleurlist == null) { break;}
db.ModifyThemeColorList(themeToModify, couleurlist);
break;
case "5":
theme = false;
break;
default:
Console.WriteLine("\nEntrez un choix valide.\n");
break;
} }
break; }
default:
Console.WriteLine("< Veuillez rentrer une des options proposées à l'ecran ! >");
break;
} }
} }

@ -10,10 +10,9 @@ namespace Notus_Persistance
{ {
public class Stub : IManager public class Stub : IManager
{ {
void errorMess() public void SaveDatabaseData(Database database)
{ {
Console.WriteLine("Pas d'enregistrement de données dans le stub."); throw new NotImplementedException();
return;
} }
//Loaders //Loaders
@ -24,103 +23,15 @@ namespace Notus_Persistance
database.AddUser(new User("Benjamin", "labsent@gmail.com", "Moto2005")); database.AddUser(new User("Benjamin", "labsent@gmail.com", "Moto2005"));
database.AddUser(new User("Liam", "liammonchanin@gmail.com", "Baguette")); database.AddUser(new User("Liam", "liammonchanin@gmail.com", "Baguette"));
database.AddUser(new User("Brigitte", "Macroutte@gmail.com", "49Trois")); database.AddUser(new User("Brigitte", "Macroutte@gmail.com", "49Trois"));
foreach(User user in database.GetUserList().Where(x => x.GetUsername().Contains("m")))
{
user.CreateNote("Note 1", "");
user.CreateNote("Note 2", "");
user.CreateNote("Note 3", "");
}
return database; return database;
} }
List<User> IManager.LoadUserData()
{
List<User> users = new List<User>();
users.Add(new User("Nicolas", "leHeros@gmail.com", "Feur"));
users.Add(new User("Benjamin", "labsent@gmail.com", "Moto2005"));
users.Add(new User("Liam", "liammonchanin@gmail.com", "Baguette"));
users.Add(new User("Brigitte", "Macroutte@gmail.com", "49Trois"));
return users;
}
List<Note> IManager.LoadNote()
{
List<Note> notes = new List<Note>();
notes.Add(new Note("Note_1", "Logo_1", new User("Liam", "Liam@gmail.com", "Oui")));
notes.Add(new Note("Note_2", "Logo_3", new User("Liam", "Liam@gmail.com", "Oui")));
notes.Add(new Note("Note_3", "Logo_5", new User("Liam", "Liam@gmail.com", "Oui")));
notes.Add(new Note("Note_4", "Logo_7", new User("Liam", "Liam@gmail.com", "Oui")));
notes.Add(new Note("Note_5", "Logo_9", new User("Liam", "Liam@gmail.com", "Oui")));
return notes;
}
List<Theme> IManager.LoadTheme()
{
List<Theme> themes = new List<Theme>();
themes.Add(new Theme("Tropiques", new List<string> { }));
themes.Add(new Theme("Savane", new List<string> { }));
themes.Add(new Theme("Nuit", new List<string> { }));
return themes;
}
List<Logo> IManager.LoadLogo()
{
List<Logo> logos = new List<Logo>();
logos.Add(new Logo("pinguin", "pinguin.png"));
logos.Add(new Logo("ours", "ours.png"));
logos.Add(new Logo("caddie", "caddie.png"));
logos.Add(new Logo("croix", "croix.png"));
return logos;
}
List<Tags> IManager.LoadTags()
{
List<Tags> tags = new List<Tags>();
tags.Add(new Tags("courses", "vert"));
tags.Add(new Tags("urgent", "rouge"));
tags.Add(new Tags("enfants", "bleu"));
return tags;
}
List<NoteImage> IManager.LoadNoteImage()
{
List<NoteImage> noteImages = new List<NoteImage>();
noteImages.Add(new NoteImage(1, "soupe.png", "2.4"));
noteImages.Add(new NoteImage(2, "baguette.png", "5.2"));
noteImages.Add(new NoteImage(3, "cailloux.png", "3.10"));
return noteImages;
}
//Savers
void IManager.SaveNote(Note note)
{
errorMess();
}
void IManager.SaveDatabaseData(Database database)
{
errorMess();
}
void IManager.SaveUserData(User user)
{
errorMess();
}
void IManager.SaveTheme(Theme theme)
{
errorMess();
}
void IManager.SaveLogo(Logo logo)
{
errorMess();
}
void IManager.SaveTags(Tags tag)
{
errorMess();
}
void IManager.SaveNoteImage(NoteImage noteImage)
{
errorMess();
}
} }
} }

@ -19,9 +19,7 @@ namespace Notus_UnitTest_Database
[Test] [Test]
public void GetLogoLink_LogoExists_ReturnsLogoLink() public void GetLogoLink_LogoExists_ReturnsLogoLink()
{ {
string logoName = "Logo2"; Assert.That(database.GetLogoLink("Logo2"), Is.EqualTo("link2"));
string logoLink = database.GetLogoLink(logoName);
Assert.That(logoLink, Is.EqualTo("link2"));
} }
[Test] [Test]

@ -29,15 +29,5 @@ namespace Notus_UnitTest_Database
Assert.That(theme.GetColor(1), Is.EqualTo(newColorList[1])); Assert.That(theme.GetColor(1), Is.EqualTo(newColorList[1]));
Assert.That(theme.GetColor(2), Is.EqualTo(newColorList[2])); Assert.That(theme.GetColor(2), Is.EqualTo(newColorList[2]));
} }
[Test]
public void ModifyThemeColorList_NonExistingTheme_ThrowsException()
{
List<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
// no add :)
List<string> newColorList = new List<string> { "Red", "Green", "Blue" };
Assert.Throws<NotFoundException>(() => database.ModifyThemeColorList(theme, newColorList), "Theme not found.");
}
} }
} }

@ -5,34 +5,55 @@ namespace Notus_UnitTest_User
[TestFixture] [TestFixture]
public class SearchNoteByNameTests public class SearchNoteByNameTests
{ {
private User owner;
private string searchName;
[SetUp]
public void SetUp()
{
owner = new("Owner", "owner@example.com", "password");
owner.CreateNote("Note 1", "image1.png");
owner.CreateNote("Note 2", "image2.png");
owner.CreateNote("Another Note", "image3.png");
owner.AddFavorite(owner.GetNoteList()[0]);
owner.AddFavorite(owner.GetNoteList()[1]);
owner.AddFavorite(owner.GetNoteList()[2]);
searchName = "note";
}
[Test] [Test]
public void SearchNoteByName_WhenMatchingNotesExist_NotesReturned() public void SearchNoteByName_WhenMatchingNotesExist_NotesReturned()
{ {
User user = new User("TestUser", "testuser@example.com", "password"); List<Note> result = owner.SearchNoteByName(owner.GetNoteList(),"note");
Note note1 = new Note("Note 1", "image1.png", user); Assert.That(result, Has.Count.EqualTo(3));
Note note2 = new Note("Note 2", "image2.png", user); CollectionAssert.Contains(result, owner.GetNoteList()[0]);
Note note3 = new Note("Another Note", "image3.png", user); CollectionAssert.Contains(result, owner.GetNoteList()[1]);
user.GetNoteList().Add(note1); CollectionAssert.Contains(result, owner.GetNoteList()[2]);
user.GetNoteList().Add(note2);
user.GetNoteList().Add(note3);
List<Note> result = user.SearchNoteByName("note");
Assert.That(result.Count, Is.EqualTo(3));
CollectionAssert.Contains(result, note1);
CollectionAssert.Contains(result, note2);
CollectionAssert.Contains(result, note3);
} }
[Test] [Test]
public void SearchNoteByName_WhenNoMatchingNotesExist_EmptyListReturned() public void SearchNoteByName_WhenNoMatchingNotesExist_EmptyListReturned()
{ {
User user = new User("TestUser", "testuser@example.com", "password"); List<Note> result = owner.SearchNoteByName(owner.GetNoteList(), "test");
Note note1 = new Note("Note 1", "image1.png", user); Assert.That(result, Is.Empty);
Note note2 = new Note("Note 2", "image2.png", user);
user.GetNoteList().Add(note1);
user.GetNoteList().Add(note2);
List<Note> result = user.SearchNoteByName("test");
Assert.IsEmpty(result);
} }
[Test]
public void SearchFavoriteNoteByName_ShouldReturnMatchingNotes()
{
List<Note> searchedNotes = owner.SearchNoteByName(owner.GetFavList(), searchName);
Assert.That(searchedNotes, Has.Count.EqualTo(3));
CollectionAssert.Contains(searchedNotes, owner.GetNoteList()[0]);
CollectionAssert.Contains(searchedNotes, owner.GetNoteList()[1]);
CollectionAssert.Contains(searchedNotes, owner.GetNoteList()[2]);
}
[Test]
public void SearchFavoriteNoteByName_ShouldReturnEmptyList_WhenNoMatchFound()
{
searchName = "nonexistent";
List<Note> searchedNotes = owner.SearchNoteByName(owner.GetFavList(), searchName);
Assert.That(searchedNotes, Is.Empty);
}
} }
} }
Loading…
Cancel
Save