You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar to #1486, it would be also be great to add an interface to SshCommand for testing, as this would allow mocking up the return value of SshClient.RunCommand().
This issue makes using NSubstitute (and any other mocker) to mock SSH.NET very hard. In order to mock main methods like RunCommand or CreateCommand, one must create SshCommand. But it is exact class with internal constructor which in turn uses internal class.
I made this workaround to substitute it, but it's quite clumsy:
var iSession = typeof(SshCommand).Assembly.GetType("Renci.SshNet.ISession");
if (iSession == null)
{
throw new Exception("Could not find the ISession interface");
}
var substitute = NSubstitute.Substitute.For<ISshClient>();
substitute.RunCommand(Arg.Any<string>())
.ReturnsForAnyArgs(info =>
NSubstitute.Substitute.For<SshCommand>(
NSubstitute.Substitute.For([iSession], []),
info.Arg<string>(),
Encoding.UTF8
)
);
Activity
k0ka commentedon Jul 31, 2025
This issue makes using
NSubstitute(and any other mocker) to mockSSH.NETvery hard. In order to mock main methods likeRunCommandorCreateCommand, one must createSshCommand. But it is exact class withinternalconstructor which in turn usesinternalclass.I made this workaround to substitute it, but it's quite clumsy: