Skip to content

Commit 933613e

Browse files
mus65WojciechNagorskiRob-Hague
authored
Update to MSTest 4 (#1721)
* Update to MSTest 4 * fix TestMethodForPlatformAttribute replace Execute with ExecuteAsync and fix MSTEST0057 https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0057 (link currently dead) * fix compilation error * fix MSTEST0037 https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0037 * fix MSTEST0052 https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0052 * fix MSTEST0045 Fixing this properly would require the tests to respect testContext.CancellationToken. I'm not sure this is worth fixing or how to even do it for the sync methods. https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0045 * fix MSTEST0001 I assume that parallelization would break a lot of stuff. https://learn.microsoft.com/en-us/dotnet/core/testing/mstest-analyzers/mstest0001 * Workaround for new Sonar warnings because of MSTest4 * revert analyzer fixes in OrderedDictionaryTest * use custom sync console logger for MSTest to work around microsoft/testfx#6457 * remove redundant args --------- Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com> Co-authored-by: Rob Hague <rob.hague00@gmail.com>
1 parent bf976d5 commit 933613e

File tree

221 files changed

+627
-539
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

221 files changed

+627
-539
lines changed

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<PackageVersion Include="Microsoft.Bcl.Cryptography" Version="10.0.0" />
1515
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.3" />
1616
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.9" />
17-
<PackageVersion Include="MSTest" Version="3.9.3" />
17+
<PackageVersion Include="MSTest" Version="4.0.2" />
1818
<PackageVersion Include="Moq" Version="4.20.72" />
1919
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.7.115" />
2020
<PackageVersion Include="PolySharp" Version="1.15.0" />

test/.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ dotnet_diagnostic.SA1623.severity = none
102102
# For unit test projects, we do not care about documentation.
103103
dotnet_diagnostic.SA1629.severity = none
104104

105+
# Workaround https://github.com/SonarSource/sonar-dotnet/issues/9767
106+
dotnet_diagnostic.S1450.severity = none
107+
dotnet_diagnostic.S1764.severity = none
108+
dotnet_diagnostic.S3260.severity = none
109+
dotnet_diagnostic.S5445.severity = none
110+
105111
#### .NET Compiler Platform analysers rules ####
106112

107113
# CA1001: Types that own disposable fields should be disposable
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[assembly: DoNotParallelize]

test/Renci.SshNet.IntegrationTests/AuthenticationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public void KeyboardInteractive_NoResponseSet_ThrowsSshAuthenticationException()
436436
catch (SshAuthenticationException ex)
437437
{
438438
Assert.IsNull(ex.InnerException);
439-
Assert.IsTrue(ex.Message.StartsWith("AuthenticationPrompt.Response is null for prompt \"Password: \""), $"Message was \"{ex.Message}\"");
439+
Assert.StartsWith("AuthenticationPrompt.Response is null for prompt \"Password: \"", ex.Message);
440440
}
441441
}
442442
}

test/Renci.SshNet.IntegrationTests/ConnectivityTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ public void Common_HostKeyAlgorithms_NoMatch()
432432
var ex = Assert.Throws<SshConnectionException>(client.Connect);
433433

434434
Assert.AreEqual(DisconnectReason.KeyExchangeFailed, ex.DisconnectReason);
435-
Assert.IsTrue(ex.Message.StartsWith("No matching host key algorithm"), ex.Message);
435+
Assert.StartsWith("No matching host key algorithm", ex.Message);
436436
}
437437
}
438438

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#nullable enable
2+
using Microsoft.Extensions.Logging;
3+
4+
namespace Renci.SshNet.IntegrationTests.Logging
5+
{
6+
internal class TestConsoleLogger(string categoryName) : ILogger
7+
{
8+
public IDisposable? BeginScope<TState>(TState state)
9+
where TState : notnull
10+
{
11+
return null;
12+
}
13+
14+
public bool IsEnabled(LogLevel logLevel)
15+
{
16+
return true;
17+
}
18+
19+
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter)
20+
{
21+
StringBuilder sb = new StringBuilder();
22+
sb.Append(logLevel);
23+
sb.Append(": ");
24+
sb.Append(categoryName);
25+
sb.Append(": ");
26+
27+
string message = formatter(state, exception);
28+
sb.Append(message);
29+
30+
if (exception != null)
31+
{
32+
sb.Append(": ");
33+
sb.Append(exception);
34+
}
35+
36+
string line = sb.ToString();
37+
Console.WriteLine(line);
38+
}
39+
}
40+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#nullable enable
2+
3+
using Microsoft.Extensions.Logging;
4+
5+
namespace Renci.SshNet.IntegrationTests.Logging
6+
{
7+
internal class TestConsoleLoggerProvider : ILoggerProvider
8+
{
9+
public ILogger CreateLogger(string categoryName)
10+
{
11+
return new TestConsoleLogger(categoryName);
12+
}
13+
14+
public void Dispose()
15+
{
16+
}
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#nullable enable
2+
3+
using Microsoft.Extensions.DependencyInjection;
4+
using Microsoft.Extensions.DependencyInjection.Extensions;
5+
using Microsoft.Extensions.Logging;
6+
7+
namespace Renci.SshNet.IntegrationTests.Logging
8+
{
9+
internal static class TestConsoleLoggerProviderExtensions
10+
{
11+
internal static void AddTestConsoleLogger(this ILoggingBuilder builder)
12+
{
13+
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, TestConsoleLoggerProvider>());
14+
}
15+
}
16+
}

test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.ListDirectory.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public void Test_Sftp_ListDirectory_Current()
4343

4444
var files = sftp.ListDirectory(".");
4545

46-
Assert.IsTrue(files.Count() > 0);
46+
Assert.IsGreaterThan(0, files.Count());
4747

4848
foreach (var file in files)
4949
{
@@ -71,7 +71,7 @@ public async Task Test_Sftp_ListDirectoryAsync_Current()
7171
Debug.WriteLine(file.FullName);
7272
}
7373

74-
Assert.IsTrue(count > 0);
74+
Assert.IsGreaterThan(0, count);
7575

7676
sftp.Disconnect();
7777
}
@@ -87,7 +87,7 @@ public void Test_Sftp_ListDirectory_Empty()
8787

8888
var files = sftp.ListDirectory(string.Empty);
8989

90-
Assert.IsTrue(files.Count() > 0);
90+
Assert.IsGreaterThan(0, files.Count());
9191

9292
foreach (var file in files)
9393
{
@@ -128,7 +128,7 @@ public void Test_Sftp_ListDirectory_HugeDirectory()
128128
var files = sftp.ListDirectory(".");
129129

130130
// Ensure that directory has at least 10000 items
131-
Assert.IsTrue(files.Count() > 10000);
131+
Assert.IsGreaterThan(10000, files.Count());
132132

133133
sftp.Disconnect();
134134
}
@@ -158,7 +158,7 @@ public void Test_Sftp_Change_Directory()
158158

159159
var files = sftp.ListDirectory(".");
160160

161-
Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}", sftp.WorkingDirectory)));
161+
Assert.StartsWith(string.Format("{0}", sftp.WorkingDirectory), files.First().FullName);
162162

163163
sftp.ChangeDirectory("test1_1");
164164

@@ -178,7 +178,7 @@ public void Test_Sftp_Change_Directory()
178178

179179
files = sftp.ListDirectory("test1/test1_1");
180180

181-
Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory)));
181+
Assert.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory), files.First().FullName);
182182

183183
sftp.ChangeDirectory("test1/test1_1");
184184

@@ -227,7 +227,7 @@ public async Task Test_Sftp_Change_DirectoryAsync()
227227

228228
var files = sftp.ListDirectory(".");
229229

230-
Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}", sftp.WorkingDirectory)));
230+
Assert.StartsWith(string.Format("{0}", sftp.WorkingDirectory), files.First().FullName);
231231

232232
await sftp.ChangeDirectoryAsync("test1_1", CancellationToken.None).ConfigureAwait(false);
233233

@@ -247,7 +247,7 @@ public async Task Test_Sftp_Change_DirectoryAsync()
247247

248248
files = sftp.ListDirectory("test1/test1_1");
249249

250-
Assert.IsTrue(files.First().FullName.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory)));
250+
Assert.StartsWith(string.Format("{0}/test1/test1_1", sftp.WorkingDirectory), files.First().FullName);
251251

252252
await sftp.ChangeDirectoryAsync("test1/test1_1", CancellationToken.None).ConfigureAwait(false);
253253

test/Renci.SshNet.IntegrationTests/OldIntegrationTests/SftpClientTest.SynchronizeDirectories.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void Test_Sftp_SynchronizeDirectories()
2424
string searchPattern = Path.GetFileName(uploadedFileName);
2525
var upLoadedFiles = sftp.SynchronizeDirectories(sourceDir, destDir, searchPattern);
2626

27-
Assert.IsTrue(upLoadedFiles.Count() > 0);
27+
Assert.IsGreaterThan(0, upLoadedFiles.Count());
2828

2929
foreach (var file in upLoadedFiles)
3030
{
@@ -63,7 +63,7 @@ public void Test_Sftp_BeginSynchronizeDirectories()
6363

6464
var upLoadedFiles = sftp.EndSynchronizeDirectories(asyncResult);
6565

66-
Assert.IsTrue(upLoadedFiles.Count() > 0);
66+
Assert.IsGreaterThan(0, upLoadedFiles.Count());
6767

6868
foreach (var file in upLoadedFiles)
6969
{

0 commit comments

Comments
 (0)