2
0

SshCommandTest_EndExecute_AsyncResultIsNull.cs 1.7 KB

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