diff --git a/Sources/BowlingLib/Interface/IDataManager.cs b/Sources/BowlingLib/Interface/IDataManager.cs new file mode 100644 index 0000000..b509d9b --- /dev/null +++ b/Sources/BowlingLib/Interface/IDataManager.cs @@ -0,0 +1,18 @@ +using BowlingLib.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Interface +{ + public interface IDataManager + { + void Add(Data data); + void Delete(Data data); + void Update(Data data); + IEnumerable GetAll(); + IEnumerable GetAll(int n, int j); + } +} diff --git a/Sources/BowlingLib/Model/Equipe.cs b/Sources/BowlingLib/Model/Equipe.cs index b509224..dfcbdef 100644 --- a/Sources/BowlingLib/Model/Equipe.cs +++ b/Sources/BowlingLib/Model/Equipe.cs @@ -23,6 +23,9 @@ namespace BowlingLib.Model get { return nom; } set { nom = value; } } + + public object Id { get; set; } + private int numero; public Equipe(string nom) diff --git a/Sources/BowlingLib/Model/Joueur.cs b/Sources/BowlingLib/Model/Joueur.cs index 3114ea2..a916256 100644 --- a/Sources/BowlingLib/Model/Joueur.cs +++ b/Sources/BowlingLib/Model/Joueur.cs @@ -13,19 +13,22 @@ namespace BowlingLib.Model public Joueur(string pseudo) { this.Pseudo = pseudo; - - if (pseudo == null || pseudo == "" || pseudo.Length < 3) - { - throw new ArgumentException("Le pseudo ne peut pas être vide"); - } } public string Pseudo { get { return pseudo; } - private set { pseudo = value; } + set + { + + pseudo = value; + if (pseudo == null || pseudo == "" || pseudo.Length < 3) + { + throw new ArgumentException("Le pseudo ne peut pas être vide"); + } + } } - + public int Id { get; set; } } } diff --git a/Sources/BowlingLib/Model/Manager.cs b/Sources/BowlingLib/Model/Manager.cs new file mode 100644 index 0000000..74d06b4 --- /dev/null +++ b/Sources/BowlingLib/Model/Manager.cs @@ -0,0 +1,147 @@ +using BowlingLib.Interface; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BowlingLib.Model +{ + public class Manager + { + public IDataManager joueurManager { get; private set; } + public IDataManager partieManager { get; private set; } + public IDataManager equipeManager { get; private set; } + + public Manager(IDataManager joueurManager) + { + this.joueurManager = joueurManager; + } + + public Manager(IDataManager partieManager) + { + this.partieManager = partieManager; + } + + /// + /// Ajoute un joueur à la liste des joueurs + /// + /// + public Manager(IDataManager equipeManager) + { + this.equipeManager = equipeManager; + } + + /// + /// Ajoute un joueur à la liste des joueurs + /// + /// + public void AddJoueur(Joueur joueur) + { + joueurManager.Add(joueur); + } + + /// + /// Ajoute une partie à la liste des parties + /// + /// + public void AddPartie(Partie partie) + { + partieManager.Add(partie); + } + + /// + /// Ajoute une équipe à la liste des équipes + /// + /// + public void AddEquipe(Equipe equipe) + { + equipeManager.Add(equipe); + } + + /// + /// Retourne la liste des joueurs + /// + /// + public void DeleteJoueur(Joueur joueur) + { + joueurManager.Delete(joueur); + } + + /// + /// Supprime une partie + /// + /// + public void DeletePartie(Partie partie) + { + partieManager.Delete(partie); + } + + /// + /// Supprime une équipe + /// + /// + public void DeleteEquipe(Equipe equipe) + { + equipeManager.Delete(equipe); + } + + /// + /// Retourne la liste des joueurs + /// + /// + public void UpdateJoueur(Joueur joueur) + { + joueurManager.Update(joueur); + } + + /// + /// Met à jour une partie + /// + /// + public void UpdatePartie(Partie partie) + { + partieManager.Update(partie); + } + + /// + /// Met à jour une équipe + /// + /// + public void UpdateEquipe(Equipe equipe) + { + equipeManager.Update(equipe); + } + + /// + /// Retourne la liste des joueurs + /// + /// + public IEnumerable GetAllJoueur() + { + return joueurManager.GetAll(); + } + + /// + /// Retourne les dernières parties du joueur + /// + /// + public IEnumerable GetAllPartie() + { + return partieManager.GetAll(); + } + + /// + /// Retourne les Equipe d'une partie + /// + /// + public IEnumerable GetAllEquipe() + { + return equipeManager.GetAll(); + } + + + + + } +} diff --git a/Sources/BowlingLib/Model/Partie.cs b/Sources/BowlingLib/Model/Partie.cs index 8430a9a..c24b567 100644 --- a/Sources/BowlingLib/Model/Partie.cs +++ b/Sources/BowlingLib/Model/Partie.cs @@ -11,6 +11,7 @@ namespace BowlingLib.Model { //public ReadOnlyCollection Frames; public Joueur Joueur { get; private set; } + public object Id { get; set; } public List Frames; diff --git a/Sources/BowlingStub/StubEquipe.cs b/Sources/BowlingStub/StubEquipe.cs index 4a76c4e..ccff2d8 100644 --- a/Sources/BowlingStub/StubEquipe.cs +++ b/Sources/BowlingStub/StubEquipe.cs @@ -1,26 +1,49 @@ using BowlingLib.Model; +using BowlingLib.Interface; using System; -public class StubEquipe +public class StubEquipe:IDataManager { - private List listEquipes = new List(); - public StubEquipe() - { - } - - public List ListEquipes(int n = 10, int j = 2) - { - for (int i = 0; i < n; i++) - { - listEquipes.Add(new Equipe("Equipe " + i + 1)); - - for(int k = 0; k < j; k++) + private List listEquipes = new List(); + public StubEquipe() + { + } + + public void Add(Equipe data) + { + listEquipes.Add(data); + } + + public void Delete(Equipe data) + { + listEquipes.Remove(data); + } + + public IEnumerable GetAll(int n = 10, int j = 2) + { + for (int i = 0; i < n; i++) + { + this.Add(new Equipe("Equipe " + i + 1)); + + for (int k = 0; k < j; k++) { - listEquipes.ElementAt(i).AjouterJoueur(new Joueur("Joueur " + i + 1 + "-" + k + 1)); + listEquipes.ElementAt(i).AjouterJoueur(new Joueur("Joueur " + i + 1 + "-" + k + 1)); + + } + } + return listEquipes; + } - } - } + public IEnumerable GetAll() + { return listEquipes; } + //mise à jour d'une équipe + public void Update(Equipe data) + { + int index = listEquipes.FindIndex(x => x.Id == data.Id); + listEquipes[index] = data; + } + } diff --git a/Sources/BowlingStub/StubJoueur.cs b/Sources/BowlingStub/StubJoueur.cs index 5fc7ec1..8bfdfb6 100644 --- a/Sources/BowlingStub/StubJoueur.cs +++ b/Sources/BowlingStub/StubJoueur.cs @@ -1,20 +1,41 @@ using BowlingLib.Model; +using BowlingLib.Interface; using System; -public class StubJoueur +public class StubJoueur : IDataManager + { -private List listJoueurs = new List(); - public StubJoueur() - { - } + private List listJoueurs = new List(); + + + public void Add(Joueur data) + { + listJoueurs.Add(data); + } + + public void Delete(Joueur data) + { + listJoueurs.Remove(data); + } - public List ListJoueurs(int n = 10) + public IEnumerable GetAll() { - for (int i = 0; i < n; i++) + return listJoueurs; + } + + public IEnumerable GetAll(int n=10, int j=0) + { + for (int i = 0; i < n; i++) { - listJoueurs.Add(new Joueur("Joueur " + i + 1)); - } + Add(new Joueur("Joueur " + i + 1)); + } return listJoueurs; } + public void Update(Joueur data) + { + int index = listJoueurs.FindIndex(x => x.Id == data.Id); + listJoueurs[index] = data; + } + } diff --git a/Sources/BowlingStub/StubPartie.cs b/Sources/BowlingStub/StubPartie.cs index 574254f..9e0651c 100644 --- a/Sources/BowlingStub/StubPartie.cs +++ b/Sources/BowlingStub/StubPartie.cs @@ -1,18 +1,28 @@ using BowlingLib.Model; +using BowlingLib.Interface; namespace BowlingStub { - public class StubPartie + public class StubPartie:IDataManager { - List listParties = new List(); - public StubPartie() + private List listParties = new List(); + + public void Add(Partie data) { - + listParties.Add(data); + } + public void Delete(Partie data) + { + listParties.Remove(data); + } + + public IEnumerable GetAll() + { + return listParties; } - //Fonction permettant de créer une partie pour chaque joueur - public List ListParties(int n = 10) + public IEnumerable GetAll(int n=10, int j=0) { for (int i = 0; i < n; i++) { @@ -20,9 +30,12 @@ namespace BowlingStub } return listParties; } - - + public void Update(Partie data) + { + int index = listParties.FindIndex(x => x.Id == data.Id); + listParties[index] = data; + } } } \ No newline at end of file diff --git a/Sources/Tests/BowlingAppUnitTest/UTManager.cs b/Sources/Tests/BowlingAppUnitTest/UTManager.cs new file mode 100644 index 0000000..2d628a6 --- /dev/null +++ b/Sources/Tests/BowlingAppUnitTest/UTManager.cs @@ -0,0 +1,62 @@ +using BowlingLib.Model; +using BowlingStub; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Xunit; + +namespace BowlingAppUnitTest +{ + public class UTManager + { + //test de la méthode AddJoueur using MemberData + [Fact] + public void TestAddJoueur() //Test de la méthode AddJoueur + { + //Arrange + Joueur joueur = new Joueur("Pierre"); + Manager manager = new Manager(new StubJoueur()); + + //Act + manager.AddJoueur(joueur); + + //Assert + Assert.Single(manager.joueurManager.GetAll()); + } + + //Test de la méthode AddPartie + [Fact] + public void TestAddPartie() //Test de la méthode AddPartie + { + //Arrange + Partie partie = new Partie(new Joueur("Pierre")); + Manager manager = new Manager(new StubPartie()); + + //Act + manager.AddPartie(partie); + + //Assert + Assert.Single(manager.partieManager.GetAll()); + } + + //Test de la méthode AddEquipe + //[Fact] + + //public void TestAddEquipe() //Test de la méthode AddEquipe + //{ + // //Arrange + // Equipe equipe = new Equipe("Equipe 1"); + // Manager manager = new Manager(new StubEquipe()); + + // //Act + // manager.AddEquipe(equipe); + + // //Assert + // Assert.Single(manager.equipeManager.GetAll()); + //} + + + } +} diff --git a/Sources/Tests/BowlingAppUnitTest/UTPartie.cs b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs index da4505b..af3ed50 100644 --- a/Sources/Tests/BowlingAppUnitTest/UTPartie.cs +++ b/Sources/Tests/BowlingAppUnitTest/UTPartie.cs @@ -17,8 +17,8 @@ namespace BowlingAppUnitTest { //Arrange StubPartie stubPartie = new StubPartie(); - List listParties = stubPartie.ListParties(); - Partie partie = listParties[0]; + IEnumerable listParties = stubPartie.GetAll(1); + Partie partie = listParties.ElementAt(0); partie.AddFrame(new Frame(1)); partie.AddFrame(new Frame(2)); partie.AddFrame(new Frame(3)); @@ -51,8 +51,8 @@ namespace BowlingAppUnitTest { //Arrange StubPartie stubPartie = new StubPartie(); - List listParties = stubPartie.ListParties(); - Partie partie = listParties[0]; + IEnumerable listParties = stubPartie.GetAll(1); + Partie partie = listParties.ElementAt(0); partie.AddFrame(new Frame(1)); partie.AddFrame(new Frame(2)); partie.AddFrame(new Frame(3)); @@ -90,8 +90,8 @@ namespace BowlingAppUnitTest { //Arrange StubPartie stubPartie = new StubPartie(); - List listParties = stubPartie.ListParties(); - Partie partie = listParties[0]; + IEnumerable listParties = stubPartie.GetAll(1); + Partie partie = listParties.ElementAt(0); partie.AddFrame(new Frame(1)); partie.AddFrame(new Frame(2)); partie.AddFrame(new Frame(3)); @@ -135,8 +135,8 @@ namespace BowlingAppUnitTest { //Arrange StubPartie stubPartie = new StubPartie(); - List listParties = stubPartie.ListParties(); - Partie partie = listParties[0]; + IEnumerable listParties = stubPartie.GetAll(1); + Partie partie = listParties.ElementAt(0); partie.AddFrame(new Frame(1)); partie.AddFrame(new Frame(2)); partie.AddFrame(new Frame(3)); diff --git a/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs b/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs index 83eeb4e..fa00da9 100644 --- a/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs +++ b/Sources/Tests/BowlingAppUnitTest/UnitTestJoueur.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using BowlingLib.Model; using Xunit; @@ -75,7 +76,33 @@ namespace Test.BowlingAppUnitTest public void TestJoueurStub() { StubJoueur stub = new StubJoueur(); - Assert.Equal(10, stub.ListJoueurs(10).Count); + Assert.Equal(10, stub.GetAll(10).Count()); } + + + //tester la methode remove + [Fact] + public void TestRemove() + { + StubJoueur stub = new StubJoueur(); + stub.Add(j); + stub.Delete(j); + //Compter le nombre de joueur dans un objet IEnumerable + Assert.Equal(0, stub.GetAll().Count()); + } + + //tester la methode update avec les members Data + [Fact] + public void TestUpdate() + { + StubJoueur stub = new StubJoueur(); + Joueur j = new Joueur("Paul"); + stub.Add(j); + j.Pseudo = "Augustin"; + stub.Update(j); + Assert.Equal("Augustin", stub.GetAll().First().Pseudo); + } + + } }