From 1f3ae5657118ff73eabcb50c87a5495ba0f1e935 Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Fri, 7 Jun 2024 11:51:28 +0200 Subject: [PATCH] Documentation des unit testing --- Sources/UnitTesting/CodeUT.cs | 63 ++++++++++++ Sources/UnitTesting/JetonUT.cs | 15 ++- Sources/UnitTesting/JoueurUT.cs | 79 ++++++++++----- Sources/UnitTesting/ManageurUT.cs | 78 +++++++++++---- Sources/UnitTesting/PartieUT.cs | 114 ++++++++++++++++------ Sources/UnitTesting/PlateauUT.cs | 89 ++++++++++++----- Sources/UnitTesting/ReglesClassiquesUT.cs | 6 ++ Sources/UnitTesting/ReglesDifficilesUT.cs | 8 +- 8 files changed, 346 insertions(+), 106 deletions(-) diff --git a/Sources/UnitTesting/CodeUT.cs b/Sources/UnitTesting/CodeUT.cs index 0109ac8..3b44478 100644 --- a/Sources/UnitTesting/CodeUT.cs +++ b/Sources/UnitTesting/CodeUT.cs @@ -5,8 +5,14 @@ using Xunit; namespace UnitTesting { + /// + /// + /// public class CodeUT { + /// + /// + /// [Fact] public void TestPremierConstructeurValide() { @@ -18,12 +24,18 @@ namespace UnitTesting Assert.True(code.Vide); } + /// + /// + /// [Fact] public void TestPremierConstructeurInvalide() { Assert.Throws(() => new Code(-1)); } + /// + /// + /// [Fact] public void TestAjouterJetonValide() { @@ -34,6 +46,9 @@ namespace UnitTesting Assert.Equal(jeton, code.Jetons.ElementAt(0)); } + /// + /// + /// [Fact] public void TestAjouterJetonInvalide() { @@ -45,6 +60,9 @@ namespace UnitTesting Assert.Throws(() => code.AjouterJeton(new Jeton(Couleur.Rouge))); } + /// + /// + /// [Fact] public void TestSupprimerDernierJetonValide() { @@ -57,6 +75,9 @@ namespace UnitTesting Assert.Equal(2, code.Taille); } + /// + /// + /// [Fact] public void TestSupprimerDernierJetonInvalide() { @@ -64,6 +85,9 @@ namespace UnitTesting Assert.Throws(() => code.SupprimerDernierJeton()); } + /// + /// + /// [Fact] public void TestRecupererJetonValide() { @@ -77,6 +101,9 @@ namespace UnitTesting Assert.Equal(jetonAttendu.Couleur, jeton.Couleur); } + /// + /// + /// [Fact] public void TestRecupererJetonInvalide() { @@ -85,6 +112,9 @@ namespace UnitTesting Assert.Throws(() => code.RecupererJeton(4)); } + /// + /// + /// [Fact] public void TestRecupererJetonNull() { @@ -92,6 +122,9 @@ namespace UnitTesting Assert.Throws(() => code.RecupererJeton(1)); } + /// + /// + /// [Fact] public void TestJetonsValide() { @@ -112,6 +145,9 @@ namespace UnitTesting } } + /// + /// + /// [Fact] public void TestEstCompletValide() { @@ -124,6 +160,9 @@ namespace UnitTesting Assert.True(estComplet); } + /// + /// + /// [Fact] public void TestEstCompletInvalide() { @@ -132,6 +171,9 @@ namespace UnitTesting Assert.False(estComplet); } + /// + /// + /// [Fact] public void TestTailleMaximaleValide() { @@ -145,6 +187,9 @@ namespace UnitTesting Assert.Equal(jetons.Length, tailleMaximale); } + /// + /// + /// [Fact] public void TestComparerValide() { @@ -165,6 +210,9 @@ namespace UnitTesting Assert.Equal(3, indicateurs.Count); } + /// + /// + /// [Fact] public void TestComparerDifferent() { @@ -185,6 +233,9 @@ namespace UnitTesting Assert.Empty(indicateurs); } + /// + /// + /// [Fact] public void TestComparerMonCodeIncomplet() { @@ -201,6 +252,9 @@ namespace UnitTesting Assert.Empty(indicateurs); } + /// + /// + /// [Fact] public void TestComparerSonCodeIncomplet() { @@ -215,6 +269,9 @@ namespace UnitTesting Assert.Throws(() => code1.Comparer(code2)); } + /// + /// + /// [Fact] public void TestToString() { @@ -227,6 +284,9 @@ namespace UnitTesting Assert.Equal("Code(1)", code.ToString()); } + /// + /// + /// [Fact] public void TestComparerCodeInvalide() { @@ -239,6 +299,9 @@ namespace UnitTesting Assert.Throws(() => code.Comparer(code1)); } + /// + /// + /// [Fact] public void TestComparerCodeCorrect() { diff --git a/Sources/UnitTesting/JetonUT.cs b/Sources/UnitTesting/JetonUT.cs index f55fc8c..7fd6d03 100644 --- a/Sources/UnitTesting/JetonUT.cs +++ b/Sources/UnitTesting/JetonUT.cs @@ -3,8 +3,14 @@ using Xunit; namespace UnitTesting { + /// + /// + /// public class JetonUT - { + { + /// + /// + /// [Fact] public void TestConstructeurValide() { @@ -15,8 +21,11 @@ namespace UnitTesting Jeton jeton = new Jeton(listeCouleurs[i]); Assert.Equal(listeCouleurs[i], jeton.Couleur); } - } - + } + + /// + /// + /// [Fact] public void TestEquals() { diff --git a/Sources/UnitTesting/JoueurUT.cs b/Sources/UnitTesting/JoueurUT.cs index 882ee18..864a822 100644 --- a/Sources/UnitTesting/JoueurUT.cs +++ b/Sources/UnitTesting/JoueurUT.cs @@ -9,8 +9,14 @@ using Xunit; namespace UnitTesting { + /// + /// + /// public class JoueurUT - { + { + /// + /// + /// [Fact] public void TestConstructeur1Valide() { @@ -20,9 +26,11 @@ namespace UnitTesting Assert.Equal(nom, joueur.Nom); - } - - + } + + /// + /// + /// [Fact] public void TestConstructeur2Valide() { @@ -32,8 +40,11 @@ namespace UnitTesting Assert.Equal(nom, joueur.Nom); - } - + } + + /// + /// + /// [Fact] public void TestQuandJoueurSeConnecter() { @@ -54,8 +65,11 @@ namespace UnitTesting Assert.True(eventTriggered); Assert.NotNull(eventArgs); Assert.Equal(joueur2, eventArgs?.Joueur); - } - + } + + /// + /// + /// [Fact] public void TestSeConnecterDeclencheEvenement() { @@ -75,8 +89,11 @@ namespace UnitTesting Assert.True(eventTriggered); Assert.NotNull(eventArgs); Assert.Equal(joueur2, eventArgs?.Joueur); - } - + } + + /// + /// + /// [Fact] public void TestSeConnecterThrowException() { @@ -84,8 +101,11 @@ namespace UnitTesting joueur.SeConnecter(joueur); Assert.Throws(() => joueur.SeConnecter(joueur)); - } - + } + + /// + /// + /// [Fact] public void TestToStringValide() { @@ -93,8 +113,11 @@ namespace UnitTesting Joueur joueur = new Joueur(nom); string result = joueur.ToString(); Assert.Equal(nom, result); - } - + } + + /// + /// + /// [Fact] public void TestToStringVide() { @@ -102,8 +125,11 @@ namespace UnitTesting string result = joueur.ToString(); Assert.Equal("", result); - } - + } + + /// + /// + /// [Fact] public void TestStatistiqueNonDefinie() { @@ -114,8 +140,11 @@ namespace UnitTesting double result = joueur.Statistique(regles, statistique); Assert.Equal(0, result); - } - + } + + /// + /// + /// [Fact] public void TestStatistiqueDefinie() { @@ -127,8 +156,11 @@ namespace UnitTesting double result = joueur.Statistique(regles, statistique); Assert.Equal(1, result); - } - + } + + /// + /// + /// [Fact] public void TestIncrementerStatistiqueUn() { @@ -140,8 +172,11 @@ namespace UnitTesting double result = joueur.Statistique(regles, statistique); Assert.Equal(1, result); - } - + } + + /// + /// + /// [Fact] public void TestIncrementerStatistiqueDeux() { diff --git a/Sources/UnitTesting/ManageurUT.cs b/Sources/UnitTesting/ManageurUT.cs index 0e6443d..a24e089 100644 --- a/Sources/UnitTesting/ManageurUT.cs +++ b/Sources/UnitTesting/ManageurUT.cs @@ -11,8 +11,14 @@ using Xunit; namespace UnitTesting { + /// + /// Classe test pour la classe Manageur. + /// public class ManageurUT - { + { + /// + /// Test le constructeur de Manageur. + /// [Fact] public void TestConstruteur() { @@ -27,8 +33,11 @@ namespace UnitTesting Assert.NotNull(manageur.PartiesNonTerminees); Assert.NotEmpty(manageur.Joueurs); - } - + } + + /// + /// Test la méthode Sauvegarder d'une partie. + /// [Fact] public void TestSauvegarder() { @@ -38,8 +47,11 @@ namespace UnitTesting MethodInfo? infosMethode = typeof(Manageur).GetMethod("Sauvegarder", BindingFlags.NonPublic | BindingFlags.Instance); Assert.NotNull(infosMethode); infosMethode.Invoke(manageur, []); - } - + } + + /// + /// Test la méthode ChargerPartie qui charge une partie. + /// [Fact] public void TestChargerPartie() { @@ -55,8 +67,11 @@ namespace UnitTesting Assert.Contains(nouvellePartie, manageur.Parties); Assert.Contains(nouvellePartie, manageur.PartiesNonTerminees); - } - + } + + /// + /// Test la méthode NouvellePartie de Manageur. + /// [Fact] public void TestNouvellePartie() { @@ -67,8 +82,11 @@ namespace UnitTesting Assert.Contains(nouvellePartie, manageur.Parties); Assert.Contains(nouvellePartie, manageur.PartiesNonTerminees); - } - + } + + /// + /// Premier test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie() { @@ -154,8 +172,11 @@ namespace UnitTesting Assert.NotEmpty(PartieDemanderJoueurJouer.GetInvocationList()); Assert.NotEmpty(PartiePasserLaMain.GetInvocationList()); Assert.NotEmpty(PartiePartieTerminee.GetInvocationList()); - } - + } + + /// + /// Deuxième test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie2() { @@ -203,8 +224,11 @@ namespace UnitTesting Assert.Equal(1, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue)); - } - + } + + /// + /// Troisième test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie3() { @@ -252,8 +276,11 @@ namespace UnitTesting Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite)); Assert.Equal(1, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue)); - } - + } + + /// + /// Quatrième test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie4() { @@ -301,8 +328,11 @@ namespace UnitTesting Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee)); Assert.Equal(1, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue)); - } - + } + + /// + /// Cinquième test de la méthode EcouterPartie de Manageur. + /// [Fact] public void TestEcouterPartie5() { @@ -350,8 +380,11 @@ namespace UnitTesting Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee)); Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite)); Assert.Equal(1, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue)); - } - + } + + /// + /// Test de la méthode DemanderJoueurExistant de Manageur. + /// [Fact] public void TestDemanderJoueurExistant() { @@ -367,8 +400,11 @@ namespace UnitTesting object? toto = infosMethode.Invoke(manageur, ["Toto"]); Assert.Null(toto); - } - + } + + /// + /// Test de la méthode DemanderJoueur de Manageur. + /// [Fact] public void TestDemanderJoueur() { diff --git a/Sources/UnitTesting/PartieUT.cs b/Sources/UnitTesting/PartieUT.cs index dadbae8..3b86a0f 100644 --- a/Sources/UnitTesting/PartieUT.cs +++ b/Sources/UnitTesting/PartieUT.cs @@ -15,18 +15,26 @@ using Xunit.Abstractions; namespace UnitTesting { + /// + /// Classe test pour la classe Partie. + /// public class PartieUT - { + { + /// + /// Test le premier constructeur de Partie valide. + /// [Fact] - public void TestPremierConstructeurValide() { IRegles regle = new ReglesClassiques(); Partie partie = new Partie(regle); Assert.Equal(regle, partie.Regles); - } - + } + + /// + /// Test le deuxième constructeur de Partie valide. + /// [Fact] public void TestSecondConstructeurValide() { @@ -111,8 +119,11 @@ namespace UnitTesting } } - } - + } + + /// + /// Test la méthode JouerDemanderJoueur de Partie. + /// [Fact] public void TestJouerDemanderJouer() { @@ -133,8 +144,11 @@ namespace UnitTesting partie.Jouer(); Assert.True(demanderJoueurCalled); } - } - + } + + /// + /// Test la méthode JouerDebutPartie de Partie. + /// [Fact] public void TestJouerDebutPartie() { @@ -156,8 +170,11 @@ namespace UnitTesting partie.Jouer(); Assert.True(debutPartieCalled); } - } - + } + + /// + /// Test la méthode DemanderJoueur de Partie. + /// [Fact] public void TestDemanderJoueur() { @@ -182,8 +199,11 @@ namespace UnitTesting joueurDemande.SeConnecter(joueurDemande); Assert.True(joueurConnecteCalled); } - } - + } + + /// + /// Test l'événement JoueurSeConnecterEventArgs de Partie. + /// [Fact] public void TestJoueurConnecte() { @@ -254,8 +274,11 @@ namespace UnitTesting Assert.Equal(1, tour); } } - } - + } + + /// + /// Test l'exception JoueurDejaPresentException de Partie. + /// [Fact] public void TestJoueurConnecteDejaPresent() { @@ -277,8 +300,11 @@ namespace UnitTesting partie.Jouer(); Assert.True(appelee); - } - + } + + /// + /// Test l'exception NomJoueurInterditException de Partie. + /// [Fact] public void TestJoueurConnecteNomInterdit() { @@ -297,8 +323,11 @@ namespace UnitTesting partie.Jouer(); Assert.True(appelee); - } - + } + + /// + /// Test la création d'un robot. + /// [Fact] public void TestRobot() { @@ -316,8 +345,11 @@ namespace UnitTesting partie.Jouer(); Assert.NotEmpty(partie.Robots); - } - + } + + /// + /// Test la méthode DebutPartie de Partie. + /// [Fact] public void TestDebutPartie() { @@ -366,8 +398,11 @@ namespace UnitTesting } } } - } - + } + + /// + /// Test la méthode NouveauTour de Partie. + /// [Fact] public void TestNouveauTour() { @@ -404,8 +439,11 @@ namespace UnitTesting Assert.True(demanderJoueurJouerEventTriggered); Assert.True(nouveauTourEventTriggered); - } - + } + + /// + /// Test la méthode AjouterCode de Partie et vérifie qu'il y a eu une incrémentation pour le nombre de tour. + /// [Fact] public void TestPlateauAjouterCodeIncrementation() { @@ -456,8 +494,11 @@ namespace UnitTesting Assert.Equal(1, partie.Tour); } - } - + } + + /// + /// Test la méthode AjouterCode de Partie et vérifie que la partie est terminée. + /// [Fact] public void PlateauAjouterCodeTerminee() { @@ -496,8 +537,11 @@ namespace UnitTesting Assert.True(partie.Termine); } } - } - + } + + /// + /// Test la méthode PartieTerminee de Partie et vérifie les gagnants et perdants. + /// [Fact] public void TestPartieTerminee() { @@ -539,8 +583,11 @@ namespace UnitTesting } } - } - + } + + /// + /// Test tous les événements de Partie. + /// [Fact] public void TestPartieEcoute() { @@ -608,8 +655,11 @@ namespace UnitTesting Assert.True(appel4); Assert.True(appel5); Assert.True(appel6); - } - + } + + /// + /// Test la méthode AjouterCode de Partie avec toutes ses composantes et les différentes fin. + /// [Fact] public void TestPartiePlateauAjouterCode() { diff --git a/Sources/UnitTesting/PlateauUT.cs b/Sources/UnitTesting/PlateauUT.cs index 1bb2469..340ba81 100644 --- a/Sources/UnitTesting/PlateauUT.cs +++ b/Sources/UnitTesting/PlateauUT.cs @@ -8,23 +8,35 @@ using CoreLibrary; namespace UnitTesting { + /// + /// Classe test pour la classe Plateau. + /// public class PlateauUT - { + { + /// + /// Test que le constructeur de Plateau soit valide. + /// [Fact] public void TestConstructeurValide() { Plateau plateau = new Plateau(4,12); Assert.NotNull(plateau); Assert.False(plateau.Victoire); - } - + } + + /// + /// Test que le constructeur de Plateau soit invalide. + /// [Fact] public void TestConstructeurInvalide() { Assert.Throws(() => new Plateau(-1, 10)); Assert.Throws(() => new Plateau(3, -1)); - } - + } + + /// + /// Test la méthode EstComplet de Plateau et vérifie qu'il renvoie True. + /// [Fact] public void TestEstCompletTrue() { @@ -42,8 +54,11 @@ namespace UnitTesting bool estComplet = plateau.Complet; Assert.True(estComplet); - } - + } + + /// + /// Test la méthode EstComplet de Plateau et vérifie qu'il renvoie False. + /// [Fact] public void TestEstCompletFalse() { @@ -57,13 +72,14 @@ namespace UnitTesting plateau.AjouterCode(code); plateau.AjouterCode(code); - - bool estComplet = plateau.Complet; Assert.False(estComplet); - } - + } + + /// + /// Test l'exception CodeCompletException de Plateau avec une taille de code supérieure à ce qui est défini. + /// [Fact] public void TestAjouterCodeTailleIncorrecte() { @@ -83,8 +99,11 @@ namespace UnitTesting Assert.Throws(() => code.AjouterJeton(new Jeton(Couleur.Bleu))); - } - + } + + /// + /// Test l'exception CodeIncompletException de Plateau avec un code incomplet. + /// [Fact] public void TestAjouterCodeIncomplet() { @@ -92,8 +111,11 @@ namespace UnitTesting Code code = new Code(4); Assert.Throws(() => plateau.AjouterCode(code)); - } - + } + + /// + /// Test la méthode AjouterCode de Plateau avec un bon code. + /// [Fact] public void TestAjouterCodeBonCode() { @@ -109,8 +131,11 @@ namespace UnitTesting Assert.NotNull(codeSecret); plateau.AjouterCode(codeSecret); Assert.True(plateau.Victoire); - } - + } + + /// + /// Test la méthode AjouterCode de Plateau et vérifie la grille et ses composants. + /// [Fact] public void TestGrilleAjouterCode() { @@ -139,8 +164,11 @@ namespace UnitTesting Assert.Equal(4, jetonsGrille.First().Count()); Assert.Single(indicateurs); - } - + } + + /// + /// Test que la grille du plateau est vide. + /// [Fact] public void TestGrilleEstVide() { @@ -151,8 +179,11 @@ namespace UnitTesting Assert.Empty(jetons); Assert.Empty(indicateurs); - } - + } + + /// + /// Test l'exception GrilleCompleteException de Plateau. + /// [Fact] public void TestAjouterCode_GrilleComplete_ThrowsGrilleCompleteException() { @@ -178,9 +209,11 @@ namespace UnitTesting plateau.AjouterCode(codeComplet2); Assert.Throws(() => plateau.AjouterCode(codeComplet3)); - } - - + } + + /// + /// Test l'événement QuandPlateauAjouterCode de Plateau. + /// [Fact] public void TestPlateauEcoute() { @@ -198,9 +231,11 @@ namespace UnitTesting QuandPlateauAjouterCodeInfo?.Invoke(plateau, []); Assert.True(appel); - } - - + } + + /// + /// Test la méthode AjouterCode de Plateau et vérifie tous les cas d'arrêts. + /// [Fact] public void TestAjouterCodeVictoire() { diff --git a/Sources/UnitTesting/ReglesClassiquesUT.cs b/Sources/UnitTesting/ReglesClassiquesUT.cs index 3a3606d..2ddf292 100644 --- a/Sources/UnitTesting/ReglesClassiquesUT.cs +++ b/Sources/UnitTesting/ReglesClassiquesUT.cs @@ -3,8 +3,14 @@ using Xunit; namespace UnitTesting { + /// + /// Classe de test pour la classe ReglesClassiques. + /// public class ReglesClassiquesUT { + /// + /// Test les attributs de ReglesClassiques et vérifie qu'ils soient égaux. + /// [Fact] public void Test() { diff --git a/Sources/UnitTesting/ReglesDifficilesUT.cs b/Sources/UnitTesting/ReglesDifficilesUT.cs index 52c4357..64cf2e3 100644 --- a/Sources/UnitTesting/ReglesDifficilesUT.cs +++ b/Sources/UnitTesting/ReglesDifficilesUT.cs @@ -3,8 +3,14 @@ using Xunit; namespace UnitTesting { + /// + /// Classe de test pour la classe ReglesDifficiles. + /// public class ReglesDifficilesUT - { + { + /// + /// Test les attributs de ReglesDifficiles et vérifie qu'ils soient égaux. + /// [Fact] public void Test() {