diff --git a/Sources/BowlingLib/Model/Equipe.cs b/Sources/BowlingLib/Model/Equipe.cs index dfcbdef..f06f16b 100644 --- a/Sources/BowlingLib/Model/Equipe.cs +++ b/Sources/BowlingLib/Model/Equipe.cs @@ -1,53 +1,92 @@ - -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace BowlingLib.Model -{ - public class Equipe - { - private string nom; - public ReadOnlyCollection Joueurs - { - get; - private set; - } - private List joueurs; - - public string Nom - { - get { return nom; } - set { nom = value; } - } - - public object Id { get; set; } - - private int numero; - - public Equipe(string nom) - { - this.nom = nom; - Joueurs = new ReadOnlyCollection(joueurs); - } - - public void AjouterJoueur(Joueur joueur) - { - joueurs.Add(joueur); - } - - public void SupprimerJoueur(Joueur joueur) - { - joueurs.Remove(joueur); - } - - //retourner la liste non modifiable des joueurs de l'équipe - public List GetJoueurs() - { - return joueurs.AsReadOnly().ToList(); - } - } -} + +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.ObjectModel; + +namespace BowlingLib.Model +{ + public class Equipe + { + private string nom; + + public List Joueurs = new List(); + + + public string Nom + { + get { return nom; } + set { nom = value; } + } + + + + + public Equipe(string nom, params Joueur[] joueurs) + { + this.nom = nom; + AjouterJoueurs(joueurs); + // foreach (Joueur nouv in joueurs) AjouterJoueur(nouv); + + } + public object Id { get; set; } + + private int numero; + + public Equipe(string nom) + { + this.nom = nom; + } + + + public void AjouterJoueurs(params Joueur[] joueurs) + { + foreach(var j in joueurs) + { + AjouterJoueur(j); + } + } + + public bool AjouterJoueur(Joueur joueur) + { + if(!isExist(joueur)) + { + Joueurs.Add(joueur); + return true; + }else + { + return false; + } + } + + public void SupprimerJoueur(Joueur joueur) + { + Joueurs.Remove(joueur); + } + + //retourner la liste non modifiable des joueurs de l'équipe + public long GetJoueurs() + { + return Joueurs.Count; + } + + + // Fonction permettant de vérifier si un joueur existe déjà dans la liste (l'équipe) + public bool isExist(Joueur nouvJoueur) + { + if (Joueurs.Count > 0) { + + { + if (Joueurs.Contains(nouvJoueur)) return true; + } + } + + + return false; + } + + } +} diff --git a/Sources/BowlingLib/Model/Iloader.cs b/Sources/BowlingLib/Model/Iloader.cs deleted file mode 100644 index 93593be..0000000 --- a/Sources/BowlingLib/Model/Iloader.cs +++ /dev/null @@ -1,6 +0,0 @@ -using System; - -public interface Iloader -{ - -} diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs index a916256..73102a1 100644 --- a/Sources/BowlingLib/Model/Joueur.cs +++ b/Sources/BowlingLib/Model/Joueur.cs @@ -29,6 +29,12 @@ namespace BowlingLib.Model } } + public override bool Equals(object obj) + { + return obj is Joueur joueur && + pseudo == joueur.pseudo && + Pseudo == joueur.Pseudo; + } public int Id { get; set; } } } diff --git a/Sources/Tests/BowlingAppUnitTest/UTestEquipe.cs b/Sources/Tests/BowlingAppUnitTest/UTestEquipe.cs new file mode 100644 index 0000000..e0287bc --- /dev/null +++ b/Sources/Tests/BowlingAppUnitTest/UTestEquipe.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using BowlingLib.Model; +using Xunit; + +namespace Test.BowlingAppUnitTest +{ + public class UnitTestEquipe + { + + public static IEnumerable Data_AddJoueurToEquipe() + { + yield return new object[] + { + true, + new Joueur[] + { + new Joueur("Alys"), + new Joueur("Bénita"), + new Joueur("Regis"), + new Joueur("Mania"), + new Joueur("Cornelle") + }, + new Equipe("ABRMC", + new Joueur("Alys"), + new Joueur("Bénita"), + new Joueur("Regis"), + new Joueur("Mania")), + new Joueur("Cornelle") + }; + + yield return new object[] + { + false, + new Joueur[] + { + new Joueur("Alys"), + new Joueur("Bénita"), + new Joueur("Regis"), + new Joueur("Mania") + }, + new Equipe("ABRMC", + new Joueur("Alys"), + new Joueur("Bénita"), + new Joueur("Regis"), + new Joueur("Mania")), + new Joueur("Mania") + }; + } + + + [Theory] + [MemberData(nameof(Data_AddJoueurToEquipe))] + public void Test_AddJoueurToEquipe(bool expectedResult, + Joueur[] expectedJoueurs, + Equipe equipe, + Joueur joueur) + { + + bool result = equipe.AjouterJoueur(joueur); + Assert.Equal(expectedResult, result); + Assert.Equal(expectedJoueurs.Length, equipe.GetJoueurs()); + Assert.All(expectedJoueurs, j => equipe.Joueurs.Contains(j)); + } + + } +}