Ajout de tests de classe d'exception et améloration de inscrit
continuous-integration/drone/push Build is passing Details

Code
Hugo LIVET 2 years ago
parent a0c9ca6574
commit 9f1cf7c25e

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
//using Banque;
@ -9,6 +10,56 @@ namespace Model
{
public class Inscrit
{
public string Id { get; private set; }
public string Nom { get; private set; }
public string Mail
{
get => mail;
set
{
if (value.Length == 0)
{
throw new InvalidMailException(value, "Longueur d'un mail doit être superieur a 0", new ArgumentNullException());
}
if (!Regex.IsMatch(value, "(@)(.+)"))
{
throw new InvalidMailException(value, "Un mail doit contenir le symbole '@'");
}
mail = value;
}
}
private string mail;
public string Prenom { get; private set; }
public string Mdp
{
get => mdp;
set
{
if (value.Length <= 8)
{
throw new InvalidPasswordException(value, "La longeur d'un mot de passe doit être obligatoirement superieure a 8");
}
if (!Regex.IsMatch(value, "[A-Z]+"))
{
throw new InvalidPasswordException(value, "Le mot de passe doit contenir au moins une lettre majuscule");
}
if (!Regex.IsMatch(value, "[0-9]+"))
{
throw new InvalidPasswordException(value, "Le mot de passe doit contenir au moins un chiffre");
}
mdp = value;
}
}
private string mdp;
public double SoldeTotal { get; private set; }
public Devises Dev { get; private set; }
public List<Banque> LesBanques { get; private set; } = new List<Banque>();
public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal)
{
Id = id;
@ -28,14 +79,6 @@ namespace Model
SoldeTotal = soldeTotal;
LesBanques = lesbanques;
}
public string Id { get; private set; }
public string Nom { get; private set; }
public string Mail { get; private set; }
public string Prenom { get; private set; }
public string Mdp { get; private set; }
public double SoldeTotal { get; private set; }
public Devises Dev { get; private set; }
public List<Banque> LesBanques { get; private set; } = new List<Banque>();
public void ajouterBanque(Banque banque)
{

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class InvalidMailException : ArgumentException
{
private string Mail { get; set; }
public InvalidMailException():base()
{ }
public InvalidMailException(string mail):
base(String.Format("{0} n'est pas un mail valide.", mail))
{
Mail = mail;
}
public InvalidMailException(string mail, string message):
base(message)
{
Mail = mail;
}
public InvalidMailException(string mail, string message, Exception innerException) :
base(message, innerException)
{
Mail = mail;
}
}
}

@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Model
{
public class InvalidPasswordException : ArgumentException
{
private string Mdp { get; set; }
public InvalidPasswordException() : base()
{ }
public InvalidPasswordException(string mdp) :
base(String.Format("{0} n'est pas un mot de passe valide.", mdp))
{
Mdp = mdp;
}
public InvalidPasswordException(string mdp, string message) :
base(message)
{
Mdp = mdp;
}
public InvalidPasswordException(string mdp, string message, Exception innerException) :
base(message, innerException)
{
Mdp = mdp;
}
}
}

@ -1,18 +0,0 @@
using Model;
namespace TestsUnitaires
{
public class TU_Compte
{
[Fact]
public void Ctor_Compte()
{
Compte c = new Compte("Crédit Agricole", 20000);
Assert.NotNull(c);
Assert.Equal("Crédit Agricole", c.Nom);
Assert.Equal(20000, c.Solde);
}
}
}

@ -1,35 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
namespace TestsUnitaires
{
public class TestUnitCompte
{
[Fact]
public void TestConstructeurCompte()
{
Compte c1 = new("Livret A", 234);
Compte c2 = new("&e23R_te7", 1245.34);
Assert.Equal("Livret A", c1.Nom);
Assert.Equal("&e23R_te7", c2.Nom);
Assert.Equal(234, c1.Solde);
Assert.Equal(1245.34, c2.Solde);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
namespace TestsUnitaires
{
public class TestUnitCompte
{
[Fact]
public void TestConstructeurCompte()
{
Compte c1 = new("Livret A", 234);
Compte c2 = new("&e23R_te7", 1245.34);
Assert.Equal("Livret A", c1.Nom);
Assert.Equal("&e23R_te7", c2.Nom);
Assert.Equal(234, c1.Solde);
Assert.Equal(1245.34, c2.Solde);
}
[Fact]
public void testSupprimerBanque()
{
Banque bq = new Banque("Crédit Agricole", "https://creditagricole.fr", "https://yt3.ggpht.com/a/AGF-l7_mEfX2eQaGm8GefLOg5ZMRciNw-pESE3gUWg=s900-c-k-c0xffffffff-no-rj-mo");
Inscrit i1 = new Inscrit("A1001", "Smith", "smith@gmail.com", "luke", "test", 500);
Assert.NotNull(i1.LesBanques);
i1.ajouterBanque(bq);
Assert.Contains(bq, i1.LesBanques);
i1.SupprimerBanque(bq);
[Fact]
public void testSupprimerBanque()
{
Banque bq = new Banque("Crédit Agricole", "https://creditagricole.fr", "https://yt3.ggpht.com/a/AGF-l7_mEfX2eQaGm8GefLOg5ZMRciNw-pESE3gUWg=s900-c-k-c0xffffffff-no-rj-mo");
Inscrit i1 = new Inscrit("A1001", "Smith", "smith@gmail.com", "luke", "test20000aA", 500);
Assert.NotNull(i1.LesBanques);
i1.ajouterBanque(bq);
Assert.Contains(bq, i1.LesBanques);
i1.SupprimerBanque(bq);
Assert.DoesNotContain(bq, i1.LesBanques);
}
}
}
}
}
}

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
namespace TestsUnitaires
{
public class TestUnitInscrit
{
[Fact]
public void testCtorInscrit()
{
Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000);
Assert.NotNull(i);
Assert.Equal("I001", i.Id);
Assert.Equal("LIVET", i.Nom);
Assert.Equal("Hugo.LIVET@etu.uca.fr", i.Mail);
Assert.Equal("Hugo", i.Prenom);
Assert.Equal("Tu Sauras Passss:)1215", i.Mdp);
Assert.Equal(2000, i.SoldeTotal);
}
[Fact]
public void testCtorInscrit2()
{
List<Banque> lesBanques = new List<Banque>();
Banque b = new Banque("CA", "enavantouioui.fr", "NaN.fr");
lesBanques.Add(b);
Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000, lesBanques);
Assert.NotNull(i);
Assert.Equal("I001", i.Id);
Assert.Equal("LIVET", i.Nom);
Assert.Equal("Hugo.LIVET@etu.uca.fr", i.Mail);
Assert.Equal("Hugo", i.Prenom);
Assert.Equal("Tu Sauras Passss:)1215", i.Mdp);
Assert.Equal(2000, i.SoldeTotal);
Assert.Contains(b, i.LesBanques);
lesBanques.Remove(b);
Assert.DoesNotContain(b, i.LesBanques);
}
[Fact]
public void testAjoutBanqueInscrit()
{
Banque b = new Banque("CA", "enavantouioui.fr", "NaN.fr");
Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000);
i.ajouterBanque(b);
Assert.Contains(b, i.LesBanques);
}
[Fact]
public void testSupprimerBanqueInscrit()
{
Banque b = new Banque("CA", "enavantouioui.fr", "NaN.fr");
Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000);
i.ajouterBanque(b);
i.SupprimerBanque(b);
Assert.DoesNotContain(b, i.LesBanques);
i.ajouterBanque(new Banque("CA", "enavantouioui.fr", "NaN.fr"));
i.SupprimerBanque(new Banque("CA", "enavantouioui.fr", "NaN.fr"));
Assert.DoesNotContain(new Banque("CA", "enavantouioui.fr", "NaN.fr"), i.LesBanques);
}
[Fact]
public void testChoixDeviseInscrit()
{
Inscrit i = new Inscrit("I001", "LIVET", "Hugo.LIVET@etu.uca.fr", "Hugo", "Tu Sauras Passss:)1215", 2000);
i.ChoisirDevise(Devises.Euro);
Assert.Equal(Devises.Euro, i.Dev);
}
[Theory]
[InlineData("I000001", "LIVET", "a@a.fr", "Hugo", "123Soleil@azerty", 20000, true)]//OK
[InlineData("I000002", "LIVET", "aa.fr", "Hugo", "123Soleil@azerty", 20000, false)]//Mail invalide psk pas de @
[InlineData("I000003", "LIVET", "a@a.fr", "Hugo", "123soleil@azerty", 20000, false)]//mdp Invalide psk mdp sans Maj
[InlineData("I000004", "LIVET", "a@a.fr", "Hugo", "Soleil@azerty", 20000, false)]//mdp Invalide psk pas de chiffres
public void CtorInscrit2TU(string id, string nom, string mail, string prenom, string mdp, double solde, bool notShouldThrowException)
{
if (!notShouldThrowException)
{
Assert.ThrowsAny<ArgumentException>(() => new Inscrit(id, nom, mail, prenom, mdp, solde));
return;
}
Inscrit i = new Inscrit(id, nom, mail, prenom, mdp, solde);
Assert.NotNull(i);
Assert.Equal(id, i.Id);
Assert.Equal(nom, i.Nom);
Assert.Equal(mail, i.Mail);
Assert.Equal(prenom, i.Prenom);
Assert.Equal(mdp, i.Mdp);
Assert.Equal(solde, i.SoldeTotal);
}
}
}
Loading…
Cancel
Save