|
|
|
@ -30,52 +30,70 @@ namespace UnitTesting
|
|
|
|
|
Partie partieOriginale = new Partie(regles);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FieldInfo joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
FieldInfo plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
FieldInfo courantField = typeof(Partie).GetField("courant", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
PropertyInfo tourField = typeof(Partie).GetProperty("Tour", BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
|
PropertyInfo termineField = typeof(Partie).GetProperty("Termine", BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
|
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
FieldInfo? plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
FieldInfo? courantField = typeof(Partie).GetField("courant", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
PropertyInfo? tourField = typeof(Partie).GetProperty("Tour", BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
|
PropertyInfo? termineField = typeof(Partie).GetProperty("Termine", BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<string, bool> joueurs = (Dictionary<string, bool>)joueursField.GetValue(partieOriginale);
|
|
|
|
|
joueurs.Add("Joueur1", false);
|
|
|
|
|
joueurs.Add("Joueur2", true);
|
|
|
|
|
Dictionary<string, bool>? joueurs = joueursField.GetValue(partieOriginale) as Dictionary<string, bool>;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Plateau> plateaux = (List<Plateau>)plateauxField.GetValue(partieOriginale);
|
|
|
|
|
plateaux.Add(new Plateau(4, 10));
|
|
|
|
|
plateaux.Add(new Plateau(4, 10));
|
|
|
|
|
if (joueurs != null)
|
|
|
|
|
{
|
|
|
|
|
joueurs.Add("Joueur1", false);
|
|
|
|
|
joueurs.Add("Joueur2", true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tourField.SetValue(partieOriginale, 5);
|
|
|
|
|
termineField.SetValue(partieOriginale, false);
|
|
|
|
|
|
|
|
|
|
List<Plateau>? plateaux = plateauxField.GetValue(partieOriginale) as List<Plateau>;
|
|
|
|
|
|
|
|
|
|
if (plateaux != null)
|
|
|
|
|
{
|
|
|
|
|
plateaux.Add(new Plateau(4, 10));
|
|
|
|
|
plateaux.Add(new Plateau(4, 10));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(tourField != null)
|
|
|
|
|
tourField.SetValue(partieOriginale, 5);
|
|
|
|
|
|
|
|
|
|
if (termineField != null)
|
|
|
|
|
termineField.SetValue(partieOriginale, false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var partieCopiee = new Partie(partieOriginale);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Dictionary<string, bool> joueursCopie = (Dictionary<string, bool>)joueursField.GetValue(partieCopiee);
|
|
|
|
|
List<Plateau> plateauxCopie = (List<Plateau>)plateauxField.GetValue(partieCopiee);
|
|
|
|
|
int courantCopie = (int)courantField.GetValue(partieCopiee);
|
|
|
|
|
int tourCopie = (int)tourField.GetValue(partieCopiee);
|
|
|
|
|
bool termineCopie = (bool)termineField.GetValue(partieCopiee);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(joueurs.Count, joueursCopie.Count);
|
|
|
|
|
Assert.Equal(plateaux.Count, plateauxCopie.Count);
|
|
|
|
|
Assert.Equal(5, tourCopie);
|
|
|
|
|
Assert.False(termineCopie);
|
|
|
|
|
Assert.Equal(regles, partieCopiee.Regles);
|
|
|
|
|
|
|
|
|
|
foreach (var joueur in joueurs.Keys)
|
|
|
|
|
|
|
|
|
|
Dictionary<string, bool>? joueursCopie = joueursField.GetValue(partieCopiee) as Dictionary<string, bool>;
|
|
|
|
|
List<Plateau>? plateauxCopie = plateauxField.GetValue(partieCopiee) as List<Plateau>;
|
|
|
|
|
int? courantCopie = courantField.GetValue(partieCopiee) as int?;
|
|
|
|
|
int? tourCopie = tourField.GetValue(partieCopiee) as int?;
|
|
|
|
|
bool? termineCopie = termineField.GetValue(partieCopiee) as bool?;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (joueursCopie != null && plateauxCopie != null && courantCopie != null && tourCopie != null && termineCopie != null && joueurs != null && plateaux != null)
|
|
|
|
|
{
|
|
|
|
|
Assert.Equal(joueurs.Count, joueursCopie.Count);
|
|
|
|
|
Assert.Equal(plateaux.Count, plateauxCopie.Count);
|
|
|
|
|
Assert.Equal(5, tourCopie.Value);
|
|
|
|
|
Assert.False(termineCopie.Value);
|
|
|
|
|
Assert.Equal(regles, partieCopiee.Regles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (String joueur in joueurs.Keys)
|
|
|
|
|
{
|
|
|
|
|
Assert.True(joueursCopie.ContainsKey(joueur));
|
|
|
|
|
Assert.Equal(joueurs[joueur], joueursCopie[joueur]);
|
|
|
|
|
if(joueursCopie != null)
|
|
|
|
|
{
|
|
|
|
|
Assert.True(joueursCopie.ContainsKey(joueur));
|
|
|
|
|
Assert.Equal(joueurs[joueur], joueursCopie[joueur]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var plateau in plateaux)
|
|
|
|
|
foreach (Plateau plateau in plateaux)
|
|
|
|
|
{
|
|
|
|
|
Assert.Contains(plateau, plateauxCopie);
|
|
|
|
|
if (plateauxCopie != null)
|
|
|
|
|
Assert.Contains(plateau, plateauxCopie);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|