fix unit test note

pull/19/head
Matheo THIERRY 2 years ago
parent b16da74e57
commit cfaf17f08a

@ -78,15 +78,13 @@ namespace Biblioteque_de_Class
{ {
foreach (NoteImage image in ImageList) foreach (NoteImage image in ImageList)
{ {
if (image.GetName().Equals(name)) if (image.GetName() == name)
{ {
ImageList.Remove(image); ImageList.Remove(image);
} return;
else
{
throw new Exception("Image not found");
} }
} }
throw new Exception("Image not found");
} }
/// <summary> /// <summary>

@ -16,7 +16,6 @@ string nom = "u";
string choixNom; string choixNom;
string choixCouleur; string choixCouleur;
string choixModif; string choixModif;
string _image = "u";
string choix; string choix;
string newColor = "u"; string newColor = "u";
string color = "u"; string color = "u";
@ -180,11 +179,11 @@ while (boucle == 0)
break; break;
case "10":///Ajouter une image case "10":///Ajouter une image
n.AddImage(_image, position); n.AddImage(linkimage, position);
break; break;
case "11":///Supprimer une image case "11":///Supprimer une image
n.RemoveImage(_image); n.RemoveImage(nomImage);
break; break;
case "12":///Deplacer une image case "12":///Deplacer une image

@ -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;
namespace Notus_UnitTest_User
{
[TestFixture]
public class SearchNoteByNameTests
{
[Test]
public void SearchNoteByName_WhenMatchingNotesExist_NotesReturned()
{
User user = new User("TestUser", "testuser@example.com", "password");
Note note1 = new Note("Note 1", "image1.png", user);
Note note2 = new Note("Note 2", "image2.png", user);
Note note3 = new Note("Another Note", "image3.png", user);
user.GetNoteList().Add(note1);
user.GetNoteList().Add(note2);
user.GetNoteList().Add(note3);
List<Note> result = user.SearchNoteByName("note");
Assert.That(result.Count, Is.EqualTo(3));
CollectionAssert.Contains(result, note1);
CollectionAssert.Contains(result, note2);
CollectionAssert.Contains(result, note3);
}
[Test]
public void SearchNoteByName_WhenNoMatchingNotesExist_EmptyListReturned()
{
User user = new User("TestUser", "testuser@example.com", "password");
Note note1 = new Note("Note 1", "image1.png", user);
Note note2 = new Note("Note 2", "image2.png", user);
user.GetNoteList().Add(note1);
user.GetNoteList().Add(note2);
List<Note> result = user.SearchNoteByName("test");
Assert.IsEmpty(result);
}
}
}

@ -7,30 +7,27 @@ using System.Threading.Tasks;
namespace Notus_UnitTest_Note namespace Notus_UnitTest_Note
{ {
[TestFixture]
public class AddCollaboratorTests public class AddCollaboratorTests
{ {
[TestFixture] [Test]
public class NoteTests public void AddCollaborator_WhenUserIsOwner_CollaboratorAdded()
{ {
[Test] User owner = new User("Owner", "owner@example.com", "password");
public void AddCollaborator_WhenUserIsOwner_CollaboratorAdded() User collaborator = new User("Collaborator1", "collaborator1@example.com", "password");
{ Note note = new Note("Test Note", "logo.png", owner);
User owner = new User("Owner", "owner@example.com", "password"); note.AddCollaborator(owner, collaborator);
User collaborator = new User("Collaborator1", "collaborator1@example.com", "password"); Assert.Contains(collaborator, note.GetCollaborators());
Note note = new Note("Test Note", "logo.png", owner); }
note.AddCollaborator(owner, collaborator);
Assert.Contains(collaborator, note.GetCollaborators());
}
[Test] [Test]
public void AddCollaborator_WhenUserIsNotOwner_ThrowsException() public void AddCollaborator_WhenUserIsNotOwner_ThrowsException()
{ {
User owner = new User("Owner", "owner@example.com", "password"); User owner = new User("Owner", "owner@example.com", "password");
User collaborator = new User("Collaborator1", "collaborator1@example.com", "password"); User collaborator = new User("Collaborator1", "collaborator1@example.com", "password");
User user = new User("User1", "user1@example.com", "password"); User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner); Note note = new Note("Test Note", "logo.png", owner);
Assert.Throws<Exception>(() => note.AddCollaborator(user, collaborator)); Assert.Throws<Exception>(() => note.AddCollaborator(user, collaborator));
}
} }
} }
} }

@ -7,30 +7,28 @@ using System.Threading.Tasks;
namespace Notus_UnitTest_Note namespace Notus_UnitTest_Note
{ {
[TestFixture]
public class AddEditorTests public class AddEditorTests
{ {
[TestFixture] [Test]
public class NoteTests public void AddEditor_WhenUserIsOwner_EditorAdded()
{ {
[Test] User owner = new User("Owner", "owner@example.com", "password");
public void AddEditor_WhenUserIsOwner_EditorAdded() User editor = new User("Editor1", "editor1@example.com", "password");
{ Note note = new Note("Test Note", "logo.png", owner);
User owner = new User("Owner", "owner@example.com", "password"); note.AddEditor(owner, editor);
User editor = new User("Editor1", "editor1@example.com", "password"); Assert.IsTrue(note.GetEditors().Contains(editor));
Note note = new Note("Test Note", "logo.png", owner); }
note.AddEditor(owner, editor);
Assert.IsTrue(note.GetEditors().Contains(editor));
}
[Test] [Test]
public void AddEditor_WhenUserIsNotOwner_ThrowsException() public void AddEditor_WhenUserIsNotOwner_ThrowsException()
{ {
User owner = new User("Owner", "owner@example.com", "password"); User owner = new User("Owner", "owner@example.com", "password");
User editor = new User("Editor1", "editor1@example.com", "password"); User editor = new User("Editor1", "editor1@example.com", "password");
User user = new User("User1", "user1@example.com", "password"); User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner); Note note = new Note("Test Note", "logo.png", owner);
Assert.Throws<Exception>(() => note.AddEditor(user, editor)); Assert.Throws<Exception>(() => note.AddEditor(user, editor));
}
} }
} }
} }

@ -7,32 +7,30 @@ using System.Threading.Tasks;
namespace Notus_UnitTest_Note namespace Notus_UnitTest_Note
{ {
public class vsdbjksbvd_v [TestFixture]
public class RemoveCollaboratorTests
{ {
[TestFixture] [Test]
public class NoteTests public void RemoveCollaborator_WhenUserIsOwner_CollaboratorRemoved()
{ {
[Test] User owner = new User("Owner", "owner@example.com", "password");
public void RemoveCollaborator_WhenUserIsOwner_CollaboratorRemoved() User collaborator = new User("Collaborator1", "collaborator1@example.com", "password");
{ Note note = new Note("Test Note", "logo.png", owner);
User owner = new User("Owner", "owner@example.com", "password"); note.AddCollaborator(owner, collaborator);
User collaborator = new User("Collaborator1", "collaborator1@example.com", "password"); note.RemoveCollaborator(owner, collaborator);
Note note = new Note("Test Note", "logo.png", owner); Assert.IsFalse(note.GetCollaborators().Contains(collaborator));
note.AddCollaborator(owner, collaborator); }
note.RemoveCollaborator(owner, collaborator);
Assert.IsFalse(note.GetCollaborators().Contains(collaborator));
}
[Test] [Test]
public void RemoveCollaborator_WhenUserIsNotOwner_ThrowsException() public void RemoveCollaborator_WhenUserIsNotOwner_ThrowsException()
{ {
User owner = new User("Owner", "owner@example.com", "password"); User owner = new User("Owner", "owner@example.com", "password");
User collaborator = new User("Collaborator1", "collaborator1@example.com", "password"); User collaborator = new User("Collaborator1", "collaborator1@example.com", "password");
User user = new User("User1", "user1@example.com", "password"); User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner); Note note = new Note("Test Note", "logo.png", owner);
note.AddCollaborator(owner, collaborator); note.AddCollaborator(owner, collaborator);
Assert.Throws<Exception>(() => note.RemoveCollaborator(user, collaborator)); Assert.Throws<Exception>(() => note.RemoveCollaborator(user, collaborator));
}
} }
} }
} }

@ -7,32 +7,30 @@ using System.Threading.Tasks;
namespace Notus_UnitTest_Note namespace Notus_UnitTest_Note
{ {
[TestFixture]
public class RemoveEditorTests public class RemoveEditorTests
{ {
[TestFixture] [Test]
public class NoteTests public void RemoveEditor_WhenUserIsOwner_EditorRemoved()
{ {
[Test] User owner = new User("Owner", "owner@example.com", "password");
public void RemoveEditor_WhenUserIsOwner_EditorRemoved() User editor = new User("Editor1", "editor1@example.com", "password");
{ Note note = new Note("Test Note", "logo.png", owner);
User owner = new User("Owner", "owner@example.com", "password"); note.AddEditor(owner, editor);
User editor = new User("Editor1", "editor1@example.com", "password"); note.RemoveEditor(owner, editor);
Note note = new Note("Test Note", "logo.png", owner); Assert.IsFalse(note.GetEditors().Contains(editor));
note.AddEditor(owner, editor); }
note.RemoveEditor(owner, editor);
Assert.IsFalse(note.GetEditors().Contains(editor));
}
[Test] [Test]
public void RemoveEditor_WhenUserIsNotOwner_ThrowsException() public void RemoveEditor_WhenUserIsNotOwner_ThrowsException()
{ {
User owner = new User("Owner", "owner@example.com", "password"); User owner = new User("Owner", "owner@example.com", "password");
User editor = new User("Editor1", "editor1@example.com", "password"); User editor = new User("Editor1", "editor1@example.com", "password");
User user = new User("User1", "user1@example.com", "password"); User user = new User("User1", "user1@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner); Note note = new Note("Test Note", "logo.png", owner);
note.AddEditor(owner, editor); note.AddEditor(owner, editor);
Assert.Throws<Exception>(() => note.RemoveEditor(user, editor)); Assert.Throws<Exception>(() => note.RemoveEditor(user, editor));
}
} }
} }
} }

@ -15,8 +15,7 @@ namespace Notus_UnitTest_Note
{ {
User owner = new User("Owner", "owner@example.com", "password"); User owner = new User("Owner", "owner@example.com", "password");
Note note = new Note("Test Note", "logo.png", owner); Note note = new Note("Test Note", "logo.png", owner);
NoteImage image = new NoteImage(1, "image.png", "top"); note.AddImage("image.png", "top");
note.GetImageList().Add(image);
note.RemoveImage(1); note.RemoveImage(1);
Assert.That(note.GetImageList().Count, Is.EqualTo(0)); Assert.That(note.GetImageList().Count, Is.EqualTo(0));
} }

@ -16,15 +16,10 @@ namespace Notus_UnitTest_Note
[Test] [Test]
public void VerifyOwner_UserIsNotOwner_ReturnsFalse() public void VerifyOwner_UserIsNotOwner_ReturnsFalse()
{ {
// Arrange
User owner = new User("John", "john@example.com", "choco"); User owner = new User("John", "john@example.com", "choco");
User anotherUser = new User("Jane", "jane@example.com", "choco"); User anotherUser = new User("Jane", "jane@example.com", "choco");
Note note = new Note("My Note", "path/to/logo.png", owner); Note note = new Note("My Note", "path/to/logo.png", owner);
// Act
bool isOwner = note.VerifyOwner(anotherUser); bool isOwner = note.VerifyOwner(anotherUser);
// Assert
Assert.IsFalse(isOwner); Assert.IsFalse(isOwner);
} }
} }

@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_UnitTest_Database", "
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest_Note", "Notus_UnitTest_Logo\Notus_UnitTest_Note.csproj", "{7B7F1062-9498-44E5-AC77-84BC90A3B730}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest_Note", "Notus_UnitTest_Logo\Notus_UnitTest_Note.csproj", "{7B7F1062-9498-44E5-AC77-84BC90A3B730}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest_User", "Notus_UnitTest\Notus_UnitTest_User\Notus_UnitTest_User.csproj", "{AFCEAA99-3A25-4E9E-B498-72DD76A6B7FF}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -47,6 +49,10 @@ Global
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Debug|Any CPU.Build.0 = 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.ActiveCfg = Release|Any CPU
{7B7F1062-9498-44E5-AC77-84BC90A3B730}.Release|Any CPU.Build.0 = 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
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save