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)
{
if (image.GetName().Equals(name))
if (image.GetName() == name)
{
ImageList.Remove(image);
}
else
{
throw new Exception("Image not found");
return;
}
}
throw new Exception("Image not found");
}
/// <summary>

@ -16,7 +16,6 @@ string nom = "u";
string choixNom;
string choixCouleur;
string choixModif;
string _image = "u";
string choix;
string newColor = "u";
string color = "u";
@ -180,11 +179,11 @@ while (boucle == 0)
break;
case "10":///Ajouter une image
n.AddImage(_image, position);
n.AddImage(linkimage, position);
break;
case "11":///Supprimer une image
n.RemoveImage(_image);
n.RemoveImage(nomImage);
break;
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
{
[TestFixture]
public class AddCollaboratorTests
{
[TestFixture]
public class NoteTests
[Test]
public void AddCollaborator_WhenUserIsOwner_CollaboratorAdded()
{
[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());
}
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));
}
[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));
}
}
}

@ -7,30 +7,28 @@ using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class AddEditorTests
{
[TestFixture]
public class NoteTests
[Test]
public void AddEditor_WhenUserIsOwner_EditorAdded()
{
[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));
}
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));
}
[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));
}
}
}

@ -7,32 +7,30 @@ using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
public class vsdbjksbvd_v
[TestFixture]
public class RemoveCollaboratorTests
{
[TestFixture]
public class NoteTests
[Test]
public void RemoveCollaborator_WhenUserIsOwner_CollaboratorRemoved()
{
[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));
}
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));
}
[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));
}
}
}

@ -7,32 +7,30 @@ using System.Threading.Tasks;
namespace Notus_UnitTest_Note
{
[TestFixture]
public class RemoveEditorTests
{
[TestFixture]
public class NoteTests
[Test]
public void RemoveEditor_WhenUserIsOwner_EditorRemoved()
{
[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));
}
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));
}
[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));
}
}
}

@ -15,8 +15,7 @@ namespace Notus_UnitTest_Note
{
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.AddImage("image.png", "top");
note.RemoveImage(1);
Assert.That(note.GetImageList().Count, Is.EqualTo(0));
}

@ -16,15 +16,10 @@ namespace Notus_UnitTest_Note
[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);
}
}

@ -15,6 +15,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Notus_UnitTest_Database", "
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest_Note", "Notus_UnitTest_Logo\Notus_UnitTest_Note.csproj", "{7B7F1062-9498-44E5-AC77-84BC90A3B730}"
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
GlobalSection(SolutionConfigurationPlatforms) = preSolution
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}.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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save