optimisation
continuous-integration/drone/push Build is passing Details

pull/19/head
Matheo THIERRY 2 years ago
parent 96c7a0c679
commit d3b0e7b0a6

@ -53,7 +53,7 @@ namespace Biblioteque_de_Class
{
if (logo.GetName() == name) { return logo.GetLogoLink(); }
}
throw new LogoNotFoundException("No logo link found.");
throw new NotFoundException("No logo link found.");
}
/// <summary>
@ -68,7 +68,7 @@ namespace Biblioteque_de_Class
return user;
}
}
throw new UserAlreadyUsedException("No user found with this username.");
throw new AlreadyUsedException("No user found with this username.");
}
/// <summary>
@ -103,11 +103,11 @@ namespace Biblioteque_de_Class
{
if (existingUser.GetUsername() == user.GetUsername())
{
throw new UserAlreadyUsedException("Username already used.");
throw new AlreadyUsedException("Username already used.");
}
else if (existingUser.GetEmail() == user.GetEmail())
{
throw new UserAlreadyUsedException("Email already used.");
throw new AlreadyUsedException("Email already used.");
}
}
UserList.Add(user);
@ -124,7 +124,7 @@ namespace Biblioteque_de_Class
}
else
{
throw new UserNotFoundException("User not found.");
throw new NotFoundException("User not found.");
}
}
@ -137,7 +137,7 @@ namespace Biblioteque_de_Class
{
if (existingTheme.GetName() == theme.GetName())
{
throw new ThemeAlreadyUsedException("Theme already used.");
throw new AlreadyUsedException("Theme already used.");
}
}
ThemeList.Add(theme);
@ -154,7 +154,7 @@ namespace Biblioteque_de_Class
}
else
{
throw new ThemeNotFoundException("Theme not found.");
throw new NotFoundException("Theme not found.");
}
}
@ -170,7 +170,7 @@ namespace Biblioteque_de_Class
return theme;
}
}
throw new ThemeNotFoundException("No theme found with this name.");
throw new NotFoundException("No theme found with this name.");
}
/// <summary>
@ -186,7 +186,7 @@ namespace Biblioteque_de_Class
return;
}
}
throw new ThemeNotFoundException("Theme not found.");
throw new NotFoundException("Theme not found.");
}
/// <summary>
@ -205,7 +205,7 @@ namespace Biblioteque_de_Class
return;
}
}
throw new ThemeNotFoundException("Theme not found.");
throw new NotFoundException("Theme not found.");
}
}
}

@ -6,51 +6,27 @@ using System.Threading.Tasks;
namespace Biblioteque_de_Class
{
public class LogoNotFoundException : Exception
public class NotAllowedException : Exception
{
public LogoNotFoundException(string message) : base(message)
public NotAllowedException(string message) : base(message)
{
}
}
public class UserNotFoundException : Exception
public class AlreadyUsedException : Exception
{
public UserNotFoundException(string message) : base(message)
public AlreadyUsedException(string message) : base(message)
{
}
}
public class UserAlreadyUsedException : Exception
public class NotFoundException : Exception
{
public UserAlreadyUsedException(string message) : base(message)
public NotFoundException(string message) : base(message)
{
}
}
public class UserNotOwnerException : Exception
public class AlreadyExistException : Exception
{
public UserNotOwnerException(string message) : base(message)
{
}
}
public class UserNotEditorException : Exception
{
public UserNotEditorException(string message) : base(message)
{
}
}
public class ThemeNotFoundException : Exception
{
public ThemeNotFoundException(string message) : base(message)
{
}
}
public class ThemeAlreadyUsedException : Exception
{
public ThemeAlreadyUsedException(string message) : base(message)
{
}
}
public class NoteImageNotFoundException : Exception
{
public NoteImageNotFoundException(string message) : base(message)
public AlreadyExistException(string message) : base(message)
{
}
}

@ -84,7 +84,7 @@ namespace Biblioteque_de_Class
return;
}
}
throw new NoteImageNotFoundException("Image not found");
throw new NotFoundException("Image not found");
}
/// <summary>
@ -101,7 +101,7 @@ namespace Biblioteque_de_Class
public void AddCollaborator(User owner, User user)
{
if (VerifyOwner(owner)) { Collaborators.Add(user); }
else { throw new UserNotOwnerException("User is not the owner"); }
else { throw new NotAllowedException("User is not the owner"); }
}
/// <summary>
@ -110,7 +110,7 @@ namespace Biblioteque_de_Class
public void RemoveCollaborator(User owner, User user)
{
if (VerifyOwner(owner)) { Collaborators.Remove(user); }
else { throw new UserNotOwnerException("User is not the owner"); }
else { throw new NotAllowedException("User is not the owner"); }
}
/// <summary>
@ -119,7 +119,7 @@ namespace Biblioteque_de_Class
public void AddEditor(User owner, User user)
{
if (VerifyOwner(owner)) { Editors.Add(user); }
else { throw new UserNotOwnerException("User is not the owner"); }
else { throw new NotAllowedException("User is not the owner"); }
}
/// <summary>
@ -128,7 +128,7 @@ namespace Biblioteque_de_Class
public void RemoveEditor(User owner, User user)
{
if (VerifyOwner(owner)) { Editors.Remove(user); }
else { throw new UserNotOwnerException("User is not the owner"); }
else { throw new NotAllowedException("User is not the owner"); }
}
}
}

@ -110,7 +110,7 @@ namespace Biblioteque_de_Class
{
if (FavList.Contains(note))
{
throw new Exception("Note already in favorites");
throw new AlreadyExistException("Note already in favorites");
}
FavList.Add(note);
}
@ -126,7 +126,7 @@ namespace Biblioteque_de_Class
}
else
{
throw new NullReferenceException("Note not found");
throw new NotFoundException("Note not found");
}
}
@ -139,7 +139,7 @@ namespace Biblioteque_de_Class
{
if (existingNote.GetName() == name)
{
throw new Exception("Note already exists");
throw new AlreadyExistException("Note already exists");
}
}
Note note = new Note(name, imagePath, this);
@ -159,7 +159,7 @@ namespace Biblioteque_de_Class
}
else
{
throw new NullReferenceException("Note not found");
throw new NotFoundException("Note not found");
}
}
@ -172,7 +172,7 @@ namespace Biblioteque_de_Class
{
if (tag.GetName() == name)
{
throw new Exception("Tag already exists");
throw new AlreadyExistException("Tag already exists");
}
}
TagList.Add(new Tags(name, color));
@ -200,11 +200,11 @@ namespace Biblioteque_de_Class
{
if (!TagList.Contains(tagToAdd))
{
throw new Exception("Tag not found");
throw new NotFoundException("Tag not found");
}
if (!NoteList.Contains(note))
{
throw new Exception("Note not found");
throw new NotFoundException("Note not found");
}
NoteTagged[note].Add(tagToAdd);
}
@ -216,11 +216,11 @@ namespace Biblioteque_de_Class
{
if (!TagList.Contains(tagToRemove))
{
throw new Exception("Tag not found");
throw new NotFoundException("Tag not found");
}
if (!NoteList.Contains(note))
{
throw new Exception("Note not found");
throw new NotFoundException("Note not found");
}
NoteTagged[note].Remove(tagToRemove);
}

@ -33,7 +33,7 @@ namespace Notus_UnitTest_Database
List<string> listcolor = new();
Theme theme = new Theme("ocean", listcolor);
database.AddTheme(theme);
Assert.Throws<ThemeAlreadyUsedException>(() => database.AddTheme(theme), "Theme already used.");
Assert.Throws<AlreadyUsedException>(() => database.AddTheme(theme), "Theme already used.");
}
}
}

@ -34,7 +34,7 @@ namespace Notus_UnitTest_Database
database.GetUserList().Add(existingUser);
User newUser = new User("John1", "rien", "choco");
newUser.SetEmail("Jane@example.com");
Assert.Throws<UserAlreadyUsedException>(() => database.AddUser(newUser), "Username already used.");
Assert.Throws<AlreadyUsedException>(() => database.AddUser(newUser), "Username already used.");
}
[Test]
@ -45,7 +45,7 @@ namespace Notus_UnitTest_Database
database.GetUserList().Add(existingUser);
User newUser = new User("Jane", "rien", "choco");
newUser.SetEmail("john2@example.com");
Assert.Throws<UserAlreadyUsedException>(() => database.AddUser(newUser), "Email already used.");
Assert.Throws<AlreadyUsedException>(() => database.AddUser(newUser), "Email already used.");
}
}
}

@ -28,7 +28,7 @@ namespace Notus_UnitTest_Database
public void GetLogoLink_LogoDoesNotExist_ThrowsException()
{
string logoName = "Logo4";
Assert.Throws<LogoNotFoundException>(() => database.GetLogoLink(logoName));
Assert.Throws<NotFoundException>(() => database.GetLogoLink(logoName));
}
}
}

@ -30,7 +30,7 @@ namespace Notus_UnitTest_Database
[Test]
public void GetTheme_NonExistingTheme_ThrowsException()
{
Assert.Throws<ThemeNotFoundException>(() => database.GetTheme("NonExistingTheme"), "No theme found with this name.");
Assert.Throws<NotFoundException>(() => database.GetTheme("NonExistingTheme"), "No theme found with this name.");
}
}
}

@ -30,7 +30,7 @@ namespace Notus_UnitTest_Database
public void GetUser_UserDoesNotExist_ThrowsException()
{
string userName = "Eve";
Assert.Throws<UserAlreadyUsedException>(() => database.GetUser(userName));
Assert.Throws<AlreadyUsedException>(() => database.GetUser(userName));
}
}
}

@ -37,7 +37,7 @@ namespace Notus_UnitTest_Database
Theme theme = new Theme("ocean", listcolor);
// no add :)
List<string> newColorList = new List<string> { "Red", "Green", "Blue" };
Assert.Throws<ThemeNotFoundException>(() => database.ModifyThemeColorList(theme, newColorList), "Theme not found.");
Assert.Throws<NotFoundException>(() => database.ModifyThemeColorList(theme, newColorList), "Theme not found.");
}
}
}

@ -34,7 +34,7 @@ namespace Notus_UnitTest_Database
List<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
string newName = "Light";
Assert.Throws<ThemeNotFoundException>(() => database.ModifyThemeName(theme, newName), "Theme not found.");
Assert.Throws<NotFoundException>(() => database.ModifyThemeName(theme, newName), "Theme not found.");
}
}
}

@ -32,7 +32,7 @@ namespace Notus_UnitTest_Database
{
List<string> listcolor = new();
Theme theme = new Theme("ocean", listcolor);
Assert.Throws<ThemeNotFoundException>(() => database.RemoveTheme(theme), "Theme already used.");
Assert.Throws<NotFoundException>(() => database.RemoveTheme(theme), "Theme already used.");
}
}
}

@ -32,7 +32,7 @@ namespace Notus_UnitTest_Database
{
User user = new User("John", "rien", "choco");
user.SetEmail("john@example.com");
Assert.Throws<UserNotFoundException>(() => database.RemoveUser(user), "User not found.");
Assert.Throws<NotFoundException>(() => database.RemoveUser(user), "User not found.");
}
}
}

@ -22,7 +22,7 @@ namespace Notus_UnitTest_Note
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<UserNotOwnerException>(() => note.AddCollaborator(user, collaborator));
Assert.Throws<NotAllowedException>(() => note.AddCollaborator(user, collaborator));
}
}
}

@ -22,7 +22,7 @@ namespace Notus_UnitTest_Note
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<UserNotOwnerException>(() => note.AddEditor(user, editor));
Assert.Throws<NotAllowedException>(() => note.AddEditor(user, editor));
}
}

@ -29,7 +29,7 @@ namespace Notus_UnitTest_Note
User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
note.AddCollaborator(owner, collaborator);
Assert.Throws<UserNotOwnerException>(() => note.RemoveCollaborator(user, collaborator));
Assert.Throws<NotAllowedException>(() => note.RemoveCollaborator(user, collaborator));
}
}

@ -29,7 +29,7 @@ namespace Notus_UnitTest_Note
User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
note.AddEditor(owner, editor);
Assert.Throws<UserNotOwnerException>(() => note.RemoveEditor(user, editor));
Assert.Throws<NotAllowedException>(() => note.RemoveEditor(user, editor));
}
}

@ -25,7 +25,7 @@ namespace Notus_UnitTest_Note
{
User owner = new User("Owner", "owner@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner);
Assert.Throws<NoteImageNotFoundException>(() => note.RemoveImage(1));
Assert.Throws<NotFoundException>(() => note.RemoveImage(1));
}
}
}

Loading…
Cancel
Save