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.
mastermind/Sources/UnitTesting/ReglesClassiquesUT.cs

85 lines
2.6 KiB

using CoreLibrary;
using CoreLibrary.Core;
using CoreLibrary.Exceptions;
using CoreLibrary.Joueurs;
using CoreLibrary.Regles;
using System.Reflection;
using Xunit;
namespace UnitTesting
{
public class ReglesClassiquesUT
{
[Fact]
public void TestNom()
{
Assert.Equal("Règles classiques", new ReglesClassiques().Nom);
}
[Fact]
public void TestJoueurCourantPartieNonCommencee()
{
ReglesClassiques regles = new ReglesClassiques();
Assert.Throws<PartieNonCommenceeException>(() => regles.JoueurCourant());
}
[Fact]
public void TestPasserLaMainPartieNonCommencee()
{
ReglesClassiques regles = new ReglesClassiques();
Assert.Throws<PartieNonCommenceeException>(() => regles.PasserLaMain());
}
[Fact]
public void TestEstTerminee()
{
ReglesClassiques regles = new ReglesClassiques();
regles.AjouterJoueur("joueur1");
regles.AjouterJoueur("joueur2");
regles.CommencerLaPartie();
Plateau plateauj1 = regles.JoueurCourant().Plateau;
Type type = typeof(Plateau);
FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(fieldInfo);
Code? codeSecret = (Code?)fieldInfo.GetValue(plateauj1);
Assert.NotNull(codeSecret);
regles.JoueurCourant().Plateau.AjouterCode(codeSecret);
bool estTerminee = regles.EstTerminee();
Assert.True(estTerminee);
}
[Fact]
public void TestGagants()
{
ReglesClassiques regles = new ReglesClassiques();
Partie partie = new Partie(regles);
regles.AjouterJoueur("joueur1");
regles.AjouterJoueur("joueur2");
regles.CommencerLaPartie();
Plateau plateauj1 = regles.JoueurCourant().Plateau;
Type type = typeof(Plateau);
FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(fieldInfo);
Code? codeSecret = (Code?)fieldInfo.GetValue(plateauj1);
Assert.NotNull(codeSecret);
regles.JoueurCourant().Plateau.AjouterCode(codeSecret);
IEnumerable<Joueur> gagnants = regles.Gagnants();
Assert.Single(gagnants);
Assert.Contains(regles.JoueurCourant(), gagnants);
}
}
}