From 34070bc5d80ca050c3350909dd1c7797c6165dd4 Mon Sep 17 00:00:00 2001 From: "nicolas.barbosa" Date: Fri, 17 May 2024 18:48:25 +0200 Subject: [PATCH] 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); + } } }