ADD unitTest for Database and fix class missing methodes

UnitTest
Matheo THIERRY 2 years ago
parent 1e0cb17daf
commit 55a4f3da5c

@ -20,6 +20,9 @@ namespace Biblioteque_de_Class
public string GetName() { return Name; }
public string GetLogoLink() { return LogoLink; }
public void SetName(string name) { Name = name; }
public void SetLogoLink(string logoLink) { LogoLink = logoLink; }
public override string ToString() => $"Logo -> Name: {Name}\nLink: {LogoLink}";
}
}

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Biblioteque_de_Class
{
public class Manager
{
}
}

@ -55,9 +55,9 @@ namespace Biblioteque_de_Class
public override string ToString() => $"Note -> Name: {Name}\nLogoPath: {LogoPath}\nNumber of lines: {TextLineList.Count()}";
public void ModifyName(string name) { Name = name; }
public void ModifyLogoPath(string logoPath) { LogoPath = logoPath; }
public void ModifyModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); }
public void SetName(string name) { Name = name; }
public void SetLogoPath(string logoPath) { LogoPath = logoPath; }
public void SetModificationDate() { ModificationDate = DateOnly.FromDateTime(DateTime.Now); }
/// <summary>
/// vérifier si l'utilisateur est le propriétaire de la note

@ -23,6 +23,10 @@ namespace Biblioteque_de_Class
public string GetImageLink() { return ImageLink; }
public string GetPosition() { return Position; }
public void SetName(string name) { Name = name; }
public void SetImageLink(string imageLink) { ImageLink = imageLink; }
public void SetPosition(string position) { Position = position; }
public override string ToString() => $"image -> name: {Name}\nlink: {ImageLink}";
}
}

@ -19,6 +19,8 @@ namespace Biblioteque_de_Class
public string GetName() { return Name; }
public string GetColor() { return Color; }
public void SetName(string name) { Name = name; }
public void SetColor(string color) { Color = color; }
public override string ToString() => $"tag -> name: {Name}\ncolor: {Color}";
}

@ -45,6 +45,11 @@ namespace Biblioteque_de_Class
public bool GetIsConnected() { return IsConnected; }
public Dictionary<Note, List<Tags>> GetNoteTagged() { return NoteTagged; }
public void SetUsername(string username) { Username = username; }
public void SetEmail(string email) { Email = email; }
public void SetPassword(string password) { Password = password; }
public void SetIsConnected(bool isConnected) { IsConnected = isConnected; }
public override string ToString() => $"username: {Username}\nemail: {Email}\npassword: {Password}\nOwned notes: {NoteList.Count}";
/// <summary>

@ -0,0 +1,18 @@
using Notus_Persistance;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_Console
{
public class Manager
{
PersistenceManager pers { get; set; }
public Manager(PersistenceManager pers)
{
this.pers = pers;
}
}
}

@ -0,0 +1,14 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_Persistance
{
public class Manager : PersistenceManager
{
PersistenceManager pers { get; set; }
}
}

@ -8,7 +8,7 @@ using System.Threading.Tasks;
namespace Notus_Persistance
{
internal class Stub
public class Stub
{
public static void SaveDatabaseData(Database database)
{

@ -0,0 +1,39 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Database
{
public class AddThemeTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
}
[Test]
public void AddTheme_NewTheme_ThemeAddedToList()
{
List<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
database.AddTheme(theme);
CollectionAssert.Contains(database.GetThemeList(), theme);
}
[Test]
public void AddTheme_ExistingTheme_ThrowsException()
{
List<string> listcolor = new();
Theme theme = new Theme("ocean", listcolor);
database.GetThemeList().Add(theme);
Assert.Throws<Exception>(() => database.AddTheme(theme), "Theme already used.");
}
}
}

@ -0,0 +1,51 @@
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 AddUserTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
}
[Test]
public void AddUser_ValidUser_UserAddedToList()
{
User user = new User("John", "rien", "choco") ;
user.SetEmail("john@example.com");
database.AddUser(user);
CollectionAssert.Contains(database.GetUserList(), user);
}
[Test]
public void AddUser_DuplicateUsername_ThrowsException()
{
User existingUser = new User("John1", "rien", "choco");
existingUser.SetEmail("john1@example.com");
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.");
}
[Test]
public void AddUser_DuplicateEmail_ThrowsException()
{
User existingUser = new User("John2", "rien", "choco");
existingUser.SetEmail("john2@example.com");
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.");
}
}
}

@ -0,0 +1,42 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Database
{
[TestFixture]
public class ComparePasswordTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
User user = new User("John","rien","choco");
user.SetPassword("password123");
database.GetUserList().Add(user);
}
[Test]
public void ComparePassword_CorrectPassword_ReturnsTrue()
{
User user = database.GetUserList()[0];
string password = "password123";
bool result = database.ComparePassword(user, password);
Assert.IsTrue(result);
}
[Test]
public void ComparePassword_IncorrectPassword_ReturnsFalse()
{
User user = database.GetUserList()[0];
string password = "incorrectPassword";
bool result = database.ComparePassword(user, password);
Assert.IsFalse(result);
}
}
}

@ -0,0 +1,39 @@
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 FindMailTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
User user = new User("John");
user.SetEmail("john@example.com");
database.GetUserList().Add(user);
}
[Test]
public void FindEmail_ExistingEmail_ReturnsTrue()
{
string email = "john@example.com";
bool result = database.FindEmail(email);
Assert.IsTrue(result);
}
[Test]
public void FindEmail_NonExistingEmail_ReturnsFalse()
{
string email = "jane@example.com";
bool result = database.FindEmail(email);
Assert.IsFalse(result);
}
}
}

@ -3,7 +3,7 @@ using Biblioteque_de_Class;
namespace Notus_UnitTest_Database
{
[TestFixture]
public class GetLogoLinkTests
public class GetLogoLinksTests
{
private Database database;
@ -11,32 +11,24 @@ namespace Notus_UnitTest_Database
public void Setup()
{
database = new Database();
database.GetDefaultLogoList().Add(new Logo("Logo1", "link1"));
database.GetDefaultLogoList().Add(new Logo("Logo2", "link2"));
database.GetDefaultLogoList().Add(new Logo("Logo3", "link3"));
}
// ... Existing tests for other methods ...
// GetLogoLink
[Test]
public void GetLogoLink_ExistingLogoName_ReturnsLogoLink()
public void GetLogoLink_LogoExists_ReturnsLogoLink()
{
// Arrange
Logo logo1 = new Logo("Logo1", "logo1.png");
Logo logo2 = new Logo("Logo2", "logo2.png");
database.GetDefaultLogoList().Add(logo1);
database.GetDefaultLogoList().Add(logo2);
// Act
string result = database.GetLogoLink("Logo1");
// Assert
Assert.AreEqual("logo1.png", result);
string logoName = "Logo2";
string logoLink = database.GetLogoLink(logoName);
Assert.That(logoLink, Is.EqualTo("link2"));
}
[Test]
public void GetLogoLink_NonExistingLogoName_ThrowsException()
public void GetLogoLink_LogoDoesNotExist_ThrowsException()
{
// Act & Assert
Assert.Throws<Exception>(() => database.GetLogoLink("Logo3"));
string logoName = "Logo4";
Assert.Throws<Exception>(() => database.GetLogoLink(logoName));
}
}
}

@ -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_Database
{
public class GetThemeTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
}
[Test]
public void GetTheme_ExistingTheme_ReturnsTheme()
{
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));
}
[Test]
public void GetTheme_NonExistingTheme_ThrowsException()
{
Assert.Throws<Exception>(() => database.GetTheme("NonExistingTheme"), "No theme found with this name.");
}
}
}

@ -0,0 +1,36 @@
using Biblioteque_de_Class;
namespace Notus_UnitTest_Database
{
[TestFixture]
public class GetUserTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
database.GetUserList().Add(new User("John","rien","choco"));
database.GetUserList().Add(new User("Alice", "rien", "choco"));
database.GetUserList().Add(new User("Bob", "rien", "choco"));
}
[Test]
public void GetUser_UserExists_ReturnsUser()
{
string userName = "Alice";
User user = database.GetUser(userName);
Assert.IsNotNull(user);
Assert.That(user.GetUsername(), Is.EqualTo(userName));
}
[Test]
public void GetUser_UserDoesNotExist_ThrowsException()
{
string userName = "Eve";
Assert.Throws<Exception>(() => database.GetUser(userName));
}
}
}

@ -0,0 +1,43 @@
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 ModifyThemeColorListTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
}
[Test]
public void ModifyThemeColorList_ExistingTheme_ModifiesColors()
{
List<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
database.GetThemeList().Add(theme);
List<string> newColorList = new List<string> { "Red", "Green", "Blue" };
database.ModifyThemeColorList(theme, newColorList);
Assert.That(theme.GetColor(0), Is.EqualTo(newColorList[0]));
Assert.That(theme.GetColor(1), Is.EqualTo(newColorList[1]));
Assert.That(theme.GetColor(2), Is.EqualTo(newColorList[2]));
}
[Test]
public void ModifyThemeColorList_NonExistingTheme_ThrowsException()
{
List<string> listcolor = new List<string>() { "Blue", "Dark", "Grey" };
Theme theme = new Theme("ocean", listcolor);
// no add :)
List<string> newColorList = new List<string> { "Red", "Green", "Blue" };
Assert.Throws<Exception>(() => database.ModifyThemeColorList(theme, newColorList), "Theme not found.");
}
}
}

@ -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_Database
{
public class ModifyThemeNameTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
}
[Test]
public void GetTheme_ExistingTheme_ReturnsTheme()
{
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));
}
[Test]
public void GetTheme_NonExistingTheme_ThrowsException()
{
Assert.Throws<Exception>(() => database.GetTheme("NonExistingTheme"), "No theme found with this name.");
}
}
}

@ -17,4 +17,8 @@
<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_Database
{
public class RemoveUserTests
{
private Database database;
[SetUp]
public void Setup()
{
database = new Database();
}
[Test]
public void RemoveUser_ExistingUser_UserRemovedFromList()
{
User user = new User("John","rien","choco");
user.SetEmail("john@example.com");
database.GetUserList().Add(user);
database.RemoveUser(user);
CollectionAssert.DoesNotContain(database.GetUserList(), user);
}
[Test]
public void RemoveUser_NonExistingUser_ThrowsException()
{
User user = new User("John", "rien", "choco");
user.SetEmail("john@example.com");
Assert.Throws<Exception>(() => database.RemoveUser(user), "User not found.");
}
}
}

@ -1,24 +1,16 @@
using Biblioteque_de_Class;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Notus_UnitTest_Database
{
[TestFixture]
public class DatabaseTests
public class SearchUserTests
{
private Database database;
[SetUp]
public void Setup()
{
// Create an instance of the Database class
database = new Database();
// Add some dummy users for testing
database.GetUserList().Add(new User("John", "john@example.com", "choco"));
database.GetUserList().Add(new User("Jane", "jane@example.com", "choco"));
database.GetUserList().Add(new User("Alice", "alice@example.com", "choco"));
@ -27,13 +19,8 @@ namespace Notus_UnitTest_Database
[Test]
public void SearchUser_UserExists_ReturnsMatchingUsers()
{
// Arrange
string searchName = "Jo";
// Act
List<User> searchedUsers = database.SearchUser(searchName);
// Assert
Assert.That(searchedUsers.Count, Is.EqualTo(1));
Assert.That(searchedUsers[0].GetUsername(), Is.EqualTo("John"));
}
@ -41,14 +28,27 @@ namespace Notus_UnitTest_Database
[Test]
public void SearchUser_UserDoesNotExist_ReturnsEmptyList()
{
// Arrange
string searchName = "Bob";
List<User> searchedUsers = database.SearchUser(searchName);
Assert.IsEmpty(searchedUsers);
}
// Act
[Test]
public void SearchUser_CaseInsensitiveSearch_ReturnsMatchingUsers()
{
string searchName = "ALICE";
List<User> searchedUsers = database.SearchUser(searchName);
Assert.That(searchedUsers.Count, Is.EqualTo(1));
Assert.That(searchedUsers[0].GetUsername(), Is.EqualTo("Alice"));
}
// Assert
Assert.IsEmpty(searchedUsers);
[Test]
public void SearchUser_PartialMatch_ReturnsMatchingUsers()
{
string searchName = "ane";
List<User> searchedUsers = database.SearchUser(searchName);
Assert.That(searchedUsers.Count, Is.EqualTo(1));
Assert.That(searchedUsers[0].GetUsername(), Is.EqualTo("Jane"));
}
}
}
}

@ -11,7 +11,7 @@ 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", "Notus_UnitTest\Notus_UnitTest.csproj", "{8DCE500B-E01F-44CA-933E-DDE95111899B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notus_UnitTest_Database", "Tests\Notus_UnitTest_Database\Notus_UnitTest_Database.csproj", "{EE443C17-B31D-4AD0-9141-920876E7DF79}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -37,10 +37,10 @@ Global
{184478A9-E14F-42E0-B963-B3A4474C9C1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{184478A9-E14F-42E0-B963-B3A4474C9C1C}.Release|Any CPU.Build.0 = Release|Any CPU
{8DCE500B-E01F-44CA-933E-DDE95111899B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8DCE500B-E01F-44CA-933E-DDE95111899B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8DCE500B-E01F-44CA-933E-DDE95111899B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8DCE500B-E01F-44CA-933E-DDE95111899B}.Release|Any CPU.Build.0 = Release|Any CPU
{EE443C17-B31D-4AD0-9141-920876E7DF79}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save