2
0

ChannelTest_SendEof_ChannelIsNotOpen.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Moq;
  5. using Renci.SshNet.Common;
  6. using Renci.SshNet.Messages;
  7. namespace Renci.SshNet.Tests.Classes.Channels
  8. {
  9. [TestClass]
  10. public class ChannelTest_SendEof_ChannelIsNotOpen : ChannelTestBase
  11. {
  12. private uint _localWindowSize;
  13. private uint _localPacketSize;
  14. private uint _localChannelNumber;
  15. private ChannelStub _channel;
  16. private List<ChannelEventArgs> _channelClosedRegister;
  17. private IList<ExceptionEventArgs> _channelExceptionRegister;
  18. private InvalidOperationException _actualException;
  19. protected override void SetupData()
  20. {
  21. var random = new Random();
  22. _localChannelNumber = (uint)random.Next(0, int.MaxValue);
  23. _localWindowSize = (uint)random.Next(0, int.MaxValue);
  24. _localPacketSize = (uint)random.Next(0, int.MaxValue);
  25. _channelClosedRegister = new List<ChannelEventArgs>();
  26. _channelExceptionRegister = new List<ExceptionEventArgs>();
  27. _actualException = null;
  28. }
  29. protected override void SetupMocks()
  30. {
  31. }
  32. protected override void Arrange()
  33. {
  34. base.Arrange();
  35. _channel = new ChannelStub(SessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
  36. _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
  37. _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
  38. }
  39. protected override void Act()
  40. {
  41. try
  42. {
  43. _channel.SendEof();
  44. Assert.Fail();
  45. }
  46. catch (InvalidOperationException ex)
  47. {
  48. _actualException = ex;
  49. }
  50. }
  51. [TestMethod]
  52. public void IsOpenShouldReturnFalse()
  53. {
  54. Assert.IsFalse(_channel.IsOpen);
  55. }
  56. [TestMethod]
  57. public void SendEofShouldHaveThrownInvalidOperationException()
  58. {
  59. Assert.IsNotNull(_actualException);
  60. Assert.IsNull(_actualException.InnerException);
  61. Assert.AreEqual("The channel is closed.", _actualException.Message);
  62. }
  63. [TestMethod]
  64. public void SendMessageOnSessionShouldNeverBeInvoked()
  65. {
  66. SessionMock.Verify(p => p.SendMessage(It.IsAny<Message>()), Times.Never);
  67. }
  68. [TestMethod]
  69. public void ClosedEventShouldNeverHaveFired()
  70. {
  71. Assert.AreEqual(0, _channelClosedRegister.Count);
  72. }
  73. [TestMethod]
  74. public void ExceptionShouldNeverHaveFired()
  75. {
  76. Assert.AreEqual(0, _channelExceptionRegister.Count);
  77. }
  78. }
  79. }