code smell
continuous-integration/drone/push Build is passing Details

master
Camille TURPIN-ETIENNE 11 months ago
parent be7317210d
commit b1b19c77f5

@ -25,11 +25,11 @@ namespace UnitTesting
[Fact] [Fact]
public void Partie_Constructeur_De_Copie_Cree_Une_Nouvelle_Instance_Avec_Les_Memes_Donnees() public void Partie_Constructeur_De_Copie_Cree_Une_Nouvelle_Instance_Avec_Les_Memes_Donnees()
{ {
IRegles regles = new ReglesClassiques(); IRegles regles = new ReglesClassiques();
Partie partieOriginale = new Partie(regles); Partie partieOriginale = new Partie(regles);
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);
FieldInfo? courantField = typeof(Partie).GetField("courant", BindingFlags.NonPublic | BindingFlags.Instance); FieldInfo? courantField = typeof(Partie).GetField("courant", BindingFlags.NonPublic | BindingFlags.Instance);
@ -37,63 +37,65 @@ namespace UnitTesting
PropertyInfo? termineField = typeof(Partie).GetProperty("Termine", BindingFlags.Public | BindingFlags.Instance); PropertyInfo? termineField = typeof(Partie).GetProperty("Termine", BindingFlags.Public | BindingFlags.Instance);
Dictionary<string, bool>? joueurs = joueursField.GetValue(partieOriginale) as Dictionary<string, bool>; if (joueursField != null && plateauxField != null)
if (joueurs != null)
{ {
joueurs.Add("Joueur1", false); Dictionary<string, bool>? joueurs = joueursField.GetValue(partieOriginale) as Dictionary<string, bool>;
joueurs.Add("Joueur2", true); if (joueurs != null)
} {
joueurs.Add("Joueur1", false);
joueurs.Add("Joueur2", true);
}
List<Plateau>? plateaux = plateauxField.GetValue(partieOriginale) as List<Plateau>; 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 (plateaux != null)
{
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);
Dictionary<string, bool>? joueursCopie = joueursField.GetValue(partieCopiee) as Dictionary<string, bool>; Dictionary<string, bool>? joueursCopie = joueursField.GetValue(partieCopiee) as Dictionary<string, bool>;
List<Plateau>? plateauxCopie = plateauxField.GetValue(partieCopiee) as List<Plateau>; List<Plateau>? plateauxCopie = plateauxField.GetValue(partieCopiee) as List<Plateau>;
int? courantCopie = courantField.GetValue(partieCopiee) as int?; int? courantCopie = courantField.GetValue(partieCopiee) as int?;
int? tourCopie = tourField.GetValue(partieCopiee) as int?; int? tourCopie = tourField.GetValue(partieCopiee) as int?;
bool? termineCopie = termineField.GetValue(partieCopiee) as bool?; bool? termineCopie = termineField.GetValue(partieCopiee) as bool?;
if (joueursCopie != null && plateauxCopie != null && courantCopie != null && tourCopie != null && termineCopie != null && joueurs != null && plateaux != null) 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)
{
if(joueursCopie != null)
{ {
Assert.True(joueursCopie.ContainsKey(joueur)); Assert.Equal(joueurs.Count, joueursCopie.Count);
Assert.Equal(joueurs[joueur], joueursCopie[joueur]); 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)
{
if(joueursCopie != null)
{
Assert.True(joueursCopie.ContainsKey(joueur));
Assert.Equal(joueurs[joueur], joueursCopie[joueur]);
}
} }
foreach (Plateau plateau in plateaux) foreach (Plateau plateau in plateaux)
{ {
if (plateauxCopie != null) if (plateauxCopie != null)
Assert.Contains(plateau, plateauxCopie); Assert.Contains(plateau, plateauxCopie);
}
} }
} }
} }

Loading…
Cancel
Save