|
|
|
@ -154,6 +154,34 @@ namespace UnitTesting
|
|
|
|
|
Assert.NotEmpty(PartieDemanderJoueurJouer.GetInvocationList());
|
|
|
|
|
Assert.NotEmpty(PartiePasserLaMain.GetInvocationList());
|
|
|
|
|
Assert.NotEmpty(PartiePartieTerminee.GetInvocationList());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEcouterPartie2()
|
|
|
|
|
{
|
|
|
|
|
IPersistance persistance = new PersistanceStub();
|
|
|
|
|
Manageur manageur = new Manageur(persistance);
|
|
|
|
|
|
|
|
|
|
MethodInfo? infosMethode = typeof(Manageur).GetMethod("EcouterPartie", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
Assert.NotNull(infosMethode);
|
|
|
|
|
|
|
|
|
|
Partie partie = new Partie(new ReglesClassiques());
|
|
|
|
|
|
|
|
|
|
infosMethode.Invoke(manageur, [partie]);
|
|
|
|
|
|
|
|
|
|
FieldInfo? PartiePartieTermineeInfos = typeof(Partie)
|
|
|
|
|
.GetField("PartiePartieTerminee", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(PartiePartieTermineeInfos);
|
|
|
|
|
|
|
|
|
|
EventHandler<PartiePartieTermineeEventArgs>? PartiePartieTerminee =
|
|
|
|
|
PartiePartieTermineeInfos.GetValue(partie) as EventHandler<PartiePartieTermineeEventArgs>;
|
|
|
|
|
|
|
|
|
|
PartiePartieTerminee =
|
|
|
|
|
PartiePartieTermineeInfos.GetValue(partie) as EventHandler<PartiePartieTermineeEventArgs>;
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(PartiePartieTerminee);
|
|
|
|
|
Assert.NotEmpty(PartiePartieTerminee.GetInvocationList());
|
|
|
|
|
|
|
|
|
|
Joueur celeste = manageur.DemanderJoueur("Céleste");
|
|
|
|
|
Robot robot = new Robot();
|
|
|
|
@ -177,6 +205,153 @@ namespace UnitTesting
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEcouterPartie3()
|
|
|
|
|
{
|
|
|
|
|
IPersistance persistance = new PersistanceStub();
|
|
|
|
|
Manageur manageur = new Manageur(persistance);
|
|
|
|
|
|
|
|
|
|
MethodInfo? infosMethode = typeof(Manageur).GetMethod("EcouterPartie", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
Assert.NotNull(infosMethode);
|
|
|
|
|
|
|
|
|
|
Partie partie = new Partie(new ReglesClassiques());
|
|
|
|
|
|
|
|
|
|
infosMethode.Invoke(manageur, [partie]);
|
|
|
|
|
|
|
|
|
|
FieldInfo? PartiePartieTermineeInfos = typeof(Partie)
|
|
|
|
|
.GetField("PartiePartieTerminee", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(PartiePartieTermineeInfos);
|
|
|
|
|
|
|
|
|
|
EventHandler<PartiePartieTermineeEventArgs>? PartiePartieTerminee =
|
|
|
|
|
PartiePartieTermineeInfos.GetValue(partie) as EventHandler<PartiePartieTermineeEventArgs>;
|
|
|
|
|
|
|
|
|
|
PartiePartieTerminee =
|
|
|
|
|
PartiePartieTermineeInfos.GetValue(partie) as EventHandler<PartiePartieTermineeEventArgs>;
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(PartiePartieTerminee);
|
|
|
|
|
Assert.NotEmpty(PartiePartieTerminee.GetInvocationList());
|
|
|
|
|
|
|
|
|
|
Joueur celeste = manageur.DemanderJoueur("Céleste");
|
|
|
|
|
Robot robot = new Robot();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.CoupMoyen));
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee));
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite));
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue));
|
|
|
|
|
|
|
|
|
|
int tour = 10;
|
|
|
|
|
IReadOnlyList<string> gagnants = [robot.Nom];
|
|
|
|
|
IReadOnlyList<string> perdants = [celeste.Nom];
|
|
|
|
|
|
|
|
|
|
PartiePartieTerminee.Invoke(null, new PartiePartieTermineeEventArgs(
|
|
|
|
|
tour, gagnants, perdants
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
Assert.Equal(tour, celeste.Statistique(new ReglesClassiques(), Statistique.CoupMoyen));
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEcouterPartie4()
|
|
|
|
|
{
|
|
|
|
|
IPersistance persistance = new PersistanceStub();
|
|
|
|
|
Manageur manageur = new Manageur(persistance);
|
|
|
|
|
|
|
|
|
|
MethodInfo? infosMethode = typeof(Manageur).GetMethod("EcouterPartie", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
Assert.NotNull(infosMethode);
|
|
|
|
|
|
|
|
|
|
Partie partie = new Partie(new ReglesClassiques());
|
|
|
|
|
|
|
|
|
|
infosMethode.Invoke(manageur, [partie]);
|
|
|
|
|
|
|
|
|
|
FieldInfo? PartiePartieTermineeInfos = typeof(Partie)
|
|
|
|
|
.GetField("PartiePartieTerminee", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(PartiePartieTermineeInfos);
|
|
|
|
|
|
|
|
|
|
EventHandler<PartiePartieTermineeEventArgs>? PartiePartieTerminee =
|
|
|
|
|
PartiePartieTermineeInfos.GetValue(partie) as EventHandler<PartiePartieTermineeEventArgs>;
|
|
|
|
|
|
|
|
|
|
PartiePartieTerminee =
|
|
|
|
|
PartiePartieTermineeInfos.GetValue(partie) as EventHandler<PartiePartieTermineeEventArgs>;
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(PartiePartieTerminee);
|
|
|
|
|
Assert.NotEmpty(PartiePartieTerminee.GetInvocationList());
|
|
|
|
|
|
|
|
|
|
Joueur celeste = manageur.DemanderJoueur("Céleste");
|
|
|
|
|
Robot robot = new Robot();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.CoupMoyen));
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee));
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite));
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue));
|
|
|
|
|
|
|
|
|
|
int tour = 10;
|
|
|
|
|
IReadOnlyList<string> gagnants = [robot.Nom, celeste.Nom];
|
|
|
|
|
IReadOnlyList<string> perdants = [];
|
|
|
|
|
|
|
|
|
|
PartiePartieTerminee.Invoke(null, new PartiePartieTermineeEventArgs(
|
|
|
|
|
tour, gagnants, perdants
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
Assert.Equal(tour, celeste.Statistique(new ReglesClassiques(), Statistique.CoupMoyen));
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestEcouterPartie5()
|
|
|
|
|
{
|
|
|
|
|
IPersistance persistance = new PersistanceStub();
|
|
|
|
|
Manageur manageur = new Manageur(persistance);
|
|
|
|
|
|
|
|
|
|
MethodInfo? infosMethode = typeof(Manageur).GetMethod("EcouterPartie", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
Assert.NotNull(infosMethode);
|
|
|
|
|
|
|
|
|
|
Partie partie = new Partie(new ReglesClassiques());
|
|
|
|
|
|
|
|
|
|
infosMethode.Invoke(manageur, [partie]);
|
|
|
|
|
|
|
|
|
|
FieldInfo? PartiePartieTermineeInfos = typeof(Partie)
|
|
|
|
|
.GetField("PartiePartieTerminee", BindingFlags.Instance | BindingFlags.NonPublic);
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(PartiePartieTermineeInfos);
|
|
|
|
|
|
|
|
|
|
EventHandler<PartiePartieTermineeEventArgs>? PartiePartieTerminee =
|
|
|
|
|
PartiePartieTermineeInfos.GetValue(partie) as EventHandler<PartiePartieTermineeEventArgs>;
|
|
|
|
|
|
|
|
|
|
PartiePartieTerminee =
|
|
|
|
|
PartiePartieTermineeInfos.GetValue(partie) as EventHandler<PartiePartieTermineeEventArgs>;
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(PartiePartieTerminee);
|
|
|
|
|
Assert.NotEmpty(PartiePartieTerminee.GetInvocationList());
|
|
|
|
|
|
|
|
|
|
Joueur celeste = manageur.DemanderJoueur("Céleste");
|
|
|
|
|
Robot robot = new Robot();
|
|
|
|
|
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.CoupMoyen));
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieGagnee));
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartieEgalite));
|
|
|
|
|
Assert.Equal(0, celeste.Statistique(new ReglesClassiques(), Statistique.PartiePerdue));
|
|
|
|
|
|
|
|
|
|
int tour = 10;
|
|
|
|
|
IReadOnlyList<string> gagnants = [];
|
|
|
|
|
IReadOnlyList<string> perdants = [robot.Nom, celeste.Nom];
|
|
|
|
|
|
|
|
|
|
PartiePartieTerminee.Invoke(null, new PartiePartieTermineeEventArgs(
|
|
|
|
|
tour, gagnants, perdants
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
Assert.Equal(tour, celeste.Statistique(new ReglesClassiques(), Statistique.CoupMoyen));
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void TestDemanderJoueurExistant()
|
|
|
|
|
{
|
|
|
|
|