From 9db9b545a2916c09f941bd23823b47d124036426 Mon Sep 17 00:00:00 2001 From: victor perez ngounou Date: Mon, 24 Oct 2022 13:11:34 +0200 Subject: [PATCH 1/5] ImplementAsyncAwait #63 --- Sources/Business/IDataManager.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/Business/IDataManager.cs b/Sources/Business/IDataManager.cs index a4628e8..cd3369f 100644 --- a/Sources/Business/IDataManager.cs +++ b/Sources/Business/IDataManager.cs @@ -13,10 +13,10 @@ namespace Business /// public interface IDataManager { - bool Add(Data data); - bool Delete(Data data); - bool Update(Data data); - Data GetDataWithName(string name); - IEnumerable GetAll(); + Task Add(Data data); + Task Delete(Data data); + Task Update(Data data); + Task GetDataWithName(string name); + Task> GetAll(); } } From adbd742d39921302ec2e3943f6742fe5cfd40b53 Mon Sep 17 00:00:00 2001 From: Arafamamadouelaphi <92931011+Arafamamadouelaphi@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:11:13 +0100 Subject: [PATCH 2/5] AsyncAwait #63 --- Sources/BowlingMaping/EquipeDbDataManager.cs | 27 +++++----- Sources/BowlingMaping/JoueurDbDataManager.cs | 30 ++++++----- Sources/BowlingMaping/PartieDbDataManager.cs | 31 ++++++------ Sources/Business/IPartieDbDataManager.cs | 2 +- Sources/Business/Manager.cs | 52 ++++++++++---------- 5 files changed, 72 insertions(+), 70 deletions(-) diff --git a/Sources/BowlingMaping/EquipeDbDataManager.cs b/Sources/BowlingMaping/EquipeDbDataManager.cs index 63f737e..ce00454 100644 --- a/Sources/BowlingMaping/EquipeDbDataManager.cs +++ b/Sources/BowlingMaping/EquipeDbDataManager.cs @@ -3,6 +3,7 @@ using BowlingEF.Context; using BowlingEF.Entities; using BowlingLib.Model; using Business; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -14,7 +15,7 @@ namespace BowlingMaping public class EquipeDbDataManager : IDataManager { #region Méthodes - public bool Add(Equipe _equipe) + public async Task Add(Equipe _equipe) { bool result = false; using (var context = new BowlingContext()) @@ -30,62 +31,62 @@ namespace BowlingMaping }).ToList() }; context.Equipes.Add(entity); - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } return result; } - public bool Delete(Equipe _equipe) + public async Task Delete(Equipe _equipe) { bool result = false; using (var context = new BowlingContext()) { EquipeEntity entity = context.Equipes.Find(_equipe.Id); context.Equipes.Remove(entity); - result = context.SaveChanges() == 1; + result =await context.SaveChangesAsync() == 1; } return result; } - public IEnumerable GetAll() + public async Task> GetAll() { using (var context = new BowlingContext()) { - return context.Equipes.Select(e => new Equipe + return await context.Equipes.Select(e => new Equipe ( e.Id, e.Nom, e.Joueurs.Select(j => new Joueur(j.Id, j.Pseudo)).ToArray() - )).ToList(); + )).ToListAsync(); } } - public Equipe GetDataWithName(string name) + public async Task GetDataWithName(string name) { using (var context = new BowlingContext()) { - return context.Equipes.Where(e => e.Nom == name).Select(e => new Equipe + return await context.Equipes.Where(e => e.Nom == name).Select(e => new Equipe ( e.Id, e.Nom, e.Joueurs.Select(j => new Joueur(j.Id, j.Pseudo)).ToArray() - )).FirstOrDefault(); + )).FirstOrDefaultAsync(); } } - public bool Update(Equipe data) + public async Task< bool> Update(Equipe data) { bool result = false; using (var context = new BowlingContext()) { - EquipeEntity entity = context.Equipes.Find(data.Id); + EquipeEntity entity = context.Equipes.Find(data.Id); entity.Nom = data.Nom; entity.Joueurs = data.Joueurs.Select(j => new JoueurEntity { Id = j.Id, Pseudo = j.Pseudo }).ToList(); - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } return result; } diff --git a/Sources/BowlingMaping/JoueurDbDataManager.cs b/Sources/BowlingMaping/JoueurDbDataManager.cs index fea1f31..fc90c5c 100644 --- a/Sources/BowlingMaping/JoueurDbDataManager.cs +++ b/Sources/BowlingMaping/JoueurDbDataManager.cs @@ -2,6 +2,7 @@ using BowlingEF.Entities; using BowlingLib.Model; using Business; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -21,7 +22,7 @@ namespace BowlingMaping /// /// /// - public bool Add(Joueur _joueur) + public async Task Add(Joueur _joueur) { bool result = false; using (var context = new BowlingContext()) @@ -32,7 +33,7 @@ namespace BowlingMaping Pseudo = _joueur.Pseudo, }; context.Joueurs.Add(entity); - result = context.SaveChanges() == 1; + result =await context.SaveChangesAsync() == 1; } return result; } @@ -42,7 +43,7 @@ namespace BowlingMaping /// /// /// - public bool Delete(Joueur _joueur) + public async Task< bool> Delete(Joueur _joueur) { bool result = false; @@ -52,7 +53,7 @@ namespace BowlingMaping { JoueurEntity entity = context.Joueurs.Find(_joueur.Id); context.Joueurs.Remove(entity); - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } return result; @@ -64,12 +65,12 @@ namespace BowlingMaping /// recupère tous les joueurs de la Base de données /// /// - public IEnumerable GetAll() + public async Task< IEnumerable >GetAll() { using (var context = new BowlingContext()) { - List joueurs = new List(); - foreach (var item in context.Joueurs) + List joueurs = new List(); + foreach (var item in await context.Joueurs.ToListAsync()) joueurs.Add(new Joueur(item.Id, item.Pseudo)); return joueurs; } @@ -80,22 +81,19 @@ namespace BowlingMaping /// /// /// - public Joueur GetDataWithName(string name) + public async Task GetDataWithName(string name) { using (var context = new BowlingContext()) { Joueur _joueur = null; - - var query = from joueur in context.Joueurs - where joueur.Pseudo == name - select joueur; - foreach (var item in query) - _joueur = new Joueur(item.Id, item.Pseudo); + + var query = await context.Joueurs.FirstOrDefaultAsync(n => n.Pseudo == n.Pseudo); + _joueur = new Joueur(query.Id, query.Pseudo); return _joueur; } } - public bool Update(Joueur _joueur) + public async Task Update(Joueur _joueur) { bool result = false; using (var context = new BowlingContext()) @@ -104,7 +102,7 @@ namespace BowlingMaping if (entity!=null) { entity.Pseudo = _joueur.Pseudo; - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } } return result; diff --git a/Sources/BowlingMaping/PartieDbDataManager.cs b/Sources/BowlingMaping/PartieDbDataManager.cs index 85f628e..782f009 100644 --- a/Sources/BowlingMaping/PartieDbDataManager.cs +++ b/Sources/BowlingMaping/PartieDbDataManager.cs @@ -2,6 +2,7 @@ using BowlingEF.Entities; using BowlingLib.Model; using Business; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -21,7 +22,7 @@ namespace BowlingMaping /// /// /// - public bool Add(Partie _partie) + public async Task Add(Partie _partie) { bool result = false; using (var context = new BowlingContext()) @@ -34,7 +35,7 @@ namespace BowlingMaping Score = _partie.Score }; context.Parties.Add(entity); - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } return result; } @@ -44,14 +45,14 @@ namespace BowlingMaping /// /// /// - public bool Delete(Partie _partie) + public async Task Delete(Partie _partie) { bool result = false; using (var context = new BowlingContext()) { PartieEntity entity = context.Parties.Find(_partie.Id); context.Parties.Remove(entity); - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } return result; } @@ -61,7 +62,7 @@ namespace BowlingMaping /// /// /// - public bool Update(Partie _partie) + public async Task Update(Partie _partie) { bool result = false; using (var context = new BowlingContext()) @@ -70,7 +71,7 @@ namespace BowlingMaping entity.Date = _partie.Date; entity.JoueurId = _partie.Joueur.Id; entity.Score = _partie.Score; - result = context.SaveChanges() == 1; + result =await context.SaveChangesAsync() == 1; } return result; } @@ -80,12 +81,12 @@ namespace BowlingMaping /// /// /// - public Partie GetDataWithName(string name) + public async Task GetDataWithName(string name) { Partie result = null; using (var context = new BowlingContext()) { - PartieEntity entity = context.Parties.Find(name); + PartieEntity entity = await context.Parties.FindAsync(name); Joueur joueur = new Joueur(entity.Joueur.Id, entity.Joueur.Pseudo); List frames = new List(); foreach (FrameEntity frameEntity in entity.Frames) @@ -102,12 +103,12 @@ namespace BowlingMaping /// Retourne Toutes les parties en base de donné /// /// - public IEnumerable GetAll() + public async Task> GetAll() { List result = new List(); using (var context = new BowlingContext()) { - foreach (PartieEntity entity in context.Parties.OrderBy(item => item.Date)) + foreach (PartieEntity entity in await context.Parties.ToListAsync()) { Joueur joueur = new Joueur(entity.Joueur.Id, entity.Joueur.Pseudo); List frames = new List(); @@ -119,7 +120,7 @@ namespace BowlingMaping result.Add(new Partie(entity.Id, joueur, frames, entity.Date, entity.Score)); } } - return result; + return result.OrderBy(item => item.Date); } /// @@ -127,14 +128,14 @@ namespace BowlingMaping /// /// /// - public IEnumerable GetAllWithDate(DateTime date) + public async Task> GetAllWithDate(DateTime date) { List result = new List(); using (var context = new BowlingContext()) { - foreach (PartieEntity entity in context.Parties.OrderBy(item => item.Date)) + foreach (PartieEntity entity in await context.Parties.ToListAsync()) { - if (entity.Date == date) + if (entity.Date.Date == date.Date) { Joueur joueur = new Joueur(entity.Joueur.Id, entity.Joueur.Pseudo); List frames = new List(); @@ -147,7 +148,7 @@ namespace BowlingMaping } } } - return result; + return result.OrderBy(item => item.Date); } #endregion diff --git a/Sources/Business/IPartieDbDataManager.cs b/Sources/Business/IPartieDbDataManager.cs index 7e641bb..7be4253 100644 --- a/Sources/Business/IPartieDbDataManager.cs +++ b/Sources/Business/IPartieDbDataManager.cs @@ -12,6 +12,6 @@ namespace Business /// public interface IPartieDbDataManager : IDataManager { - IEnumerable GetAllWithDate(DateTime date); + Task> GetAllWithDate(DateTime date); } } diff --git a/Sources/Business/Manager.cs b/Sources/Business/Manager.cs index edeb4b1..66bbd1b 100644 --- a/Sources/Business/Manager.cs +++ b/Sources/Business/Manager.cs @@ -70,13 +70,15 @@ namespace Business /// /// /// - public bool AddJoueur(Joueur joueur) + public Task AddJoueur(Joueur joueur) { if (joueurDataManager == null) { - return false; + return Task.FromResult(false); } - return joueurDataManager.Add(joueur); + return joueurDataManager.Add(joueur); + + } /// @@ -84,11 +86,11 @@ namespace Business /// /// /// - public bool AddPartie(Partie partie) + public Task AddPartie(Partie partie) { if (partieDataManager == null) { - return false; + return Task.FromResult( false); } return partieDataManager.Add(partie); } @@ -98,118 +100,118 @@ namespace Business /// /// /// - public bool AddEquipe(Equipe equipe) + public async Task AddEquipe(Equipe equipe) { if (equipeDataManager == null) { return false; } - return equipeDataManager.Add(equipe); + return await equipeDataManager.Add(equipe); } /// /// Retourne la liste des joueurs /// /// - public bool DeleteJoueur(Joueur joueur) + public async Task DeleteJoueur(Joueur joueur) { if (joueurDataManager == null) { return false; } - return JoueurDataManager.Delete(joueur); + return await JoueurDataManager.Delete(joueur); } /// /// Supprime une partie /// /// - public bool DeletePartie(Partie partie) + public async Task DeletePartie(Partie partie) { if (partieDataManager == null) { return false; } - return partieDataManager.Delete(partie); + return await partieDataManager.Delete(partie); } /// /// Supprime une équipe /// /// - public bool DeleteEquipe(Equipe equipe) + public async Task DeleteEquipe(Equipe equipe) { if (equipeDataManager == null) { return false; } - return equipeDataManager.Delete(equipe); + return await equipeDataManager.Delete(equipe); } /// /// Retourne la liste des joueurs /// /// - public bool UpdateJoueur(Joueur joueur) + public async Task UpdateJoueur(Joueur joueur) { if (joueurDataManager == null) { return false; } - return JoueurDataManager.Update(joueur); + return await JoueurDataManager.Update(joueur); } /// /// Met à jour une partie /// /// - public bool UpdatePartie(Partie partie) + public async Task UpdatePartie(Partie partie) { if (partieDataManager == null) { return false; } - return partieDataManager.Update(partie); + return await partieDataManager.Update(partie); } /// /// Met à jour une équipe /// /// - public bool UpdateEquipe(Equipe equipe) + public async Task UpdateEquipe(Equipe equipe) { if (equipeDataManager == null) { return false; } - return equipeDataManager.Update(equipe); + return await equipeDataManager.Update(equipe); } /// /// Retourne la liste des joueurs /// /// - public IEnumerable GetAllJoueur() + public async Task> GetAllJoueur() { - return JoueurDataManager.GetAll(); + return await JoueurDataManager.GetAll(); } /// /// Retourne les dernières parties du joueur /// /// - public IEnumerable GetAllPartie() + public async Task> GetAllPartie() { - return partieDataManager.GetAll(); + return await partieDataManager.GetAll(); } /// /// Retourne les Equipe en fonction d'une partie /// /// - public IEnumerable GetAllEquipe() + public async Task> GetAllEquipe() { - return equipeDataManager.GetAll(); + return await equipeDataManager.GetAll(); } #endregion From bbaae88fb08f982c634f1af117a4488c9c73fa88 Mon Sep 17 00:00:00 2001 From: Arafamamadouelaphi <92931011+Arafamamadouelaphi@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:11:13 +0100 Subject: [PATCH 3/5] AsyncAwait #63 --- Sources/BowlingMaping/EquipeDbDataManager.cs | 27 +++++++++--------- Sources/BowlingMaping/JoueurDbDataManager.cs | 30 +++++++++----------- 2 files changed, 28 insertions(+), 29 deletions(-) diff --git a/Sources/BowlingMaping/EquipeDbDataManager.cs b/Sources/BowlingMaping/EquipeDbDataManager.cs index 63f737e..ce00454 100644 --- a/Sources/BowlingMaping/EquipeDbDataManager.cs +++ b/Sources/BowlingMaping/EquipeDbDataManager.cs @@ -3,6 +3,7 @@ using BowlingEF.Context; using BowlingEF.Entities; using BowlingLib.Model; using Business; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -14,7 +15,7 @@ namespace BowlingMaping public class EquipeDbDataManager : IDataManager { #region Méthodes - public bool Add(Equipe _equipe) + public async Task Add(Equipe _equipe) { bool result = false; using (var context = new BowlingContext()) @@ -30,62 +31,62 @@ namespace BowlingMaping }).ToList() }; context.Equipes.Add(entity); - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } return result; } - public bool Delete(Equipe _equipe) + public async Task Delete(Equipe _equipe) { bool result = false; using (var context = new BowlingContext()) { EquipeEntity entity = context.Equipes.Find(_equipe.Id); context.Equipes.Remove(entity); - result = context.SaveChanges() == 1; + result =await context.SaveChangesAsync() == 1; } return result; } - public IEnumerable GetAll() + public async Task> GetAll() { using (var context = new BowlingContext()) { - return context.Equipes.Select(e => new Equipe + return await context.Equipes.Select(e => new Equipe ( e.Id, e.Nom, e.Joueurs.Select(j => new Joueur(j.Id, j.Pseudo)).ToArray() - )).ToList(); + )).ToListAsync(); } } - public Equipe GetDataWithName(string name) + public async Task GetDataWithName(string name) { using (var context = new BowlingContext()) { - return context.Equipes.Where(e => e.Nom == name).Select(e => new Equipe + return await context.Equipes.Where(e => e.Nom == name).Select(e => new Equipe ( e.Id, e.Nom, e.Joueurs.Select(j => new Joueur(j.Id, j.Pseudo)).ToArray() - )).FirstOrDefault(); + )).FirstOrDefaultAsync(); } } - public bool Update(Equipe data) + public async Task< bool> Update(Equipe data) { bool result = false; using (var context = new BowlingContext()) { - EquipeEntity entity = context.Equipes.Find(data.Id); + EquipeEntity entity = context.Equipes.Find(data.Id); entity.Nom = data.Nom; entity.Joueurs = data.Joueurs.Select(j => new JoueurEntity { Id = j.Id, Pseudo = j.Pseudo }).ToList(); - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } return result; } diff --git a/Sources/BowlingMaping/JoueurDbDataManager.cs b/Sources/BowlingMaping/JoueurDbDataManager.cs index fea1f31..fc90c5c 100644 --- a/Sources/BowlingMaping/JoueurDbDataManager.cs +++ b/Sources/BowlingMaping/JoueurDbDataManager.cs @@ -2,6 +2,7 @@ using BowlingEF.Entities; using BowlingLib.Model; using Business; +using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; @@ -21,7 +22,7 @@ namespace BowlingMaping /// /// /// - public bool Add(Joueur _joueur) + public async Task Add(Joueur _joueur) { bool result = false; using (var context = new BowlingContext()) @@ -32,7 +33,7 @@ namespace BowlingMaping Pseudo = _joueur.Pseudo, }; context.Joueurs.Add(entity); - result = context.SaveChanges() == 1; + result =await context.SaveChangesAsync() == 1; } return result; } @@ -42,7 +43,7 @@ namespace BowlingMaping /// /// /// - public bool Delete(Joueur _joueur) + public async Task< bool> Delete(Joueur _joueur) { bool result = false; @@ -52,7 +53,7 @@ namespace BowlingMaping { JoueurEntity entity = context.Joueurs.Find(_joueur.Id); context.Joueurs.Remove(entity); - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } return result; @@ -64,12 +65,12 @@ namespace BowlingMaping /// recupère tous les joueurs de la Base de données /// /// - public IEnumerable GetAll() + public async Task< IEnumerable >GetAll() { using (var context = new BowlingContext()) { - List joueurs = new List(); - foreach (var item in context.Joueurs) + List joueurs = new List(); + foreach (var item in await context.Joueurs.ToListAsync()) joueurs.Add(new Joueur(item.Id, item.Pseudo)); return joueurs; } @@ -80,22 +81,19 @@ namespace BowlingMaping /// /// /// - public Joueur GetDataWithName(string name) + public async Task GetDataWithName(string name) { using (var context = new BowlingContext()) { Joueur _joueur = null; - - var query = from joueur in context.Joueurs - where joueur.Pseudo == name - select joueur; - foreach (var item in query) - _joueur = new Joueur(item.Id, item.Pseudo); + + var query = await context.Joueurs.FirstOrDefaultAsync(n => n.Pseudo == n.Pseudo); + _joueur = new Joueur(query.Id, query.Pseudo); return _joueur; } } - public bool Update(Joueur _joueur) + public async Task Update(Joueur _joueur) { bool result = false; using (var context = new BowlingContext()) @@ -104,7 +102,7 @@ namespace BowlingMaping if (entity!=null) { entity.Pseudo = _joueur.Pseudo; - result = context.SaveChanges() == 1; + result = await context.SaveChangesAsync() == 1; } } return result; From 24c633622ba58914ea8ef4ef39e50fd7bbf9f81d Mon Sep 17 00:00:00 2001 From: Arafamamadouelaphi <92931011+Arafamamadouelaphi@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:35:11 +0100 Subject: [PATCH 4/5] AsyncAwait #63 --- Sources/BowlingMaping/JoueurDbDataManager.cs | 2 +- Sources/BowlingMaping/PartieDbDataManager.cs | 1 + Sources/BowlingStub/StubEquipe.cs | 12 +++++------ Sources/BowlingStub/StubJoueur.cs | 16 +++++++-------- Sources/BowlingStub/StubPartie.cs | 14 ++++++------- Sources/Tests/BowlingAppUnitTest/UTManager.cs | 20 ++----------------- 6 files changed, 25 insertions(+), 40 deletions(-) diff --git a/Sources/BowlingMaping/JoueurDbDataManager.cs b/Sources/BowlingMaping/JoueurDbDataManager.cs index fc90c5c..92ab7f2 100644 --- a/Sources/BowlingMaping/JoueurDbDataManager.cs +++ b/Sources/BowlingMaping/JoueurDbDataManager.cs @@ -65,7 +65,7 @@ namespace BowlingMaping /// recupère tous les joueurs de la Base de données /// /// - public async Task< IEnumerable >GetAll() + public async Task> GetAll() { using (var context = new BowlingContext()) { diff --git a/Sources/BowlingMaping/PartieDbDataManager.cs b/Sources/BowlingMaping/PartieDbDataManager.cs index 782f009..4934ccc 100644 --- a/Sources/BowlingMaping/PartieDbDataManager.cs +++ b/Sources/BowlingMaping/PartieDbDataManager.cs @@ -133,6 +133,7 @@ namespace BowlingMaping List result = new List(); using (var context = new BowlingContext()) { + var query = context.Parties.Where(item => item.Date == date); foreach (PartieEntity entity in await context.Parties.ToListAsync()) { if (entity.Date.Date == date.Date) diff --git a/Sources/BowlingStub/StubEquipe.cs b/Sources/BowlingStub/StubEquipe.cs index 565e3e7..52ca6ea 100644 --- a/Sources/BowlingStub/StubEquipe.cs +++ b/Sources/BowlingStub/StubEquipe.cs @@ -13,7 +13,7 @@ namespace BowlingStub } - public bool Add(Equipe data) + public async Task Add(Equipe data) { if (data != null) { @@ -23,7 +23,7 @@ namespace BowlingStub return false; } - public bool Delete(Equipe data) + public async Task Delete(Equipe data) { if (data != null) { @@ -48,7 +48,7 @@ namespace BowlingStub } - public IEnumerable GetAll() + public async Task> GetAll() { Load(); return listEquipes; @@ -56,7 +56,7 @@ namespace BowlingStub //mise à jour d'une équipe - public bool Update(Equipe data) + public async Task Update(Equipe data) { if (data != null) { @@ -70,12 +70,12 @@ namespace BowlingStub } - public Equipe GetDataWithName(string name) + public async Task GetDataWithName(string name) { throw new NotImplementedException(); } - public IEnumerable GetAllWithDate(DateTime date) + public async Task> GetAllWithDate(DateTime date) { throw new NotImplementedException(); } diff --git a/Sources/BowlingStub/StubJoueur.cs b/Sources/BowlingStub/StubJoueur.cs index 72e96fd..89b787f 100644 --- a/Sources/BowlingStub/StubJoueur.cs +++ b/Sources/BowlingStub/StubJoueur.cs @@ -10,7 +10,7 @@ namespace BowlingStub private List listJoueurs = new List(); - public bool Add(Joueur data) + public async Task Add(Joueur data) { if (data != null) { @@ -20,22 +20,22 @@ namespace BowlingStub return false; } - public bool Delete(Joueur data) + public async Task Delete(Joueur data) { if (data != null) { listJoueurs.Remove(data); - return true; + return true; } return false; } - public IEnumerable GetAll() + public async Task> GetAll() { return listJoueurs; } //n represente le nbr de joueurs a creer dans la liste - public IEnumerable GetAllJoueur(int n = 10) + public async Task >GetAllJoueur(int n = 10) { for (int i = 0; i < n; i++) { @@ -44,17 +44,17 @@ namespace BowlingStub return listJoueurs; } ///ged - public Joueur GetDataWithId(int id) + public async TaskGetDataWithId (int id) { throw new NotImplementedException(); } - public Joueur GetDataWithName(string name) + public async Task GetDataWithName(string name) { throw new NotImplementedException(); }// - public bool Update(Joueur data) + public async Task Update(Joueur data) { if (data != null) { diff --git a/Sources/BowlingStub/StubPartie.cs b/Sources/BowlingStub/StubPartie.cs index 9adf8d8..3cb2977 100644 --- a/Sources/BowlingStub/StubPartie.cs +++ b/Sources/BowlingStub/StubPartie.cs @@ -7,7 +7,7 @@ namespace BowlingStub { private List listParties = new List(); - public bool Add(Partie data) + public async Task Add(Partie data) { if (data != null) { @@ -17,7 +17,7 @@ namespace BowlingStub return false; } - public bool Delete(Partie data) + public async Task Delete(Partie data) { if (data != null) { @@ -27,7 +27,7 @@ namespace BowlingStub return false; } - public IEnumerable GetAll() + public async Task> GetAll() { return listParties; } @@ -42,22 +42,22 @@ namespace BowlingStub } //GDW? - public Partie GetDataWithId(int id) + public async Task GetDataWithId(int id) { throw new NotImplementedException(); } - public Partie GetDataWithName(string name) + public async Task GetDataWithName(string name) { throw new NotImplementedException(); } - public bool Update(Partie data) + public async Task Update(Partie data) { if (data != null) { - int index = listParties.FindIndex(x => x.Id == data.Id); + int index = listParties. FindIndex(x => x.Id == data.Id); listParties[index] = data; } return false; diff --git a/Sources/Tests/BowlingAppUnitTest/UTManager.cs b/Sources/Tests/BowlingAppUnitTest/UTManager.cs index 7142db8..78ec9f6 100644 --- a/Sources/Tests/BowlingAppUnitTest/UTManager.cs +++ b/Sources/Tests/BowlingAppUnitTest/UTManager.cs @@ -24,7 +24,7 @@ namespace BowlingAppUnitTest manager.AddJoueur(joueur); //Assert - Assert.Single(manager.JoueurDataManager.GetAll()); + Assert.Single(manager.JoueurDataManager.GetAll().Result); } //Test de la méthode AddPartie @@ -39,25 +39,9 @@ namespace BowlingAppUnitTest manager.AddPartie(partie); //Assert - Assert.Single(manager.PartieDataManager.GetAll()); + Assert.Single(manager.PartieDataManager.GetAll().Result); } - //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()); - //} - } } From 7fd34380ea7789ab448769fc0b4cec1228e55255 Mon Sep 17 00:00:00 2001 From: Arafamamadouelaphi <92931011+Arafamamadouelaphi@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:35:11 +0100 Subject: [PATCH 5/5] stubequipeAsyncAwait --- Sources/BowlingStub/StubJoueur.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/BowlingStub/StubJoueur.cs b/Sources/BowlingStub/StubJoueur.cs index 72e96fd..89b787f 100644 --- a/Sources/BowlingStub/StubJoueur.cs +++ b/Sources/BowlingStub/StubJoueur.cs @@ -10,7 +10,7 @@ namespace BowlingStub private List listJoueurs = new List(); - public bool Add(Joueur data) + public async Task Add(Joueur data) { if (data != null) { @@ -20,22 +20,22 @@ namespace BowlingStub return false; } - public bool Delete(Joueur data) + public async Task Delete(Joueur data) { if (data != null) { listJoueurs.Remove(data); - return true; + return true; } return false; } - public IEnumerable GetAll() + public async Task> GetAll() { return listJoueurs; } //n represente le nbr de joueurs a creer dans la liste - public IEnumerable GetAllJoueur(int n = 10) + public async Task >GetAllJoueur(int n = 10) { for (int i = 0; i < n; i++) { @@ -44,17 +44,17 @@ namespace BowlingStub return listJoueurs; } ///ged - public Joueur GetDataWithId(int id) + public async TaskGetDataWithId (int id) { throw new NotImplementedException(); } - public Joueur GetDataWithName(string name) + public async Task GetDataWithName(string name) { throw new NotImplementedException(); }// - public bool Update(Joueur data) + public async Task Update(Joueur data) { if (data != null) {