Compare commits

...

25 Commits

Author SHA1 Message Date
Matheo THIERRY 365742508e conflit fix
continuous-integration/drone/push Build is failing Details
2 years ago
Matheo THIERRY 9b2afcc6b2 oublie de datamember sur note
2 years ago
Matheo THIERRY 13f9923f6c Add SaveDefaultData_Test to ToXML_Tests
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY c60fc07efc exclude all exception
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY 9d40742045 ADD Save default and exclude exception from coverage
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY 3ec2199411 end User_Tests.cs
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY d1875e97eb Add ToXml_Tests
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY b6fc6871ab fix StubTests
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY 1f568ba29f Add Stub_Test
continuous-integration/drone/push Build is failing Details
2 years ago
Matheo THIERRY 975b5fbde7 fix change Exception to test
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY 2eb4330263 work in progress UserTests
continuous-integration/drone/push Build is failing Details
2 years ago
Matheo THIERRY 091b016244 try fixed sonar not working
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY 46d86bc107 test coverage didn't working
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY 76eece9089 change sln
continuous-integration/drone/push Build is passing Details
2 years ago
Matheo THIERRY 1478707057 test sonar et add tempo path to xml
continuous-integration/drone/push Build is failing Details
2 years ago
Matheo THIERRY d2688b2d92 working in progress UserTests.cs
2 years ago
Matheo THIERRY b1d05eabfe oublie sauvegarde user test
2 years ago
Matheo THIERRY 2d177dc028 tranfers pour pc iut starting coding usertest
2 years ago
Matheo THIERRY 2071f8ba32 Fix persistance - working | database tests reworked
2 years ago
Matheo THIERRY 9bbd0f3e4f reglage bug programs et finition
2 years ago
Matheo THIERRY 1b4352e22b reglage
2 years ago
Matheo THIERRY 6ce50be142 upgrade program et fix class finished
2 years ago
Matheo THIERRY 6005c16a35 oublie database sauvegarde
2 years ago
Matheo THIERRY 72aa47ee35 tranfert pour continuer sur pc iut
2 years ago
Matheo THIERRY 67245868b2 debut huge upgrade
2 years ago

@ -6,6 +6,7 @@ trigger:
branch:
- developpement
- master
- upgradeclass
event:
- push
@ -46,4 +47,21 @@ steps:
- dotnet sonarscanner end /d:sonar.login=$${sonar_token}
branch:
- developpement
depends_on: [build,tests]
depends_on: [build,tests]
- name: generate-and-deploy-docs
image: hub.codefirst.iut.uca.fr/thomas.bellembois/codefirst-docdeployer
failure: ignore
volumes:
- name: docs
path: /docs
commands:
- /entrypoint.sh
when:
branch:
- master
# environment:
# NODOXYGEN: true
volumes:
- name: docs
temp: {}

@ -11,13 +11,13 @@ using System.Web;
namespace Biblioteque_de_Class
{
[DataContract(IsReference = true)]
[DataContract]
public class Database
{
[DataMember]
private List<Logo> DefaultLogoList;
public List<Logo> DefaultLogoList { get; private set; }
[DataMember]
private List<Theme> ThemeList;
public List<Theme> ThemeList { get; private set; }
[DataMember]
private List<User> UserList = null!;
public List<User> Users { get => UserList; private set
@ -33,30 +33,25 @@ namespace Biblioteque_de_Class
DefaultLogoList = new List<Logo>();
ThemeList = new List<Theme>();
UserList = new List<User>();
AddedThemeList = new Dictionary<User, List<Theme>>();
}
public List<Logo> GetDefaultLogoList() { return DefaultLogoList; }
public List<Theme> GetThemeList() { return ThemeList; }
public List<User> GetUserList() { return UserList; }
public Dictionary<User,List<Theme>> GetAddedThemeFromUser() { return AddedThemeList; }
public void SetDefaultLogoList(List<Logo> defaultLogoList) { DefaultLogoList = defaultLogoList; }
public void SetDefaultThemeList(List<Theme> defaultThemeList) { ThemeList = defaultThemeList; }
public void SetUserList(List<User> userList) { UserList = userList; }
/// <summary>
/// recherche un utilisateur dans la liste d'utilisateur
/// </summary>
public bool SearchUser(string mail, string psswd)
public User SearchUser(string name)
{
foreach (User u in UserList)
foreach(User user in UserList)
{
if (mail.Equals(u.GetEmail()) && psswd.Equals(u.GetPassword()))
if (user.Username == name)
{
return true;
return user;
}
}
return false;
throw new NotFoundException("No user found with this username.");
}
/// <summary>
@ -66,7 +61,7 @@ namespace Biblioteque_de_Class
{
foreach (Logo logo in DefaultLogoList)
{
if (logo.GetName() == name) { return logo.GetLogoLink(); }
if (logo.Name == name) { return logo.LogoLink; }
}
throw new NotFoundException("No logo link found.");
}
@ -78,7 +73,7 @@ namespace Biblioteque_de_Class
{
foreach (User user in UserList)
{
if (user.GetUsername() == name)
if (user.Username == name)
{
return user;
}
@ -89,7 +84,7 @@ namespace Biblioteque_de_Class
/// <summary>
/// comparer le mot de passe entré avec celui de l'utilisateur
/// </summary>
public static bool ComparePassword(User user, string? password) => user.GetPassword() == password;
public static bool ComparePassword(User user, string? password) => user.Password == password;
/// <summary>
/// rechercher un mail dans la liste d'utilisateur
@ -98,7 +93,7 @@ namespace Biblioteque_de_Class
{
foreach (User user in UserList)
{
if (string.Equals(user.GetEmail(), email))
if (string.Equals(user.Email, email))
{
return true;
}
@ -113,11 +108,11 @@ namespace Biblioteque_de_Class
{
foreach (User existingUser in UserList)
{
if (existingUser.GetUsername() == user.GetUsername())
if (existingUser.Username == user.Username)
{
throw new AlreadyUsedException("Username already used.");
}
else if (existingUser.GetEmail() == user.GetEmail())
else if (existingUser.Email == user.Email)
{
throw new AlreadyUsedException("Email already used.");
}
@ -147,85 +142,65 @@ namespace Biblioteque_de_Class
{
foreach (Theme existingTheme in ThemeList)
{
if (existingTheme.GetName() == theme.GetName())
if (existingTheme.Name == theme.Name)
{
throw new AlreadyUsedException("Theme already used.");
throw new AlreadyExistException("Theme already Existing.");
}
}
ThemeList.Add(theme);
}
/// <summary>
/// supprimer un theme dans la liste de theme
/// </summary>
public void RemoveTheme(Theme theme)
{
if (ThemeList.Contains(theme))
{
if (theme.GetName().Length > 6 && theme.GetName()[..6] != "Static" )
{
throw new AlreadyUsedException("This theme is used a default theme.");
}
ThemeList.Remove(theme);
}
else
{
throw new NotFoundException("Theme not found.");
}
}
/// <summary>
/// récupérer un theme
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
/// <exception cref="NotFoundException"></exception>
public Theme GetTheme(string name)
{
foreach (Theme theme in ThemeList)
{
if (theme.GetName() == name)
if (theme.Name == name)
{
return theme;
}
}
throw new NotFoundException("No theme found with this name.");
throw new NotFoundException("Theme not found.");
}
/// <summary>
/// modifier le nom d'un theme
/// changer le pseudo d'un utilisateur
/// </summary>
public void ModifyThemeName(Theme theme, string newName)
/// <param name="user"></param>
/// <param name="newUsername"></param>
/// <exception cref="AlreadyUsedException"></exception>
public void ChangeUsername(User user, string newUsername)
{
foreach (Theme existingTheme in ThemeList)
foreach(User existingUser in UserList)
{
if (existingTheme.GetName() == theme.GetName())
if(existingUser.Username == newUsername)
{
existingTheme.SetName(newName);
return;
throw new AlreadyUsedException("this username is already used.");
}
}
throw new NotFoundException("Theme not found.");
user.Username = newUsername;
}
/// <summary>
/// modifier la liste de couleur d'un theme
/// vérifier si le nom du theme n'est pas déjà pris
/// </summary>
public void ModifyThemeColorList(Theme theme, List<string> newColorList)
/// <param name="name"></param>
/// <returns></returns>
public bool VerifThemeNameNotTaken(string name)
{
foreach (Theme existingTheme in ThemeList)
foreach (Theme theme in ThemeList)
{
if (existingTheme.GetName() == theme.GetName())
if (theme.Name == name)
{
for (int i = 0; i < 3; i++)
{
existingTheme.ChangeColor(existingTheme.GetColor(i), newColorList[i]);
}
return;
return false;
}
}
}
public List<Theme> AddedThemeOfOneUser(User user)
{
return GetAddedThemeFromUser()[user];
return true;
}
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
@ -7,7 +8,7 @@ using System.Threading.Tasks;
namespace Biblioteque_de_Class
{
[Serializable]
[Serializable, ExcludeFromCodeCoverage]
public class NotAllowedException : Exception
{
public NotAllowedException(string message) : base(message)
@ -17,7 +18,7 @@ namespace Biblioteque_de_Class
{
}
}
[Serializable]
[Serializable, ExcludeFromCodeCoverage]
public class AlreadyUsedException : Exception
{
public AlreadyUsedException(string message) : base(message)
@ -27,7 +28,7 @@ namespace Biblioteque_de_Class
{
}
}
[Serializable]
[Serializable, ExcludeFromCodeCoverage]
public class NotFoundException : Exception
{
public NotFoundException(string message) : base(message)
@ -37,7 +38,7 @@ namespace Biblioteque_de_Class
{
}
}
[Serializable]
[Serializable, ExcludeFromCodeCoverage]
public class AlreadyExistException : Exception
{
public AlreadyExistException(string message) : base(message)
@ -48,10 +49,7 @@ namespace Biblioteque_de_Class
}
}
[Serializable]
[Serializable, ExcludeFromCodeCoverage]
public class FileException : Exception
{
public FileException(string message) : base(message)

@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Biblioteque_de_Class
{
public class HashCodeModel
{
public 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();
}
}
}
}

@ -8,10 +8,9 @@ namespace Biblioteque_de_Class
{
public interface IManager
{
public void SaveDatabaseData(List<User> UserList, Dictionary<User, List<Theme>> AddedThemeFromUser);
public Database LoadDatabaseData();
public void SaveDatabaseData(List<User> UserList);
public void SaveDefaultData(List<Theme> DefaultThemeList, List<Logo> DefaultLogoList);
public List<User> LoadDatabaseData();
public List<Theme> LoadDefaultTheme();
public List<Logo> LoadDefaultLogo();
}

@ -1,15 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Biblioteque_de_Class
{
[DataContract]
public class Logo
{
private string Name { get; set; }
private string LogoLink { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string LogoLink { get; set; }
public Logo(string name, string logoLink)
{
@ -17,12 +21,6 @@ namespace Biblioteque_de_Class
LogoLink = logoLink;
}
public string GetName() { return Name; }
public string GetLogoLink() { return LogoLink; }
public void SetName(string name) { Name = name; }
public void SetLogoLink(string logoLink) { LogoLink = logoLink; }
public override string ToString() => $"Logo -> Name: {Name}\nLink: {LogoLink}";
}
}

@ -10,17 +10,19 @@ namespace Biblioteque_de_Class
[DataContract(IsReference = true)]
public class Note
{
[DataMember]
public int id { get; init; }
[DataMember]
private string name;
[DataMember]
public string Name
{
get { return name; }
private set { if (value == null) { name = "Unnamed Note"; } else { name = value; } }
set { if (value == null) { name = "Unnamed Note"; } else { name = value; } }
}
[DataMember]
private string Text { get; set; } = "";
public string Text { get; private set; } = "";
[DataMember]
private string logoPath;
@ -32,65 +34,63 @@ namespace Biblioteque_de_Class
}
[DataMember]
private DateOnly CreationDate { get; }
public DateOnly CreationDate { get; init; }
[DataMember]
private DateOnly ModificationDate { get; set; }
public DateOnly ModificationDate { get; private set; }
[DataMember]
private readonly List<NoteImage> ImageList;
public List<NoteImage> ImageList { get; private set; }
[DataMember]
private readonly List<User> Collaborators;
public List<User> Collaborators { get; private set; }
[DataMember]
private readonly List<User> Editors;
public List<User> Editors { get; private set; }
[DataMember]
private readonly User Owner;
public User Owner { get; private set; }
public Note(string name, string logoPath, User owner)
public Note(int initId,string name, string logoPath, User owner)
{
id = initId;
Name = name;
LogoPath = logoPath;
CreationDate = DateOnly.FromDateTime(DateTime.Now);
ModificationDate = DateOnly.FromDateTime(DateTime.Now);
ImageList = new List<NoteImage>();
Collaborators = new List<User>();
Editors = new List<User>();
Editors = new List<User>() { owner };
Owner = owner;
}
public string GetName() { return Name; }
public string GetLogoPath() { return LogoPath; }
public string GetText() { return Text; }
public DateOnly GetCreationDate() { return CreationDate; }
public DateOnly GetModificationDate() { return ModificationDate; }
public List<NoteImage> GetImageList() { return ImageList; }
public List<User> GetCollaborators() { return Collaborators; }
public List<User> GetEditors() { return Editors; }
public User GetOwner() { return Owner; }
public override string ToString() => $"Note -> Name: {Name}\nLogoPath: {LogoPath}";
public void SetName(string name) { Name = name; }
public void SetLogoPath(string logoPath) { LogoPath = logoPath; }
public void SetModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); }
/// <summary>
/// vérifier si l'utilisateur est le propriétaire de la note
/// </summary>
public bool VerifyOwner(User user)
{
return user == Owner;
{
if (user == Owner) { return true; }
else { throw new NotAllowedException("User is not the owner"); }
}
public void AddImage(string imageLink, string position)
/// <summary>
/// ajouter une image à la note
/// </summary>
/// <param name="imageLink"></param>
/// <param name="position"></param>
public void AddImage(string imageLink, List<int> position)
{
int newname = ImageList.Count + 1;
string newname = (ImageList.Count + 1).ToString();
ImageList.Add(new NoteImage(newname, imageLink, position));
}
public void RemoveImage(int name)
/// <summary>
/// supprimer une image de la note
/// </summary>
/// <param name="name"></param>
/// <exception cref="NotFoundException"></exception>
public void RemoveImage(string name)
{
foreach (NoteImage image in ImageList)
{
if (image.GetName() == name)
if (image.Name == name)
{
ImageList.Remove(image);
return;
@ -99,8 +99,14 @@ namespace Biblioteque_de_Class
throw new NotFoundException("Image not found");
}
public void AddText(string text)
/// <summary>
/// ajouter du texte à la note
/// </summary>
/// <param name="text"></param>
public void AddText( User user, string text)
{
if (user == Owner || Editors.Contains(user)) { ModificationDate = DateOnly.FromDateTime(DateTime.Now); }
else { throw new NotAllowedException("User is not the owner or an editor"); }
Text = Text + "\n" + text;
}
@ -118,8 +124,7 @@ namespace Biblioteque_de_Class
public void AddCollaborator(User owner, User user)
{
if (VerifyOwner(owner)) { Collaborators.Add(user); }
else { throw new NotAllowedException("User is not the owner"); }
user.GetNoteList().Add(this);
user.NoteList.Add(this);
}
/// <summary>
@ -128,8 +133,7 @@ namespace Biblioteque_de_Class
public void RemoveCollaborator(User owner, User user)
{
if (VerifyOwner(owner)) { Collaborators.Remove(user); }
else { throw new NotAllowedException("User is not the owner"); }
user.GetNoteList().Remove(this);
user.NoteList.Remove(this);
}
/// <summary>
@ -137,8 +141,8 @@ namespace Biblioteque_de_Class
/// </summary>
public void AddEditor(User owner, User user)
{
if (Editors.Contains(user)) { throw new AlreadyExistException("user already in editors."); }
if (VerifyOwner(owner)) { Editors.Add(user); }
else { throw new NotAllowedException("User is not the owner"); }
}
/// <summary>
@ -146,8 +150,28 @@ namespace Biblioteque_de_Class
/// </summary>
public void RemoveEditor(User owner, User user)
{
if (!Editors.Contains(user)) { throw new NotFoundException("user not found in editors."); }
if (VerifyOwner(owner)) { Editors.Remove(user); }
else { throw new NotAllowedException("User is not the owner"); }
}
/// <summary>
/// changer le nom de la note
/// </summary>
/// <param name="user"></param>
/// <param name="newName"></param>
public void ChangeName(User user, string newName)
{
if (VerifyOwner(user)) { Name = newName; }
}
/// <summary>
/// changer le logo de la note
/// </summary>
/// <param name="user"></param>
/// <param name="newLogoPath"></param>
public void ChangeLogo(User user, string newLogoPath)
{
if (VerifyOwner(user)) { LogoPath = newLogoPath; }
}
}
}

@ -1,32 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Biblioteque_de_Class
{
[DataContract]
public class NoteImage
{
private int Name { get; set; }
private string ImageLink { get; set; }
private string Position { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string ImageLink { get; set; }
[DataMember]
public List<int> Position { get; set; }
public NoteImage(int name, string imageLink, string position)
public NoteImage(string name, string imageLink, List<int> position)
{
Name = name;
ImageLink = imageLink;
Position = position;
}
public int GetName() { return Name; }
public string GetImageLink() { return ImageLink; }
public string GetPosition() { return Position; }
public void SetName(int 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}";
}
}

@ -12,17 +12,40 @@ namespace Biblioteque_de_Class
{
persistence = pers;
}
public void SaveDatabaseData(Database database)
{
persistence.SaveDatabaseData(database.UserList);
}
public void SaveDatabaseData(Database database)
public void SaveDefaultData(Database database)
{
persistence.SaveDatabaseData(database.GetUserList(), database.GetAddedThemeFromUser());
persistence.SaveDefaultData(database.ThemeList, database.DefaultLogoList);
}
public Database LoadDatabaseData()
{
db = persistence.LoadDatabaseData();
//db.SetDefaultThemeList(persistence.LoadDefaultTheme());
//db.SetDefaultLogoList(persistence.LoadDefaultLogo());
db.SetUserList(persistence.LoadDatabaseData());
db.SetDefaultThemeList(persistence.LoadDefaultTheme());
db.SetDefaultLogoList(persistence.LoadDefaultLogo());
return db;
}
public Database GetOnlyDatabaseUser()
{
db.SetUserList(persistence.LoadDatabaseData());
return db;
}
public Database GetOnlyDatabaseDefaultTheme()
{
db.SetDefaultThemeList(persistence.LoadDefaultTheme());
return db;
}
public Database GetOnlyDatabaseDefaultLogo()
{
db.SetDefaultLogoList(persistence.LoadDefaultLogo());
return db;
}
}

@ -1,15 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Biblioteque_de_Class
{
[DataContract]
public class Tags
{
private string Name { get; set; }
private string Color { get; set; }
[DataMember]
public string Name { get; set; }
[DataMember]
public string Color { get; set; }
public Tags(string name, string color)
{
@ -17,11 +21,6 @@ namespace Biblioteque_de_Class
Color = color;
}
public string GetName() { return Name; }
public string GetColor() { return Color; }
public void SetName(string name) { Name = name; }
public void SetColor(string color) { Color = color; }
public override string ToString() => $"tag -> name: {Name}\ncolor: {Color}";
}
}

@ -1,15 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
namespace Biblioteque_de_Class
{
[DataContract]
public class Theme
{
private string Name { get; set; }
private readonly List<string> ColorList;
[DataMember]
public string Name { get; set; }
[DataMember]
public List<string> ColorList { get; private set; }
public Theme(string name, List<string> colorList)
{
@ -17,11 +21,6 @@ namespace Biblioteque_de_Class
ColorList = colorList;
}
public string GetName() { return Name; }
public void SetName(string name) { Name = name; }
public List<string> GetColorList() { return ColorList; }
public string GetColor(int index) { return ColorList[index]; }
public override string ToString() => $"name: {Name}\ncolor 1: {ColorList[0]}\ncolor 2: {ColorList[1]}\ncolor 3: {ColorList[2]}\n";
/// <summary>

@ -5,29 +5,30 @@ using System.Runtime.Serialization;
namespace Biblioteque_de_Class
{
[DataContract(IsReference = true)]
[DataContract]
public class User
{
[DataMember]
private string Username { get; set; }
public string Username { get; set; }
[DataMember]
private string Email { get; set; }
public string Email { get; private set; }
[DataMember]
private string Password { get; set; }
public string Password { get; private set; }
[DataMember]
private string Picture { get; set; }
public string Picture { get; private set; }
[DataMember]
private Theme Theme;
public Theme UseTheme { get; set; }
[DataMember]
private List<Note> NoteList;
public List<Note> NoteList { get; set; }
[DataMember]
private List<Tags> TagList;
public List<Tags> TagList { get; private set; }
[DataMember]
private List<Note> FavList;
public List<Note> FavList { get; private set; }
[DataMember(EmitDefaultValue = false)]
private bool IsConnected { get; set; }
public bool IsConnected { get; set; }
[DataMember]
private Dictionary<Note, List<Tags>> NoteTagged;
public Dictionary<Note, List<Tags>> NoteTagged { get; set; }
public List<Theme> AddedTheme { get; set; }
public User(string username, string email, string password)
{
@ -35,44 +36,39 @@ namespace Biblioteque_de_Class
Email = email;
Password = password;
Picture = "defaultpicture.png";
UseTheme = new("", ",,".Split(',').ToList());
NoteList = new List<Note>();
TagList = new List<Tags>();
FavList = new List<Note>();
NoteTagged = new Dictionary<Note, List<Tags>>();
AddedTheme = new List<Theme>();
}
public string GetUsername() { return Username; }
public string GetEmail() { return Email; }
public string GetPassword() { return Password;}
public string GetPicture() { return Picture;}
public Theme GetTheme() { return Theme; }
public List<Note> GetNoteList() { return NoteList; }
public List<Tags> GetTagList() { return TagList; }
public List<Note> GetFavList() { return FavList; }
public bool GetIsConnected() { return IsConnected; }
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 SetEmail(string email) { Email = email; }
public void SetPassword(string password) { Password = password; }
public void SetPicture(string picture) { Picture = picture; }
public void SetTheme(Theme theme) { Theme = theme; }
public void SetIsConnected(bool isConnected) { IsConnected = isConnected; }
public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}";
/// <summary>
/// rechercher une note dans la liste de note de l'utilisateur et la liste de note favoris de l'utilisateur
/// </summary>
public List<Note> SearchNoteByName(List<Note> ToResearchIntoList, string name)
public List<Note> SearchNoteByName(List<Note> toResearchIntoList, string name)
{
List<Note> searchedNotes = new List<Note>();
string search = name.ToLower();
foreach (Note note in ToResearchIntoList)
foreach (Note note in toResearchIntoList)
{
if (note.Name.ToLower().Contains(search))
{
searchedNotes.Add(note);
}
}
return searchedNotes;
}
public List<Note> SearchNoteByTag(List<Note> toResearchIntoList, string name)
{
List<Note> searchedNotes = new();
Tags tagtoresearchby = GetTagByName(name);
foreach(Note note in toResearchIntoList)
{
if (note.GetName().ToLower().Contains(search))
if (NoteTagged[note].Contains(tagtoresearchby))
{
searchedNotes.Add(note);
}
@ -89,7 +85,7 @@ namespace Biblioteque_de_Class
string search = name.ToLower();
foreach (Tags tag in ToResearchIntoList)
{
if (tag.GetName().ToLower().Contains(search))
if (tag.Name.ToLower().Contains(search))
{
searchedTags.Add(tag);
}
@ -97,13 +93,21 @@ namespace Biblioteque_de_Class
return searchedTags;
}
/// <summary>
/// rechercher par date de création ou de modification
/// </summary>
/// <param name="ToResearchIntoList"></param>
/// <param name="name"></param>
/// <param name="FirstDate"></param>
/// <param name="SecondeDate"></param>
/// <returns></returns>
public List<Note> SearchNoteByDate(List<Note> ToResearchIntoList, string name, DateOnly FirstDate, DateOnly SecondeDate)
{
List<Note> searchedNotes = new List<Note>();
string search = name.ToLower();
foreach (Note note in ToResearchIntoList)
{
if (note.GetName().ToLower().Contains(search) && note.GetCreationDate() >= FirstDate && note.GetCreationDate() <= SecondeDate || note.GetModificationDate() >= FirstDate && note.GetModificationDate() <= SecondeDate)
if (note.Name.ToLower().Contains(search) && note.CreationDate >= FirstDate && note.CreationDate <= SecondeDate || note.Name.ToLower().Contains(search) && note.ModificationDate >= FirstDate && note.ModificationDate <= SecondeDate)
{
searchedNotes.Add(note);
}
@ -111,11 +115,17 @@ namespace Biblioteque_de_Class
return searchedNotes;
}
/// <summary>
/// rechercher par nom de la note
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
/// <exception cref="NotFoundException"></exception>
public Note GetNoteByName(string name)
{
foreach (Note note in NoteList)
{
if (note.GetName() == name)
if (note.Name == name)
{
return note;
}
@ -123,11 +133,17 @@ namespace Biblioteque_de_Class
throw new NotFoundException("Note not found");
}
/// <summary>
/// rechercher par nom du tag
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
/// <exception cref="NotFoundException"></exception>
public Tags GetTagByName(string name)
{
foreach (Tags tag in TagList)
{
if (tag.GetName() == name)
if (tag.Name == name)
{
return tag;
}
@ -165,28 +181,32 @@ namespace Biblioteque_de_Class
/// <summary>
///creer une note
/// </summary>
public void CreateNote(string name, string imagePath)
public Note CreateNote(string name, string imagePath)
{
foreach (Note existingNote in NoteList)
{
if (existingNote.GetName() == name)
if (existingNote.Name == name)
{
throw new AlreadyExistException("Note already exists");
}
}
Note note = new Note(name, imagePath, this);
Note note;
if (NoteList.Count == 0) { note = new Note(0, name, imagePath, this); }
else { note = new Note(NoteList[NoteList.Count - 1].id + 1, name, imagePath, this); }
NoteList.Add(note);
NoteTagged.Add(note, new List<Tags>());
return note;
}
/// <summary>
/// supprimer une note
/// </summary>
public void DeleteNote(string note)
public void DeleteNote(Note note)
{
note.VerifyOwner(this);
foreach (Note existingNote in NoteList)
{
if (existingNote.GetName() == note)
if (existingNote == note)
{
NoteList.Remove(existingNote);
NoteTagged.Remove(existingNote);
@ -203,7 +223,7 @@ namespace Biblioteque_de_Class
{
foreach (Tags tag in TagList)
{
if (tag.GetName() == name)
if (tag.Name == name)
{
throw new AlreadyExistException("Tag already exists");
}
@ -214,22 +234,51 @@ namespace Biblioteque_de_Class
/// <summary>
/// supprimer un tag
/// </summary>
public void DeleteTag(string name)
public void DeleteTag(Tags tagtodelete)
{
foreach (Tags tag in TagList)
{
if (tag.GetName() == name)
if (tag == tagtodelete)
{
TagList.Remove(tag);
return;
}
}
throw new NotFoundException("Tag not found");
}
public void EditTagName(Tags tag, string newName)
{
if (!TagList.Contains(tag))
{
throw new NotFoundException("Tag not found");
}
else
{
foreach (Tags existingTag in TagList)
{
if (existingTag.Name == newName)
{
throw new AlreadyExistException("Tag already exists");
}
}
}
tag.Name = newName;
}
public void EditTagColor(Tags tag, string newColor)
{
if (!TagList.Contains(tag))
{
throw new NotFoundException("Tag not found");
}
tag.Color = newColor;
}
/// <summary>
/// ajouter un tag a une note
/// </summary>
public void AddTagToNoteList(Note note, Tags tagToAdd)
public void AddTagFromNoteList(Note note, Tags tagToAdd)
{
if (!TagList.Contains(tagToAdd))
{
@ -259,20 +308,186 @@ namespace Biblioteque_de_Class
}
/// <summary>
/// ajouter plusieur tag a une note
/// modifier le nom d'une note
/// </summary>
/// <param name="note"></param>
/// <param name="newname"></param>
/// <exception cref="AlreadyUsedException"></exception>
public void SetNoteName(Note note, string newname)
{
if (!NoteList.Contains(note))
{
throw new NotFoundException("Note not found");
}
foreach(Note n in NoteList)
{
if(n.Name == newname)
{
throw new AlreadyUsedException("This name is already used");
}
}
note.Name = newname;
}
/// <summary>
/// modifier le mot de passe de l'utilisateur
/// </summary>
/// <param name="newPassword"></param>
/// <exception cref="AlreadyExistException"></exception>
/// <exception cref="NotAllowedException"></exception>
public void ChangePassword(string newPassword)
{
if (newPassword.Length < 8) { throw new NotAllowedException("this password is too short."); }
if (Password == HashCodeModel.GetSHA256Hash(newPassword).ToString())
{
throw new AlreadyUsedException("this password is already used.");
}
else
{
Password = HashCodeModel.GetSHA256Hash(newPassword).ToString();
}
}
/// <summary>
/// modifier le theme de l'utilisateur
/// </summary>
/// <param name="theme"></param>
/// <exception cref="AlreadyExistException"></exception>
public void ChangeTheme(Theme theme)
{
if (UseTheme.Name == theme.Name)
{
throw new AlreadyExistException("this theme is already selected.");
}
UseTheme = theme;
}
public void ChangeThemeName(Theme theme, string newName)
{
foreach (Theme existingTheme in AddedTheme)
{
if (existingTheme.Name == newName)
{
throw new AlreadyExistException("this theme is already existing.");
}
}
if (theme.Name == newName)
{
throw new AlreadyExistException("this theme is already selected.");
}
theme.Name = newName;
}
public void ChangeThemeColors(Theme theme, List<string> newColor)
{
int compteurSameColor = 0;
for(int i = 0; i < theme.ColorList.Count; i++)
{
if (theme.ColorList[i] == newColor[i])
{
compteurSameColor++;
}
}
if (compteurSameColor == theme.ColorList.Count)
{
throw new AlreadyExistException("this theme those colors");
}
if (theme.ColorList.Count != newColor.Count)
{
throw new NotFoundException("this theme doesn't have the same number of colors");
}
for (int i = 0; i < theme.ColorList.Count; i++)
{
theme.ChangeColor(theme.ColorList[i], newColor[i]);
}
}
/// <summary>
/// ajouter un theme dans la liste de theme
/// </summary>
public void AddTagsToNoteList(Note note, List<Tags> tags)
public void AddTheme(Theme theme)
{
NoteTagged.Add(note, tags);
foreach (Theme existingTheme in AddedTheme)
{
if (existingTheme.Name == theme.Name)
{
throw new AlreadyExistException("Theme already used.");
}
}
AddedTheme.Add(theme);
}
/// <summary>
///supprimer tout les tags d'une note
/// supprimer un theme dans la liste de theme
/// </summary>
public void RemoveTagsFromNoteList(Note note)
public void RemoveTheme(Theme theme)
{
NoteTagged.Remove(note);
if (AddedTheme.Contains(theme))
{
AddedTheme.Remove(theme);
}
else
{
throw new NotFoundException("Theme not found.");
}
}
/// <summary>
/// recuperer un theme dans la liste de theme ajouté par l'utilisateur
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
/// <exception cref="NotFoundException"></exception>
public Theme GetTheme(string name)
{
foreach (Theme theme in AddedTheme)
{
if (theme.Name == name)
{
return theme;
}
}
throw new NotFoundException("Theme not found.");
}
/// <summary>
/// modifier l'email de l'utilisateur
/// </summary>
/// <param name="newEmail"></param>
/// <exception cref="AlreadyExistException"></exception>
public void ChangeEmail(string newEmail)
{
if (newEmail.Length < 3 ) { throw new NotAllowedException("this is not a mail address."); }
if (Email == newEmail) { throw new AlreadyUsedException("this email is the same."); }
Email = newEmail;
}
/// <summary>
/// changer la photo de profil de l'utilisateur
/// </summary>
/// <param name="path"></param>
public void ChangeProfilePicture(string path)
{
if (path.Length < 3)
{
Picture = "default.png";
}
else
{
List<string> picture = new();
picture = path.Split('.').ToList();
string extension = picture.Last();
if (extension != "png" && extension != "jpg" && extension != "jpeg")
{
throw new NotFoundException("this extension is not allowed.");
}
Picture = path;
}
}
public void SetDefaultTheme(Theme theme)
{
UseTheme = theme;
}
}
}

@ -0,0 +1,496 @@
<?xml version="1.0" encoding="utf-8"?>
<Database xmlns:i="http://www.w3.org/2001/XMLSchema-instance" i:type="ArrayOfUser" xmlns="http://schemas.datacontract.org/2004/07/Biblioteque_de_Class">
<User>
<Email>leHeros@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Id="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<Collaborators>
<User>
<Email>labsent@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Id="i2">
<Collaborators />
<CreationDate xmlns:d9p1="http://schemas.datacontract.org/2004/07/System" />
<Editors>
<User>
<Email>labsent@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i2" />
<Note z:Ref="i1" />
</NoteList>
<NoteTagged xmlns:d11p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d11p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d11p1:Key z:Ref="i2" />
<d11p1:Value />
</d11p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>fa7d77716ab4b614012aef71d589ef1bd018e1e25438c8546d1a2ce83b52c5c4</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 1</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d12p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d12p1:string>,,</d12p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Benjamin</Username>
</User>
</Editors>
<ImageList />
<LogoPath>DefaultLogo.png</LogoPath>
<ModificationDate xmlns:d9p1="http://schemas.datacontract.org/2004/07/System" />
<Name>Note 1</Name>
<Owner>
<Email>labsent@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i2" />
<Note z:Ref="i1" />
</NoteList>
<NoteTagged xmlns:d10p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d10p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d10p1:Key z:Ref="i2" />
<d10p1:Value />
</d10p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>fa7d77716ab4b614012aef71d589ef1bd018e1e25438c8546d1a2ce83b52c5c4</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 1</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d11p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d11p1:string>,,</d11p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Benjamin</Username>
</Owner>
<Text></Text>
<logoPath>DefaultLogo.png</logoPath>
<name>Note 1</name>
</Note>
<Note z:Ref="i1" />
</NoteList>
<NoteTagged xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d7p1:Key z:Ref="i2" />
<d7p1:Value />
</d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>fa7d77716ab4b614012aef71d589ef1bd018e1e25438c8546d1a2ce83b52c5c4</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 1</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d8p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d8p1:string>,,</d8p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Benjamin</Username>
</User>
<User>
<Email>liammonchanin@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Id="i3">
<Collaborators />
<CreationDate xmlns:d9p1="http://schemas.datacontract.org/2004/07/System" />
<Editors>
<User>
<Email>liammonchanin@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i3" />
<Note z:Ref="i1" />
</NoteList>
<NoteTagged xmlns:d11p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d11p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d11p1:Key z:Ref="i3" />
<d11p1:Value />
</d11p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>dd13d2e59703e108138db99aadebdc3e308e175d5649061baf2764ab6c039a9b</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 2</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d12p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d12p1:string>,,</d12p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Liam</Username>
</User>
</Editors>
<ImageList />
<LogoPath>DefaultLogo.png</LogoPath>
<ModificationDate xmlns:d9p1="http://schemas.datacontract.org/2004/07/System" />
<Name>Note 2</Name>
<Owner>
<Email>liammonchanin@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i3" />
<Note z:Ref="i1" />
</NoteList>
<NoteTagged xmlns:d10p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d10p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d10p1:Key z:Ref="i3" />
<d10p1:Value />
</d10p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>dd13d2e59703e108138db99aadebdc3e308e175d5649061baf2764ab6c039a9b</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 2</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d11p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d11p1:string>,,</d11p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Liam</Username>
</Owner>
<Text></Text>
<logoPath>DefaultLogo.png</logoPath>
<name>Note 2</name>
</Note>
<Note z:Ref="i1" />
</NoteList>
<NoteTagged xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d7p1:Key z:Ref="i3" />
<d7p1:Value />
</d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>dd13d2e59703e108138db99aadebdc3e308e175d5649061baf2764ab6c039a9b</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 2</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d8p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d8p1:string>,,</d8p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Liam</Username>
</User>
</Collaborators>
<CreationDate xmlns:d5p1="http://schemas.datacontract.org/2004/07/System" />
<Editors>
<User>
<Email>leHeros@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i1" />
</NoteList>
<NoteTagged xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d7p1:Key z:Ref="i1" />
<d7p1:Value>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 0</Name>
</Tags>
</d7p1:Value>
</d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>2cbb89e6f9b003468ecfc7957b6c2a2da22c8e2f600cb115323800dc0da20467</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 0</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d8p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d8p1:string>,,</d8p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Nicolas</Username>
</User>
<User>
<Email>liammonchanin@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i3" />
<Note z:Ref="i1" />
</NoteList>
<NoteTagged xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d7p1:Key z:Ref="i3" />
<d7p1:Value />
</d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>dd13d2e59703e108138db99aadebdc3e308e175d5649061baf2764ab6c039a9b</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 2</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d8p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d8p1:string>,,</d8p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Liam</Username>
</User>
</Editors>
<ImageList />
<LogoPath>DefaultLogo.png</LogoPath>
<ModificationDate xmlns:d5p1="http://schemas.datacontract.org/2004/07/System" />
<Name>Note 0</Name>
<Owner>
<Email>leHeros@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i1" />
</NoteList>
<NoteTagged xmlns:d6p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d6p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d6p1:Key z:Ref="i1" />
<d6p1:Value>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 0</Name>
</Tags>
</d6p1:Value>
</d6p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>2cbb89e6f9b003468ecfc7957b6c2a2da22c8e2f600cb115323800dc0da20467</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 0</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d7p1:string>,,</d7p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Nicolas</Username>
</Owner>
<Text></Text>
<logoPath>DefaultLogo.png</logoPath>
<name>Note 0</name>
</Note>
</NoteList>
<NoteTagged xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d3p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d3p1:Key z:Ref="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" />
<d3p1:Value>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 0</Name>
</Tags>
</d3p1:Value>
</d3p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>2cbb89e6f9b003468ecfc7957b6c2a2da22c8e2f600cb115323800dc0da20467</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 0</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string>,,</d4p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Nicolas</Username>
</User>
<User>
<Email>labsent@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i2" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" />
<Note z:Ref="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" />
</NoteList>
<NoteTagged xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d3p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d3p1:Key z:Ref="i2" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" />
<d3p1:Value />
</d3p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>fa7d77716ab4b614012aef71d589ef1bd018e1e25438c8546d1a2ce83b52c5c4</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 1</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string>,,</d4p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Benjamin</Username>
</User>
<User>
<Email>liammonchanin@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i3" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" />
<Note z:Ref="i1" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" />
</NoteList>
<NoteTagged xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d3p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d3p1:Key z:Ref="i3" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" />
<d3p1:Value />
</d3p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>dd13d2e59703e108138db99aadebdc3e308e175d5649061baf2764ab6c039a9b</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 2</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string>,,</d4p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Liam</Username>
</User>
<User>
<Email>Macroutte@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Id="i4" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/">
<Collaborators />
<CreationDate xmlns:d5p1="http://schemas.datacontract.org/2004/07/System" />
<Editors>
<User>
<Email>Macroutte@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i4" />
</NoteList>
<NoteTagged xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d7p1:Key z:Ref="i4" />
<d7p1:Value />
</d7p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>2dd6f72e332902136f9f27bcae97ccf3dab2cfc45f5cea43a7fbb91847b04716</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 3</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d8p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d8p1:string>,,</d8p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Brigitte</Username>
</User>
</Editors>
<ImageList />
<LogoPath>DefaultLogo.png</LogoPath>
<ModificationDate xmlns:d5p1="http://schemas.datacontract.org/2004/07/System" />
<Name>Note 3</Name>
<Owner>
<Email>Macroutte@gmail.com</Email>
<FavList />
<NoteList>
<Note z:Ref="i4" />
</NoteList>
<NoteTagged xmlns:d6p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d6p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d6p1:Key z:Ref="i4" />
<d6p1:Value />
</d6p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>2dd6f72e332902136f9f27bcae97ccf3dab2cfc45f5cea43a7fbb91847b04716</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 3</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d7p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d7p1:string>,,</d7p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Brigitte</Username>
</Owner>
<Text></Text>
<logoPath>DefaultLogo.png</logoPath>
<name>Note 3</name>
</Note>
</NoteList>
<NoteTagged xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d3p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
<d3p1:Key z:Ref="i4" xmlns:z="http://schemas.microsoft.com/2003/10/Serialization/" />
<d3p1:Value />
</d3p1:KeyValueOfNoteArrayOfTagsw0Ob5Kw8>
</NoteTagged>
<Password>2dd6f72e332902136f9f27bcae97ccf3dab2cfc45f5cea43a7fbb91847b04716</Password>
<Picture>defaultpicture.png</Picture>
<TagList>
<Tags>
<Color>#5555FF</Color>
<Name>Tag 3</Name>
</Tags>
</TagList>
<UseTheme>
<ColorList xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<d4p1:string>,,</d4p1:string>
</ColorList>
<Name></Name>
</UseTheme>
<Username>Brigitte</Username>
</User>
</Database>

File diff suppressed because it is too large Load Diff

@ -12,73 +12,69 @@ namespace Notus_Persistance
{
public class Stub : IManager
{
public void SaveDatabaseData(List<User> UserList, Dictionary<User, List<Theme>> AddedThemeFromUser)
public void SaveDatabaseData(List<User> UserList)
{
throw new NotImplementedException();
}
public void SaveDefaultData(List<Theme> DefaultThemeList, List<Logo> DefaultLogoList)
{
throw new NotImplementedException() ;
}
//Loaders
Database IManager.LoadDatabaseData()
List<User> IManager.LoadDatabaseData()
{
Database database = new Database();
List<User> userList = new List<User>();
Note nselect;
User uselect;
// add some users
database.AddUser(new User("Nicolas", "leHeros@gmail.com", "Feur"));
database.AddUser(new User("Benjamin", "labsent@gmail.com", "Moto2005"));
database.AddUser(new User("Liam", "liammonchanin@gmail.com", "Baguette"));
database.AddUser(new User("Brigitte", "Brigitte@gmail.com", "493"));
userList.Add(new User("Nicolas", "leHeros@gmail.com", "FeurFeur"));
userList.Add(new User("Benjamin", "labsent@gmail.com", "Moto2005"));
userList.Add(new User("Liam", "liammonchanin@gmail.com", "Baguette"));
userList.Add(new User("Brigitte", "Macroutte@gmail.com", "4949Trois"));
// add some notes and tags to go faster
foreach (User user in database.GetUserList().Where(x => x.GetUsername().Contains("a")))
for (int i = 0; i < userList.Count; i++)
{
user.CreateNote("Note 1", "");
user.CreateNote("Note 2", "");
user.CreateNote("Note 3", "");
user.CreateTag("Tag 1", "#FA0034");
user.CreateTag("Tag 2", "#2500A4");
userList[i].CreateNote($"Note {i}", "DefaultLogo.png");
userList[i].CreateTag($"Tag {i}", "#5555FF");
}
// add note to user for sharing note test mixed with tag
foreach (User user in database.GetUserList())
{
if (user.GetEmail().Equals("leHeros@gmail.com") && user.GetUsername().Equals("Nicolas") && user.GetPassword().Equals("Feur"))
{
uselect = user;
uselect.CreateNote("Note 4", "Logo_1");
uselect.CreateTag("Tag 3", "#00FF00");
//nselect = (Note)uselect.GetNoteList().Where(x => x.GetName() == "Note 4");
//uselect.AddTagToNoteList(nselect, (Tags)uselect.GetTagList().Where(x => x.GetName() == "Tag 3"));
//nselect.AddCollaborator(uselect, (User)database.GetUserList().Where(x => x.GetUsername() == "Benjamin"));
//uselect = (User)database.GetUserList().Where(x => x.GetUsername() == "Benjamin");
uselect.CreateTag("Tag 4", "#FF0000");
}
}
uselect = userList[0];
nselect = uselect.NoteList[0];
nselect.AddCollaborator(uselect, userList[1]);
nselect.AddCollaborator(uselect, userList[2]);
uselect.AddTagFromNoteList(nselect, uselect.TagList[0]);
nselect.AddEditor(uselect, userList[2]);
// add some default logos and themes
database.GetDefaultLogoList().Add(new Logo("Logo_1", "logo"));
database.GetDefaultLogoList().Add(new Logo("Logo_2", "logo"));
database.GetDefaultLogoList().Add(new Logo("Logo_3", "logo"));
List<string> colorListHexaCode = new("FF0000,00FF00,0000FF".Split(','));
database.AddTheme(new Theme("Theme_1", colorListHexaCode));
colorListHexaCode = new("FF00FF,00FFFF,FFFF00".Split(','));
database.AddTheme(new Theme("Theme_2", colorListHexaCode));
colorListHexaCode = new("000000,FFFFFF,000000".Split(','));
database.AddTheme(new Theme("Theme_3", colorListHexaCode));
foreach (User user in userList)
{
user.ChangePassword(user.Password);
}
return database;
return userList;
}
public List<Theme> LoadDefaultTheme()
{
throw new NotImplementedException();
List<Theme> DefaultThemeList = new List<Theme>();
DefaultThemeList.Add(new("blacktheme", "#000000,#FF00FF,#OOFFOO".Split(',').ToList()));
DefaultThemeList.Add(new("whitetheme", "#FFFFFF,#FF00FF,#OOFFOO".Split(',').ToList()));
return DefaultThemeList;
}
public List<Logo> LoadDefaultLogo()
{
throw new NotImplementedException();
List<Logo> DefaultLogoList = new List<Logo>();
DefaultLogoList.Add(new("default","DefaultLogo.png"));
DefaultLogoList.Add(new("1", "Logo1.png"));
DefaultLogoList.Add(new("2", "Logo2.png"));
return DefaultLogoList;
}
}

@ -1,107 +0,0 @@
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;
using System.Text.Json.Serialization;
namespace Notus_Persistance
{
public class ToJSON : IManager
{
private const string DatabaseDataFilePath = "data.json";
private const string DefaultThemePath = "";
private const string DefaultLogoPath = "";
private static readonly DataContractJsonSerializer DatabasejsonSerializer = new(typeof(Database));
public void SaveDatabaseData(List<User> UserList, Dictionary<User, List<Theme>> AddedThemeFromUser)
{
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, UserList);
DatabasejsonSerializer.WriteObject(writer, AddedThemeFromUser);
}
}
}
public Database LoadDatabaseData()
{
if (File.Exists(DatabaseDataFilePath))
{
using (FileStream fileStream = File.OpenRead(DatabaseDataFilePath))
{
Database? database = (Database?)DatabasejsonSerializer.ReadObject(fileStream);
if (database == null)
{
throw new FileException("Failed to load database. The loaded object is null.");
}
else
{
return database;
}
}
}
else
{
throw new FileException("No data file found.");
}
}
public List<Theme> LoadDefaultTheme()
{
if (File.Exists(DefaultThemePath))
{
using (FileStream fileStream = File.OpenRead(DefaultThemePath))
{
List<Theme>? DefaultThemeList = (List<Theme>?)DatabasejsonSerializer.ReadObject(fileStream);
if (DefaultThemeList == null)
{
throw new FileException("Failed to Default Theme. The loaded object is null.");
}
else
{
return DefaultThemeList;
}
}
}
else
{
throw new FileException("No data file found.");
}
}
public List<Logo> LoadDefaultLogo()
{
if (File.Exists(DefaultLogoPath))
{
using (FileStream fileStream = File.OpenRead(DefaultLogoPath))
{
List<Logo>? DefaultLogoList = (List<Logo>?)DatabasejsonSerializer.ReadObject(fileStream);
if (DefaultLogoList == null)
{
throw new FileException("Failed to Default Logo. The loaded object is null.");
}
else
{
return DefaultLogoList;
}
}
}
else
{
throw new FileException("No data file found.");
}
}
}
}

@ -1,41 +1,66 @@
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.Xml.Serialization;
using System.IO;
using System.Diagnostics.CodeAnalysis;
namespace Notus_Persistance
{
[ExcludeFromCodeCoverage]
public class ToXML : IManager
{
private const string DataFilePath = "data.xml";
private const string DefaultThemePath = "";
private const string DefaultLogoPath = "";
private static readonly DataContractSerializer DatabaseXmlSerializer = new(typeof(Database));
// /../../../..
private string DataFilePath { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "NotusData");
private const string DataFileName = "/Userdata.xml";
private const string DefaultThemeName = "/defaultTheme.xml";
private const string DefaultLogoName = "/defaultLogo.xml";
private static readonly DataContractSerializer DatabaseXmlSerializer = new(typeof(Database), GetKnownTypes());
public void SaveDatabaseData(List<User> UserList, Dictionary<User, List<Theme>> AddedThemeFromUser)
public void SaveDatabaseData(List<User> UserList)
{
if (!Directory.Exists(DataFilePath))
{
Directory.CreateDirectory(DataFilePath);
}
XmlWriterSettings settings = new() { Indent = true };
using TextWriter tw = File.CreateText(DataFilePath);
using TextWriter tw = File.CreateText(Path.Combine(DataFilePath + DataFileName));
using XmlWriter writer = XmlWriter.Create(tw, settings);
DatabaseXmlSerializer.WriteObject(writer, UserList);
DatabaseXmlSerializer.WriteObject(writer, AddedThemeFromUser);
}
public Database LoadDatabaseData()
public void SaveDefaultData(List<Theme> DefaultThemeList, List<Logo> DefaultLogoList)
{
if (!Directory.Exists(DataFilePath))
{ Directory.CreateDirectory(DataFilePath); }
XmlWriterSettings settings = new() { Indent = true };
using TextWriter tw = File.CreateText(Path.Combine(DataFilePath + DefaultThemeName));
using XmlWriter writer = XmlWriter.Create(tw, settings);
DatabaseXmlSerializer.WriteObject(writer, DefaultThemeList);
using TextWriter tw2 = File.CreateText(Path.Combine(DataFilePath + DefaultLogoName));
using XmlWriter writer2 = XmlWriter.Create(tw2, settings);
DatabaseXmlSerializer.WriteObject(writer2, DefaultLogoList);
}
private static IEnumerable<Type> GetKnownTypes()
{
yield return typeof(User);
yield return typeof(List<User>);
yield return typeof(Theme);
yield return typeof(List<Theme>);
yield return typeof(Logo);
yield return typeof(List<Logo>);
}
public List<User> LoadDatabaseData()
{
if (File.Exists(DataFilePath))
if (File.Exists(Path.Combine(DataFilePath + DataFileName)))
{
using (FileStream fileStream = File.OpenRead(DataFilePath))
using (FileStream fileStream = File.OpenRead(Path.Combine(DataFilePath + DataFileName)))
{
return DatabaseXmlSerializer.ReadObject(fileStream) is not Database database
? throw new FileException("Failed to load the database. The loaded object is null.")
: database;
return DatabaseXmlSerializer.ReadObject(fileStream) is not List<User> user
? throw new FileException("Failed to load Database. The loaded object is null.")
: user;
}
}
else
@ -46,9 +71,9 @@ namespace Notus_Persistance
public List<Theme> LoadDefaultTheme()
{
if (File.Exists(DefaultThemePath))
if (File.Exists(Path.Combine(DataFilePath + DefaultThemeName)))
{
using (FileStream fileStream = File.OpenRead(DefaultThemePath))
using (FileStream fileStream = File.OpenRead(Path.Combine(DataFilePath + DefaultThemeName)))
{
return DatabaseXmlSerializer.ReadObject(fileStream) is not List<Theme> DefaultThemeList
? throw new FileException("Failed to load Default Theme. The loaded object is null.")
@ -63,9 +88,9 @@ namespace Notus_Persistance
public List<Logo> LoadDefaultLogo()
{
if (File.Exists(DefaultLogoPath))
if (File.Exists(Path.Combine(DataFilePath + DefaultLogoName)))
{
using (FileStream fileStream = File.OpenRead(DefaultLogoPath))
using (FileStream fileStream = File.OpenRead(Path.Combine(DataFilePath + DefaultLogoName)))
{
return DatabaseXmlSerializer.ReadObject(fileStream) is not List<Logo> DefaultLogoList
? throw new FileException("Failed to load Default Logo. The loaded object is null.")

@ -1,36 +0,0 @@
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}") = "Biblioteque_de_Class", "Biblioteque_de_Class\Biblioteque_de_Class.csproj", "{92DD50C5-EEAD-44ED-AEFF-E21935725477}"
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
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{92DD50C5-EEAD-44ED-AEFF-E21935725477}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{92DD50C5-EEAD-44ED-AEFF-E21935725477}.Debug|Any CPU.Build.0 = Debug|Any CPU
{92DD50C5-EEAD-44ED-AEFF-E21935725477}.Release|Any CPU.ActiveCfg = Release|Any CPU
{92DD50C5-EEAD-44ED-AEFF-E21935725477}.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
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {61F7FB11-1E47-470C-91E2-47F8143E1572}
EndGlobalSection
EndGlobal

@ -1,39 +0,0 @@
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<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
database.AddTheme(theme);
CollectionAssert.Contains(database.GetThemeList(), theme);
}
[Test]
public void AddTheme_ExistingTheme_ThrowsException()
{
List<string> listcolor = new();
Theme theme = new Theme("ocean", listcolor);
database.AddTheme(theme);
Assert.Throws<AlreadyUsedException>(() => database.AddTheme(theme), "Theme already used.");
}
}
}

@ -1,51 +0,0 @@
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<AlreadyUsedException>(() => 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<AlreadyUsedException>(() => database.AddUser(newUser), "Email already used.");
}
}
}

@ -1,42 +0,0 @@
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";
var result = Database.ComparePassword(user, password);
Assert.That(result, Is.True);
}
[Test]
public void ComparePassword_IncorrectPassword_ReturnsFalse()
{
User user = database.GetUserList()[0];
string password = "incorrectPassword";
var result = Database.ComparePassword(user, password);
Assert.That(result, Is.False);
}
}
}

@ -1,39 +0,0 @@
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","rien","choco");
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);
}
}
}

@ -1,32 +0,0 @@
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()
{
Assert.That(database.GetLogoLink("Logo2"), Is.EqualTo("link2"));
}
[Test]
public void GetLogoLink_LogoDoesNotExist_ThrowsException()
{
string logoName = "Logo4";
Assert.Throws<NotFoundException>(() => database.GetLogoLink(logoName));
}
}
}

@ -1,36 +0,0 @@
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<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
database.GetThemeList().Add(theme);
Theme retrievedTheme = database.GetTheme("ocean");
Assert.That(retrievedTheme, Is.EqualTo(theme));
}
[Test]
public void GetTheme_NonExistingTheme_ThrowsException()
{
Assert.Throws<NotFoundException>(() => database.GetTheme("NonExistingTheme"), "No theme found with this name.");
}
}
}

@ -1,36 +0,0 @@
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<AlreadyUsedException>(() => database.GetUser(userName));
}
}
}

@ -1,33 +0,0 @@
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<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
database.GetThemeList().Add(theme);
List<string> newColorList = new List<string> { "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]));
}
}
}

@ -1,40 +0,0 @@
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 ModifyThemeName_ExistingTheme_ModifiesName()
{
List<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
database.GetThemeList().Add(theme);
string newName = "Light";
database.ModifyThemeName(theme, newName);
Assert.That(theme.GetName(), Is.EqualTo(newName));
}
[Test]
public void ModifyThemeName_NonExistingTheme_ThrowsException()
{
List<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
string newName = "Light";
Assert.Throws<NotFoundException>(() => database.ModifyThemeName(theme, newName), "Theme not found.");
}
}
}

@ -1,38 +0,0 @@
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 RemoveThemeTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
}
[Test]
public void RemoveTheme_NewTheme_ThemeAddedToList()
{
List<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
database.AddTheme(theme);
database.RemoveTheme(theme);
CollectionAssert.DoesNotContain(database.GetThemeList(), theme);
}
[Test]
public void RemoveTheme_ExistingTheme_ThrowsException()
{
List<string> listcolor = new();
Theme theme = new Theme("ocean", listcolor);
Assert.Throws<NotFoundException>(() => database.RemoveTheme(theme), "Theme already used.");
}
}
}

@ -1,38 +0,0 @@
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<NotFoundException>(() => database.RemoveUser(user), "User not found.");
}
}
}

@ -1,54 +0,0 @@
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<User> 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<User> searchedUsers = database.SearchUser(searchName);
Assert.IsEmpty(searchedUsers);
}
[Test]
public void SearchUser_CaseInsensitiveSearch_ReturnsMatchingUsers()
{
string searchName = "ALICE";
List<User> 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<User> searchedUsers = database.SearchUser(searchName);
Assert.That(searchedUsers.Count, Is.EqualTo(1));
Assert.That(searchedUsers[0].GetUsername(), Is.EqualTo("Jane"));
}*/
}
}

@ -1,28 +0,0 @@
using Biblioteque_de_Class;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class AddCollaboratorTests
{
[Test]
public void AddCollaborator_WhenUserIsOwner_CollaboratorAdded()
{
User owner = new User("Owner", "owner@example.com", "password");
User collaborator = new User("Collaborator1", "collaborator1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
note.AddCollaborator(owner, collaborator);
Assert.Contains(collaborator, note.GetCollaborators());
}
[Test]
public void AddCollaborator_WhenUserIsNotOwner_ThrowsException()
{
User owner = new User("Owner", "owner@example.com", "password");
User collaborator = new User("Collaborator1", "collaborator1@example.com", "password");
User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
Assert.Throws<NotAllowedException>(() => note.AddCollaborator(user, collaborator));
}
}
}

@ -1,29 +0,0 @@
using Biblioteque_de_Class;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class AddEditorTests
{
[Test]
public void AddEditor_WhenUserIsOwner_EditorAdded()
{
User owner = new User("Owner", "owner@example.com", "password");
User editor = new User("Editor1", "editor1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
note.AddEditor(owner, editor);
Assert.IsTrue(note.GetEditors().Contains(editor));
}
[Test]
public void AddEditor_WhenUserIsNotOwner_ThrowsException()
{
User owner = new User("Owner", "owner@example.com", "password");
User editor = new User("Editor1", "editor1@example.com", "password");
User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
Assert.Throws<NotAllowedException>(() => note.AddEditor(user, editor));
}
}
}

@ -1,23 +0,0 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
public class AddImageTests
{
[Test]
public void AddImage_WhenImageLinkIsValid_ImageAddedToList()
{
User owner = new User("Owner", "owner@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
string imageLink = "image.png";
string position = "top";
note.AddImage(imageLink, position);
Assert.That(note.GetImageList().Count, Is.EqualTo(1));
}
}
}

@ -1,36 +0,0 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class RemoveCollaboratorTests
{
[Test]
public void RemoveCollaborator_WhenUserIsOwner_CollaboratorRemoved()
{
User owner = new User("Owner", "owner@example.com", "password");
User collaborator = new User("Collaborator1", "collaborator1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
note.AddCollaborator(owner, collaborator);
note.RemoveCollaborator(owner, collaborator);
Assert.IsFalse(note.GetCollaborators().Contains(collaborator));
}
[Test]
public void RemoveCollaborator_WhenUserIsNotOwner_ThrowsException()
{
User owner = new User("Owner", "owner@example.com", "password");
User collaborator = new User("Collaborator1", "collaborator1@example.com", "password");
User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
note.AddCollaborator(owner, collaborator);
Assert.Throws<NotAllowedException>(() => note.RemoveCollaborator(user, collaborator));
}
}
}

@ -1,36 +0,0 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class RemoveEditorTests
{
[Test]
public void RemoveEditor_WhenUserIsOwner_EditorRemoved()
{
User owner = new User("Owner", "owner@example.com", "password");
User editor = new User("Editor1", "editor1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
note.AddEditor(owner, editor);
note.RemoveEditor(owner, editor);
Assert.IsFalse(note.GetEditors().Contains(editor));
}
[Test]
public void RemoveEditor_WhenUserIsNotOwner_ThrowsException()
{
User owner = new User("Owner", "owner@example.com", "password");
User editor = new User("Editor1", "editor1@example.com", "password");
User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
note.AddEditor(owner, editor);
Assert.Throws<NotAllowedException>(() => note.RemoveEditor(user, editor));
}
}
}

@ -1,31 +0,0 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class RemoveImageTests
{
[Test]
public void RemoveImage_WhenImageExists_ImageRemovedFromList()
{
User owner = new User("Owner", "owner@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
note.AddImage("image.png", "top");
note.RemoveImage(1);
Assert.That(note.GetImageList().Count, Is.EqualTo(0));
}
[Test]
public void RemoveImage_WhenImageDoesNotExist_ExceptionThrown()
{
User owner = new User("Owner", "owner@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
Assert.Throws<NotFoundException>(() => note.RemoveImage(1));
}
}
}

@ -1,80 +0,0 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class SetTests
{
private User owner;
private Note note;
[SetUp]
public void Setup()
{
owner = new User("John","rien","choco");
note = new Note("note","logo.png",owner);
}
[Test]
public void GetName_ShouldReturnName()
{
string actualName = note.GetName();
Assert.That(actualName, Is.EqualTo("note"));
}
[Test]
public void GetLogoPath_ShouldReturnLogoPath()
{
string actualLogoPath = note.GetLogoPath();
Assert.That(actualLogoPath, Is.EqualTo("logo.png"));
}
[Test]
public void GetCreationDate_ShouldReturnCreationDate()
{
DateOnly actualCreationDate = note.GetCreationDate();
Assert.That(actualCreationDate, Is.EqualTo(DateOnly.FromDateTime(DateTime.Now)));
}
[Test]
public void GetModificationDate_ShouldReturnModificationDate()
{
DateOnly actualModificationDate = note.GetModificationDate();
Assert.That(actualModificationDate, Is.EqualTo(DateOnly.FromDateTime(DateTime.Now)));
}
[Test]
public void GetImageList_ShouldReturnImageList()
{
List<NoteImage> actualImageList = note.GetImageList();
Assert.That(actualImageList, Is.EqualTo(new List<NoteImage>()));
}
[Test]
public void GetCollaborators_ShouldReturnCollaborators()
{
List<User> actualCollaborators = note.GetCollaborators();
Assert.That(actualCollaborators, Is.EqualTo(new List<User>()));
}
[Test]
public void GetEditors_ShouldReturnEditors()
{
List<User> actualEditors = note.GetEditors();
Assert.That(actualEditors, Is.EqualTo(new List<User>()));
}
[Test]
public void GetOwner_ShouldReturnOwner()
{
User actualOwner = note.GetOwner();
Assert.That(actualOwner, Is.EqualTo(owner));
}
}
}

@ -1,26 +0,0 @@
using Biblioteque_de_Class;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class VerifyOwnerTests
{
[Test]
public void VerifyOwner_UserIsOwner_ReturnsTrue()
{
User owner = new User("John", "john@example.com", "choco");
Note note = new Note("My Note", "path/to/logo.png", owner);
bool isOwner = note.VerifyOwner(owner);
Assert.IsTrue(isOwner);
}
[Test]
public void VerifyOwner_UserIsNotOwner_ReturnsFalse()
{
User owner = new User("John", "john@example.com", "choco");
User anotherUser = new User("Jane", "jane@example.com", "choco");
Note note = new Note("My Note", "path/to/logo.png", owner);
bool isOwner = note.VerifyOwner(anotherUser);
Assert.IsFalse(isOwner);
}
}
}

@ -1,32 +0,0 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class VerifyPrivilegeTests
{
[Test]
public void VerifyPrivilege_WhenUserIsEditor_ReturnsTrue()
{
User editor = new User("Editor1", "editor1@example.com", "password");
Note note = new Note("Test Note", "logo.png", new User("Owner", "owner@example.com", "password"));
note.AddEditor(note.GetOwner(), editor);
bool result = note.VerifyPrivilege(editor);
Assert.IsTrue(result);
}
[Test]
public void VerifyPrivilege_WhenUserIsNotEditor_ThrowsException()
{
User editor = new User("Editor1", "editor1@example.com", "password");
Note note = new Note("Test Note", "logo.png", new User("Owner", "owner@example.com", "password"));
bool result = note.VerifyPrivilege(editor);
Assert.IsFalse(result);
}
}
}

@ -1,24 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
<PackageReference Include="coverlet.collector" Version="3.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Biblioteque_de_Class\Biblioteque_de_Class.csproj" />
</ItemGroup>
</Project>

@ -1,59 +0,0 @@
using Biblioteque_de_Class;
namespace Notus_UnitTest_User
{
[TestFixture]
public class SearchNoteByNameTests
{
private User owner;
private string searchName;
[SetUp]
public void SetUp()
{
owner = new("Owner", "owner@example.com", "password");
owner.CreateNote("Note 1", "image1.png");
owner.CreateNote("Note 2", "image2.png");
owner.CreateNote("Another Note", "image3.png");
owner.AddFavorite(owner.GetNoteList()[0]);
owner.AddFavorite(owner.GetNoteList()[1]);
owner.AddFavorite(owner.GetNoteList()[2]);
searchName = "note";
}
[Test]
public void SearchNoteByName_WhenMatchingNotesExist_NotesReturned()
{
List<Note> result = owner.SearchNoteByName(owner.GetNoteList(),"note");
Assert.That(result, Has.Count.EqualTo(3));
CollectionAssert.Contains(result, owner.GetNoteList()[0]);
CollectionAssert.Contains(result, owner.GetNoteList()[1]);
CollectionAssert.Contains(result, owner.GetNoteList()[2]);
}
[Test]
public void SearchNoteByName_WhenNoMatchingNotesExist_EmptyListReturned()
{
List<Note> result = owner.SearchNoteByName(owner.GetNoteList(), "test");
Assert.That(result, Is.Empty);
}
[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);
}
}
}

@ -1 +0,0 @@
global using NUnit.Framework;

@ -0,0 +1,223 @@
using Biblioteque_de_Class;
namespace UnitTests_Model
{
[TestFixture]
public class Database_Tests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
database.UserList.Add(new User("John", "john@example.com", "password123"));
database.UserList.Add(new User("Jane", "jane@example.com", "choco"));
database.UserList.Add(new User("Alice", "alice@example.com", "choco"));
database.DefaultLogoList.Add(new Logo("Logo1", "link1"));
database.DefaultLogoList.Add(new Logo("Logo2", "link2"));
database.DefaultLogoList.Add(new Logo("Logo3", "link3"));
}
// SearchUser tests
[Test]
public void SearchUser_UserDoesNotExist_ThrowsException()
{
string searchName = "Bob";
Assert.Throws<NotFoundException>(() => database.SearchUser(searchName));
}
[Test]
public void SearchUser_CaseInsensitiveSearch_ReturnsMatchingUsers()
{
string searchName = "Alice";
User searchedUser = database.SearchUser(searchName);
Assert.That(searchedUser.Username, Is.EqualTo("Alice"));
}
// GetLogoLink tests
[Test]
public void GetLogoLink_LogoExists_ReturnsLogoLink()
{
Assert.That(database.GetLogoLink("Logo2"), Is.EqualTo("link2"));
}
[Test]
public void GetLogoLink_LogoDoesNotExist_ThrowsException()
{
string logoName = "Logo4";
Assert.Throws<NotFoundException>(() => database.GetLogoLink(logoName));
}
// GetUser tests
[Test]
public void GetUser_UserExists_ReturnsUser()
{
string userName = "Alice";
User user = database.GetUser(userName);
Assert.IsNotNull(user);
Assert.That(user.Username, Is.EqualTo(userName));
}
[Test]
public void GetUser_UserDoesNotExist_ThrowsException()
{
string userName = "Eve";
Assert.Throws<AlreadyUsedException>(() => database.GetUser(userName));
}
// ComparePassword tests
[Test]
public void ComparePassword_CorrectPassword_ReturnsTrue()
{
User user = database.UserList[0];
string password = "password123";
bool result = Database.ComparePassword(user, password);
Assert.That(result, Is.True);
}
[Test]
public void ComparePassword_IncorrectPassword_ReturnsFalse()
{
User user = database.UserList[0];
string password = "incorrectPassword";
bool result = Database.ComparePassword(user, password);
Assert.That(result, Is.False);
}
// FindEmail tests
[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 = "olivedecarglass@example.com";
bool result = database.FindEmail(email);
Assert.IsFalse(result);
}
// AddUser tests
[Test]
public void AddUser_ValidUser_AddsUserToList()
{
User user = new User("Bob", "bob@example.com", "password123");
database.AddUser(user);
Assert.That(database.UserList, Contains.Item(user));
}
[Test]
public void AddUser_DuplicateUserName_ThrowsException()
{
User user = new User("John", "johnDae@example.com", "password123");
Assert.Throws<AlreadyUsedException>(() => database.AddUser(user));
}
[Test]
public void AddUser_DuplicateUserEmail_ThrowsException()
{
User user = new User("Bob", "john@example.com", "password123");
Assert.Throws<AlreadyUsedException>(() => database.AddUser(user));
}
// removeUser tests
[Test]
public void RemoveUser_ExistingUser_RemovesUserFromList()
{
User user = database.UserList[0];
database.RemoveUser(user);
Assert.That(database.UserList, !Contains.Item(user));
}
[Test]
public void RemoveUser_NotExistingUser_ThrowsException()
{
User user = new User("Bob", "bob@example.com", "password123");
Assert.Throws<NotFoundException>(() => database.RemoveUser(user));
}
// AddTheme tests
[Test]
public void AddTheme_ValidTheme_AddsThemeToList()
{
Theme theme = new Theme("Theme1", ",,,".Split().ToList());
database.AddTheme(theme);
Assert.That(database.ThemeList, Contains.Item(theme));
}
[Test]
public void AddTheme_DuplicateTheme_ThrowsException()
{
Theme theme = new Theme("Theme1", ",,,".Split().ToList());
database.ThemeList.Add(theme);
Assert.Throws<AlreadyExistException>(() => database.AddTheme(theme));
}
// GetTheme tests
[Test]
public void GetTheme_ExistingTheme_ReturnsTheme()
{
Theme expectedTheme = new Theme("Theme1", ",,,".Split().ToList());
database.ThemeList.Add(expectedTheme);
Theme theme = database.GetTheme("Theme1");
Assert.IsNotNull(theme);
Assert.That(theme, Is.EqualTo(expectedTheme));
}
[Test]
public void GetTheme_NonExistingTheme_ReturnsNull()
{
Theme expectedTheme = new Theme("Theme1", ",,,".Split().ToList());
database.ThemeList.Add(expectedTheme);
Assert.Throws<NotFoundException>(() => database.GetTheme("NonExistingTheme"));
}
// ChangeUsername tests
[Test]
public void ChangeUsername_CorrectReplaceName_ChangesUsername()
{
User userSelected = database.UserList[0];
string newUsername = "duberlute";
database.ChangeUsername(userSelected, newUsername);
User updatedUser = database.UserList.Where(u => u.Username == newUsername).First();
Assert.IsNotNull(updatedUser);
Assert.That(updatedUser.Username, Is.EqualTo(newUsername));
}
[Test]
public void ChangeUsername_UsernameAlreadyUsed_ThrowsException()
{
User userNotSelected = database.UserList[2];
string newUsername = "Jane";
Assert.Throws<AlreadyUsedException>(() => database.ChangeUsername(userNotSelected, newUsername));
}
// VerifThemeNameNotTaken tests
[Test]
public void VerifThemeNameNotTaken_NameNotTaken_ReturnsTrue()
{
string themeName = "NewTheme";
bool result = database.VerifThemeNameNotTaken(themeName);
Assert.IsTrue(result);
}
[Test]
public void VerifThemeNameNotTaken_NameAlreadyTaken_ReturnsFalse()
{
Theme expectedTheme = new Theme("Theme1", ",,,".Split().ToList());
database.ThemeList.Add(expectedTheme);
string themeName = "Theme1";
bool result = database.VerifThemeNameNotTaken(themeName);
Assert.IsFalse(result);
}
}
}

@ -0,0 +1,265 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTests_Model
{
[TestFixture]
public class Note_Tests
{
private User owner;
private Note note;
[SetUp]
public void Setup()
{
owner = new User("John", "john@example.com", "password123");
note = new Note(1, "Note 1", "logoPath", owner);
}
[Test]
public void Note_Constructor_InitializesProperties()
{
Assert.That(note.id, Is.EqualTo(1));
Assert.That(note.Name, Is.EqualTo("Note 1"));
Assert.That(note.LogoPath, Is.EqualTo("logoPath"));
Assert.That(note.Owner, Is.EqualTo(owner));
Assert.That(note.ImageList.Count, Is.EqualTo(0));
Assert.That(note.Collaborators.Count, Is.EqualTo(0));
Assert.That(note.Editors.Count, Is.EqualTo(1));
Assert.That(note.Editors[0], Is.EqualTo(owner));
}
[Test]
public void Note_VerifyOwner_UserIsOwner_ReturnsTrue()
{
bool result = note.VerifyOwner(owner);
Assert.IsTrue(result);
}
[Test]
public void Note_VerifyOwner_UserIsNotOwner_ThrowsNotAllowedException()
{
User otherUser = new User("Jane", "jane@example.com", "password123");
Assert.Throws<NotAllowedException>(() => note.VerifyOwner(otherUser));
}
[Test]
public void Note_AddImage_ValidData_AddsImage()
{
string imageLink = "imageLink";
List<int> position = new List<int> { 1, 2, 3 };
note.AddImage(imageLink, position);
Assert.That(note.ImageList.Count, Is.EqualTo(1));
Assert.That(note.ImageList[0].Name, Is.EqualTo("1"));
Assert.That(note.ImageList[0].ImageLink, Is.EqualTo(imageLink));
Assert.That(note.ImageList[0].Position, Is.EqualTo(position));
}
[Test]
public void Note_RemoveImage_ExistingImage_RemovesImage()
{
string imageLink = "imageLink";
List<int> position = new List<int> { 1, 2, 3 };
note.AddImage(imageLink, position);
note.RemoveImage("1");
Assert.That(note.ImageList.Count, Is.EqualTo(0));
}
[Test]
public void Note_RemoveImage_NonExistingImage_ThrowsNotFoundException()
{
string imageLink = "imageLink";
List<int> position = new List<int> { 1, 2, 3 };
note.AddImage(imageLink, position);
Assert.Throws<NotFoundException>(() => note.RemoveImage("2"));
}
[Test]
public void Note_AddText_UserIsOwner_AddsText()
{
User user = owner;
string text = "Some text";
note.AddText(user, text);
Assert.That(note.Text, Is.EqualTo("\n" + text));
Assert.That(note.ModificationDate, Is.EqualTo(DateOnly.FromDateTime(DateTime.Now)));
}
[Test]
public void Note_AddText_UserIsEditor_AddsText()
{
User user = new User("Editor", "editor@example.com", "password123");
note.AddEditor(owner, user);
string text = "Some text";
note.AddText(user, text);
Assert.That(note.Text, Is.EqualTo("\n"+text));
Assert.That(note.ModificationDate, Is.EqualTo(DateOnly.FromDateTime(DateTime.Now)));
}
[Test]
public void Note_AddText_UserIsNotOwnerOrEditor_ThrowsNotAllowedException()
{
User user = new User("Jane", "jane@example.com", "password123");
string text = "Some text";
Assert.Throws<NotAllowedException>(() => note.AddText(user, text));
}
[Test]
public void Note_VerifyPrivilege_UserIsEditor_ReturnsTrue()
{
User editor = new User("Editor", "editor@example.com", "password123");
note.AddEditor(owner, editor);
bool result = note.VerifyPrivilege(editor);
Assert.IsTrue(result);
}
[Test]
public void Note_VerifyPrivilege_UserIsNotEditor_ReturnsFalse()
{
User user = new User("User", "user@example.com", "password123");
bool result = note.VerifyPrivilege(user);
Assert.IsFalse(result);
}
[Test]
public void Note_AddCollaborator_UserIsOwner_AddsCollaborator()
{
User collaborator = new User("Collaborator", "collaborator@example.com", "password123");
note.AddCollaborator(owner, collaborator);
Assert.That(note.Collaborators.Count, Is.EqualTo(1));
Assert.That(note.Collaborators[0], Is.EqualTo(collaborator));
Assert.IsTrue(collaborator.NoteList.Contains(note));
}
[Test]
public void Note_AddCollaborator_UserIsNotOwner_ThrowsNotAllowedException()
{
User otherUser = new User("OtherUser", "otheruser@example.com", "password123");
User collaborator = new User("Collaborator", "collaborator@example.com", "password123");
Assert.Throws<NotAllowedException>(() => note.AddCollaborator(otherUser, collaborator));
}
[Test]
public void Note_RemoveCollaborator_UserIsOwner_RemovesCollaborator()
{
User collaborator = new User("Collaborator", "collaborator@example.com", "password123");
note.AddCollaborator(owner, collaborator);
note.RemoveCollaborator(owner, collaborator);
Assert.That(note.Collaborators.Count, Is.EqualTo(0));
Assert.IsFalse(collaborator.NoteList.Contains(note));
}
[Test]
public void Note_RemoveCollaborator_UserIsNotOwner_ThrowsNotAllowedException()
{
User otherUser = new User("OtherUser", "otheruser@example.com", "password123");
User collaborator = new User("Collaborator", "collaborator@example.com", "password123");
note.AddCollaborator(owner, collaborator);
Assert.Throws<NotAllowedException>(() => note.RemoveCollaborator(otherUser, collaborator));
}
[Test]
public void Note_AddEditor_UserAlreadyEditor_ThrowsAlreadyExistException()
{
User editor = new User("Editor", "editor@example.com", "password123");
note.AddEditor(owner, editor);
Assert.Throws<AlreadyExistException>(() => note.AddEditor(owner, editor));
}
[Test]
public void Note_AddEditor_UserIsOwner_AddsEditor()
{
User editor = new User("Editor", "editor@example.com", "password123");
note.AddEditor(owner, editor);
Assert.That(note.Editors.Count, Is.EqualTo(2));
Assert.That(note.Editors[1], Is.EqualTo(editor));
}
[Test]
public void Note_RemoveEditor_UserNotEditor_ThrowsNotFoundException()
{
User user = new User("User", "user@example.com", "password123");
Assert.Throws<NotFoundException>(() => note.RemoveEditor(owner, user));
}
[Test]
public void Note_RemoveEditor_UserIsOwner_RemovesEditor()
{
User editor = new User("Editor", "editor@example.com", "password123");
note.AddEditor(owner, editor);
note.RemoveEditor(owner, editor);
Assert.That(note.Editors.Count, Is.EqualTo(1));
Assert.IsFalse(note.Editors.Contains(editor));
}
[Test]
public void Note_ChangeName_UserIsOwner_ChangesName()
{
User user = owner;
string newName = "New Note Name";
note.ChangeName(user, newName);
Assert.That(note.Name, Is.EqualTo(newName));
}
[Test]
public void Note_ChangeName_UserIsNotOwner_NameNotChanged()
{
User user = new User("OtherUser", "otheruser@example.com", "password123");
string newName = "New Note Name";
Assert.Throws<NotAllowedException>(() => note.ChangeName(user, newName));
}
[Test]
public void Note_ChangeLogo_UserIsOwner_ChangesLogo()
{
User user = owner;
string newLogoPath = "newLogoPath";
note.ChangeLogo(user, newLogoPath);
Assert.That(note.LogoPath, Is.EqualTo(newLogoPath));
}
[Test]
public void Note_ChangeLogo_UserIsNotOwner_LogoNotChanged()
{
User user = new User("OtherUser", "otheruser@example.com", "password123");
string newLogoPath = "newLogoPath";
Assert.Throws<NotAllowedException>(() => note.ChangeLogo(user, newLogoPath));
}
}
}

@ -0,0 +1,481 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTests_Model
{
public class User_Tests
{
private User user;
[SetUp]
public void Setup()
{
user = new User("John", "john@example.com", "password123");
user.CreateTag("tag1","#FF0000");
user.CreateTag("tag2", "#00FF00");
user.CreateNote("note1", "default.png");
user.AddTagFromNoteList(user.NoteList[0], user.TagList[0]);
user.CreateNote("note2", "default.png");
user.AddTheme(new Theme("white","#FFAAAA,#000000,#999999".Split(',').ToList()));
}
//test searchnoteByName
[Test]
public void User_SearchNoteByName_ValidData_ReturnsNote()
{
Note note = user.SearchNoteByName(user.NoteList,"note1").First();
Assert.That(note.Name, Is.EqualTo("note1"));
}
[Test]
public void User_SearchNoteByName_InvalidData_ReturnsNull()
{
Assert.That(user.SearchNoteByName(user.NoteList, "note3"), Is.Empty);
}
//test seachNoteBytag
[Test]
public void User_SearchNoteByTag_ValidData_ReturnsNote()
{
Note note = user.SearchNoteByTag(user.NoteList, "tag1").First();
Assert.That(note.Name, Is.EqualTo("note1"));
}
[Test]
public void User_SearchNoteByTag_InvalidData_ReturnsNull()
{
Assert.Throws<NotFoundException>(() => user.SearchNoteByTag(user.NoteList, "tag3"));
}
//test SearchNoteByDate
[Test]
public void User_SearchNoteByDate_ValidData_ReturnsNote()
{
Note note = user.SearchNoteByDate(user.NoteList, "note1", DateOnly.FromDateTime(DateTime.Now), DateOnly.FromDateTime(DateTime.Now)).First();
Assert.That(note.Name, Is.EqualTo("note1"));
}
[Test]
public void User_SearchNoteByDate_InvalidData_ReturnsNull()
{
Assert.That(user.SearchNoteByDate(user.NoteList, "note3", DateOnly.FromDateTime(DateTime.Now), DateOnly.FromDateTime(DateTime.Now)), Is.Empty);
}
//test GetNoteByName
[Test]
public void User_GetNoteByName_ValidData_ReturnsNote()
{
Note note = user.GetNoteByName("note1");
Assert.That(note.Name, Is.EqualTo("note1"));
}
[Test]
public void User_GetNoteByName_InvalidData_ReturnsNull()
{
Assert.Throws<NotFoundException>(() => user.GetNoteByName("note3"));
}
//test searchTagByName
[Test]
public void User_SearchTagByName_ValidData_ReturnsTag()
{
Tags tag = user.SearchTagByName(user.TagList, "tag1").First();
Assert.That(tag.Name, Is.EqualTo("tag1"));
}
[Test]
public void User_SearchTagByName_InvalidData_ReturnsNull()
{
Assert.That(user.SearchTagByName(user.TagList, "tag3"), Is.Empty);
}
//test AddFavorite
[Test]
public void User_AddFavorite_ValidData_AddNote()
{
user.AddFavorite(user.NoteList[0]);
Assert.That(user.FavList.Count, Is.EqualTo(1));
}
[Test]
public void User_AddFavorite_InvalidData_ThrowException()
{
user.AddFavorite(user.NoteList[0]);
Assert.Throws<AlreadyExistException>(() => user.AddFavorite(user.NoteList[0]));
}
//test RemoveFavorite
[Test]
public void User_RemoveFavorite_ValidData_RemoveNote()
{
user.AddFavorite(user.NoteList[0]);
user.RemoveFavorite(user.NoteList[0]);
Assert.That(user.FavList, Is.Empty);
}
[Test]
public void User_RemoveFavorite_InvalidData_ThrowException()
{
Assert.Throws<NotFoundException>(() => user.RemoveFavorite(user.NoteList[0]));
}
//test createNote
[Test]
public void User_CreateNote_ValidData_AddNote()
{
user.CreateNote("note3", "default.png");
Assert.That(user.NoteList.Count, Is.EqualTo(3));
}
[Test]
public void User_CreateNote_InvalidData_ThrowException()
{
user.CreateNote("note3", "default.png");
Assert.Throws<AlreadyExistException>(() => user.CreateNote("note3", "default.png"));
}
[Test]
public void User_CreateNote_ValidData_secondNote_AddNote()
{
User user2 = new User("John", "rien", "choco");
user2.CreateNote("note3", "default.png");
user2.CreateNote("note4", "default.png");
Assert.That(user2.NoteList.Count, Is.EqualTo(2));
Assert.That(user2.NoteList[1].id, Is.EqualTo(1));
}
//test DeleteNote
[Test]
public void User_DeleteNote_ValidData_RemoveNote()
{
Note note = user.NoteList[0];
user.DeleteNote(note);
Assert.That(user.NoteList.Count, Is.EqualTo(1));
}
[Test]
public void User_DeleteNote_InvalidData_ThrowException()
{
Note note = user.NoteList[0];
user.DeleteNote(note);
Assert.Throws<NotFoundException>(() => user.DeleteNote(note));
}
//test CreateTag
[Test]
public void User_CreateTag_ValidData_AddTag()
{
user.CreateTag("tag3", "#FF0000");
Assert.That(user.TagList.Count, Is.EqualTo(3));
}
[Test]
public void User_CreateTag_InvalidData_ThrowException()
{
user.CreateTag("tag3", "#FF0000");
Assert.Throws<AlreadyExistException>(() => user.CreateTag("tag2", "#FF0000"));
}
//test DeleteTag
[Test]
public void User_DeleteTag_ValidData_RemoveTag()
{
Tags tag = user.TagList[0];
user.DeleteTag(tag);
Assert.That(user.TagList.Count, Is.EqualTo(1));
}
[Test]
public void User_DeleteTag_InvalidData_ThrowException()
{
Tags tag = user.TagList[0];
user.DeleteTag(tag);
Assert.Throws<NotFoundException>(() => user.DeleteTag(tag));
}
//test EditTagName
[Test]
public void User_EditTagName_ValidData_EditTag()
{
user.EditTagName(user.TagList[0], "tag3");
Assert.That(user.TagList[0].Name, Is.EqualTo("tag3"));
}
[Test]
public void User_EditTagName_InvalidData_ThrowException()
{
Tags tags = new Tags("tag2", "#FF0000");
Assert.Throws<NotFoundException>(() => user.EditTagName(tags, "tag1"));
}
[Test]
public void User_EditTagName_InvalidData2_ThrowException()
{
Assert.Throws<AlreadyExistException>(() => user.EditTagName(user.TagList[0], "tag1"));
}
//test EditTagColor
[Test]
public void User_EditTagColor_ValidData_EditTag()
{
user.EditTagColor(user.TagList[0], "#FF0000");
Assert.That(user.TagList[0].Color, Is.EqualTo("#FF0000"));
}
[Test]
public void User_EditTagColor_InvalidData_ThrowException()
{
Tags tags = new Tags("tag2", "#FF0000");
Assert.Throws<NotFoundException>(() => user.EditTagColor(tags, "#000000"));
}
//Test AddTagFromNoteList
[Test]
public void User_AddTagFromNoteList_ValidData_AddTag()
{
user.AddTagFromNoteList(user.NoteList[0], user.TagList[1]);
Assert.That(user.NoteTagged[user.NoteList[0]].Count, Is.EqualTo(2));
}
[Test]
public void User_AddTagFromNoteList_InvalidData_ThrowException()
{
Tags tags = new Tags("tag2", "#FF0000");
Assert.Throws<NotFoundException>(() => user.AddTagFromNoteList(user.NoteList[0], tags));
}
[Test]
public void User_AddTagFromNoteList_InvalidData2_ThrowException()
{
User uvide = new User("", "", "");
Note note = new Note(4,"rien", "default.png", uvide);
Assert.Throws<NotFoundException>(() => user.AddTagFromNoteList(note, user.TagList[0]));
}
//Test RemoveTagFromNoteList
[Test]
public void User_RemoveTagFromNoteList_ValidData_RemoveTag()
{
user.RemoveTagFromNoteList(user.NoteList[0], user.TagList[0]);
Assert.That(user.NoteTagged[user.NoteList[0]], Is.Empty);
}
[Test]
public void User_RemoveTagFromNoteList_InvalidData_ThrowException()
{
Tags tags = new Tags("tag2", "#FF0000");
Assert.Throws<NotFoundException>(() => user.RemoveTagFromNoteList(user.NoteList[0], tags));
}
[Test]
public void User_RemoveTagFromNoteList_InvalidData2_ThrowException()
{
User uvide = new User("", "", "");
Note note = new Note(4, "rien", "default.png", uvide);
Assert.Throws<NotFoundException>(() => user.RemoveTagFromNoteList(note, user.TagList[0]));
}
//test SetNoteName
[Test]
public void User_SetNoteName_ValidData_EditNote()
{
user.SetNoteName(user.NoteList[0], "note3");
Assert.That(user.NoteList[0].Name, Is.EqualTo("note3"));
}
[Test]
public void User_SetNoteName_InvalidData_ThrowException()
{
User uvide = new User("", "", "");
Note note = new Note(4, "rien", "default.png", uvide);
Assert.Throws<NotFoundException>(() => user.SetNoteName(note, "note2"));
}
[Test]
public void User_SetNoteName_InvalidData2_ThrowException()
{
Assert.Throws<AlreadyUsedException>(() => user.SetNoteName(user.NoteList[0], "note1"));
}
//test ChangePassword
[Test]
public void User_ChangePassword_ValidData_ChangePassword()
{
user.ChangePassword("chocoChoco");
Assert.That(user.Password, Is.EqualTo(HashCodeModel.GetSHA256Hash("chocoChoco").ToString()));
}
[Test]
public void User_ChangePassword_InvalidData_ThrowException()
{
user.ChangePassword("chocoChoco");
Assert.Throws<AlreadyUsedException>(() => user.ChangePassword("chocoChoco"));
}
[Test]
public void User_ChangePassword_InvalidData1_ThrowException()
{
Assert.Throws<NotAllowedException>(() => user.ChangePassword("choco"));
}
[Test]
public void User_ChangePassword_InvalidData2_ThrowException()
{
Assert.Throws<NotAllowedException>(() => user.ChangePassword(""));
}
//test ChangeTheme
[Test]
public void User_ChangeTheme_ValidData_ChangeTheme()
{
user.ChangeTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList()));
Assert.That(user.UseTheme.Name, Is.EqualTo("dark"));
}
[Test]
public void User_ChangeTheme_InvalidData_ThrowException()
{
user.ChangeTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList()));
Assert.Throws<AlreadyExistException>(() => user.ChangeTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList())));
}
//test ChangeThemeName
[Test]
public void User_ChangeThemeName_ValidData_ChangeThemeName()
{
user.ChangeThemeName(user.AddedTheme[0], "dark");
Assert.That(user.AddedTheme[0].Name, Is.EqualTo("dark"));
}
[Test]
public void User_ChangeThemeName_InvalidData_ThrowException()
{
user.AddTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList()));
Assert.Throws<AlreadyExistException>(() => user.ChangeThemeName(user.AddedTheme[0], "dark"));
}
[Test]
public void User_ChangeThemeName_InvalidData2_ThrowException()
{
Assert.Throws<AlreadyExistException>(() => user.ChangeThemeName(user.AddedTheme[0], "white"));
}
//test ChangeThemeColors
[Test]
public void User_ChangeThemeColors_ValidData_ChangeThemeColors()
{
// Arrange
var theme = new Theme("blacktheme", new List<string> { "#000000", "#FF00FF", "#OOFFOO" });
var newColors = new List<string> { "#111111", "#222222", "#333333" };
// Act
user.ChangeThemeColors(theme, newColors);
// Assert
Assert.That(theme.ColorList[0], Is.EqualTo(newColors[0]));
Assert.That(theme.ColorList[1], Is.EqualTo(newColors[1]));
Assert.That(theme.ColorList[2], Is.EqualTo(newColors[2]));
}
[Test]
public void User_ChangeThemeColors_InvalidData_ThrowException()
{
// Arrange
var theme = new Theme("blacktheme", new List<string> { "#000000", "#FF00FF", "#OOFFOO" });
var sameColors = new List<string> { "#000000", "#FF00FF", "#OOFFOO" };
// Act & Assert
Assert.Throws<AlreadyExistException>(() => user.ChangeThemeColors(theme, sameColors));
}
[Test]
public void User_ChangeThemeColors_InvalidData1_ThrowException()
{
// Arrange
var theme = new Theme("blacktheme", new List<string> { "#000000", "#FF00FF", "#OOFFOO" });
var differentColors = new List<string> { "#111111", "#222222", "#333333", "#444444" };
// Act & Assert
Assert.Throws<NotFoundException>(() => user.ChangeThemeColors(theme, differentColors));
}
//test AddTheme
[Test]
public void User_AddTheme_ValidData_AddTheme()
{
user.AddTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList()));
Assert.That(user.AddedTheme[1].Name, Is.EqualTo("dark"));
}
[Test]
public void User_AddTheme_InvalidData_ThrowException()
{
user.AddTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList()));
Assert.Throws<AlreadyExistException>(() => user.AddTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList())));
}
//test RemoveTheme
[Test]
public void User_RemoveTheme_ValidData_RemoveTheme()
{
user.AddTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList()));
user.RemoveTheme(user.AddedTheme[1]);
Assert.That(user.AddedTheme.Count, Is.EqualTo(1));
}
[Test]
public void User_RemoveTheme_InvalidData_ThrowException()
{
Assert.Throws<NotFoundException>(() => user.RemoveTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList())));
}
//test GetTheme
[Test]
public void User_GetTheme_ValidData_GetTheme()
{
user.AddTheme(new Theme("dark", "#0000FF,#FF00FF,#FFFFFF".Split(',').ToList()));
Assert.That(user.GetTheme("dark").Name, Is.EqualTo("dark"));
}
[Test]
public void User_GetTheme_InvalidData_ThrowException()
{
Assert.Throws<NotFoundException>(() => user.GetTheme("dark"));
}
//test ChangeEmail
[Test]
public void User_ChangeEmail_ValidData_ChangeEmail()
{
user.ChangeEmail("nouvelleEmail@gmail.com");
Assert.That(user.Email, Is.EqualTo("nouvelleEmail@gmail.com"));
}
[Test]
public void User_ChangeEmail_InvalidData_ThrowException()
{
Assert.Throws<NotAllowedException>(() => user.ChangeEmail(""));
}
//test ChangeProfilePicture
[Test]
public void User_ChangeProfilePicture_ValidData_ChangeProfilePicture()
{
user.ChangeProfilePicture("nouvellePhoto.png");
Assert.That(user.Picture, Is.EqualTo("nouvellePhoto.png"));
}
[Test]
public void User_ChangeProfilePicture_InvalidData_ThrowException()
{
Assert.Throws<NotFoundException>(() => user.ChangeProfilePicture("photosansextesion"));
}
[Test]
public void User_ChangeProfilePicture_InvalidData2_ThrowException()
{
user.ChangeProfilePicture("");
Assert.That(user.Picture, Is.EqualTo("default.png"));
}
}
}

@ -0,0 +1,76 @@
using Biblioteque_de_Class;
using Notus_Persistance;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTests_Persistance
{
public class Stub_Tests
{
PersistenceManager manager;
Database result;
[SetUp]
public void Setup()
{
manager = new PersistenceManager(new Stub());
result = new Database();
}
[Test]
public void SaveDatabaseData_Test()
{
Assert.Throws<NotImplementedException>(() => manager.SaveDatabaseData(result));
}
[Test]
public void LoadDatabaseData_Test()
{
result = manager.GetOnlyDatabaseUser();
Assert.NotNull(result);
Assert.NotNull(result.UserList);
Assert.That(result.UserList.Count, Is.EqualTo(4));
User user1 = result.UserList[0];
Assert.That(user1.Username, Is.EqualTo("Nicolas"));
Assert.That(user1.Email, Is.EqualTo("leHeros@gmail.com"));
Assert.That(user1.Password, Is.EqualTo(HashCodeModel.GetSHA256Hash("FeurFeur")));
Note user1Note = user1.NoteList[0];
Tags user1Tag = user1.TagList[0];
Assert.That(user1Note.Name, Is.EqualTo("Note 0"));
Assert.That(user1Note.LogoPath, Is.EqualTo("DefaultLogo.png"));
Assert.That(user1Tag.Name, Is.EqualTo("Tag 0"));
Assert.That(user1Tag.Color, Is.EqualTo("#5555FF"));
}
[Test]
public void LoadDefaultTheme_Test()
{
result = manager.GetOnlyDatabaseDefaultTheme();
Assert.NotNull(result);
Assert.That(result.ThemeList.Count, Is.EqualTo(2));
Theme theme1 = result.ThemeList[0];
Assert.That(theme1.Name, Is.EqualTo("blacktheme"));
Assert.That(theme1.ColorList[0], Is.EqualTo("#000000"));
Assert.That(theme1.ColorList[1], Is.EqualTo("#FF00FF"));
Assert.That(theme1.ColorList[2], Is.EqualTo("#OOFFOO"));
}
[Test]
public void LoadDefaultLogo_Test()
{
result = manager.GetOnlyDatabaseDefaultLogo();
Assert.NotNull(result);
Assert.That(result.DefaultLogoList.Count, Is.EqualTo(3));
Logo logo1 = result.DefaultLogoList[0];
Assert.That(logo1.Name, Is.EqualTo("default"));
Assert.That(logo1.LogoLink, Is.EqualTo("DefaultLogo.png"));
}
}
}

@ -0,0 +1,115 @@
using Biblioteque_de_Class;
using Notus_Persistance;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace UnitTests_Persistance
{
public class ToXML_Tests
{
PersistenceManager manager;
Database result;
[SetUp]
public void Setup()
{
manager = new PersistenceManager(new Stub());
result = new Database();
}
[Test]
public void SaveDatabaseData_Test()
{
PersistenceManager manager2 = new PersistenceManager(new ToXML());
Database result2 = manager.LoadDatabaseData();
manager2.SaveDatabaseData(result2);
Database result3 = manager2.GetOnlyDatabaseUser();
Assert.NotNull(result3);
Assert.That(result2.UserList.Count, Is.EqualTo(result3.UserList.Count));
Assert.That(result2.UserList[0].Username, Is.EqualTo(result3.UserList[0].Username));
Assert.That(result2.UserList[0].Email, Is.EqualTo(result3.UserList[0].Email));
Assert.That(result2.UserList[0].Password, Is.EqualTo(result3.UserList[0].Password));
}
[Test]
public void LoadDefaultData_Test()
{
PersistenceManager manager2 = new PersistenceManager(new ToXML());
Database result2 = new();
result2.SetDefaultThemeList(manager.GetOnlyDatabaseDefaultTheme().ThemeList);
result2.SetDefaultLogoList(manager.GetOnlyDatabaseDefaultLogo().DefaultLogoList);
manager2.SaveDefaultData(result2);
Database result3 = new();
result3.SetDefaultThemeList(manager2.GetOnlyDatabaseDefaultTheme().ThemeList);
result3.SetDefaultLogoList(manager2.GetOnlyDatabaseDefaultLogo().DefaultLogoList);
Assert.NotNull(result3);
Assert.That(result2.ThemeList.Count, Is.EqualTo(result3.ThemeList.Count));
Assert.That(result2.DefaultLogoList.Count, Is.EqualTo(result3.DefaultLogoList.Count));
Assert.That(result2.ThemeList[0].Name, Is.EqualTo(result3.ThemeList[0].Name));
Assert.That(result2.ThemeList[0].ColorList[0], Is.EqualTo(result3.ThemeList[0].ColorList[0]));
Assert.That(result2.ThemeList[0].ColorList[1], Is.EqualTo(result3.ThemeList[0].ColorList[1]));
Assert.That(result2.ThemeList[0].ColorList[2], Is.EqualTo(result3.ThemeList[0].ColorList[2]));
Assert.That(result2.DefaultLogoList[0].Name, Is.EqualTo(result3.DefaultLogoList[0].Name));
Assert.That(result2.DefaultLogoList[0].LogoLink, Is.EqualTo(result3.DefaultLogoList[0].LogoLink));
}
[Test]
public void LoadDatabaseData_Test()
{
result = manager.GetOnlyDatabaseUser();
Assert.NotNull(result);
Assert.NotNull(result.UserList);
Assert.That(result.UserList.Count, Is.EqualTo(4));
User user1 = result.UserList[0];
Assert.That(user1.Username, Is.EqualTo("Nicolas"));
Assert.That(user1.Email, Is.EqualTo("leHeros@gmail.com"));
Assert.That(user1.Password, Is.EqualTo(HashCodeModel.GetSHA256Hash("FeurFeur")));
Note user1Note = user1.NoteList[0];
Tags user1Tag = user1.TagList[0];
Assert.That(user1Note.Name, Is.EqualTo("Note 0"));
Assert.That(user1Note.LogoPath, Is.EqualTo("DefaultLogo.png"));
Assert.That(user1Tag.Name, Is.EqualTo("Tag 0"));
Assert.That(user1Tag.Color, Is.EqualTo("#5555FF"));
}
[Test]
public void LoadDefaultTheme_Test()
{
result = manager.GetOnlyDatabaseDefaultTheme();
Assert.NotNull(result);
Assert.That(result.ThemeList.Count, Is.EqualTo(2));
Theme theme1 = result.ThemeList[0];
Assert.That(theme1.Name, Is.EqualTo("blacktheme"));
Assert.That(theme1.ColorList[0], Is.EqualTo("#000000"));
Assert.That(theme1.ColorList[1], Is.EqualTo("#FF00FF"));
Assert.That(theme1.ColorList[2], Is.EqualTo("#OOFFOO"));
}
[Test]
public void LoadDefaultLogo_Test()
{
result = manager.GetOnlyDatabaseDefaultLogo();
Assert.NotNull(result);
Assert.That(result.DefaultLogoList.Count, Is.EqualTo(3));
Logo logo1 = result.DefaultLogoList[0];
Assert.That(logo1.Name, Is.EqualTo("default"));
Assert.That(logo1.LogoLink, Is.EqualTo("DefaultLogo.png"));
}
}
}

@ -19,6 +19,7 @@
<ItemGroup>
<ProjectReference Include="..\..\Biblioteque_de_Class\Biblioteque_de_Class.csproj" />
<ProjectReference Include="..\..\Notus_Persistence\Notus_Persistance.csproj" />
</ItemGroup>
</Project>

@ -18,11 +18,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_Console", "Notus_Cons
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_Persistance", "Notus_Persistence\Notus_Persistance.csproj", "{184478A9-E14F-42E0-B963-B3A4474C9C1C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_UnitTest_Database", "Tests\Notus_UnitTest_Database\Notus_UnitTest_Database.csproj", "{EE443C17-B31D-4AD0-9141-920876E7DF79}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests_Model", "Tests\UnitTests_Model\UnitTests_Model.csproj", "{CB4664CE-F451-401D-862F-4A74A80B8161}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_UnitTest_Note", "Tests\Notus_UnitTest_Note\Notus_UnitTest_Note.csproj", "{7B7F1062-9498-44E5-AC77-84BC90A3B730}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_UnitTest_User", "Tests\Notus_UnitTest_User\Notus_UnitTest_User.csproj", "{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests_Persistance", "Tests\UnitTests_Persistance\UnitTests_Persistance.csproj", "{E2BCA278-8741-4116-B0E0-B20849D66739}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -48,18 +46,14 @@ Global
{184478A9-E14F-42E0-B963-B3A4474C9C1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.Build.0 = Release|Any CPU
{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
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Release|Any CPU.Build.0 = Release|Any CPU
{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}.Release|Any CPU.Build.0 = Release|Any CPU
{CB4664CE-F451-401D-862F-4A74A80B8161}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB4664CE-F451-401D-862F-4A74A80B8161}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB4664CE-F451-401D-862F-4A74A80B8161}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB4664CE-F451-401D-862F-4A74A80B8161}.Release|Any CPU.Build.0 = Release|Any CPU
{E2BCA278-8741-4116-B0E0-B20849D66739}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2BCA278-8741-4116-B0E0-B20849D66739}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2BCA278-8741-4116-B0E0-B20849D66739}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2BCA278-8741-4116-B0E0-B20849D66739}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -3,17 +3,21 @@ 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}"
ProjectSection(ProjectDependencies) = postProject
{184478A9-E14F-42E0-B963-B3A4474C9C1C} = {184478A9-E14F-42E0-B963-B3A4474C9C1C}
{92DD50C5-EEAD-44ED-AEFF-E21935725477} = {92DD50C5-EEAD-44ED-AEFF-E21935725477}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Biblioteque_de_Class", "Biblioteque_de_Class\Biblioteque_de_Class.csproj", "{92DD50C5-EEAD-44ED-AEFF-E21935725477}"
EndProject
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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_UnitTest_Database", "Tests\Notus_UnitTest_Database\Notus_UnitTest_Database.csproj", "{EE443C17-B31D-4AD0-9141-920876E7DF79}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest_Note", "Tests\Notus_UnitTest_Note\Notus_UnitTest_Note.csproj", "{7B7F1062-9498-44E5-AC77-84BC90A3B730}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests_Model", "Tests\UnitTests_Model\UnitTests_Model.csproj", "{CB4664CE-F451-401D-862F-4A74A80B8161}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest_User", "Tests\Notus_UnitTest_User\Notus_UnitTest_User.csproj", "{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests_Persistance", "Tests\UnitTests_Persistance\UnitTests_Persistance.csproj", "{E2BCA278-8741-4116-B0E0-B20849D66739}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -33,18 +37,14 @@ Global
{184478A9-E14F-42E0-B963-B3A4474C9C1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.Build.0 = Release|Any CPU
{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
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Release|Any CPU.Build.0 = Release|Any CPU
{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}.Release|Any CPU.Build.0 = Release|Any CPU
{CB4664CE-F451-401D-862F-4A74A80B8161}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB4664CE-F451-401D-862F-4A74A80B8161}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB4664CE-F451-401D-862F-4A74A80B8161}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB4664CE-F451-401D-862F-4A74A80B8161}.Release|Any CPU.Build.0 = Release|Any CPU
{E2BCA278-8741-4116-B0E0-B20849D66739}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E2BCA278-8741-4116-B0E0-B20849D66739}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E2BCA278-8741-4116-B0E0-B20849D66739}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E2BCA278-8741-4116-B0E0-B20849D66739}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save