diff --git a/src/common/interop-tests/InteropTests.cs b/src/common/interop-tests/InteropTests.cs
index d1bf8c4aed..aa01689c42 100644
--- a/src/common/interop-tests/InteropTests.cs
+++ b/src/common/interop-tests/InteropTests.cs
@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System;
using System.Threading;
using interop;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -9,46 +10,73 @@ using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.Interop.Tests
{
[TestClass]
- public class InteropTests
+ public class InteropTests : IDisposable
{
private const string ServerSidePipe = "\\\\.\\pipe\\serverside";
private const string ClientSidePipe = "\\\\.\\pipe\\clientside";
- private TwoWayPipeMessageIPCManaged clientPipe;
+ internal TwoWayPipeMessageIPCManaged ClientPipe { get; set; }
+
+ private bool disposedValue;
[TestInitialize]
public void Initialize()
{
- clientPipe = new TwoWayPipeMessageIPCManaged(ClientSidePipe, ServerSidePipe, null);
+ ClientPipe = new TwoWayPipeMessageIPCManaged(ClientSidePipe, ServerSidePipe, null);
}
[TestCleanup]
public void Cleanup()
{
- clientPipe.End();
+ ClientPipe.End();
}
[TestMethod]
public void TestSend()
{
var testString = "This string is a test\n";
- var reset = new AutoResetEvent(false);
-
- var serverPipe = new TwoWayPipeMessageIPCManaged(
- ServerSidePipe,
- ClientSidePipe,
- (string msg) =>
+ using (var reset = new AutoResetEvent(false))
+ {
+ using (var serverPipe = new TwoWayPipeMessageIPCManaged(
+ ServerSidePipe,
+ ClientSidePipe,
+ (string msg) =>
+ {
+ Assert.AreEqual(testString, msg);
+ reset.Set();
+ }))
{
- Assert.AreEqual(testString, msg);
- reset.Set();
- });
- serverPipe.Start();
- clientPipe.Start();
+ serverPipe.Start();
+ ClientPipe.Start();
- clientPipe.Send(testString);
- reset.WaitOne();
+ ClientPipe.Send(testString);
+ reset.WaitOne();
- serverPipe.End();
+ serverPipe.End();
+ }
+ }
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (!disposedValue)
+ {
+ if (disposing)
+ {
+ ClientPipe.Dispose();
+ }
+
+ // TODO: free unmanaged resources (unmanaged objects) and override finalizer
+ // TODO: set large fields to null
+ disposedValue = true;
+ }
+ }
+
+ public void Dispose()
+ {
+ // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
+ Dispose(disposing: true);
+ GC.SuppressFinalize(this);
}
}
}
diff --git a/src/common/interop-tests/Microsoft.Interop.Tests.csproj b/src/common/interop-tests/Microsoft.Interop.Tests.csproj
index 30e6e94211..c8582f3940 100644
--- a/src/common/interop-tests/Microsoft.Interop.Tests.csproj
+++ b/src/common/interop-tests/Microsoft.Interop.Tests.csproj
@@ -77,7 +77,6 @@
true
-
true
@@ -107,6 +106,11 @@
+
+ 3.3.0
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+ all
+
1.1.118
runtime; build; native; contentfiles; analyzers; buildtransitive