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.
94 lines
3.3 KiB
94 lines
3.3 KiB
using ConsoleApp;
|
|
using CoreLibrary.Core;
|
|
using Xunit;
|
|
|
|
namespace UnitTesting
|
|
{
|
|
public class UtilsUT
|
|
{
|
|
[Fact]
|
|
public void TestCouleursTerminal()
|
|
{
|
|
Dictionary < Couleur, ConsoleColor> expectedCouleursTerminal = new Dictionary<Couleur, ConsoleColor>()
|
|
{
|
|
{Couleur.NOIR, ConsoleColor.Black },
|
|
{Couleur.BLANC, ConsoleColor.White },
|
|
{Couleur.ROUGE, ConsoleColor.Red },
|
|
{Couleur.VERT, ConsoleColor.Green },
|
|
{Couleur.BLEU, ConsoleColor.Blue },
|
|
{Couleur.JAUNE, ConsoleColor.DarkYellow }
|
|
};
|
|
|
|
var actualCouleursTerminal = typeof(Utils).GetField("couleursTerminal", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)!.GetValue(null);
|
|
|
|
Assert.Equal(expectedCouleursTerminal, actualCouleursTerminal);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestIndicateursTerminal()
|
|
{
|
|
Dictionary<Indicateur, ConsoleColor> expectedIndicateursTerminal = new Dictionary<Indicateur, ConsoleColor>()
|
|
{
|
|
{Indicateur.BONNEPLACE, ConsoleColor.Black },
|
|
{Indicateur.BONNECOULEUR, ConsoleColor.White }
|
|
};
|
|
|
|
var actualIndicateursTerminal = typeof(Utils).GetField("indicateursTerminal", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static)!.GetValue(null);
|
|
|
|
Assert.Equal(expectedIndicateursTerminal, actualIndicateursTerminal);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestDessinerPionValide()
|
|
{
|
|
TextWriter sortieDefaut = Console.Out;
|
|
|
|
using (StringWriter sw = new StringWriter())
|
|
{
|
|
Console.SetOut(sw);
|
|
Utils.DessinerPion(Couleur.NOIR);
|
|
string expected = " O ";
|
|
Assert.Equal(expected, sw.ToString());
|
|
}
|
|
|
|
Console.SetOut(sortieDefaut);
|
|
}
|
|
|
|
[Fact]
|
|
public void TestDessinerTitre()
|
|
{
|
|
TextWriter sortieDefaut = Console.Out;
|
|
|
|
// Capture de la sortie console
|
|
using (StringWriter sw = new StringWriter())
|
|
{
|
|
Console.SetOut(sw);
|
|
|
|
// Appel de la fonction à tester
|
|
Utils.DessinerTitre();
|
|
|
|
// Récupération de la sortie console dans une chaîne
|
|
string consoleOutput = sw.ToString();
|
|
|
|
// Chaîne attendue pour le titre
|
|
string titreAttendu = @"
|
|
__ __ _ _ _
|
|
| \/ | __ _ ___| |_ ___ _ _ _ __ (_) _ _ __| |
|
|
| |\/| |/ _` |(_-<| _|/ -_)| '_|| ' \ | || ' \ / _` |
|
|
|_| |_|\__,_|/__/ \__|\___||_| |_|_|_||_||_||_|\__,_|
|
|
|
|
───────────────────────────────────────────────────────";
|
|
|
|
consoleOutput = consoleOutput.Replace("\n", "").Replace("\r", "");
|
|
titreAttendu = titreAttendu.Replace("\n", "").Replace("\r", "");
|
|
// Assertion pour vérifier si la sortie console correspond au titre attendu
|
|
Assert.Equal(titreAttendu.Trim(), consoleOutput.Trim());
|
|
}
|
|
|
|
Console.SetOut(sortieDefaut);
|
|
}
|
|
|
|
}
|
|
|
|
}
|