Merge branch 'UT' of https://codefirst.iut.uca.fr/git/nicolas.barbosa/mastermind into UT
continuous-integration/drone/push Build is passing Details

master
commit 7f40e9a3b2

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\CoreLibrary\CoreLibrary.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,27 @@
// Cas 3 - Plateau rempli, code mauvaise couleur
using CoreLibrary.Core;
using System.Reflection;
Code code3 = new Code(1);
code3.AjouterJeton(new Jeton(Couleur.Rouge));
Plateau plateau3;
Code? codeSecret3;
do
{
plateau3 = new Plateau(1, 1);
FieldInfo? codeSecretInfo3 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
codeSecret3 = codeSecretInfo3.GetValue(plateau2) as Code;
Assert.NotNull(codeSecret3);
} while (codeSecret3.RecupererJeton(0).Equals(code3.RecupererJeton(0)));
plateau3.AjouterCode(codeSecret3);
MethodInfo? EstCodePossible3 = typeof(Robot).GetMethod("EstCodePossible", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
Assert.NotNull(EstCodePossible3);
object? estPossibleObj3 = EstCodePossible3.Invoke(new Robot(), [plateau3, code3]);
Assert.NotNull(estPossibleObj3);
Assert.IsType<bool>(estPossibleObj3);
Assert.False((bool)estPossibleObj3);

@ -1,49 +0,0 @@
using CoreLibrary.Joueurs;
using System.Runtime.Serialization;
namespace CoreLibrary.Exceptions
{
/// <summary>
/// Exception levée lorsqu'un joueur se connecte alors qu'il l'est déjà.
/// </summary>
[Serializable]
public class JoueurDejaConnecteException : Exception
{
// Message par défaut
private const string messageDefaut = "Le joueur est déjà connecté.";
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="JoueurDejaConnecteException"/> avec le message par défaut.
/// </summary>
public JoueurDejaConnecteException() : base(messageDefaut)
{}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="JoueurDejaConnecteException"/> avec le message spécifié.
/// </summary>
public JoueurDejaConnecteException(string message) : base(message)
{}
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="JoueurDejaConnecteException"/> avec le joueur spécifié.
/// </summary>
public JoueurDejaConnecteException(Joueur joueur) : base($"Le joueur {joueur.Nom} est déjà connecté.")
{ }
/// <summary>
/// Initialise une nouvelle instance de la classe <see cref="JoueurDejaConnecteException"/> avec le message et l'exception parent spécifiés.
/// </summary>
public JoueurDejaConnecteException(string message, Exception exception) : base(message, exception)
{}
[Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")]
protected JoueurDejaConnecteException(SerializationInfo info, StreamingContext contexte) : base(info, contexte)
{}
[Obsolete("This method is obsolete. Use alternative methods for data retrieval.", DiagnosticId = "SYSLIB0051")]
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
}
}
}

@ -1,83 +0,0 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
{
public class JoueurDejaConnecteExceptionUT
{
[Fact]
public void ExceptionDefaut()
{
Assert.ThrowsAsync<JoueurDejaConnecteException>(() => throw new JoueurDejaConnecteException());
}
[Fact]
public void ExceptionMessage()
{
string message = "Mon super gros problème.";
Assert.ThrowsAsync<JoueurDejaConnecteException>(() => throw new JoueurDejaConnecteException(message));
try
{
throw new JoueurDejaConnecteException(message);
}
catch (JoueurDejaConnecteException e)
{
Assert.Equal(message, e.Message);
}
}
[Fact]
public void ExceptionMessageEtException()
{
string message = "Mon super gros problème.";
string message2 = "Pas de chance...";
InvalidOperationException parent = new InvalidOperationException(message2);
Assert.ThrowsAsync<JoueurDejaConnecteException>(() => throw new JoueurDejaConnecteException(message, parent));
try
{
throw new JoueurDejaConnecteException(message, parent);
}
catch (JoueurDejaConnecteException e)
{
Assert.Equal(message, e.Message);
Assert.NotNull(e.InnerException);
Assert.IsType<InvalidOperationException>(e.InnerException);
Assert.Equal(message2, e.InnerException.Message);
}
}
[Fact]
public void ExceptionSerialisation()
{
JoueurDejaConnecteException exception = new JoueurDejaConnecteException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(JoueurDejaConnecteException), 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
JoueurDejaConnecteException exceptionSerialisee =
(JoueurDejaConnecteException)FormatterServices.GetUninitializedObject(typeof(JoueurDejaConnecteException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(JoueurDejaConnecteException).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);
}
}
}

@ -77,15 +77,6 @@ namespace UnitTesting
Assert.Equal(joueur2, eventArgs?.Joueur); Assert.Equal(joueur2, eventArgs?.Joueur);
} }
[Fact]
public void TestSeConnecterThrowException()
{
Joueur joueur = new Joueur("Joueur");
joueur.SeConnecter(joueur);
Assert.Throws<JoueurDejaConnecteException>(() => joueur.SeConnecter(joueur));
}
[Fact] [Fact]
public void TestToStringValide() public void TestToStringValide()
{ {

@ -2,9 +2,6 @@
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
{ {
@ -57,8 +54,6 @@ namespace UnitTesting
plateau.AjouterCode(code); plateau.AjouterCode(code);
plateau.AjouterCode(code); plateau.AjouterCode(code);
bool estComplet = plateau.Complet; bool estComplet = plateau.Complet;
Assert.False(estComplet); Assert.False(estComplet);

@ -0,0 +1,73 @@
using CoreLibrary;
using CoreLibrary.Core;
using CoreLibrary.Evenements;
using CoreLibrary.Joueurs;
using System.Reflection;
using Xunit;
namespace UnitTesting
{
public class RobotUT
{
[Fact]
public void TestEstCodePossible()
{
// Cas 1 - Plateau vide
Plateau plateau1 = new Plateau(1, 1);
Code code1 = new Code(1);
code1.AjouterJeton(new Jeton(Couleur.Rouge));
MethodInfo? EstCodePossible1 = typeof(Robot).GetMethod("EstCodePossible", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
Assert.NotNull(EstCodePossible1);
object? estPossibleObj1 = EstCodePossible1.Invoke(new Robot(), [plateau1, code1]);
Assert.NotNull(estPossibleObj1);
Assert.IsType<bool>(estPossibleObj1);
Assert.True((bool)estPossibleObj1);
// Cas 2 - Plateau rempli, code juste
Plateau plateau2 = new Plateau(1, 1);
FieldInfo? codeSecretInfo2 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(codeSecretInfo2);
Code? codeSecret2 = codeSecretInfo2.GetValue(plateau2) as Code;
Assert.NotNull(codeSecret2);
plateau2.AjouterCode(codeSecret2);
MethodInfo? EstCodePossible2 = typeof(Robot).GetMethod("EstCodePossible", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
Assert.NotNull(EstCodePossible2);
object? estPossibleObj2 = EstCodePossible2.Invoke(new Robot(), [plateau2, codeSecret2]);
Assert.NotNull(estPossibleObj2);
Assert.IsType<bool>(estPossibleObj2);
Assert.True((bool)estPossibleObj2);
// Cas 3 - Plateau rempli, code mauvaise couleur
Code code3 = new Code(1);
code3.AjouterJeton(new Jeton(Couleur.Rouge));
Plateau plateau3;
Code? codeSecret3;
do
{
plateau3 = new Plateau(1, 1);
FieldInfo? codeSecretInfo3 = typeof(Plateau).GetField("codeSecret", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.NotNull(codeSecretInfo3);
codeSecret3 = codeSecretInfo3.GetValue(plateau3) as Code;
Assert.NotNull(codeSecret3);
} while (codeSecret3.RecupererJeton(0).Equals(code3.RecupererJeton(0)));
plateau3.AjouterCode(codeSecret3);
MethodInfo? EstCodePossible3 = typeof(Robot).GetMethod("EstCodePossible", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);
Assert.NotNull(EstCodePossible3);
object? estPossibleObj3 = EstCodePossible3.Invoke(new Robot(), [plateau3, code3]);
Assert.NotNull(estPossibleObj3);
Assert.IsType<bool>(estPossibleObj3);
Assert.False((bool)estPossibleObj3);
}
}
}

@ -16,6 +16,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTesting", "UnitTesting\
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistance", "Persistance\Persistance.csproj", "{B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Persistance", "Persistance\Persistance.csproj", "{B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1\ConsoleApp1.csproj", "{2C86B541-6E8A-4C92-BC64-582413B22A49}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -44,6 +46,10 @@ Global
{B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}.Debug|Any CPU.Build.0 = Debug|Any CPU {B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}.Release|Any CPU.ActiveCfg = Release|Any CPU {B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}.Release|Any CPU.Build.0 = Release|Any CPU {B9E8C10D-9E0E-42F1-8F2C-1E2200DD96FA}.Release|Any CPU.Build.0 = Release|Any CPU
{2C86B541-6E8A-4C92-BC64-582413B22A49}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C86B541-6E8A-4C92-BC64-582413B22A49}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C86B541-6E8A-4C92-BC64-582413B22A49}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C86B541-6E8A-4C92-BC64-582413B22A49}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

Loading…
Cancel
Save