From 6fe01f66988ac924598489e66ad4e81c388bec40 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Mon, 13 May 2024 22:49:54 +0200 Subject: [PATCH] tentative tests unitaires sur une exception --- .../UnitTesting/DemanderJoueurEventArgsUT.cs | 3 +- .../UnitTesting/GrilleCompleteExceptionUT.cs | 54 +++++++++++++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 Sources/UnitTesting/GrilleCompleteExceptionUT.cs diff --git a/Sources/UnitTesting/DemanderJoueurEventArgsUT.cs b/Sources/UnitTesting/DemanderJoueurEventArgsUT.cs index 0a8d594..7662d5d 100644 --- a/Sources/UnitTesting/DemanderJoueurEventArgsUT.cs +++ b/Sources/UnitTesting/DemanderJoueurEventArgsUT.cs @@ -1,5 +1,4 @@ -using CoreLibrary; -using CoreLibrary.Events; +using CoreLibrary.Events; using Xunit; namespace UnitTesting diff --git a/Sources/UnitTesting/GrilleCompleteExceptionUT.cs b/Sources/UnitTesting/GrilleCompleteExceptionUT.cs new file mode 100644 index 0000000..592fd65 --- /dev/null +++ b/Sources/UnitTesting/GrilleCompleteExceptionUT.cs @@ -0,0 +1,54 @@ +using CoreLibrary.Exceptions; +using Xunit; + +namespace UnitTesting +{ + public class GrilleCompleteExceptionUT + { + [Fact] + public void ExceptionDefaut() + { + Assert.ThrowsAsync(() => throw new GrilleCompleteException()); + } + + [Fact] + public void ExceptionMessage() + { + string message = "Mon super gros problème."; + + Assert.ThrowsAsync(() => throw new GrilleCompleteException(message)); + + try + { + throw new GrilleCompleteException(message); + } + catch(GrilleCompleteException 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 GrilleCompleteException(message, parent)); + + try + { + throw new GrilleCompleteException(message, parent); + } + catch (GrilleCompleteException e) + { + Assert.Equal(message, e.Message); + Assert.NotNull(e.InnerException); + Assert.IsType(e.InnerException); + Assert.Equal(message2, e.InnerException.Message); + } + } + + } +}