Test Partie
continuous-integration/drone/push Build is passing Details

master
Camille TURPIN-ETIENNE 11 months ago
parent 0e99108b0c
commit 6a80ecdb75

@ -60,7 +60,7 @@ namespace CoreLibrary.Joueurs
{
if (EstConnecte)
throw new JoueurDejaConnecteException(this);
EstConnecte = true;
QuandJoueurSeConnecter(joueur);
}

@ -100,10 +100,10 @@ namespace UnitTesting
[Fact]
public void TestToStringValide()
{
Joueur joueur = new Joueur("Joueur");
string nom = "Joueur";
Joueur joueur = new Joueur(nom);
string result = joueur.ToString();
Assert.Equal("Joueur1", result);
Assert.Equal(nom, result);
}
[Fact]

@ -273,10 +273,6 @@ namespace UnitTesting
MethodInfo? methodInfo = typeof(Partie).GetMethod("DebutPartie", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo?.Invoke(partie, null);
PropertyInfo? tourProperty = typeof(Partie).GetProperty("Tour", BindingFlags.Public | BindingFlags.Instance);
Assert.NotNull(tourProperty);
if (tourProperty != null)
@ -305,5 +301,179 @@ namespace UnitTesting
}
}
}
[Fact]
public void TestNouveauTour()
{
IRegles regle = new ReglesClassiques();
Partie partie = new Partie(regle);
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo? plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
if (joueursField != null && plateauxField != null)
{
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
if (joueurs != null && plateaux != null)
{
joueurs.Add("Joueur10", false);
joueurs.Add("Joueur50", false);
plateaux.Add(new Plateau(regle.TailleCode, regle.NbTour));
plateaux.Add(new Plateau(regle.TailleCode, regle.NbTour));
}
}
bool demanderJoueurJouerEventTriggered = false;
bool nouveauTourEventTriggered = false;
partie.PartieDemanderJoueurJouer += (sender, e) => demanderJoueurJouerEventTriggered = true;
partie.PartieNouveauTour += (sender, e) => nouveauTourEventTriggered = true;
MethodInfo? methodInfo = typeof(Partie).GetMethod("NouveauTour", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo?.Invoke(partie, null);
Assert.True(demanderJoueurJouerEventTriggered);
Assert.True(nouveauTourEventTriggered);
}
[Fact]
public void TestPlateauAjouterCodeIncrementation()
{
IRegles regle = new ReglesClassiques();
Partie partie = new Partie(regle);
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo? plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
if (joueursField != null && plateauxField != null)
{
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
if (joueurs != null && plateaux != null)
{
joueurs.Add("Joueur1", false);
joueurs.Add("Joueur2", false);
plateaux.Add(new Plateau(regle.TailleCode, regle.NbTour));
plateaux.Add(new Plateau(regle.TailleCode, regle.NbTour));
}
}
Plateau plateau = new Plateau(regle.TailleCode, regle.NbTour);
PlateauAjouterCodeEventArgs eventArgs = new PlateauAjouterCodeEventArgs(plateau);
MethodInfo? methodInfo = typeof(Partie).GetMethod("PlateauAjouterCode", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo?.Invoke(partie, new object?[] { null, eventArgs });
FieldInfo? courantField = typeof(Partie).GetField("courant", BindingFlags.NonPublic | BindingFlags.Instance);
if(courantField != null)
{
int? courant = ((int?)courantField.GetValue(partie)).GetValueOrDefault();
Assert.Equal(1, courant);
Assert.Equal(0, partie.Tour);
}
methodInfo?.Invoke(partie, new object?[] { null, eventArgs });
if(courantField != null)
{
int courant2 = ((int?)courantField.GetValue(partie)).GetValueOrDefault();
Assert.Equal(0, courant2);
Assert.Equal(1, partie.Tour);
}
}
[Fact]
public void PlateauAjouterCodeTerminee()
{
IRegles regle = new ReglesClassiques();
Partie partie = new Partie(regle);
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo? plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
Plateau plateau = new Plateau(regle.TailleCode, regle.NbTour);
if (joueursField != null && plateauxField != null)
{
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
if (joueurs != null && plateaux != null)
{
joueurs.Add("Joueur1", false);
joueurs.Add("Joueur2", false);
plateaux.Add(plateau);
plateaux.Add(plateau);
PropertyInfo? victoireProperty = typeof(Plateau).GetProperty("Victoire");
if (victoireProperty != null)
{
victoireProperty.SetValue(plateau, true);
}
FieldInfo? courantField = typeof(Partie).GetField("courant", BindingFlags.NonPublic | BindingFlags.Instance);
if (courantField != null)
{
courantField.SetValue(partie, 1);
}
PlateauAjouterCodeEventArgs eventArgs = new PlateauAjouterCodeEventArgs(plateau);
MethodInfo? methodInfo = typeof(Partie).GetMethod("PlateauAjouterCode", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo?.Invoke(partie, new object?[] { null, eventArgs });
Assert.True(partie.Termine);
}
}
}
[Fact]
public void TestPartieTerminee()
{
// Création de la partie avec des règles de jeu
IRegles regle = new ReglesClassiques();
Partie partie = new Partie(regle);
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
FieldInfo? plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
Plateau plateau1 = new Plateau(regle.TailleCode, regle.NbTour);
Plateau plateau2 = new Plateau(regle.TailleCode, regle.NbTour);
if (joueursField != null && plateauxField != null)
{
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
if (joueurs != null && plateaux != null)
{
joueurs.Add("Joueur1", false);
joueurs.Add("Joueur2", false);
plateaux.Add(plateau1);
plateaux.Add(plateau2);
PropertyInfo? victoireProperty = typeof(Plateau).GetProperty("Victoire");
if (victoireProperty != null)
{
victoireProperty.SetValue(plateau1, true);
}
MethodInfo? methodInfo = typeof(Partie).GetMethod("PartieTerminee", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo?.Invoke(partie, null);
Assert.True(partie.Termine);
partie.PartiePartieTerminee += (sender, e) =>
{
Assert.True(partie.Termine);
Assert.Contains("Joueur1", e.Gagnants);
Assert.Contains("Joueur2", e.Perdants);
};
}
}
}
}
}

Loading…
Cancel
Save