From 35a3e81c20f2d9992743d49e8f32a6e5de5896e2 Mon Sep 17 00:00:00 2001 From: luevard Date: Wed, 12 Oct 2022 16:51:30 +0200 Subject: [PATCH] =?UTF-8?q?Ajout=20test=20unitaire=20de=20banque,modificat?= =?UTF-8?q?ion=20de=20la=20classe=20banque=20et=20ajout=20de=20m=C3=A9thod?= =?UTF-8?q?e=20dans=20banque?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Code/ConsEco.sln | 9 +- Code/Model/Banque.cs | 25 ++++- Code/Model/Inscrit.cs | 106 +++++++++++----------- Code/Model/Stub.cs | 2 + Code/TestsUnitaires/TestUnitBanque.cs | 58 ++++++++++++ Code/TestsUnitaires/TestsUnitaires.csproj | 4 + 6 files changed, 145 insertions(+), 59 deletions(-) create mode 100644 Code/TestsUnitaires/TestUnitBanque.cs diff --git a/Code/ConsEco.sln b/Code/ConsEco.sln index ad4e961..78d70d3 100644 --- a/Code/ConsEco.sln +++ b/Code/ConsEco.sln @@ -5,11 +5,14 @@ VisualStudioVersion = 17.2.32616.157 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IHM", "IHM\IHM.csproj", "{355FC972-9C0D-4CBD-8003-EFBDACA7CFFF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{ACFA83F8-98C8-43AE-9328-B3F751098FFA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{ACFA83F8-98C8-43AE-9328-B3F751098FFA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestFonctionnel", "TestFonctionnel\TestFonctionnel.csproj", "{7AC4F84F-1124-4EC1-BF38-17F3F4FBEB3E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestFonctionnel", "TestFonctionnel\TestFonctionnel.csproj", "{7AC4F84F-1124-4EC1-BF38-17F3F4FBEB3E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsUnitaires", "TestsUnitaires\TestsUnitaires.csproj", "{B1AE713C-B5DE-4E81-A33F-818AAD0548A7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestsUnitaires", "TestsUnitaires\TestsUnitaires.csproj", "{B1AE713C-B5DE-4E81-A33F-818AAD0548A7}" + ProjectSection(ProjectDependencies) = postProject + {ACFA83F8-98C8-43AE-9328-B3F751098FFA} = {ACFA83F8-98C8-43AE-9328-B3F751098FFA} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Code/Model/Banque.cs b/Code/Model/Banque.cs index 07b43ae..2cb64f1 100644 --- a/Code/Model/Banque.cs +++ b/Code/Model/Banque.cs @@ -11,7 +11,7 @@ namespace Model public string Nom { get; private set; } public string UrlSite { get; private set; } public string UrlLogo { get; private set; } - public List ListeDesComptes { get; private set; } + public List ListeDesComptes { get; private set; } = new List(); public Banque(string nom, string urlSite, string urlLogo) { @@ -28,14 +28,33 @@ namespace Model ListeDesComptes = lescomptes; } - private void AjouterCompte(Compte compte) + public void AjouterCompte(Compte compte) { ListeDesComptes.Add(compte); } - private void SupprimerCompte(Compte compte) + public void SupprimerCompte(Compte compte) { ListeDesComptes.Remove(compte); } + + public bool ExisteCompte(string s) + { + foreach (Compte compte in ListeDesComptes) + { + if (compte.Nom.Equals(s)) + return true; + } + return false; + } + public Compte ReturnCompte(string s) + { + foreach (Compte compte in ListeDesComptes) + { + if (compte.Nom.Equals(s)) + return compte; + } + throw new KeyNotFoundException(); + } } } diff --git a/Code/Model/Inscrit.cs b/Code/Model/Inscrit.cs index e6e362c..771f949 100644 --- a/Code/Model/Inscrit.cs +++ b/Code/Model/Inscrit.cs @@ -1,54 +1,54 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -//using Banque; - -namespace Model -{ - public class Inscrit - { - public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal) - { - Id = id; - Nom = nom; - Mail = mail; - Prenom = prenom; - Mdp = mdp; - SoldeTotal = soldeTotal; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +//using Banque; + +namespace Model +{ + public class Inscrit + { + public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal) + { + Id = id; + Nom = nom; + Mail = mail; + Prenom = prenom; + Mdp = mdp; + SoldeTotal = soldeTotal; } - public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal,Listlesbanques) - { - Id = id; - Nom = nom; - Mail = mail; - Prenom = prenom; - Mdp = mdp; - 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; } - private List LesBanques { get; set; } - - /*public void ajouterBanque(Banque b) - { - TouteLesBanques.Add(b); - } - public void ajouterBanque(Banque b) - { - TouteLesBanques.Remove(b); - }*/ - public void ChoisirDevise(Devises devise) - { - Dev = devise; - } - - } -} + public Inscrit(string id, string nom, string mail, string prenom, string mdp, double soldeTotal,Listlesbanques) + { + Id = id; + Nom = nom; + Mail = mail; + Prenom = prenom; + Mdp = mdp; + 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; } + private List LesBanques { get; set; } + + /*public void ajouterBanque(Banque b) + { + TouteLesBanques.Add(b); + } + public void ajouterBanque(Banque b) + { + TouteLesBanques.Remove(b); + }*/ + public void ChoisirDevise(Devises devise) + { + Dev = devise; + } + + } +} diff --git a/Code/Model/Stub.cs b/Code/Model/Stub.cs index 1799fc8..67fbc68 100644 --- a/Code/Model/Stub.cs +++ b/Code/Model/Stub.cs @@ -11,6 +11,8 @@ namespace Model public List Banques = new(); public List Inscrits = new(); public List Comptes = new(); + + // ajouter load all pour tout les inscrits public List LoadInscrit() { Inscrits.Add(new("00001", "Evard", "lucasevard@gmail.com","Lucas","test",10,LoadBanques())); diff --git a/Code/TestsUnitaires/TestUnitBanque.cs b/Code/TestsUnitaires/TestUnitBanque.cs new file mode 100644 index 0000000..b2d4b5c --- /dev/null +++ b/Code/TestsUnitaires/TestUnitBanque.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Model; + +namespace TestsUnitaires +{ + public class TestUnitBanque + { + Banque test = new("BNP Paribas", "https://mabanque.bnpparibas/", "https://logos-marques.com/wp-content/uploads/2020/12/BNP-Paribas-logo.png"); + Banque test2 = new("BNP Paribas", "https://mabanque.bnpparibas/", "https://logos-marques.com/wp-content/uploads/2020/12/BNP-Paribas-logo.png", listeCompte); + + [Fact] + public void testConstructeur1() + { + Assert.NotNull(test); + Assert.Equal("BNP Paribas", test.Nom); + Assert.NotEqual("https://mabanque.bnpparibas/", test.Nom); + Assert.Equal("https://mabanque.bnpparibas/", test.UrlSite); + Assert.Equal("https://logos-marques.com/wp-content/uploads/2020/12/BNP-Paribas-logo.png", test.UrlLogo); + } + [Fact] + public void testConstructeur2() + { + List listeCompte = new(); + Compte tc = new("Livret A", 16956); + listeCompte.Add(tc); + Assert.NotNull(test2); + Assert.NotNull(test2.ListeDesComptes); + Assert.Equal("BNP Paribas", test.Nom); + Assert.NotEqual("https://mabanque.bnpparibas/", test2.Nom); + Assert.Equal("https://mabanque.bnpparibas/", test2.UrlSite); + Assert.Equal("https://logos-marques.com/wp-content/uploads/2020/12/BNP-Paribas-logo.png", test2.UrlLogo); + Assert.Contains(tc, test2.ListeDesComptes); + } + [Fact] + public void testAjouterCompte() + { + Compte tc = new("Livret A", 16956); + Assert.NotNull(test.ListeDesComptes); + test.AjouterCompte(tc); + Assert.Contains(tc, test.ListeDesComptes); + } + [Fact] + public void testSupprimerCompte() + { + Compte tc = new("Livret A", 16956); + Assert.NotNull(test.ListeDesComptes); + test.AjouterCompte(tc); + Assert.Contains(tc, test.ListeDesComptes); + test.SupprimerCompte(tc); + Assert.DoesNotContain(tc, test.ListeDesComptes); + } + + } +} \ No newline at end of file diff --git a/Code/TestsUnitaires/TestsUnitaires.csproj b/Code/TestsUnitaires/TestsUnitaires.csproj index 89d8ebd..5f195f2 100644 --- a/Code/TestsUnitaires/TestsUnitaires.csproj +++ b/Code/TestsUnitaires/TestsUnitaires.csproj @@ -21,4 +21,8 @@ + + + +