Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Round 2 of analyzer fixes and general cleanup. #1132

Merged
merged 1 commit into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 11 additions & 0 deletions .editorconfig_soon → .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,11 @@ dotnet_diagnostic.IDE0045.severity = none
# Configured using 'dotnet_style_prefer_conditional_expression_over_return'
dotnet_diagnostic.IDE0046.severity = suggestion

# IDE0047: Remove unnecessary parentheses
#
# Removing "unnecessary" parentheses is not always a clear win for readability.
dotnet_diagnostic.IDE0047.severity = suggestion

# IDE0055: Fix formatting
#
# When enabled, diagnostics are reported for indented object initializers.
Expand All @@ -547,6 +552,12 @@ dotnet_diagnostic.IDE0046.severity = suggestion
# There are no settings to configure this correctly, unless https://github.com/dotnet/roslyn/issues/63256 (or similar) is ever implemented.
dotnet_diagnostic.IDE0055.severity = none

# IDE0130: Namespace does not match folder structure
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0130
#
# TODO: Remove when https://github.com/sshnet/SSH.NET/issues/1129 is fixed
dotnet_diagnostic.IDE0130.severity = none

# IDE0270: Null check can be simplified
#
# var inputPath = originalDossierPathList.Find(x => x.id == updatedPath.id);
Expand Down
2 changes: 0 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)src\Renci.SshNet.snk</AssemblyOriginatorKeyFile>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<LangVersion>latest</LangVersion>
<!--
<WarningLevel>9999</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
-->
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
</PropertyGroup>

Expand Down
32 changes: 32 additions & 0 deletions src/Renci.SshNet.Tests/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[*.cs]

#### SYSLIB diagnostics ####

# SYSLIB1045: Use 'GeneratedRegexAttribute' to generate the regular expression implementation at compile-time
#
# TODO: Remove this when https://github.com/sshnet/SSH.NET/issues/1131 is implemented.
dotnet_diagnostic.SYSLIB1045.severity = none

### StyleCop Analyzers rules ###

#### .NET Compiler Platform analysers rules ####

# IDE0007: Use var instead of explicit type
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0007
dotnet_diagnostic.IDE0007.severity = suggestion

# IDE0028: Use collection initializers
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0028
dotnet_diagnostic.IDE0028.severity = suggestion

# IDE0058: Remove unnecessary expression value
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0058
dotnet_diagnostic.IDE0058.severity = suggestion

# IDE0059: Remove unnecessary value assignment
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0059
dotnet_diagnostic.IDE0059.severity = suggestion

# IDE0230: Use UTF-8 string literal
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0230
dotnet_diagnostic.IDE0230.severity = suggestion
12 changes: 6 additions & 6 deletions src/Renci.SshNet.Tests/Classes/BaseClientTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ namespace Renci.SshNet.Tests.Classes
{
public abstract class BaseClientTestBase : TripleATestBase
{
internal Mock<IServiceFactory> _serviceFactoryMock { get; private set; }
internal Mock<ISocketFactory> _socketFactoryMock { get; private set; }
internal Mock<ISession> _sessionMock { get; private set; }
internal Mock<IServiceFactory> ServiceFactoryMock { get; private set; }
internal Mock<ISocketFactory> SocketFactoryMock { get; private set; }
internal Mock<ISession> SessionMock { get; private set; }

protected virtual void CreateMocks()
{
_serviceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
_socketFactoryMock = new Mock<ISocketFactory>(MockBehavior.Strict);
_sessionMock = new Mock<ISession>(MockBehavior.Strict);
ServiceFactoryMock = new Mock<IServiceFactory>(MockBehavior.Strict);
SocketFactoryMock = new Mock<ISocketFactory>(MockBehavior.Strict);
SessionMock = new Mock<ISession>(MockBehavior.Strict);
}

protected virtual void SetupData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ protected override void SetupData()

protected override void SetupMocks()
{
_serviceFactoryMock.Setup(p => p.CreateSocketFactory())
.Returns(_socketFactoryMock.Object);
_serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object))
.Returns(_sessionMock.Object);
_sessionMock.Setup(p => p.Connect());
_sessionMock.Setup(p => p.Dispose());
ServiceFactoryMock.Setup(p => p.CreateSocketFactory())
.Returns(SocketFactoryMock.Object);
ServiceFactoryMock.Setup(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object))
.Returns(SessionMock.Object);
SessionMock.Setup(p => p.Connect());
SessionMock.Setup(p => p.Dispose());
}

protected override void TearDown()
{
if (_client != null)
{
_sessionMock.Setup(p => p.OnDisconnecting());
_sessionMock.Setup(p => p.Dispose());
SessionMock.Setup(p => p.OnDisconnecting());
SessionMock.Setup(p => p.Dispose());
_client.Dispose();
}
}
Expand All @@ -46,7 +46,7 @@ protected override void Arrange()
{
base.Arrange();

_client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object)
_client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object)
{
OnConnectedException = _onConnectException
};
Expand Down Expand Up @@ -75,26 +75,26 @@ public void ConnectShouldRethrowExceptionThrownByOnConnect()
[TestMethod]
public void CreateSocketFactoryOnServiceFactoryShouldBeInvokedOnce()
{
_serviceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
ServiceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
}

[TestMethod]
public void CreateSessionOnServiceFactoryShouldBeInvokedOnce()
{
_serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object),
ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object),
Times.Once);
}

[TestMethod]
public void ConnectOnSessionShouldBeInvokedOnce()
{
_sessionMock.Verify(p => p.Connect(), Times.Once);
SessionMock.Verify(p => p.Connect(), Times.Once);
}

[TestMethod]
public void DisposeOnSessionShouldBeInvokedOnce()
{
_sessionMock.Verify(p => p.Dispose(), Times.Once);
SessionMock.Verify(p => p.Dispose(), Times.Once);
}

[TestMethod]
Expand All @@ -104,7 +104,7 @@ public void ErrorOccuredOnSessionShouldNoLongerBeSignaledViaErrorOccurredOnBaseC

_client.ErrorOccurred += (sender, args) => Interlocked.Increment(ref errorOccurredSignalCount);

_sessionMock.Raise(p => p.ErrorOccured += null, new ExceptionEventArgs(new Exception()));
SessionMock.Raise(p => p.ErrorOccured += null, new ExceptionEventArgs(new Exception()));

Assert.AreEqual(0, errorOccurredSignalCount);
}
Expand All @@ -116,7 +116,7 @@ public void HostKeyReceivedOnSessionShouldNoLongerBeSignaledViaHostKeyReceivedOn

_client.HostKeyReceived += (sender, args) => Interlocked.Increment(ref hostKeyReceivedSignalCount);

_sessionMock.Raise(p => p.HostKeyReceived += null, new HostKeyEventArgs(GetKeyHostAlgorithm()));
SessionMock.Raise(p => p.HostKeyReceived += null, new HostKeyEventArgs(GetKeyHostAlgorithm()));

Assert.AreEqual(0, hostKeyReceivedSignalCount);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Threading;

using Microsoft.VisualStudio.TestTools.UnitTesting;

using Moq;
using Renci.SshNet.Connection;

using Renci.SshNet.Messages.Transport;

namespace Renci.SshNet.Tests.Classes
Expand All @@ -24,22 +26,23 @@ protected override void SetupData()

protected override void SetupMocks()
{
_serviceFactoryMock.Setup(p => p.CreateSocketFactory())
.Returns(_socketFactoryMock.Object);
_serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object))
.Returns(_sessionMock.Object);
_sessionMock.Setup(p => p.Connect());
_sessionMock.Setup(p => p.IsConnected).Returns(true);
_sessionMock.Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
.Returns(true)
.Callback(() => Interlocked.Increment(ref _keepAliveCount));
_ = ServiceFactoryMock.Setup(p => p.CreateSocketFactory())
.Returns(SocketFactoryMock.Object);
_ = ServiceFactoryMock.Setup(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object))
.Returns(SessionMock.Object);
_ = SessionMock.Setup(p => p.Connect());
_ = SessionMock.Setup(p => p.IsConnected)
.Returns(true);
_ = SessionMock.Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
.Returns(true)
.Callback(() => Interlocked.Increment(ref _keepAliveCount));
}

protected override void Arrange()
{
base.Arrange();

_client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object);
_client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object);
_client.Connect();
_client.KeepAliveInterval = _keepAliveInterval;
}
Expand All @@ -48,8 +51,8 @@ protected override void TearDown()
{
if (_client != null)
{
_sessionMock.Setup(p => p.OnDisconnecting());
_sessionMock.Setup(p => p.Dispose());
SessionMock.Setup(p => p.OnDisconnecting());
SessionMock.Setup(p => p.Dispose());
_client.Dispose();
}
}
Expand All @@ -72,25 +75,25 @@ public void KeepAliveIntervalShouldReturnConfiguredValue()
[TestMethod]
public void CreateSocketFactoryOnServiceFactoryShouldBeInvokedOnce()
{
_serviceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
ServiceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
}

[TestMethod]
public void CreateSessionOnServiceFactoryShouldBeInvokedOnce()
{
_serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object), Times.Once);
ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object), Times.Once);
}

[TestMethod]
public void ConnectOnSessionShouldBeInvokedOnce()
{
_sessionMock.Verify(p => p.Connect(), Times.Once);
SessionMock.Verify(p => p.Connect(), Times.Once);
}

[TestMethod]
public void IsConnectedOnSessionShouldBeInvokedOnce()
{
_sessionMock.Verify(p => p.IsConnected, Times.Once);
SessionMock.Verify(p => p.IsConnected, Times.Once);
}

[TestMethod]
Expand All @@ -99,7 +102,7 @@ public void SendMessageOnSessionShouldBeInvokedOneTime()
// allow keep-alive to be sent once
Thread.Sleep(100);

_sessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(1));
SessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(1));
}

private class MyClient : BaseClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ protected override void SetupData()

protected override void SetupMocks()
{
_serviceFactoryMock.Setup(p => p.CreateSocketFactory())
.Returns(_socketFactoryMock.Object);
_serviceFactoryMock.Setup(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object))
.Returns(_sessionMock.Object);
_sessionMock.Setup(p => p.Connect());
_sessionMock.Setup(p => p.IsConnected).Returns(true);
_sessionMock.Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
ServiceFactoryMock.Setup(p => p.CreateSocketFactory())
.Returns(SocketFactoryMock.Object);
ServiceFactoryMock.Setup(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object))
.Returns(SessionMock.Object);
SessionMock.Setup(p => p.Connect());
SessionMock.Setup(p => p.IsConnected).Returns(true);
SessionMock.Setup(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()))
.Returns(true)
.Callback(() => Interlocked.Increment(ref _keepAliveCount));
}
Expand All @@ -38,16 +38,16 @@ protected override void Arrange()
{
base.Arrange();

_client = new MyClient(_connectionInfo, false, _serviceFactoryMock.Object);
_client = new MyClient(_connectionInfo, false, ServiceFactoryMock.Object);
_client.Connect();
}

protected override void TearDown()
{
if (_client != null)
{
_sessionMock.Setup(p => p.OnDisconnecting());
_sessionMock.Setup(p => p.Dispose());
SessionMock.Setup(p => p.OnDisconnecting());
SessionMock.Setup(p => p.Dispose());
_client.Dispose();
}
}
Expand All @@ -74,32 +74,32 @@ public void KeepAliveIntervalShouldReturnConfiguredValue()
[TestMethod]
public void CreateSocketFactoryOnServiceFactoryShouldBeInvokedOnce()
{
_serviceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
ServiceFactoryMock.Verify(p => p.CreateSocketFactory(), Times.Once);
}

[TestMethod]
public void CreateSessionOnServiceFactoryShouldBeInvokedOnce()
{
_serviceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, _socketFactoryMock.Object),
ServiceFactoryMock.Verify(p => p.CreateSession(_connectionInfo, SocketFactoryMock.Object),
Times.Once);
}

[TestMethod]
public void ConnectOnSessionShouldBeInvokedOnce()
{
_sessionMock.Verify(p => p.Connect(), Times.Once);
SessionMock.Verify(p => p.Connect(), Times.Once);
}

[TestMethod]
public void IsConnectedOnSessionShouldBeInvokedOnce()
{
_sessionMock.Verify(p => p.IsConnected, Times.Once);
SessionMock.Verify(p => p.IsConnected, Times.Once);
}

[TestMethod]
public void SendMessageOnSessionShouldBeInvokedThreeTimes()
{
_sessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(3));
SessionMock.Verify(p => p.TrySendMessage(It.IsAny<IgnoreMessage>()), Times.Exactly(3));
}

private class MyClient : BaseClient
Expand Down
Loading