Test Partie

master
Camille TURPIN-ETIENNE 11 months ago
parent e9402b247c
commit d193fea54d

@ -7,6 +7,8 @@ using CoreLibrary;
using CoreLibrary.Core;
using CoreLibrary.Joueurs;
using CoreLibrary.Regles;
using CoreLibrary.Evenements;
namespace UnitTesting
{
@ -23,7 +25,7 @@ namespace UnitTesting
}
[Fact]
public void Partie_Constructeur_De_Copie_Cree_Une_Nouvelle_Instance_Avec_Les_Memes_Donnees()
public void TestSecondConstructeurValide()
{
IRegles regles = new ReglesClassiques();
@ -107,5 +109,201 @@ namespace UnitTesting
}
}
[Fact]
public void TestJouerDemanderJouer()
{
IRegles regle = new ReglesClassiques();
Partie partie = new Partie(regle);
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
if(joueursField != null)
{
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
if (joueurs != null)
{
joueurs.Add("Joueur1", false);
}
bool demanderJoueurCalled = false;
partie.PartieDemanderJoueur += (sender, e) => demanderJoueurCalled = true;
partie.Jouer();
Assert.True(demanderJoueurCalled);
}
}
[Fact]
public void TestJouerDebutPartie()
{
IRegles regle = new ReglesClassiques();
Partie partie = new Partie(regle);
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
if (joueursField != null)
{
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
if (joueurs != null)
{
joueurs.Add("Joueur1", false);
joueurs.Add("Joueur2", false);
}
bool debutPartieCalled = false;
partie.PartieDebutPartie += (sender, e) => debutPartieCalled = true;
partie.Jouer();
Assert.True(debutPartieCalled);
}
}
[Fact]
public void TestDemanderJoueur()
{
IRegles regle = new ReglesClassiques();
Partie partie = new Partie(regle);
Joueur? joueurDemande = null;
partie.PartieDemanderJoueur += (sender, e) =>
{
joueurDemande = e.JoueurDemande;
};
MethodInfo? methodInfo = typeof(Partie).GetMethod("DemanderJoueur", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo?.Invoke(partie, null);
Assert.NotNull(joueurDemande);
bool joueurConnecteCalled = false;
if (joueurDemande != null)
{
joueurDemande.JoueurSeConnecter += (sender, e) => joueurConnecteCalled = true;
joueurDemande.SeConnecter(joueurDemande);
Assert.True(joueurConnecteCalled);
}
}
[Fact]
public void TestJoueurConnecte()
{
IRegles regle = new ReglesClassiques();
Partie partie = new Partie(regle);
bool demanderJoueurAppelée = false;
partie.PartieDemanderJoueur += (sender, e) => demanderJoueurAppelée = true;
Joueur? joueur1 = new Joueur("Joueur1");
JoueurSeConnecterEventArgs joueur1EventArgs = new JoueurSeConnecterEventArgs(joueur1);
MethodInfo? methodInfo = typeof(Partie).GetMethod("JoueurConnecte", BindingFlags.NonPublic | BindingFlags.Instance);
methodInfo?.Invoke(partie, new object?[] { null, joueur1EventArgs });
Assert.True(demanderJoueurAppelée);
FieldInfo? joueursField = typeof(Partie).GetField("joueurs", BindingFlags.NonPublic | BindingFlags.Instance);
if (joueursField != null)
{
Dictionary<string,bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
if(joueurs != null)
Assert.True(joueurs.ContainsKey(joueur1.Nom));
}
FieldInfo? plateauxField = typeof(Partie).GetField("plateaux", BindingFlags.NonPublic | BindingFlags.Instance);
if (plateauxField != null)
{
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
if(plateaux != null)
Assert.Single(plateaux);
}
Joueur joueur2 = new Joueur("Joueur2");
JoueurSeConnecterEventArgs joueur2EventArgs = new JoueurSeConnecterEventArgs(joueur2);
demanderJoueurAppelée = false;
methodInfo?.Invoke(partie, new object?[] { null, joueur2EventArgs });
if(joueursField != null)
{
Dictionary<string, bool>? joueurs = joueursField.GetValue(partie) as Dictionary<string, bool>;
if(joueurs != null)
{
Assert.Equal(2, joueurs.Count);
Assert.True(joueurs.ContainsKey(joueur2.Nom));
}
}
if (plateauxField != null)
{
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
if (plateaux != null)
Assert.Equal(2, plateaux.Count);
}
PropertyInfo? tourProperty = typeof(Partie).GetProperty("Tour", BindingFlags.Public | BindingFlags.Instance);
if (tourProperty != null)
{
object? tourValue = tourProperty.GetValue(partie);
int? tour = tourValue as int?;
if (tour != null)
{
Assert.Equal(1, tour);
}
}
}
[Fact]
public void TestDebutPartie()
{
IRegles regle = new ReglesClassiques();
Partie partie = new Partie(regle);
PropertyInfo? plateauxField = typeof(Partie).GetProperty("plateaux", BindingFlags.Public | BindingFlags.Instance);
if (plateauxField != null)
{
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
if (plateaux != null)
{
plateaux.Add(new Plateau(4, 10));
plateaux.Add(new Plateau(4, 10));
}
}
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)
{
object? tourValue = tourProperty.GetValue(partie);
int? tour = tourValue as int?;
if (tour != null)
{
Assert.Equal(1, tour);
}
}
bool plateauAjouterCodeCalled = false;
if (plateauxField != null)
{
List<Plateau>? plateaux = plateauxField.GetValue(partie) as List<Plateau>;
if (plateaux != null)
{
foreach (Plateau plateau in plateaux)
{
plateau.PlateauAjouterCode += (sender, e) => plateauAjouterCodeCalled = true;
plateau.AjouterCode(new Code(regle.TailleCode));
Assert.True(plateauAjouterCodeCalled);
}
}
}
}
}
}

Loading…
Cancel
Save