ChannelTest_SendEof_ChannelIsOpen.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.Connection;
  7. namespace Renci.SshNet.Tests.Classes.Channels
  8. {
  9. [TestClass]
  10. public class ChannelTest_SendEof_ChannelIsOpen : ChannelTestBase
  11. {
  12. private uint _localChannelNumber;
  13. private uint _localWindowSize;
  14. private uint _localPacketSize;
  15. private uint _remoteChannelNumber;
  16. private uint _remoteWindowSize;
  17. private uint _remotePacketSize;
  18. private ChannelStub _channel;
  19. private List<ChannelEventArgs> _channelClosedRegister;
  20. private IList<ExceptionEventArgs> _channelExceptionRegister;
  21. protected override void SetupData()
  22. {
  23. var random = new Random();
  24. _localChannelNumber = (uint)random.Next(0, int.MaxValue);
  25. _localWindowSize = (uint)random.Next(0, int.MaxValue);
  26. _localPacketSize = (uint)random.Next(0, int.MaxValue);
  27. _remoteChannelNumber = (uint)random.Next(0, int.MaxValue);
  28. _remoteWindowSize = (uint)random.Next(0, int.MaxValue);
  29. _remotePacketSize = (uint)random.Next(0, int.MaxValue);
  30. _channelClosedRegister = new List<ChannelEventArgs>();
  31. _channelExceptionRegister = new List<ExceptionEventArgs>();
  32. }
  33. protected override void SetupMocks()
  34. {
  35. SessionMock.Setup(p => p.SendMessage(It.Is<ChannelEofMessage>(e => e.LocalChannelNumber == _remoteChannelNumber)));
  36. }
  37. protected override void Arrange()
  38. {
  39. base.Arrange();
  40. _channel = new ChannelStub(SessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
  41. _channel.Closed += (sender, args) => _channelClosedRegister.Add(args);
  42. _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
  43. _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize);
  44. _channel.SetIsOpen(true);
  45. }
  46. protected override void Act()
  47. {
  48. _channel.SendEof();
  49. }
  50. [TestMethod]
  51. public void IsOpenShouldReturnTrue()
  52. {
  53. Assert.IsTrue(_channel.IsOpen);
  54. }
  55. [TestMethod]
  56. public void SendMessageOnSessionShouldBeInvokedOnceWithChannelEofMessage()
  57. {
  58. SessionMock.Verify(
  59. p => p.SendMessage(It.Is<ChannelEofMessage>(e => e.LocalChannelNumber == _remoteChannelNumber)),
  60. Times.Once);
  61. }
  62. [TestMethod]
  63. public void ClosedEventShouldNeverHaveFired()
  64. {
  65. Assert.AreEqual(0, _channelClosedRegister.Count);
  66. }
  67. [TestMethod]
  68. public void ExceptionShouldNeverHaveFired()
  69. {
  70. Assert.AreEqual(0, _channelExceptionRegister.Count);
  71. }
  72. }
  73. }