diff --git a/Sources/UnitTesting/JoueurDejaConnecteExceptionUT.cs b/Sources/UnitTesting/JoueurDejaConnecteExceptionUT.cs new file mode 100644 index 0000000..f1035e6 --- /dev/null +++ b/Sources/UnitTesting/JoueurDejaConnecteExceptionUT.cs @@ -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(() => throw new JoueurDejaConnecteException()); + } + + [Fact] + public void ExceptionMessage() + { + string message = "Mon super gros problème."; + + Assert.ThrowsAsync(() => 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(() => 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(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); + } + } +} diff --git a/Sources/UnitTesting/JoueurDejaPresentExceptionUT.cs b/Sources/UnitTesting/JoueurDejaPresentExceptionUT.cs new file mode 100644 index 0000000..d6b3975 --- /dev/null +++ b/Sources/UnitTesting/JoueurDejaPresentExceptionUT.cs @@ -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(() => throw new JoueurDejaPresentException()); + } + + [Fact] + public void ExceptionMessage() + { + string message = "Mon super gros problème."; + + Assert.ThrowsAsync(() => 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(() => 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(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); + } + } +} diff --git a/Sources/UnitTesting/NomJoueurInterditExceptionUT.cs b/Sources/UnitTesting/NomJoueurInterditExceptionUT.cs new file mode 100644 index 0000000..6659841 --- /dev/null +++ b/Sources/UnitTesting/NomJoueurInterditExceptionUT.cs @@ -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(() => throw new NomJoueurInterditException()); + } + + [Fact] + public void ExceptionMessage() + { + string message = "Mon super gros problème."; + + Assert.ThrowsAsync(() => 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(() => 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(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); + } + } +} diff --git a/Sources/UnitTesting/ReglesClassiquesUT.cs b/Sources/UnitTesting/ReglesClassiquesUT.cs index 8aa5746..3a3606d 100644 --- a/Sources/UnitTesting/ReglesClassiquesUT.cs +++ b/Sources/UnitTesting/ReglesClassiquesUT.cs @@ -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(); } } } diff --git a/Sources/UnitTesting/ReglesDifficilesUT.cs b/Sources/UnitTesting/ReglesDifficilesUT.cs new file mode 100644 index 0000000..52c4357 --- /dev/null +++ b/Sources/UnitTesting/ReglesDifficilesUT.cs @@ -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(); + } + } +}