SshCommandTest.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using Renci.SshNet.Common;
  3. using Renci.SshNet.Tests.Common;
  4. using Renci.SshNet.Tests.Properties;
  5. using System;
  6. namespace Renci.SshNet.Tests.Classes
  7. {
  8. /// <summary>
  9. /// Represents SSH command that can be executed.
  10. /// </summary>
  11. [TestClass]
  12. public partial class SshCommandTest : TestBase
  13. {
  14. [TestMethod]
  15. [ExpectedException(typeof(SshConnectionException))]
  16. public void Test_Execute_SingleCommand_Without_Connecting()
  17. {
  18. using (var client = new SshClient(Resources.HOST, Resources.USERNAME, Resources.PASSWORD))
  19. {
  20. var result = ExecuteTestCommand(client);
  21. Assert.IsTrue(result);
  22. }
  23. }
  24. private static bool ExecuteTestCommand(SshClient s)
  25. {
  26. var testValue = Guid.NewGuid().ToString();
  27. var command = string.Format("echo {0}", testValue);
  28. var cmd = s.CreateCommand(command);
  29. var result = cmd.Execute();
  30. result = result.Substring(0, result.Length - 1); // Remove \n character returned by command
  31. return result.Equals(testValue);
  32. }
  33. }
  34. }