Skip to content

Commit 41dde35

Browse files
CopilotRob-Hague
andauthored
Replace custom TestMethodForPlatformAttribute with MSTest OSCondition (#1766)
* Initial plan * Replace TestMethodForPlatformAttribute with OSCondition attribute Co-authored-by: Rob-Hague <5132141+Rob-Hague@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Rob-Hague <5132141+Rob-Hague@users.noreply.github.com>
1 parent 085dead commit 41dde35

7 files changed

+28
-65
lines changed

test/Renci.SshNet.Tests/Classes/Connection/DirectConnectorTest_Connect_TimeoutConnectingToServer.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
using System.Globalization;
44
using System.Net;
55
using System.Net.Sockets;
6-
using System.Runtime.InteropServices;
76

87
using Microsoft.VisualStudio.TestTools.UnitTesting;
98

109
using Moq;
1110

1211
using Renci.SshNet.Common;
13-
using Renci.SshNet.Tests.Common;
1412

1513
namespace Renci.SshNet.Tests.Classes.Connection
1614
{
@@ -72,23 +70,26 @@ protected override void Act()
7270
}
7371
}
7472

75-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
73+
[TestMethod]
74+
[OSCondition(OperatingSystems.Windows)]
7675
public void ConnectShouldHaveThrownSshOperationTimeoutExceptionOnWindows()
7776
{
7877
Assert.IsNull(_actualException.InnerException);
7978
Assert.IsInstanceOfType<SshOperationTimeoutException>(_actualException);
8079
Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Connection failed to establish within {0} milliseconds.", _connectionInfo.Timeout.TotalMilliseconds), _actualException.Message);
8180
}
8281

83-
[TestMethodForPlatform(nameof(OSPlatform.Linux))]
82+
[TestMethod]
83+
[OSCondition(OperatingSystems.Linux)]
8484
public void ConnectShouldHaveThrownSocketExceptionOnLinux()
8585
{
8686
Assert.IsNull(_actualException.InnerException);
8787
Assert.IsInstanceOfType<SocketException>(_actualException);
8888
Assert.AreEqual("Connection refused", _actualException.Message);
8989
}
9090

91-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
91+
[TestMethod]
92+
[OSCondition(OperatingSystems.Windows)]
9293
public void ConnectShouldHaveRespectedTimeoutOnWindows()
9394
{
9495
var errorText = string.Format("Elapsed: {0}, Timeout: {1}",

test/Renci.SshNet.Tests/Classes/Connection/HttpConnectorTest_Connect_TimeoutConnectingToProxy.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
using System.Globalization;
44
using System.Net;
55
using System.Net.Sockets;
6-
using System.Runtime.InteropServices;
76

87
using Microsoft.VisualStudio.TestTools.UnitTesting;
98

109
using Moq;
1110

1211
using Renci.SshNet.Common;
13-
using Renci.SshNet.Tests.Common;
1412

1513
namespace Renci.SshNet.Tests.Classes.Connection
1614
{
@@ -82,23 +80,26 @@ protected override void Act()
8280
}
8381
}
8482

85-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
83+
[TestMethod]
84+
[OSCondition(OperatingSystems.Windows)]
8685
public void ConnectShouldHaveThrownSshOperationTimeoutExceptionOnWindows()
8786
{
8887
Assert.IsNull(_actualException.InnerException);
8988
Assert.IsInstanceOfType<SshOperationTimeoutException>(_actualException);
9089
Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Connection failed to establish within {0} milliseconds.", _connectionInfo.Timeout.TotalMilliseconds), _actualException.Message);
9190
}
9291

93-
[TestMethodForPlatform(nameof(OSPlatform.Linux))]
92+
[TestMethod]
93+
[OSCondition(OperatingSystems.Linux)]
9494
public void ConnectShouldHaveThrownSshOperationTimeoutExceptionOnLinux()
9595
{
9696
Assert.IsNull(_actualException.InnerException);
9797
Assert.IsInstanceOfType<SocketException>(_actualException);
9898
Assert.AreEqual("Connection refused", _actualException.Message);
9999
}
100100

101-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
101+
[TestMethod]
102+
[OSCondition(OperatingSystems.Windows)]
102103
public void ConnectShouldHaveRespectedTimeoutOnWindows()
103104
{
104105
var errorText = string.Format("Elapsed: {0}, Timeout: {1}",

test/Renci.SshNet.Tests/Classes/Connection/Socks4ConnectorTest_Connect_TimeoutConnectingToProxy.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
using System.Diagnostics;
33
using System.Globalization;
44
using System.Net.Sockets;
5-
using System.Runtime.InteropServices;
65

76
using Microsoft.VisualStudio.TestTools.UnitTesting;
87

98
using Moq;
109

1110
using Renci.SshNet.Common;
12-
using Renci.SshNet.Tests.Common;
1311

1412
namespace Renci.SshNet.Tests.Classes.Connection
1513
{
@@ -70,23 +68,26 @@ protected override void Act()
7068
}
7169
}
7270

73-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
71+
[TestMethod]
72+
[OSCondition(OperatingSystems.Windows)]
7473
public void ConnectShouldHaveThrownSshOperationTimeoutExceptionOnWindows()
7574
{
7675
Assert.IsNull(_actualException.InnerException);
7776
Assert.IsInstanceOfType<SshOperationTimeoutException>(_actualException);
7877
Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Connection failed to establish within {0} milliseconds.", _connectionInfo.Timeout.TotalMilliseconds), _actualException.Message);
7978
}
8079

81-
[TestMethodForPlatform(nameof(OSPlatform.Linux))]
80+
[TestMethod]
81+
[OSCondition(OperatingSystems.Linux)]
8282
public void ConnectShouldHaveThrownSshOperationTimeoutExceptionOnLinux()
8383
{
8484
Assert.IsNull(_actualException.InnerException);
8585
Assert.IsInstanceOfType<SocketException>(_actualException);
8686
Assert.AreEqual("Connection refused", _actualException.Message);
8787
}
8888

89-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
89+
[TestMethod]
90+
[OSCondition(OperatingSystems.Windows)]
9091
public void ConnectShouldHaveRespectedTimeoutOnWindows()
9192
{
9293
var errorText = string.Format("Elapsed: {0}, Timeout: {1}",

test/Renci.SshNet.Tests/Classes/Connection/Socks5ConnectorTest_Connect_TimeoutConnectingToProxy.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
using System.Diagnostics;
33
using System.Globalization;
44
using System.Net.Sockets;
5-
using System.Runtime.InteropServices;
65

76
using Microsoft.VisualStudio.TestTools.UnitTesting;
87

98
using Moq;
109

1110
using Renci.SshNet.Common;
12-
using Renci.SshNet.Tests.Common;
1311

1412
namespace Renci.SshNet.Tests.Classes.Connection
1513
{
@@ -71,23 +69,26 @@ protected override void Act()
7169
}
7270
}
7371

74-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
72+
[TestMethod]
73+
[OSCondition(OperatingSystems.Windows)]
7574
public void ConnectShouldHaveThrownSshOperationTimeoutExceptionOnWindows()
7675
{
7776
Assert.IsNull(_actualException.InnerException);
7877
Assert.IsInstanceOfType<SshOperationTimeoutException>(_actualException);
7978
Assert.AreEqual(string.Format(CultureInfo.InvariantCulture, "Connection failed to establish within {0} milliseconds.", _connectionInfo.Timeout.TotalMilliseconds), _actualException.Message);
8079
}
8180

82-
[TestMethodForPlatform(nameof(OSPlatform.Linux))]
81+
[TestMethod]
82+
[OSCondition(OperatingSystems.Linux)]
8383
public void ConnectShouldHaveThrownSshOperationTimeoutExceptionOnLinux()
8484
{
8585
Assert.IsNull(_actualException.InnerException);
8686
Assert.IsInstanceOfType<SocketException>(_actualException);
8787
Assert.AreEqual("Connection refused", _actualException.Message);
8888
}
8989

90-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
90+
[TestMethod]
91+
[OSCondition(OperatingSystems.Windows)]
9192
public void ConnectShouldHaveRespectedTimeoutOnWindows()
9293
{
9394
var errorText = string.Format("Elapsed: {0}, Timeout: {1}",

test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Dispose_PortStarted_ChannelNotBound.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Net;
44
using System.Net.Sockets;
5-
using System.Runtime.InteropServices;
65
using System.Threading;
76

87
using Microsoft.Extensions.Logging.Abstractions;
@@ -12,7 +11,6 @@
1211

1312
using Renci.SshNet.Channels;
1413
using Renci.SshNet.Common;
15-
using Renci.SshNet.Tests.Common;
1614

1715
namespace Renci.SshNet.Tests.Classes
1816
{
@@ -108,7 +106,8 @@ public void ForwardedPortShouldRefuseNewConnections()
108106
}
109107

110108
// TODO We should investigate why this method doesn't work on Linux
111-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
109+
[TestMethod]
110+
[OSCondition(OperatingSystems.Windows)]
112111
public void ExistingConnectionShouldBeClosed()
113112
{
114113
try

test/Renci.SshNet.Tests/Classes/ForwardedPortDynamicTest_Stop_PortStarted_ChannelNotBound.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Net;
44
using System.Net.Sockets;
5-
using System.Runtime.InteropServices;
65
using System.Threading;
76

87
using Microsoft.Extensions.Logging.Abstractions;
@@ -12,7 +11,6 @@
1211

1312
using Renci.SshNet.Channels;
1413
using Renci.SshNet.Common;
15-
using Renci.SshNet.Tests.Common;
1614

1715
namespace Renci.SshNet.Tests.Classes
1816
{
@@ -112,7 +110,8 @@ public void ForwardedPortShouldRefuseNewConnections()
112110
}
113111

114112
// TODO We should investigate why this method doesn't work on Linux
115-
[TestMethodForPlatform(nameof(OSPlatform.Windows))]
113+
[TestMethod]
114+
[OSCondition(OperatingSystems.Windows)]
116115
public void ExistingConnectionShouldBeClosed()
117116
{
118117
try

test/Renci.SshNet.Tests/Common/TestMethodForPlatformAttribute.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)