From ea575472a084cc6708baf4db3c9698eeeb293fcf Mon Sep 17 00:00:00 2001 From: olegkap_cp Date: Mon, 10 Jan 2011 18:19:30 +0000 Subject: [PATCH] Fix reusing command object to execute different commands. Add Test_Execute_Command_Same_Object_Different_Commands test --- .../SshClientTests/TestSshCommand.cs | 27 ++++++++++++++----- Renci.SshClient/Renci.SshClient/SshCommand.cs | 2 ++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/Renci.SshClient/Renci.SshClient.Tests/SshClientTests/TestSshCommand.cs b/Renci.SshClient/Renci.SshClient.Tests/SshClientTests/TestSshCommand.cs index e10eba69..3db970bb 100644 --- a/Renci.SshClient/Renci.SshClient.Tests/SshClientTests/TestSshCommand.cs +++ b/Renci.SshClient/Renci.SshClient.Tests/SshClientTests/TestSshCommand.cs @@ -1,13 +1,11 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; using System.Diagnostics; -using System.Threading.Tasks; +using System.Text; using System.Threading; -using Renci.SshClient.Tests.Properties; +using System.Threading.Tasks; +using Microsoft.VisualStudio.TestTools.UnitTesting; using Renci.SshClient.Common; +using Renci.SshClient.Tests.Properties; namespace Renci.SshClient.Tests.SshClientTests { @@ -306,6 +304,22 @@ namespace Renci.SshClient.Tests.SshClientTests } } + /// + /// Tests for Issue 563. + /// + [TestMethod] + public void Test_Execute_Command_Same_Object_Different_Commands() + { + using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD)) + { + client.Connect(); + var cmd = client.CreateCommand("ls -l"); + cmd.Execute(); + cmd.Execute("ls -l"); + client.Disconnect(); + } + } + private static bool ExecuteTestCommand(Renci.SshClient.SshClient s) { var testValue = Guid.NewGuid().ToString(); @@ -316,5 +330,6 @@ namespace Renci.SshClient.Tests.SshClientTests result = result.Substring(0, result.Length - 1); // Remove \n chararacter returned by command return result.Equals(testValue); } + } } diff --git a/Renci.SshClient/Renci.SshClient/SshCommand.cs b/Renci.SshClient/Renci.SshClient/SshCommand.cs index 858f7557..358efe46 100644 --- a/Renci.SshClient/Renci.SshClient/SshCommand.cs +++ b/Renci.SshClient/Renci.SshClient/SshCommand.cs @@ -179,6 +179,8 @@ namespace Renci.SshClient this._channel.Close(); + this._channel = null; + this._asyncResult = null; return this.Result;