|
|
@ -9,6 +9,8 @@ using CoreLibrary.Joueurs;
|
|
|
|
using CoreLibrary.Regles;
|
|
|
|
using CoreLibrary.Regles;
|
|
|
|
using CoreLibrary.Evenements;
|
|
|
|
using CoreLibrary.Evenements;
|
|
|
|
using CoreLibrary.Exceptions;
|
|
|
|
using CoreLibrary.Exceptions;
|
|
|
|
|
|
|
|
using System.Diagnostics.Tracing;
|
|
|
|
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace UnitTesting
|
|
|
|
namespace UnitTesting
|
|
|
@ -56,15 +58,15 @@ namespace UnitTesting
|
|
|
|
plateaux.Add(new Plateau(4, 10));
|
|
|
|
plateaux.Add(new Plateau(4, 10));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(tourField != null)
|
|
|
|
|
|
|
|
|
|
|
|
if (tourField != null)
|
|
|
|
tourField.SetValue(partieOriginale, 5);
|
|
|
|
tourField.SetValue(partieOriginale, 5);
|
|
|
|
|
|
|
|
|
|
|
|
if (termineField != null)
|
|
|
|
if (termineField != null)
|
|
|
|
termineField.SetValue(partieOriginale, false);
|
|
|
|
termineField.SetValue(partieOriginale, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var partieCopiee = new Partie(partieOriginale);
|
|
|
|
var partieCopiee = new Partie(partieOriginale);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -107,7 +109,7 @@ namespace UnitTesting
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -118,7 +120,7 @@ namespace UnitTesting
|
|
|
|
Partie partie = new Partie(regle);
|
|
|
|
Partie partie = new Partie(regle);
|
|
|
|
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
|
|
|
if(joueursField != null)
|
|
|
|
if (joueursField != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
|
|
|
|
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
|
|
|
|
if (joueurs != null)
|
|
|
|
if (joueurs != null)
|
|
|
@ -130,7 +132,7 @@ namespace UnitTesting
|
|
|
|
partie.PartieDemanderJoueur += (sender, e) => demanderJoueurCalled = true;
|
|
|
|
partie.PartieDemanderJoueur += (sender, e) => demanderJoueurCalled = true;
|
|
|
|
partie.Jouer();
|
|
|
|
partie.Jouer();
|
|
|
|
Assert.True(demanderJoueurCalled);
|
|
|
|
Assert.True(demanderJoueurCalled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
@ -205,8 +207,8 @@ namespace UnitTesting
|
|
|
|
|
|
|
|
|
|
|
|
if (joueursField != null)
|
|
|
|
if (joueursField != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Dictionary<string,bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
|
|
|
|
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
|
|
|
|
if(joueurs != null)
|
|
|
|
if (joueurs != null)
|
|
|
|
Assert.True(joueurs.ContainsKey(joueur1.Nom));
|
|
|
|
Assert.True(joueurs.ContainsKey(joueur1.Nom));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -214,7 +216,7 @@ namespace UnitTesting
|
|
|
|
if (plateauxField != null)
|
|
|
|
if (plateauxField != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
|
|
|
|
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
|
|
|
|
if(plateaux != null)
|
|
|
|
if (plateaux != null)
|
|
|
|
Assert.Single(plateaux);
|
|
|
|
Assert.Single(plateaux);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -224,15 +226,15 @@ namespace UnitTesting
|
|
|
|
demanderJoueurAppelée = false;
|
|
|
|
demanderJoueurAppelée = false;
|
|
|
|
methodInfo?.Invoke(partie, new object?[] { null, joueur2EventArgs });
|
|
|
|
methodInfo?.Invoke(partie, new object?[] { null, joueur2EventArgs });
|
|
|
|
|
|
|
|
|
|
|
|
if(joueursField != null)
|
|
|
|
if (joueursField != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
|
|
|
|
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
|
|
|
|
if(joueurs != null)
|
|
|
|
if (joueurs != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Assert.Equal(2, joueurs.Count);
|
|
|
|
Assert.Equal(2, joueurs.Count);
|
|
|
|
Assert.True(joueurs.ContainsKey(joueur2.Nom));
|
|
|
|
Assert.True(joueurs.ContainsKey(joueur2.Nom));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (plateauxField != null)
|
|
|
|
if (plateauxField != null)
|
|
|
@ -262,7 +264,8 @@ namespace UnitTesting
|
|
|
|
|
|
|
|
|
|
|
|
bool appelee = false;
|
|
|
|
bool appelee = false;
|
|
|
|
|
|
|
|
|
|
|
|
partie.PartieDemanderJoueur += (sender, e) => {
|
|
|
|
partie.PartieDemanderJoueur += (sender, e) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
appelee = true;
|
|
|
|
appelee = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (e.Indice == 1)
|
|
|
|
if (e.Indice == 1)
|
|
|
@ -284,7 +287,8 @@ namespace UnitTesting
|
|
|
|
|
|
|
|
|
|
|
|
bool appelee = false;
|
|
|
|
bool appelee = false;
|
|
|
|
|
|
|
|
|
|
|
|
partie.PartieDemanderJoueur += (sender, e) => {
|
|
|
|
partie.PartieDemanderJoueur += (sender, e) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
appelee = true;
|
|
|
|
appelee = true;
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Throws<NomJoueurInterditException>(() => e.JoueurDemande.SeConnecter(new Joueur("Robot")));
|
|
|
|
Assert.Throws<NomJoueurInterditException>(() => e.JoueurDemande.SeConnecter(new Joueur("Robot")));
|
|
|
@ -304,7 +308,8 @@ namespace UnitTesting
|
|
|
|
Assert.NotNull(partie.Robots);
|
|
|
|
Assert.NotNull(partie.Robots);
|
|
|
|
Assert.Empty(partie.Robots);
|
|
|
|
Assert.Empty(partie.Robots);
|
|
|
|
|
|
|
|
|
|
|
|
partie.PartieDemanderJoueur += (sender, e) => {
|
|
|
|
partie.PartieDemanderJoueur += (sender, e) =>
|
|
|
|
|
|
|
|
{
|
|
|
|
e.JoueurDemande.SeConnecter(new Robot());
|
|
|
|
e.JoueurDemande.SeConnecter(new Robot());
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -395,10 +400,10 @@ namespace UnitTesting
|
|
|
|
MethodInfo? methodInfo = typeof(Partie).GetMethod("NouveauTour", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
MethodInfo? methodInfo = typeof(Partie).GetMethod("NouveauTour", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
methodInfo?.Invoke(partie, null);
|
|
|
|
methodInfo?.Invoke(partie, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(demanderJoueurJouerEventTriggered);
|
|
|
|
Assert.True(demanderJoueurJouerEventTriggered);
|
|
|
|
Assert.True(nouveauTourEventTriggered);
|
|
|
|
Assert.True(nouveauTourEventTriggered);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
@ -407,7 +412,7 @@ namespace UnitTesting
|
|
|
|
IRegles regle = new ReglesClassiques();
|
|
|
|
IRegles regle = new ReglesClassiques();
|
|
|
|
Partie partie = new Partie(regle);
|
|
|
|
Partie partie = new Partie(regle);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
FieldInfo? plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
FieldInfo? plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
if (joueursField != null && plateauxField != null)
|
|
|
|
if (joueursField != null && plateauxField != null)
|
|
|
@ -423,17 +428,17 @@ namespace UnitTesting
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Plateau plateau = new Plateau(regle.TailleCode, regle.NbTour);
|
|
|
|
Plateau plateau = new Plateau(regle.TailleCode, regle.NbTour);
|
|
|
|
PlateauAjouterCodeEventArgs eventArgs = new PlateauAjouterCodeEventArgs(plateau);
|
|
|
|
PlateauAjouterCodeEventArgs eventArgs = new PlateauAjouterCodeEventArgs(plateau);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MethodInfo? methodInfo = typeof(Partie).GetMethod("PlateauAjouterCode", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
MethodInfo? methodInfo = typeof(Partie).GetMethod("PlateauAjouterCode", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
methodInfo?.Invoke(partie, new object?[] { null, eventArgs });
|
|
|
|
methodInfo?.Invoke(partie, new object?[] { null, eventArgs });
|
|
|
|
|
|
|
|
|
|
|
|
FieldInfo? courantField = typeof(Partie).GetField("courant", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
FieldInfo? courantField = typeof(Partie).GetField("courant", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
|
|
|
if(courantField != null)
|
|
|
|
if (courantField != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int? courant = ((int?)courantField.GetValue(partie)).GetValueOrDefault();
|
|
|
|
int? courant = ((int?)courantField.GetValue(partie)).GetValueOrDefault();
|
|
|
|
|
|
|
|
|
|
|
@ -441,16 +446,16 @@ namespace UnitTesting
|
|
|
|
Assert.Equal(0, partie.Tour);
|
|
|
|
Assert.Equal(0, partie.Tour);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
methodInfo?.Invoke(partie, new object?[] { null, eventArgs });
|
|
|
|
methodInfo?.Invoke(partie, new object?[] { null, eventArgs });
|
|
|
|
|
|
|
|
|
|
|
|
if(courantField != null)
|
|
|
|
if (courantField != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int courant2 = ((int?)courantField.GetValue(partie)).GetValueOrDefault();
|
|
|
|
int courant2 = ((int?)courantField.GetValue(partie)).GetValueOrDefault();
|
|
|
|
Assert.Equal(0, courant2);
|
|
|
|
Assert.Equal(0, courant2);
|
|
|
|
Assert.Equal(1, partie.Tour);
|
|
|
|
Assert.Equal(1, partie.Tour);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
@ -520,7 +525,7 @@ namespace UnitTesting
|
|
|
|
victoireProperty.SetValue(plateau1, true);
|
|
|
|
victoireProperty.SetValue(plateau1, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MethodInfo? methodInfo = typeof(Partie).GetMethod("PartieTerminee", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
MethodInfo? methodInfo = typeof(Partie).GetMethod("PartieTerminee", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
methodInfo?.Invoke(partie, null);
|
|
|
|
methodInfo?.Invoke(partie, null);
|
|
|
|
|
|
|
|
|
|
|
@ -536,5 +541,74 @@ namespace UnitTesting
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void TestPartieEcoute()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Partie partie = new Partie(new ReglesClassiques());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FieldInfo? joueursInfo = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
FieldInfo? plateauxInfo = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(joueursInfo);
|
|
|
|
|
|
|
|
Assert.NotNull(plateauxInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<string, bool>? joueurs = joueursInfo.GetValue(partie) as Dictionary<string, bool>;
|
|
|
|
|
|
|
|
List<Plateau>? plateaux = plateauxInfo.GetValue(partie) as List<Plateau>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(joueurs);
|
|
|
|
|
|
|
|
Assert.NotNull(plateaux);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
joueurs.Add("Céleste", true);
|
|
|
|
|
|
|
|
plateaux.Add(new Plateau(4, 12));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MethodInfo? QuandPartieDemanderJoueurInfo = typeof(Partie).GetMethod("QuandPartieDemanderJoueur", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
MethodInfo? QuandPartieDebutPartieInfo = typeof(Partie).GetMethod("QuandPartieDebutPartie", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
MethodInfo? QuandPartieDemanderJoueurJouerInfo = typeof(Partie).GetMethod("QuandPartieDemanderJoueurJouer", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
MethodInfo? QuandPartieNouveauTourInfo = typeof(Partie).GetMethod("QuandPartieNouveauTour", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
MethodInfo? QuandPartiePasserLaMainInfo = typeof(Partie).GetMethod("QuandPartiePasserLaMain", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
MethodInfo? QuandPartiePartieTermineeInfo = typeof(Partie).GetMethod("QuandPartiePartieTerminee", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(QuandPartieDemanderJoueurInfo);
|
|
|
|
|
|
|
|
Assert.NotNull(QuandPartieDebutPartieInfo);
|
|
|
|
|
|
|
|
Assert.NotNull(QuandPartieDemanderJoueurJouerInfo);
|
|
|
|
|
|
|
|
Assert.NotNull(QuandPartieNouveauTourInfo);
|
|
|
|
|
|
|
|
Assert.NotNull(QuandPartiePasserLaMainInfo);
|
|
|
|
|
|
|
|
Assert.NotNull(QuandPartiePartieTermineeInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QuandPartieDemanderJoueurInfo?.Invoke(partie, [new Joueur()]);
|
|
|
|
|
|
|
|
QuandPartieDebutPartieInfo?.Invoke(partie, []);
|
|
|
|
|
|
|
|
QuandPartieDemanderJoueurJouerInfo?.Invoke(partie, [new Code(4)]);
|
|
|
|
|
|
|
|
QuandPartieNouveauTourInfo?.Invoke(partie, [new Code(4)]);
|
|
|
|
|
|
|
|
QuandPartiePasserLaMainInfo?.Invoke(partie, []);
|
|
|
|
|
|
|
|
QuandPartiePartieTermineeInfo?.Invoke(partie, [new List<string>(["Céleste"]), new List<string>(["Robot 1"])]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool appel1 = false;
|
|
|
|
|
|
|
|
partie.PartieDemanderJoueur += (sender, e) => appel1 = true;
|
|
|
|
|
|
|
|
bool appel2 = false;
|
|
|
|
|
|
|
|
partie.PartieDebutPartie += (sender, e) => appel2 = true;
|
|
|
|
|
|
|
|
bool appel3 = false;
|
|
|
|
|
|
|
|
partie.PartieDemanderJoueurJouer += (sender, e) => appel3 = true;
|
|
|
|
|
|
|
|
bool appel4 = false;
|
|
|
|
|
|
|
|
partie.PartieNouveauTour += (sender, e) => appel4 = true;
|
|
|
|
|
|
|
|
bool appel5 = false;
|
|
|
|
|
|
|
|
partie.PartiePasserLaMain += (sender, e) => appel5 = true;
|
|
|
|
|
|
|
|
bool appel6 = false;
|
|
|
|
|
|
|
|
partie.PartiePartieTerminee += (sender, e) => appel6 = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QuandPartieDemanderJoueurInfo?.Invoke(partie, [new Joueur()]);
|
|
|
|
|
|
|
|
QuandPartieDebutPartieInfo?.Invoke(partie, []);
|
|
|
|
|
|
|
|
QuandPartieDemanderJoueurJouerInfo?.Invoke(partie, [new Code(4)]);
|
|
|
|
|
|
|
|
QuandPartieNouveauTourInfo?.Invoke(partie, [new Code(4)]);
|
|
|
|
|
|
|
|
QuandPartiePasserLaMainInfo?.Invoke(partie, []);
|
|
|
|
|
|
|
|
QuandPartiePartieTermineeInfo?.Invoke(partie, [new List<string>(["Céleste"]), new List<string>(["Robot 1"])]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(appel1);
|
|
|
|
|
|
|
|
Assert.True(appel2);
|
|
|
|
|
|
|
|
Assert.True(appel3);
|
|
|
|
|
|
|
|
Assert.True(appel4);
|
|
|
|
|
|
|
|
Assert.True(appel5);
|
|
|
|
|
|
|
|
Assert.True(appel6);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|