UnitTest to Note (bugs not removed yet)

pull/19/head
Matheo THIERRY 2 years ago
parent a68a1e8812
commit 2b3b0dba3a

@ -67,21 +67,26 @@ namespace Biblioteque_de_Class
}
public void AddImage(string imageLink, string position)
{
int newname = ImageList.Count() + 1;
ImageList.Add(new NoteImage(newname, imageLink, position));
}
public void RemoveImage(int name)
{
foreach (NoteImage image in ImageList)
{
if (image.GetImageLink() == imageLink)
if (image.GetName().Equals(name))
{
ImageList.Remove(image);
}
else
{
/// Do something
throw new Exception("Image not found");
}
}
}
public void RemoveImage(string image)
{
/// Need a new data structure to store images
}
/// <summary>
/// vérifier si l'utilisateur est un éditeur de la note
/// </summary>

@ -8,22 +8,22 @@ namespace Biblioteque_de_Class
{
public class NoteImage
{
private string Name { get; set; }
private int Name { get; set; }
private string ImageLink { get; set; }
private string Position { get; set; }
public NoteImage(string name, string imageLink, string position)
public NoteImage(int name, string imageLink, string position)
{
Name = name;
ImageLink = imageLink;
Position = position;
}
public string GetName() { return Name; }
public int GetName() { return Name; }
public string GetImageLink() { return ImageLink; }
public string GetPosition() { return Position; }
public void SetName(string name) { Name = name; }
public void SetName(int name) { Name = name; }
public void SetImageLink(string imageLink) { ImageLink = imageLink; }
public void SetPosition(string position) { Position = position; }

@ -5,7 +5,7 @@ using System.Diagnostics;
string Upseudo = "u";
string Umail = "u";
string Upassword = "u";
string nomImag = "u";
int nomImage = 1;
string linkimage = "u";
string position = "u";
string nomNote = "u";

@ -0,0 +1,36 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
public class AddCollaboratorTests
{
[TestFixture]
public class NoteTests
{
[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<Exception>(() => note.AddCollaborator(user, collaborator));
}
}
}
}

@ -0,0 +1,36 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
public class AddEditorTests
{
[TestFixture]
public class NoteTests
{
[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<Exception>(() => note.AddEditor(user, editor));
}
}
}
}

@ -0,0 +1,23 @@
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));
}
}
}

@ -0,0 +1,24 @@
<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>

@ -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_Note
{
public class vsdbjksbvd_v
{
[TestFixture]
public class NoteTests
{
[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<Exception>(() => note.RemoveCollaborator(user, collaborator));
}
}
}
}

@ -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_Note
{
public class RemoveEditorTests
{
[TestFixture]
public class NoteTests
{
[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<Exception>(() => note.RemoveEditor(user, editor));
}
}
}
}

@ -0,0 +1,32 @@
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);
NoteImage image = new NoteImage(1, "image.png", "top");
note.GetImageList().Add(image);
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<Exception>(() => note.RemoveImage(1));
}
}
}

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

@ -0,0 +1,31 @@
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()
{
// Arrange
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);
// Act
bool isOwner = note.VerifyOwner(anotherUser);
// Assert
Assert.IsFalse(isOwner);
}
}
}

@ -0,0 +1,31 @@
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 user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", new User("Owner", "owner@example.com", "password"));
Assert.Throws<Exception>(() => note.VerifyPrivilege(user));
}
}
}

@ -18,19 +18,23 @@ namespace Notus_UnitTest_Database
}
[Test]
public void GetTheme_ExistingTheme_ReturnsTheme()
public void ModifyThemeName_ExistingTheme_ModifiesName()
{
List<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
database.GetThemeList().Add(theme);
Theme retrievedTheme = database.GetTheme("Dark");
Assert.That(retrievedTheme, Is.EqualTo(theme));
string newName = "Light";
database.ModifyThemeName(theme, newName);
Assert.That(theme.GetName(), Is.EqualTo(newName));
}
[Test]
public void GetTheme_NonExistingTheme_ThrowsException()
public void ModifyThemeName_NonExistingTheme_ThrowsException()
{
Assert.Throws<Exception>(() => database.GetTheme("NonExistingTheme"), "No theme found with this name.");
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.");
}
}
}

@ -11,7 +11,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("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest_Database", "Tests\Notus_UnitTest_Database\Notus_UnitTest_Database.csproj", "{EE443C17-B31D-4AD0-9141-920876E7DF79}"
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", "Notus_UnitTest_Logo\Notus_UnitTest_Note.csproj", "{7B7F1062-9498-44E5-AC77-84BC90A3B730}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -41,6 +43,10 @@ Global
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save