diff --git a/Sources/Modèle/Modèle.csproj b/Sources/Modèle/Modèle.csproj
index e0d99d9..59f302d 100644
--- a/Sources/Modèle/Modèle.csproj
+++ b/Sources/Modèle/Modèle.csproj
@@ -6,4 +6,8 @@
enable
+
+
+
+
\ No newline at end of file
diff --git a/Sources/Modèle/User.cs b/Sources/Modèle/User.cs
index 2af4b4d..dd191d1 100644
--- a/Sources/Modèle/User.cs
+++ b/Sources/Modèle/User.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
+using Xunit;
namespace Modèle
{
@@ -22,14 +23,27 @@ namespace Modèle
public User(string pseudo, string nom, string prenom, string mdp)
{
+ if (string.IsNullOrWhiteSpace(pseudo) || string.IsNullOrWhiteSpace(nom) || string.IsNullOrWhiteSpace(prenom) || string.IsNullOrWhiteSpace(mdp))
+ {
+ throw new ArgumentException("Un User doit avoir un pseudo, un nom, un prénom et un mot de passe au minimum !");
+ }
+
+ //Essaye de convertir les paramètres du constructeur (excepté le mot de passe) en int, renvoie true si c'est possible
+ bool isPseudoNumeric = int.TryParse(pseudo, out _);
+ bool isNomNumeric = int.TryParse(nom, out _);
+ bool isPrenomNumeric = int.TryParse(prenom, out _);
+
+ //Si une des variables est convertissable en int, alors c'est une chaine de caractère uniquement composée de nombres
+ if ( isPseudoNumeric || isNomNumeric || isPrenomNumeric )
+ {
+ //Alors on renvoie une exception appelée "FormatException"
+ throw new FormatException("Un User ne peux pas avoir de pseudo/nom/prénom composé uniquement de nombres !");
+ }
+
Pseudo = pseudo;
Nom = nom;
Prenom = prenom;
Mdp = mdp;
- if (string.IsNullOrWhiteSpace(pseudo) || string.IsNullOrWhiteSpace(nom) || string.IsNullOrWhiteSpace(prenom) || string.IsNullOrWhiteSpace(mdp))
- {
- throw new ArgumentException("Un User doit avoir un pseudo, un nom, un prénom et un mot de passe au minimum!");
- }
}
public User(string pseudo, string nom, string prenom, string mdp, List monstresVus)
diff --git a/Sources/Tests/User_UT.cs b/Sources/Tests/User_UT.cs
index 25ac1ea..caa775e 100644
--- a/Sources/Tests/User_UT.cs
+++ b/Sources/Tests/User_UT.cs
@@ -7,47 +7,32 @@ namespace Tests
{
[Theory]
- [MemberData(nameof(DataWithoutList))]
- public void TestConstructorWithoutList(string pseudo, string nom, string prenom, string mdp)
- {
- Assert.Throws(() => new User(pseudo, nom, prenom, mdp));
- /*User u = new User(pseudo, nom, prenom, mdp);
- Assert.Equal(pseudo, u.Pseudo);
- Assert.Equal(nom, u.Nom);
- Assert.Equal(prenom, u.Prenom);
- Assert.True(u.verifyPssw(mdp));*/
+ [MemberData(nameof(ValidData_NoList))]
+ public void TestConstructorWithValidData_NoList(string pseudo, string nom, string prenom, string mdp)
+ {
+ User u = new User(pseudo, nom, prenom, mdp);
+ Assert.Equal(pseudo, u.Pseudo);
+ Assert.Equal(nom, u.Nom);
+ Assert.Equal(prenom, u.Prenom);
+ Assert.True(u.verifyPssw(mdp));
}
- public static IEnumerable