You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
3.0 KiB
83 lines
3.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using Xunit;
|
|
using CoreLibrary;
|
|
using CoreLibrary.Core;
|
|
using CoreLibrary.Joueurs;
|
|
using CoreLibrary.Regles;
|
|
|
|
namespace UnitTesting
|
|
{
|
|
public class PartieUT
|
|
{
|
|
[Fact]
|
|
|
|
public void TestPremierConstructeurValide()
|
|
{
|
|
IRegles regle = new ReglesClassiques();
|
|
|
|
Partie partie = new Partie(regle);
|
|
Assert.Equal(regle, partie.Regles);
|
|
}
|
|
|
|
[Fact]
|
|
public void Partie_Constructeur_De_Copie_Cree_Une_Nouvelle_Instance_Avec_Les_Memes_Donnees()
|
|
{
|
|
|
|
IRegles regles = new ReglesClassiques();
|
|
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);
|
|
|
|
|
|
Dictionary<string, bool> joueurs = (Dictionary<string, bool>)joueursField.GetValue(partieOriginale);
|
|
joueurs.Add("Joueur1", false);
|
|
joueurs.Add("Joueur2", true);
|
|
|
|
|
|
List<Plateau> plateaux = (List<Plateau>)plateauxField.GetValue(partieOriginale);
|
|
plateaux.Add(new Plateau(4, 10));
|
|
plateaux.Add(new Plateau(4, 10));
|
|
|
|
|
|
tourField.SetValue(partieOriginale, 5);
|
|
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)
|
|
{
|
|
Assert.True(joueursCopie.ContainsKey(joueur));
|
|
Assert.Equal(joueurs[joueur], joueursCopie[joueur]);
|
|
}
|
|
|
|
foreach (var plateau in plateaux)
|
|
{
|
|
Assert.Contains(plateau, plateauxCopie);
|
|
}
|
|
}
|
|
}
|
|
}
|