SshCommandTest_EndExecute_AsyncResultIsNull.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Globalization;
  3. using System.Text;
  4. using Microsoft.VisualStudio.TestTools.UnitTesting;
  5. using Moq;
  6. using Renci.SshNet.Tests.Common;
  7. namespace Renci.SshNet.Tests.Classes
  8. {
  9. [TestClass]
  10. public class SshCommandTest_EndExecute_AsyncResultIsNull : TestBase
  11. {
  12. private Mock<ISession> _sessionMock;
  13. private string _commandText;
  14. private Encoding _encoding;
  15. private SshCommand _sshCommand;
  16. private IAsyncResult _asyncResult;
  17. private ArgumentNullException _actualException;
  18. protected override void OnInit()
  19. {
  20. base.OnInit();
  21. Arrange();
  22. Act();
  23. }
  24. private void Arrange()
  25. {
  26. _sessionMock = new Mock<ISession>();
  27. _commandText = new Random().Next().ToString(CultureInfo.InvariantCulture);
  28. _encoding = Encoding.UTF8;
  29. _asyncResult = null;
  30. _sshCommand = new SshCommand(_sessionMock.Object, _commandText, _encoding);
  31. }
  32. private void Act()
  33. {
  34. try
  35. {
  36. _sshCommand.EndExecute(_asyncResult);
  37. Assert.Fail();
  38. }
  39. catch (ArgumentNullException ex)
  40. {
  41. _actualException = ex;
  42. }
  43. }
  44. [TestMethod]
  45. public void EndExecuteShouldHaveThrownArgumentNullException()
  46. {
  47. Assert.IsNotNull(_actualException);
  48. Assert.IsNull(_actualException.InnerException);
  49. Assert.AreEqual("asyncResult", _actualException.ParamName);
  50. }
  51. }
  52. }