|
|
@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
using ConsoleApp;
|
|
|
|
|
|
|
|
using CoreLibrary;
|
|
|
|
|
|
|
|
using CoreLibrary.Events;
|
|
|
|
|
|
|
|
using Microsoft.VisualStudio.TestPlatform.Utilities;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace UnitTesting
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
public class EvenementsUT
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void TestDemanderJoueur()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
DemanderJoueurEventArgs eventArgs = new DemanderJoueurEventArgs(1);
|
|
|
|
|
|
|
|
string expectedNom = "TestNom";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string simulatedInput = "TestNom";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (StringReader sr = new StringReader(simulatedInput))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.SetIn(sr);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Sauvegarder le flux de sortie standard
|
|
|
|
|
|
|
|
TextWriter originalConsoleOut = Console.Out;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Exécuter le test
|
|
|
|
|
|
|
|
string? nom = Evenements.DemanderJoueur(null, eventArgs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Restaurer le flux de sortie standard
|
|
|
|
|
|
|
|
Console.SetOut(originalConsoleOut);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(expectedNom, nom);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void TestCommencerLaPartie()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (var sw = new StringWriter())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.SetOut(sw);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Evenements.CommencerLaPartie(null, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string consoleOutput = sw.ToString().Trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string separateurAttendu = "───────────────────────────────────────────────────────";
|
|
|
|
|
|
|
|
string separateurDessine = consoleOutput.Split('\n')[0];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(separateurAttendu.Trim(), separateurDessine.Trim(), ignoreCase: true);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string phraseAttendue = "La partie commence, bonne chance à tous !";
|
|
|
|
|
|
|
|
string resteSortieAttendue = consoleOutput.Substring(separateurAttendu.Length).Trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal(phraseAttendue, resteSortieAttendue);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void TestAjouterJeton()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (StringWriter sw = new StringWriter())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.SetOut(sw);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Couleur couleurJeton = Couleur.BLEU;
|
|
|
|
|
|
|
|
Jeton jeton = new Jeton(couleurJeton);
|
|
|
|
|
|
|
|
AjouterJetonEventArgs eventArgs = new AjouterJetonEventArgs(jeton);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Evenements.AjouterJeton(null, eventArgs);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string consoleOutput = sw.ToString().Trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string expectedOutput = $"⬤";
|
|
|
|
|
|
|
|
Assert.Contains(expectedOutput, consoleOutput);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void TestSupprimerDernierJeton()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (StringWriter sw = new StringWriter())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.SetOut(sw);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Evenements.SupprimerDernierJeton(null, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string consoleOutput = sw.ToString().Trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal("\b\b\b \b\b\b\b\b\b", consoleOutput);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void TestAjouterCode()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (StringWriter sw = new StringWriter())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.SetOut(sw);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Evenements.AjouterCode(null, null);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string consoleOutput = sw.ToString().Trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Equal("───────────────────────────────────────────────────────", consoleOutput);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
|
|
public void TestPartieTerminee()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (StringWriter sw = new StringWriter())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Console.SetOut(sw);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Evenements.PartieTerminee(null, new PartieTermineeEventArgs(new Joueur[] { }, new Joueur[] { }));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Evenements.PartieTerminee(null, new PartieTermineeEventArgs(new Joueur[] { new Joueur("Camille", new Plateau(4, 12)) }, new Joueur[] { }));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Evenements.PartieTerminee(null, new PartieTermineeEventArgs(new Joueur[] { new Joueur("Pauline", new Plateau(4, 12)), new Joueur("Celeste", new Plateau(4, 12)) }, new Joueur[] { }));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string consoleOutput = sw.ToString().Trim();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assert.Contains("C'est une défaite des deux joueurs...", consoleOutput);
|
|
|
|
|
|
|
|
Assert.Contains("C'est une victoire de Camille.", consoleOutput);
|
|
|
|
|
|
|
|
Assert.Contains("C'est une égalité !", consoleOutput);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|