ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Renci.SshNet.Common;
  5. namespace Renci.SshNet.Tests.Classes.Channels
  6. {
  7. [TestClass]
  8. public class ChannelTest_OnSessionDisconnected_SessionIsConnectedAndChannelIsOpen : ChannelTestBase
  9. {
  10. private uint _localChannelNumber;
  11. private uint _localWindowSize;
  12. private uint _localPacketSize;
  13. private uint _remoteChannelNumber;
  14. private uint _remoteWindowSize;
  15. private uint _remotePacketSize;
  16. private ChannelStub _channel;
  17. private List<ChannelEventArgs> _channelClosedRegister;
  18. private IList<ExceptionEventArgs> _channelExceptionRegister;
  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. _remoteChannelNumber = (uint)random.Next(0, int.MaxValue);
  26. _remoteWindowSize = (uint)random.Next(0, int.MaxValue);
  27. _remotePacketSize = (uint)random.Next(0, int.MaxValue);
  28. _channelClosedRegister = new List<ChannelEventArgs>();
  29. _channelExceptionRegister = new List<ExceptionEventArgs>();
  30. }
  31. protected override void SetupMocks()
  32. {
  33. _ = SessionMock.Setup(p => p.IsConnected)
  34. .Returns(true);
  35. }
  36. protected override void Arrange()
  37. {
  38. base.Arrange();
  39. _channel = new ChannelStub(SessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
  40. _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
  41. _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
  42. _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize);
  43. _channel.SetIsOpen(true);
  44. }
  45. protected override void Act()
  46. {
  47. SessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty);
  48. }
  49. [TestMethod]
  50. public void IsOpenShouldReturnFalse()
  51. {
  52. Assert.IsFalse(_channel.IsOpen);
  53. }
  54. [TestMethod]
  55. public void ClosedEventShouldNeverHaveFired()
  56. {
  57. Assert.AreEqual(0, _channelClosedRegister.Count);
  58. }
  59. [TestMethod]
  60. public void ExceptionShouldNeverHaveFired()
  61. {
  62. Assert.AreEqual(0, _channelExceptionRegister.Count);
  63. }
  64. }
  65. }