fix all tests and ADD missing UnitTest
continuous-integration/drone/push Build is passing Details

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

@ -24,6 +24,18 @@ namespace Biblioteque_de_Class
{
}
}
public class UserNotOwnerException : 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)
@ -36,4 +48,10 @@ namespace Biblioteque_de_Class
{
}
}
public class NoteImageNotFoundException : Exception
{
public NoteImageNotFoundException(string message) : base(message)
{
}
}
}

@ -84,7 +84,7 @@ namespace Biblioteque_de_Class
return;
}
}
throw new NullReferenceException("Image not found");
throw new NoteImageNotFoundException("Image not found");
}
/// <summary>
@ -92,14 +92,7 @@ namespace Biblioteque_de_Class
/// </summary>
public bool VerifyPrivilege(User user)
{
if (Editors.Contains(user))
{
return true;
}
else
{
throw new NullReferenceException("User is not an editor");
}
return Editors.Contains(user);
}
/// <summary>
@ -108,7 +101,7 @@ namespace Biblioteque_de_Class
public void AddCollaborator(User owner, User user)
{
if (VerifyOwner(owner)) { Collaborators.Add(user); }
else { throw new NullReferenceException("User is not the owner"); }
else { throw new UserNotOwnerException("User is not the owner"); }
}
/// <summary>
@ -117,7 +110,7 @@ namespace Biblioteque_de_Class
public void RemoveCollaborator(User owner, User user)
{
if (VerifyOwner(owner)) { Collaborators.Remove(user); }
else { throw new NullReferenceException("User is not the owner"); }
else { throw new UserNotOwnerException("User is not the owner"); }
}
/// <summary>
@ -126,7 +119,7 @@ namespace Biblioteque_de_Class
public void AddEditor(User owner, User user)
{
if (VerifyOwner(owner)) { Editors.Add(user); }
else { throw new NullReferenceException("User is not the owner"); }
else { throw new UserNotOwnerException("User is not the owner"); }
}
/// <summary>
@ -135,7 +128,7 @@ namespace Biblioteque_de_Class
public void RemoveEditor(User owner, User user)
{
if (VerifyOwner(owner)) { Editors.Remove(user); }
else { throw new NullReferenceException("User is not the owner"); }
else { throw new UserNotOwnerException("User is not the owner"); }
}
}
}

@ -33,7 +33,7 @@ namespace Notus_UnitTest_Database
List<string> listcolor = new();
Theme theme = new Theme("ocean", listcolor);
database.AddTheme(theme);
Assert.Throws<Exception>(() => database.AddTheme(theme), "Theme already used.");
Assert.Throws<ThemeAlreadyUsedException>(() => 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<Exception>(() => database.AddUser(newUser), "Username already used.");
Assert.Throws<UserAlreadyUsedException>(() => 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<Exception>(() => database.AddUser(newUser), "Email already used.");
Assert.Throws<UserAlreadyUsedException>(() => database.AddUser(newUser), "Email already used.");
}
}
}

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

@ -30,7 +30,7 @@ namespace Notus_UnitTest_Database
[Test]
public void GetTheme_NonExistingTheme_ThrowsException()
{
Assert.Throws<NullReferenceException>(() => database.GetTheme("NonExistingTheme"), "No theme found with this name.");
Assert.Throws<ThemeNotFoundException>(() => 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<NullReferenceException>(() => database.GetUser(userName));
Assert.Throws<UserAlreadyUsedException>(() => 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<NullReferenceException>(() => database.ModifyThemeColorList(theme, newColorList), "Theme not found.");
Assert.Throws<ThemeNotFoundException>(() => database.ModifyThemeColorList(theme, newColorList), "Theme not found.");
}
}
}

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Notus_UnitTest_Database
{
/*public class ModifyThemeNameTests
public class ModifyThemeNameTests
{
private Database database;
@ -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<Exception>(() => database.ModifyThemeName(theme, newName), "Theme not found.");
Assert.Throws<ThemeNotFoundException>(() => database.ModifyThemeName(theme, newName), "Theme not found.");
}
}*/
}
}

@ -0,0 +1,38 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Database
{
public class 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<ThemeNotFoundException>(() => 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<NullReferenceException>(() => database.RemoveUser(user), "User not found.");
Assert.Throws<UserNotFoundException>(() => 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<Exception>(() => note.AddCollaborator(user, collaborator));
Assert.Throws<UserNotOwnerException>(() => 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<Exception>(() => note.AddEditor(user, editor));
Assert.Throws<UserNotOwnerException>(() => note.AddEditor(user, editor));
}
}

@ -18,7 +18,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Biblioteque_de_Class\Biblioteque_de_Class.csproj" />
<ProjectReference Include="..\..\Biblioteque_de_Class\Biblioteque_de_Class.csproj" />
</ItemGroup>
</Project>

@ -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<Exception>(() => note.RemoveCollaborator(user, collaborator));
Assert.Throws<UserNotOwnerException>(() => 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<Exception>(() => note.RemoveEditor(user, editor));
Assert.Throws<UserNotOwnerException>(() => 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<Exception>(() => note.RemoveImage(1));
Assert.Throws<NoteImageNotFoundException>(() => note.RemoveImage(1));
}
}
}

@ -23,9 +23,10 @@ namespace Notus_UnitTest_Note
[Test]
public void VerifyPrivilege_WhenUserIsNotEditor_ThrowsException()
{
User user = new User("User1", "user1@example.com", "password");
User editor = new User("Editor1", "editor1@example.com", "password");
Note note = new Note("Test Note", "logo.png", new User("Owner", "owner@example.com", "password"));
Assert.Throws<Exception>(() => note.VerifyPrivilege(user));
bool result = note.VerifyPrivilege(editor);
Assert.IsFalse(result);
}
}
}

Loading…
Cancel
Save