coverage regles, exceptions
continuous-integration/drone/push Build is passing Details

master
Céleste BARBOSA 11 months ago
parent d18a82054f
commit 2b419e0f79

@ -0,0 +1,83 @@
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);
}
}
}

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

@ -0,0 +1,83 @@
using CoreLibrary.Exceptions;
using System.Reflection;
using System.Runtime.Serialization;
using Xunit;
namespace UnitTesting
{
public class NomJoueurInterditExceptionUT
{
[Fact]
public void ExceptionDefaut()
{
Assert.ThrowsAsync<NomJoueurInterditException>(() => throw new NomJoueurInterditException());
}
[Fact]
public void ExceptionMessage()
{
string message = "Mon super gros problème.";
Assert.ThrowsAsync<NomJoueurInterditException>(() => throw new NomJoueurInterditException(message));
try
{
throw new NomJoueurInterditException(message);
}
catch (NomJoueurInterditException 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<NomJoueurInterditException>(() => throw new NomJoueurInterditException(message, parent));
try
{
throw new NomJoueurInterditException(message, parent);
}
catch (NomJoueurInterditException 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()
{
NomJoueurInterditException exception = new NomJoueurInterditException();
#pragma warning disable SYSLIB0050
SerializationInfo info = new SerializationInfo(typeof(NomJoueurInterditException), 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
NomJoueurInterditException exceptionSerialisee =
(NomJoueurInterditException)FormatterServices.GetUninitializedObject(typeof(NomJoueurInterditException));
#pragma warning restore SYSLIB0050
ConstructorInfo? constructeur = typeof(NomJoueurInterditException).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,9 +1,4 @@
using CoreLibrary;
using CoreLibrary.Core;
using CoreLibrary.Exceptions;
using CoreLibrary.Joueurs;
using CoreLibrary.Regles;
using System.Reflection;
using CoreLibrary.Regles;
using Xunit;
namespace UnitTesting
@ -11,9 +6,16 @@ namespace UnitTesting
public class ReglesClassiquesUT
{
[Fact]
public void TestNom()
public void Test()
{
Assert.Equal("Règles classiques", new ReglesClassiques().Nom);
Assert.Equal(1, new ReglesClassiques().Indice);
Assert.NotNull(new ReglesClassiques().Nom);
Assert.NotNull(new ReglesClassiques().Description);
Assert.Equal(2, new ReglesClassiques().NbJoueurs);
Assert.Equal(12, new ReglesClassiques().NbTour);
Assert.Equal(4, new ReglesClassiques().TailleCode);
Assert.True(new ReglesClassiques().Equals(new ReglesClassiques()));
new ReglesClassiques().GetHashCode();
}
}
}

@ -0,0 +1,21 @@
using CoreLibrary.Regles;
using Xunit;
namespace UnitTesting
{
public class ReglesDifficilesUT
{
[Fact]
public void Test()
{
Assert.Equal(2, new ReglesDifficiles().Indice);
Assert.NotNull(new ReglesDifficiles().Nom);
Assert.NotNull(new ReglesDifficiles().Description);
Assert.Equal(2, new ReglesDifficiles().NbJoueurs);
Assert.Equal(12, new ReglesDifficiles().NbTour);
Assert.Equal(6, new ReglesDifficiles().TailleCode);
Assert.True(new ReglesDifficiles().Equals(new ReglesDifficiles()));
new ReglesDifficiles().GetHashCode();
}
}
}
Loading…
Cancel
Save