|
|
@ -2,6 +2,9 @@
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Reflection;
|
|
|
|
using CoreLibrary.Core;
|
|
|
|
using CoreLibrary.Core;
|
|
|
|
using Xunit;
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
using CoreLibrary.Joueurs;
|
|
|
|
|
|
|
|
using CoreLibrary.Regles;
|
|
|
|
|
|
|
|
using CoreLibrary;
|
|
|
|
|
|
|
|
|
|
|
|
namespace UnitTesting
|
|
|
|
namespace UnitTesting
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -151,7 +154,7 @@ namespace UnitTesting
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
[Fact]
|
|
|
|
public void AjouterCode_GrilleComplete_ThrowsGrilleCompleteException()
|
|
|
|
public void TestAjouterCode_GrilleComplete_ThrowsGrilleCompleteException()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Plateau plateau = new Plateau(4, 2);
|
|
|
|
Plateau plateau = new Plateau(4, 2);
|
|
|
|
Code codeComplet1 = new Code(4);
|
|
|
|
Code codeComplet1 = new Code(4);
|
|
|
@ -178,6 +181,96 @@ namespace UnitTesting
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void TestPlateauEcoute()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Plateau plateau = new Plateau(4, 2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MethodInfo? QuandPlateauAjouterCodeInfo = typeof(Plateau).GetMethod("QuandPlateauAjouterCode", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(QuandPlateauAjouterCodeInfo);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QuandPlateauAjouterCodeInfo?.Invoke(plateau, []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool appel = false;
|
|
|
|
|
|
|
|
plateau.PlateauAjouterCode += (sender, e) => appel = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QuandPlateauAjouterCodeInfo?.Invoke(plateau, []);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.True(appel);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void TestAjouterCodeVictoire()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Cas 1 : Victoire : false, code correct : false
|
|
|
|
|
|
|
|
Code code = new Code(1);
|
|
|
|
|
|
|
|
code.AjouterJeton(new Jeton(Couleur.Rouge));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Plateau plateau;
|
|
|
|
|
|
|
|
Code? codeSecret;
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
plateau = new Plateau(1, 2);
|
|
|
|
|
|
|
|
FieldInfo? codeSecretInfo = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
Assert.NotNull(codeSecretInfo);
|
|
|
|
|
|
|
|
codeSecret = codeSecretInfo.GetValue(plateau) as Code;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(codeSecret);
|
|
|
|
|
|
|
|
} while (codeSecret.Jetons.ElementAt(0).Equals(code.Jetons.ElementAt(0)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(codeSecret);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plateau.AjouterCode(code);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cas 2 : Victoire : false, code correct : true
|
|
|
|
|
|
|
|
Plateau plateau2 = new Plateau(1, 2);
|
|
|
|
|
|
|
|
FieldInfo? codeSecretInfo2 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
Assert.NotNull(codeSecretInfo2);
|
|
|
|
|
|
|
|
Code? code2 = codeSecretInfo2.GetValue(plateau2) as Code;
|
|
|
|
|
|
|
|
Assert.NotNull(code2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plateau2.AjouterCode(code2);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cas 3 : Victoire : true, code correct : false
|
|
|
|
|
|
|
|
Code code3 = new Code(1);
|
|
|
|
|
|
|
|
code3.AjouterJeton(new Jeton(Couleur.Rouge));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Plateau plateau3;
|
|
|
|
|
|
|
|
Code? codeSecret3;
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
plateau3 = new Plateau(1, 2);
|
|
|
|
|
|
|
|
FieldInfo? codeSecretInfo3 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
Assert.NotNull(codeSecretInfo3);
|
|
|
|
|
|
|
|
codeSecret3 = codeSecretInfo3.GetValue(plateau) as Code;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(codeSecret3);
|
|
|
|
|
|
|
|
} while (codeSecret3.Jetons.ElementAt(0).Equals(code3.Jetons.ElementAt(0)));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(codeSecret3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PropertyInfo? VictoireInfo3 = typeof(Plateau).GetProperty("Victoire", BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.NotNull(VictoireInfo3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VictoireInfo3.SetValue(plateau3, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plateau3.AjouterCode(code3);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cas 4 : Victoire : true, code correct : true
|
|
|
|
|
|
|
|
Plateau plateau4 = new Plateau(1, 2);
|
|
|
|
|
|
|
|
FieldInfo? codeSecretInfo4 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
|
|
|
|
|
|
Assert.NotNull(codeSecretInfo4);
|
|
|
|
|
|
|
|
Code? code4 = codeSecretInfo4.GetValue(plateau4) as Code;
|
|
|
|
|
|
|
|
Assert.NotNull(code4);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PropertyInfo? VictoireInfo4 = typeof(Plateau).GetProperty("Victoire", BindingFlags.Public | BindingFlags.Instance);
|
|
|
|
|
|
|
|
Assert.NotNull(VictoireInfo4);
|
|
|
|
|
|
|
|
VictoireInfo4.SetValue(plateau4, true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
plateau4.AjouterCode(code4);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|