From 73481e1b22db09cfad9460b9b561889b4220fb67 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 17:04:45 +0200 Subject: [PATCH 01/13] Tests sur plateau, estboncodefalse --- Sources/UnitTesting/PlateauUT.cs | 34 ++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/Sources/UnitTesting/PlateauUT.cs b/Sources/UnitTesting/PlateauUT.cs index c2a9736..0e69ba8 100644 --- a/Sources/UnitTesting/PlateauUT.cs +++ b/Sources/UnitTesting/PlateauUT.cs @@ -133,26 +133,40 @@ namespace UnitTesting [Fact] public void TestEstBonCodeFalse() { - List couleurs = new List((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); From 07b4eff02d7efe4f663d934becb9e7fb1c2bc918 Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Fri, 17 May 2024 17:06:41 +0200 Subject: [PATCH 02/13] Test fini de ReglesClassiques ? --- Sources/UnitTesting/ReglesClassiquesUT.cs | 40 +++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/Sources/UnitTesting/ReglesClassiquesUT.cs b/Sources/UnitTesting/ReglesClassiquesUT.cs index 615974a..54b385d 100644 --- a/Sources/UnitTesting/ReglesClassiquesUT.cs +++ b/Sources/UnitTesting/ReglesClassiquesUT.cs @@ -65,11 +65,27 @@ 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); + + 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); Assert.Equal("joueur2", joueurCourantSuivant.Nom); } @@ -127,12 +143,24 @@ 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); + + joueurCourant = 1; + Assert.Equal(1, joueurCourant); bool result = regles.EstTerminee(); @@ -173,7 +201,7 @@ namespace UnitTesting } [Fact] - public void TestEstTermineeToursMaximesAtteints() + public void TestEstTermineeToursMaximumAtteints() { ReglesClassiques regles = new ReglesClassiques(); Partie partie = new Partie(regles); @@ -191,8 +219,6 @@ namespace UnitTesting Assert.True(estTerminee); } - - [Fact] public void TestGagnantsAucunGagnants() { From 06206f1ef891e9c5c542ea76656736310498577a Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Fri, 17 May 2024 17:15:02 +0200 Subject: [PATCH 03/13] Test Regles --- Sources/UnitTesting/ReglesClassiquesUT.cs | 26 +++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Sources/UnitTesting/ReglesClassiquesUT.cs b/Sources/UnitTesting/ReglesClassiquesUT.cs index 54b385d..e80bb8c 100644 --- a/Sources/UnitTesting/ReglesClassiquesUT.cs +++ b/Sources/UnitTesting/ReglesClassiquesUT.cs @@ -73,7 +73,6 @@ namespace UnitTesting int? joueurCourantAvant = (int?)fieldInfo.GetValue(regles); Assert.NotNull(joueurCourantAvant); - joueurCourantAvant++; if (joueurCourantAvant >= regles.NbJoueursMaximum) joueurCourantAvant = 0; @@ -85,7 +84,7 @@ namespace UnitTesting int? joueurCourantApres = (int?)fieldInfo.GetValue(regles); Assert.NotNull(joueurCourantApres); - Assert.Equal(joueurCourantAvant, joueurCourantApres); + Assert.NotEqual(joueurCourantAvant, joueurCourantApres); Assert.Equal("joueur2", joueurCourantSuivant.Nom); } @@ -159,8 +158,27 @@ namespace UnitTesting joueurCourant = null; Assert.Null(joueurCourant); - joueurCourant = 1; - Assert.Equal(1, 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(); From 33fea210d069e51c439d339d0fe80f70d21590ce Mon Sep 17 00:00:00 2001 From: "pauline.prady" Date: Fri, 17 May 2024 17:31:30 +0200 Subject: [PATCH 04/13] Tests --- Sources/UnitTesting/PartieUT.cs | 36 +++++++++++++++++++++++ Sources/UnitTesting/ReglesClassiquesUT.cs | 2 ++ 2 files changed, 38 insertions(+) diff --git a/Sources/UnitTesting/PartieUT.cs b/Sources/UnitTesting/PartieUT.cs index 6c62f38..9ff57e9 100644 --- a/Sources/UnitTesting/PartieUT.cs +++ b/Sources/UnitTesting/PartieUT.cs @@ -2,6 +2,8 @@ using CoreLibrary.Regles; using CoreLibrary.Core; using Xunit; +using System.Reflection; +using CoreLibrary.Events; namespace UnitTesting { @@ -164,5 +166,39 @@ namespace UnitTesting partie.Jouer(); Assert.True(eventAppelle); } + + [Fact] + public void TestCreerCodeJetonNull() + { + IRegles regles = new ReglesClassiques(); + Partie partie = new Partie(regles); + + //Type type = typeof(Partie); + + //FieldInfo? fieldInfo = type.GetField("CreerCode(Code code)", BindingFlags.NonPublic | BindingFlags.Instance); + //Assert.NotNull(fieldInfo); + + //Code? codeSecret = (Code?)fieldInfo.GetValue(plateau); + + //Assert.NotNull(codeSecret); + //plateau.AjouterCode(codeSecret); + //Assert.True(plateau.Victoire); + } + + [Fact] + public void TestQuandSupprimerDernierJeton() + { + IRegles regles = new ReglesClassiques(); + Partie partie = new Partie(regles); + bool eventAppelle = false; + + partie.SupprimerDernierJeton += (sender, e) => + { + eventAppelle = true; + }; + + partie.Jouer(); + Assert.True(eventAppelle); + } } } diff --git a/Sources/UnitTesting/ReglesClassiquesUT.cs b/Sources/UnitTesting/ReglesClassiquesUT.cs index e80bb8c..dba5535 100644 --- a/Sources/UnitTesting/ReglesClassiquesUT.cs +++ b/Sources/UnitTesting/ReglesClassiquesUT.cs @@ -84,6 +84,8 @@ namespace UnitTesting 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); } From 34070bc5d80ca050c3350909dd1c7797c6165dd4 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 18:48:25 +0200 Subject: [PATCH 05/13] test exception code complet --- Sources/UnitTesting/CodeCompletExceptionUT.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/UnitTesting/CodeCompletExceptionUT.cs b/Sources/UnitTesting/CodeCompletExceptionUT.cs index 06ebf97..865a9f6 100644 --- a/Sources/UnitTesting/CodeCompletExceptionUT.cs +++ b/Sources/UnitTesting/CodeCompletExceptionUT.cs @@ -1,4 +1,7 @@ using CoreLibrary.Exceptions; +using System.Runtime.Serialization; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text.Json; using Xunit; namespace UnitTesting @@ -22,7 +25,7 @@ namespace UnitTesting { throw new CodeCompletException(message); } - catch(CodeCompletException e) + catch (CodeCompletException e) { Assert.Equal(message, e.Message); } @@ -50,5 +53,17 @@ namespace UnitTesting } } + [Fact] + public void ExceptionSerialisation() + { + CodeCompletException exception = new CodeCompletException(); + + string jsonString = JsonSerializer.Serialize(exception); + CodeCompletException? exceptionSerialisee = + JsonSerializer.Deserialize(jsonString); + + Assert.NotNull(exceptionSerialisee); + Assert.Equal(exception.Message, exceptionSerialisee.Message); + } } } From 083ae5d1f72645e8cdece54f2a298ce1327e4ebe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9leste=20BARBOSA?= Date: Fri, 17 May 2024 18:52:06 +0200 Subject: [PATCH 06/13] =?UTF-8?q?Je=20pr=C3=A9f=C3=A8re=20le=20vert?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/UnitTesting/AjouterCodeEventArgsUT.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/UnitTesting/AjouterCodeEventArgsUT.cs b/Sources/UnitTesting/AjouterCodeEventArgsUT.cs index 4c35c6f..6c3b27f 100644 --- a/Sources/UnitTesting/AjouterCodeEventArgsUT.cs +++ b/Sources/UnitTesting/AjouterCodeEventArgsUT.cs @@ -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); From 0aafe9f688e74b81f48dcbf29741e35a7f0efbc7 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 18:58:48 +0200 Subject: [PATCH 07/13] Correction supprimerdernierjeton --- Sources/UnitTesting/PartieUT.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Sources/UnitTesting/PartieUT.cs b/Sources/UnitTesting/PartieUT.cs index 9ff57e9..0583ba3 100644 --- a/Sources/UnitTesting/PartieUT.cs +++ b/Sources/UnitTesting/PartieUT.cs @@ -190,15 +190,22 @@ namespace UnitTesting { IRegles regles = new ReglesClassiques(); Partie partie = new Partie(regles); - bool eventAppelle = false; + bool appele = false; - partie.SupprimerDernierJeton += (sender, e) => + partie.DemanderJeton += (sender, e) => { - eventAppelle = true; + return e.Indice == 0 || appele ? new Jeton() : null; + }; + + partie.SupprimerDernierJeton += (sender, e) => + { + appele = true; }; partie.Jouer(); - Assert.True(eventAppelle); + + + Assert.True(appele); } } } From 11eb607a20abc5c6f93d0436086c83b66b0562f6 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 19:03:27 +0200 Subject: [PATCH 08/13] Pourquoi ca fonctionne pas ;( --- Sources/UnitTesting/CodeCompletExceptionUT.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/UnitTesting/CodeCompletExceptionUT.cs b/Sources/UnitTesting/CodeCompletExceptionUT.cs index 865a9f6..5982a14 100644 --- a/Sources/UnitTesting/CodeCompletExceptionUT.cs +++ b/Sources/UnitTesting/CodeCompletExceptionUT.cs @@ -58,6 +58,7 @@ namespace UnitTesting { CodeCompletException exception = new CodeCompletException(); + string jsonString = JsonSerializer.Serialize(exception); CodeCompletException? exceptionSerialisee = JsonSerializer.Deserialize(jsonString); From 32917a5909ec3b2b31269f0fb7d32367a9f23df9 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 19:12:08 +0200 Subject: [PATCH 09/13] =?UTF-8?q?tentative=20de=20test=20sur=20exception?= =?UTF-8?q?=20serialis=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/UnitTesting/CodeCompletExceptionUT.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Sources/UnitTesting/CodeCompletExceptionUT.cs b/Sources/UnitTesting/CodeCompletExceptionUT.cs index 5982a14..cafd51a 100644 --- a/Sources/UnitTesting/CodeCompletExceptionUT.cs +++ b/Sources/UnitTesting/CodeCompletExceptionUT.cs @@ -58,13 +58,16 @@ namespace UnitTesting { 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 - string jsonString = JsonSerializer.Serialize(exception); - CodeCompletException? exceptionSerialisee = - JsonSerializer.Deserialize(jsonString); + #pragma warning disable SYSLIB0051 + exception.GetObjectData(info, contexte); + #pragma warning restore SYSLIB0051 - Assert.NotNull(exceptionSerialisee); - Assert.Equal(exception.Message, exceptionSerialisee.Message); + Assert.Equal(exception.Message, info.GetString("Message")); } } } From cc61e723cb8acfc20cfb12e16e2188344606a3de Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 19:16:52 +0200 Subject: [PATCH 10/13] =?UTF-8?q?fin=20exception=20s=C3=A9rialis=C3=A9e=20?= =?UTF-8?q?=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/UnitTesting/CodeCompletExceptionUT.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/UnitTesting/CodeCompletExceptionUT.cs b/Sources/UnitTesting/CodeCompletExceptionUT.cs index cafd51a..c378396 100644 --- a/Sources/UnitTesting/CodeCompletExceptionUT.cs +++ b/Sources/UnitTesting/CodeCompletExceptionUT.cs @@ -1,4 +1,5 @@ using CoreLibrary.Exceptions; +using System.Reflection; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; using System.Text.Json; @@ -68,6 +69,17 @@ namespace UnitTesting #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, new[] { typeof(SerializationInfo), typeof(StreamingContext) }, null); + Assert.NotNull(constructeur); + constructeur.Invoke(exceptionSerialisee, [info, contexte]); + + Assert.Equal(exception.Message, exceptionSerialisee.Message); } } } From ab65210bd2fbc227c73bc46b0279b5eefe6c5ce4 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 19:27:06 +0200 Subject: [PATCH 11/13] fin de tests des execeptions --- Sources/UnitTesting/CodeCompletExceptionUT.cs | 14 ++++----- .../UnitTesting/CodeIncompletExceptionUT.cs | 29 ++++++++++++++++++ .../UnitTesting/CodeInvalideExceptionUT.cs | 30 +++++++++++++++++++ Sources/UnitTesting/CodeVideExceptionUT.cs | 29 ++++++++++++++++++ .../UnitTesting/GrilleCompleteExceptionUT.cs | 29 ++++++++++++++++++ Sources/UnitTesting/IndiceCodeExceptionUT.cs | 29 ++++++++++++++++++ .../PartieNonCommenceeExceptionUT.cs | 29 ++++++++++++++++++ Sources/UnitTesting/TailleCodeExceptionUT.cs | 29 ++++++++++++++++++ .../UnitTesting/TailleGrilleExceptionUT.cs | 29 ++++++++++++++++++ 9 files changed, 240 insertions(+), 7 deletions(-) diff --git a/Sources/UnitTesting/CodeCompletExceptionUT.cs b/Sources/UnitTesting/CodeCompletExceptionUT.cs index c378396..0ac5325 100644 --- a/Sources/UnitTesting/CodeCompletExceptionUT.cs +++ b/Sources/UnitTesting/CodeCompletExceptionUT.cs @@ -59,23 +59,23 @@ namespace UnitTesting { CodeCompletException exception = new CodeCompletException(); - #pragma warning disable SYSLIB0050 +#pragma warning disable SYSLIB0050 SerializationInfo info = new SerializationInfo(typeof(CodeCompletException), new FormatterConverter()); StreamingContext contexte = new StreamingContext(StreamingContextStates.All); - #pragma warning restore SYSLIB0050 +#pragma warning restore SYSLIB0050 - #pragma warning disable SYSLIB0051 +#pragma warning disable SYSLIB0051 exception.GetObjectData(info, contexte); - #pragma warning restore SYSLIB0051 +#pragma warning restore SYSLIB0051 Assert.Equal(exception.Message, info.GetString("Message")); - #pragma warning disable SYSLIB0050 +#pragma warning disable SYSLIB0050 CodeCompletException exceptionSerialisee = (CodeCompletException) FormatterServices.GetUninitializedObject(typeof(CodeCompletException)); - #pragma warning restore SYSLIB0050 +#pragma warning restore SYSLIB0050 - ConstructorInfo? constructeur = typeof(CodeCompletException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, new[] { typeof(SerializationInfo), typeof(StreamingContext) }, null); + ConstructorInfo? constructeur = typeof(CodeCompletException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null); Assert.NotNull(constructeur); constructeur.Invoke(exceptionSerialisee, [info, contexte]); diff --git a/Sources/UnitTesting/CodeIncompletExceptionUT.cs b/Sources/UnitTesting/CodeIncompletExceptionUT.cs index b6bed0f..0476bb1 100644 --- a/Sources/UnitTesting/CodeIncompletExceptionUT.cs +++ b/Sources/UnitTesting/CodeIncompletExceptionUT.cs @@ -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); + } } } diff --git a/Sources/UnitTesting/CodeInvalideExceptionUT.cs b/Sources/UnitTesting/CodeInvalideExceptionUT.cs index 7fdf9c0..87242c6 100644 --- a/Sources/UnitTesting/CodeInvalideExceptionUT.cs +++ b/Sources/UnitTesting/CodeInvalideExceptionUT.cs @@ -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); + } + } } diff --git a/Sources/UnitTesting/CodeVideExceptionUT.cs b/Sources/UnitTesting/CodeVideExceptionUT.cs index 650dc3a..0787a4b 100644 --- a/Sources/UnitTesting/CodeVideExceptionUT.cs +++ b/Sources/UnitTesting/CodeVideExceptionUT.cs @@ -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); + } } } diff --git a/Sources/UnitTesting/GrilleCompleteExceptionUT.cs b/Sources/UnitTesting/GrilleCompleteExceptionUT.cs index 592fd65..c083a7d 100644 --- a/Sources/UnitTesting/GrilleCompleteExceptionUT.cs +++ b/Sources/UnitTesting/GrilleCompleteExceptionUT.cs @@ -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); + } } } diff --git a/Sources/UnitTesting/IndiceCodeExceptionUT.cs b/Sources/UnitTesting/IndiceCodeExceptionUT.cs index 50e40c4..a14c524 100644 --- a/Sources/UnitTesting/IndiceCodeExceptionUT.cs +++ b/Sources/UnitTesting/IndiceCodeExceptionUT.cs @@ -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); + } } } diff --git a/Sources/UnitTesting/PartieNonCommenceeExceptionUT.cs b/Sources/UnitTesting/PartieNonCommenceeExceptionUT.cs index c0733cf..e5d0c2d 100644 --- a/Sources/UnitTesting/PartieNonCommenceeExceptionUT.cs +++ b/Sources/UnitTesting/PartieNonCommenceeExceptionUT.cs @@ -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); + } } } diff --git a/Sources/UnitTesting/TailleCodeExceptionUT.cs b/Sources/UnitTesting/TailleCodeExceptionUT.cs index eda2056..7c1bfbe 100644 --- a/Sources/UnitTesting/TailleCodeExceptionUT.cs +++ b/Sources/UnitTesting/TailleCodeExceptionUT.cs @@ -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); + } } } diff --git a/Sources/UnitTesting/TailleGrilleExceptionUT.cs b/Sources/UnitTesting/TailleGrilleExceptionUT.cs index 8063a17..7d4bf33 100644 --- a/Sources/UnitTesting/TailleGrilleExceptionUT.cs +++ b/Sources/UnitTesting/TailleGrilleExceptionUT.cs @@ -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); + } } } From d0183e452a507c4fcb2b1786deec0fd4aa373798 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 19:28:39 +0200 Subject: [PATCH 12/13] mauvais code dans codevide ut --- Sources/UnitTesting/CodeVideExceptionUT.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Sources/UnitTesting/CodeVideExceptionUT.cs b/Sources/UnitTesting/CodeVideExceptionUT.cs index 0787a4b..2ad8544 100644 --- a/Sources/UnitTesting/CodeVideExceptionUT.cs +++ b/Sources/UnitTesting/CodeVideExceptionUT.cs @@ -55,10 +55,10 @@ namespace UnitTesting [Fact] public void ExceptionSerialisation() { - CodeIncompletException exception = new CodeIncompletException(); + CodeVideException exception = new CodeVideException(); #pragma warning disable SYSLIB0050 - SerializationInfo info = new SerializationInfo(typeof(CodeIncompletException), new FormatterConverter()); + SerializationInfo info = new SerializationInfo(typeof(CodeVideException), new FormatterConverter()); StreamingContext contexte = new StreamingContext(StreamingContextStates.All); #pragma warning restore SYSLIB0050 @@ -69,11 +69,11 @@ namespace UnitTesting Assert.Equal(exception.Message, info.GetString("Message")); #pragma warning disable SYSLIB0050 - CodeIncompletException exceptionSerialisee = - (CodeIncompletException)FormatterServices.GetUninitializedObject(typeof(CodeIncompletException)); + CodeVideException exceptionSerialisee = + (CodeVideException)FormatterServices.GetUninitializedObject(typeof(CodeVideException)); #pragma warning restore SYSLIB0050 - ConstructorInfo? constructeur = typeof(CodeIncompletException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null); + ConstructorInfo? constructeur = typeof(CodeVideException).GetConstructor(BindingFlags.Instance | BindingFlags.NonPublic, null, [typeof(SerializationInfo), typeof(StreamingContext)], null); Assert.NotNull(constructeur); constructeur.Invoke(exceptionSerialisee, [info, contexte]); From 74b462bc9eda203d26ab57d7a8e9f21dcbf95df2 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 19:31:00 +0200 Subject: [PATCH 13/13] code smell --- Sources/UnitTesting/PartieUT.cs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/Sources/UnitTesting/PartieUT.cs b/Sources/UnitTesting/PartieUT.cs index 0583ba3..55ab6e7 100644 --- a/Sources/UnitTesting/PartieUT.cs +++ b/Sources/UnitTesting/PartieUT.cs @@ -167,24 +167,6 @@ namespace UnitTesting Assert.True(eventAppelle); } - [Fact] - public void TestCreerCodeJetonNull() - { - IRegles regles = new ReglesClassiques(); - Partie partie = new Partie(regles); - - //Type type = typeof(Partie); - - //FieldInfo? fieldInfo = type.GetField("CreerCode(Code code)", BindingFlags.NonPublic | BindingFlags.Instance); - //Assert.NotNull(fieldInfo); - - //Code? codeSecret = (Code?)fieldInfo.GetValue(plateau); - - //Assert.NotNull(codeSecret); - //plateau.AjouterCode(codeSecret); - //Assert.True(plateau.Victoire); - } - [Fact] public void TestQuandSupprimerDernierJeton() {