diff --git a/Tests/CSharpCore/Unit/Messaging/ErrorExceptionTestFixture.cs b/Tests/CSharpCore/Unit/Messaging/ErrorExceptionTestFixture.cs index 866b3da2..ac61f86f 100644 --- a/Tests/CSharpCore/Unit/Messaging/ErrorExceptionTestFixture.cs +++ b/Tests/CSharpCore/Unit/Messaging/ErrorExceptionTestFixture.cs @@ -56,17 +56,19 @@ public void ErrorException_SerializationTest() // Act // Serialize the original exception to a memory stream - using var memoryStream = new MemoryStream(); - binaryFormatter.Serialize(memoryStream, originalException); - memoryStream.Position = 0; + using (var memoryStream = new MemoryStream()) + { + binaryFormatter.Serialize(memoryStream, originalException); + memoryStream.Position = 0; - // Deserialize the memory stream back into an object - var deserializedException = (ErrorException)binaryFormatter.Deserialize(memoryStream); + // Deserialize the memory stream back into an object + var deserializedException = (ErrorException)binaryFormatter.Deserialize(memoryStream); - // Assert - Assert.NotNull(deserializedException); - Assert.Equal(originalException.Message, deserializedException.Message); - Assert.IsType(deserializedException.InnerException); + // Assert + Assert.NotNull(deserializedException); + Assert.Equal(originalException.Message, deserializedException.Message); + Assert.IsType(deserializedException.InnerException); + } } [Fact] diff --git a/Tests/CSharpCore/Unit/Messaging/MessageFactoryExceptionTestFixture.cs b/Tests/CSharpCore/Unit/Messaging/MessageFactoryExceptionTestFixture.cs index 5a99bd08..62848839 100644 --- a/Tests/CSharpCore/Unit/Messaging/MessageFactoryExceptionTestFixture.cs +++ b/Tests/CSharpCore/Unit/Messaging/MessageFactoryExceptionTestFixture.cs @@ -56,18 +56,20 @@ public void MessageFactoryException_SerializationTest() // Act // Serialize the original exception to a memory stream - using var memoryStream = new MemoryStream(); - binaryFormatter.Serialize(memoryStream, originalException); - memoryStream.Position = 0; - - // Deserialize the memory stream back into an object - var deserializedException = (MessageFactoryException)binaryFormatter.Deserialize(memoryStream); - - // Assert - Assert.NotNull(deserializedException); - Assert.Equal(originalException.Message, deserializedException.Message); - Assert.IsType(deserializedException.InnerException); - Assert.Equal(originalException.GetBytes(), deserializedException.GetBytes()); + using (var memoryStream = new MemoryStream()) + { + binaryFormatter.Serialize(memoryStream, originalException); + memoryStream.Position = 0; + + // Deserialize the memory stream back into an object + var deserializedException = (MessageFactoryException)binaryFormatter.Deserialize(memoryStream); + + // Assert + Assert.NotNull(deserializedException); + Assert.Equal(originalException.Message, deserializedException.Message); + Assert.IsType(deserializedException.InnerException); + Assert.Equal(originalException.GetBytes(), deserializedException.GetBytes()); + } } [Fact] diff --git a/Tests/CSharpCore/Unit/Messaging/PortInUseExceptionTestFixture.cs b/Tests/CSharpCore/Unit/Messaging/PortInUseExceptionTestFixture.cs index 3d5f7460..1b46adf8 100644 --- a/Tests/CSharpCore/Unit/Messaging/PortInUseExceptionTestFixture.cs +++ b/Tests/CSharpCore/Unit/Messaging/PortInUseExceptionTestFixture.cs @@ -57,18 +57,20 @@ public void PortInUseException_SerializationTest() // Act // Serialize the original exception to a memory stream - using var memoryStream = new MemoryStream(); - binaryFormatter.Serialize(memoryStream, originalException); - memoryStream.Position = 0; + using (var memoryStream = new MemoryStream()) + { + binaryFormatter.Serialize(memoryStream, originalException); + memoryStream.Position = 0; - // Deserialize the memory stream back into an object - var deserializedException = (PortInUseException)binaryFormatter.Deserialize(memoryStream); + // Deserialize the memory stream back into an object + var deserializedException = (PortInUseException)binaryFormatter.Deserialize(memoryStream); - // Assert - Assert.NotNull(deserializedException); - Assert.Equal(originalException.Message, deserializedException.Message); - Assert.IsType(deserializedException.InnerException); - Assert.Equal(originalException.Endpoint, deserializedException.Endpoint); + // Assert + Assert.NotNull(deserializedException); + Assert.Equal(originalException.Message, deserializedException.Message); + Assert.IsType(deserializedException.InnerException); + Assert.Equal(originalException.Endpoint, deserializedException.Endpoint); + } } [Fact] diff --git a/Tests/CSharpCore/Unit/Messaging/TimeoutExceptionTestFixture.cs b/Tests/CSharpCore/Unit/Messaging/TimeoutExceptionTestFixture.cs index 43eaceb7..d24dbc07 100644 --- a/Tests/CSharpCore/Unit/Messaging/TimeoutExceptionTestFixture.cs +++ b/Tests/CSharpCore/Unit/Messaging/TimeoutExceptionTestFixture.cs @@ -56,18 +56,20 @@ public void TimeoutException_SerializationTest() // Act // Serialize the original exception to a memory stream - using var memoryStream = new MemoryStream(); - binaryFormatter.Serialize(memoryStream, originalException); - memoryStream.Position = 0; - - // Deserialize the memory stream back into an object - var deserializedException = (TimeoutException)binaryFormatter.Deserialize(memoryStream); - - // Assert - Assert.NotNull(deserializedException); - Assert.Equal(originalException.Message, deserializedException.Message); - Assert.IsType(deserializedException.InnerException); - Assert.Equal(originalException.Timeout, deserializedException.Timeout); + using (var memoryStream = new MemoryStream()) + { + binaryFormatter.Serialize(memoryStream, originalException); + memoryStream.Position = 0; + + // Deserialize the memory stream back into an object + var deserializedException = (TimeoutException)binaryFormatter.Deserialize(memoryStream); + + // Assert + Assert.NotNull(deserializedException); + Assert.Equal(originalException.Message, deserializedException.Message); + Assert.IsType(deserializedException.InnerException); + Assert.Equal(originalException.Timeout, deserializedException.Timeout); + } } [Fact]