Merge branch 'UT'
continuous-integration/drone/push Build is passing Details

master
Céleste BARBOSA 11 months ago
commit f7a8666f95

@ -9,7 +9,7 @@ namespace UnitTesting
[Fact]
public void TestConstructeurValide()
{
Code monCode = new Code([new Jeton(Couleur.ROUGE), new Jeton(Couleur.BLEU)]);
Code monCode = new Code([new Jeton(Couleur.VERT), new Jeton(Couleur.BLEU)]);
AjouterCodeEventArgs evenement = new AjouterCodeEventArgs(monCode);

@ -1,4 +1,8 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text.Json;
using Xunit;
namespace UnitTesting
@ -22,7 +26,7 @@ namespace UnitTesting
{
throw new CodeCompletException(message);
}
catch(CodeCompletException e)
catch (CodeCompletException e)
{
Assert.Equal(message, e.Message);
}
@ -50,5 +54,32 @@ namespace UnitTesting
}
}
[Fact]
public void ExceptionSerialisation()
{
CodeCompletException exception = new CodeCompletException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(CodeCompletException), new FormatterConverter());
StreamingContext contexte = new StreamingContext(StreamingContextStates.All);
#pragma warning restore SYSLIB0050
#pragma warning disable SYSLIB0051
exception.GetObjectData(info, contexte);
#pragma warning restore SYSLIB0051
Assert.Equal(exception.Message, info.GetString("Message"));
#pragma warning disable SYSLIB0050
CodeCompletException exceptionSerialisee =
(CodeCompletException) FormatterServices.GetUninitializedObject(typeof(CodeCompletException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(CodeCompletException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null);
Assert.NotNull(constructeur);
constructeur.Invoke(exceptionSerialisee, [info, contexte]);
Assert.Equal(exception.Message, exceptionSerialisee.Message);
}
}
}

@ -1,4 +1,6 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
@ -50,5 +52,32 @@ namespace UnitTesting
}
}
[Fact]
public void ExceptionSerialisation()
{
CodeIncompletException exception = new CodeIncompletException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(CodeIncompletException), new FormatterConverter());
StreamingContext contexte = new StreamingContext(StreamingContextStates.All);
#pragma warning restore SYSLIB0050
#pragma warning disable SYSLIB0051
exception.GetObjectData(info, contexte);
#pragma warning restore SYSLIB0051
Assert.Equal(exception.Message, info.GetString("Message"));
#pragma warning disable SYSLIB0050
CodeIncompletException exceptionSerialisee =
(CodeIncompletException)FormatterServices.GetUninitializedObject(typeof(CodeIncompletException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(CodeIncompletException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null);
Assert.NotNull(constructeur);
constructeur.Invoke(exceptionSerialisee, [info, contexte]);
Assert.Equal(exception.Message, exceptionSerialisee.Message);
}
}
}

@ -1,4 +1,6 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
@ -66,5 +68,33 @@ namespace UnitTesting
}
}
[Fact]
public void ExceptionSerialisation()
{
CodeInvalideException exception = new CodeInvalideException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(CodeInvalideException), new FormatterConverter());
StreamingContext contexte = new StreamingContext(StreamingContextStates.All);
#pragma warning restore SYSLIB0050
#pragma warning disable SYSLIB0051
exception.GetObjectData(info, contexte);
#pragma warning restore SYSLIB0051
Assert.Equal(exception.Message, info.GetString("Message"));
#pragma warning disable SYSLIB0050
CodeInvalideException exceptionSerialisee =
(CodeInvalideException)FormatterServices.GetUninitializedObject(typeof(CodeInvalideException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(CodeInvalideException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null);
Assert.NotNull(constructeur);
constructeur.Invoke(exceptionSerialisee, [info, contexte]);
Assert.Equal(exception.Message, exceptionSerialisee.Message);
}
}
}

@ -1,4 +1,6 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
@ -50,5 +52,32 @@ namespace UnitTesting
}
}
[Fact]
public void ExceptionSerialisation()
{
CodeVideException exception = new CodeVideException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(CodeVideException), new FormatterConverter());
StreamingContext contexte = new StreamingContext(StreamingContextStates.All);
#pragma warning restore SYSLIB0050
#pragma warning disable SYSLIB0051
exception.GetObjectData(info, contexte);
#pragma warning restore SYSLIB0051
Assert.Equal(exception.Message, info.GetString("Message"));
#pragma warning disable SYSLIB0050
CodeVideException exceptionSerialisee =
(CodeVideException)FormatterServices.GetUninitializedObject(typeof(CodeVideException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(CodeVideException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null);
Assert.NotNull(constructeur);
constructeur.Invoke(exceptionSerialisee, [info, contexte]);
Assert.Equal(exception.Message, exceptionSerialisee.Message);
}
}
}

@ -1,4 +1,6 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
@ -50,5 +52,32 @@ namespace UnitTesting
}
}
[Fact]
public void ExceptionSerialisation()
{
GrilleCompleteException exception = new GrilleCompleteException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(GrilleCompleteException), new FormatterConverter());
StreamingContext contexte = new StreamingContext(StreamingContextStates.All);
#pragma warning restore SYSLIB0050
#pragma warning disable SYSLIB0051
exception.GetObjectData(info, contexte);
#pragma warning restore SYSLIB0051
Assert.Equal(exception.Message, info.GetString("Message"));
#pragma warning disable SYSLIB0050
GrilleCompleteException exceptionSerialisee =
(GrilleCompleteException)FormatterServices.GetUninitializedObject(typeof(GrilleCompleteException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(GrilleCompleteException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null);
Assert.NotNull(constructeur);
constructeur.Invoke(exceptionSerialisee, [info, contexte]);
Assert.Equal(exception.Message, exceptionSerialisee.Message);
}
}
}

@ -1,4 +1,6 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
@ -66,5 +68,32 @@ namespace UnitTesting
}
}
[Fact]
public void ExceptionSerialisation()
{
IndiceCodeException exception = new IndiceCodeException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(IndiceCodeException), new FormatterConverter());
StreamingContext contexte = new StreamingContext(StreamingContextStates.All);
#pragma warning restore SYSLIB0050
#pragma warning disable SYSLIB0051
exception.GetObjectData(info, contexte);
#pragma warning restore SYSLIB0051
Assert.Equal(exception.Message, info.GetString("Message"));
#pragma warning disable SYSLIB0050
IndiceCodeException exceptionSerialisee =
(IndiceCodeException)FormatterServices.GetUninitializedObject(typeof(IndiceCodeException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(IndiceCodeException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null);
Assert.NotNull(constructeur);
constructeur.Invoke(exceptionSerialisee, [info, contexte]);
Assert.Equal(exception.Message, exceptionSerialisee.Message);
}
}
}

@ -1,4 +1,6 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
@ -50,5 +52,32 @@ namespace UnitTesting
}
}
[Fact]
public void ExceptionSerialisation()
{
PartieNonCommenceeException exception = new PartieNonCommenceeException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(PartieNonCommenceeException), new FormatterConverter());
StreamingContext contexte = new StreamingContext(StreamingContextStates.All);
#pragma warning restore SYSLIB0050
#pragma warning disable SYSLIB0051
exception.GetObjectData(info, contexte);
#pragma warning restore SYSLIB0051
Assert.Equal(exception.Message, info.GetString("Message"));
#pragma warning disable SYSLIB0050
PartieNonCommenceeException exceptionSerialisee =
(PartieNonCommenceeException)FormatterServices.GetUninitializedObject(typeof(PartieNonCommenceeException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(PartieNonCommenceeException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null);
Assert.NotNull(constructeur);
constructeur.Invoke(exceptionSerialisee, [info, contexte]);
Assert.Equal(exception.Message, exceptionSerialisee.Message);
}
}
}

@ -2,6 +2,8 @@
using CoreLibrary.Regles;
using CoreLibrary.Core;
using Xunit;
using System.Reflection;
using CoreLibrary.Events;
namespace UnitTesting
{
@ -164,5 +166,28 @@ namespace UnitTesting
partie.Jouer();
Assert.True(eventAppelle);
}
[Fact]
public void TestQuandSupprimerDernierJeton()
{
IRegles regles = new ReglesClassiques();
Partie partie = new Partie(regles);
bool appele = false;
partie.DemanderJeton += (sender, e) =>
{
return e.Indice == 0 || appele ? new Jeton() : null;
};
partie.SupprimerDernierJeton += (sender, e) =>
{
appele = true;
};
partie.Jouer();
Assert.True(appele);
}
}
}

@ -133,26 +133,40 @@ namespace UnitTesting
[Fact]
public void TestEstBonCodeFalse()
{
List<Couleur> couleurs = new List<Couleur>((Couleur[])Enum.GetValues(typeof(Couleur)));
Plateau plateau = new Plateau(4, 10);
Plateau plateau = new Plateau(2, 10);
Type type = typeof(Plateau);
FieldInfo? fieldInfo = type.GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(fieldInfo);
Code? codeSecret = (Code?)fieldInfo.GetValue(plateau);
Assert.NotNull(codeSecret);
Jeton[] jetons = codeSecret.Jetons().Where(jeton => jeton.HasValue).Select(jeton => jeton!.Value).ToArray();
Couleur couleurJeton = jetons[0].Couleur;
int indice = couleurs.IndexOf(couleurJeton) + 1;
if (indice >= couleurs.Count)
indice = 0;
int i = 0;
int j = 1;
while (jetons[i].Couleur == jetons[j].Couleur)
{
++i;
++j;
if (j == jetons.Length)
{
plateau = new Plateau(2, 10);
codeSecret = (Code?)fieldInfo.GetValue(plateau);
Assert.NotNull(codeSecret);
jetons = codeSecret.Jetons().Where(jeton => jeton.HasValue).Select(jeton => jeton!.Value).ToArray();
i = 0;
j = 1;
}
}
jetons[0] = new Jeton(couleurs[indice]);
Jeton tmp = jetons[0];
jetons[0] = jetons[1];
jetons[1] = tmp;
Code code = new Code(jetons);

@ -65,11 +65,28 @@ namespace UnitTesting
regles.AjouterJoueur("joueur2");
regles.CommencerLaPartie();
Joueur joueurCourantInitial = regles.JoueurCourant();
Type type = typeof(ReglesClassiques);
FieldInfo? fieldInfo = type.GetField("joueurCourant", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(fieldInfo);
int? joueurCourantAvant = (int?)fieldInfo.GetValue(regles);
Assert.NotNull(joueurCourantAvant);
if (joueurCourantAvant >= regles.NbJoueursMaximum)
joueurCourantAvant = 0;
regles.PasserLaMain();
Joueur joueurCourantSuivant = regles.JoueurCourant();
Assert.NotEqual(joueurCourantInitial, joueurCourantSuivant);
Assert.Equal(regles.JoueurCourant(), joueurCourantSuivant);
int? joueurCourantApres = (int?)fieldInfo.GetValue(regles);
Assert.NotNull(joueurCourantApres);
Assert.Equal(joueurCourantAvant, joueurCourantApres-1);
Assert.Equal(joueurCourantAvant+1, joueurCourantApres);
Assert.NotEqual(joueurCourantAvant, joueurCourantApres);
Assert.Equal("joueur2", joueurCourantSuivant.Nom);
}
@ -127,12 +144,43 @@ namespace UnitTesting
}
[Fact]
public void TestEstTermineeFalseUnJoueur()
public void TestEstTermineeFalseJoueurCourantNull()
{
ReglesClassiques regles = new ReglesClassiques();
regles.AjouterJoueur("joueur1");
regles.AjouterJoueur("joueur2");
regles.CommencerLaPartie();
regles.PasserLaMain();
Type type = typeof(ReglesClassiques);
FieldInfo? fieldInfo = type.GetField("joueurCourant", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(fieldInfo);
int? joueurCourant = (int?)fieldInfo.GetValue(regles);
joueurCourant = null;
Assert.Null(joueurCourant);
bool result = regles.EstTerminee();
Assert.False(result);
}
[Fact]
public void TestEstTermineeFalseJoueurCourantDiffDeZero()
{
ReglesClassiques regles = new ReglesClassiques();
regles.AjouterJoueur("joueur1");
regles.AjouterJoueur("joueur2");
regles.CommencerLaPartie();
Type type = typeof(ReglesClassiques);
FieldInfo? fieldInfo = type.GetField("joueurCourant", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(fieldInfo);
int? joueurCourant = (int?)fieldInfo.GetValue(regles);
joueurCourant = -1;
Assert.Equal(-1, joueurCourant);
bool result = regles.EstTerminee();
@ -173,7 +221,7 @@ namespace UnitTesting
}
[Fact]
public void TestEstTermineeToursMaximesAtteints()
public void TestEstTermineeToursMaximumAtteints()
{
ReglesClassiques regles = new ReglesClassiques();
Partie partie = new Partie(regles);
@ -191,8 +239,6 @@ namespace UnitTesting
Assert.True(estTerminee);
}
[Fact]
public void TestGagnantsAucunGagnants()
{

@ -1,4 +1,6 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
@ -65,5 +67,32 @@ namespace UnitTesting
}
}
[Fact]
public void ExceptionSerialisation()
{
TailleCodeException exception = new TailleCodeException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(TailleCodeException), new FormatterConverter());
StreamingContext contexte = new StreamingContext(StreamingContextStates.All);
#pragma warning restore SYSLIB0050
#pragma warning disable SYSLIB0051
exception.GetObjectData(info, contexte);
#pragma warning restore SYSLIB0051
Assert.Equal(exception.Message, info.GetString("Message"));
#pragma warning disable SYSLIB0050
TailleCodeException exceptionSerialisee =
(TailleCodeException)FormatterServices.GetUninitializedObject(typeof(TailleCodeException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(TailleCodeException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null);
Assert.NotNull(constructeur);
constructeur.Invoke(exceptionSerialisee, [info, contexte]);
Assert.Equal(exception.Message, exceptionSerialisee.Message);
}
}
}

@ -1,4 +1,6 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
@ -65,5 +67,32 @@ namespace UnitTesting
}
}
[Fact]
public void ExceptionSerialisation()
{
TailleGrilleException exception = new TailleGrilleException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(TailleGrilleException), new FormatterConverter());
StreamingContext contexte = new StreamingContext(StreamingContextStates.All);
#pragma warning restore SYSLIB0050
#pragma warning disable SYSLIB0051
exception.GetObjectData(info, contexte);
#pragma warning restore SYSLIB0051
Assert.Equal(exception.Message, info.GetString("Message"));
#pragma warning disable SYSLIB0050
TailleGrilleException exceptionSerialisee =
(TailleGrilleException)FormatterServices.GetUninitializedObject(typeof(TailleGrilleException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(TailleGrilleException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null);
Assert.NotNull(constructeur);
constructeur.Invoke(exceptionSerialisee, [info, contexte]);
Assert.Equal(exception.Message, exceptionSerialisee.Message);
}
}
}

Loading…
Cancel
Save