2
0

ChannelTest_OnSessionChannelEofReceived_OnEof_Exception.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.VisualStudio.TestTools.UnitTesting;
  4. using Renci.SshNet.Common;
  5. using Renci.SshNet.Messages.Connection;
  6. namespace Renci.SshNet.Tests.Classes.Channels
  7. {
  8. [TestClass]
  9. public class ChannelTest_OnSessionChannelEofReceived_Exception : ChannelTestBase
  10. {
  11. private uint _localWindowSize;
  12. private uint _localPacketSize;
  13. private uint _localChannelNumber;
  14. private uint _remoteChannelNumber;
  15. private uint _remoteWindowSize;
  16. private uint _remotePacketSize;
  17. private ChannelStub _channel;
  18. private IList<ExceptionEventArgs> _channelExceptionRegister;
  19. private Exception _onEofException;
  20. protected override void SetupData()
  21. {
  22. var random = new Random();
  23. _localWindowSize = (uint)random.Next(0, 1000);
  24. _localPacketSize = (uint)random.Next(1001, int.MaxValue);
  25. _localChannelNumber = (uint)random.Next(0, int.MaxValue);
  26. _remoteChannelNumber = (uint)random.Next(0, int.MaxValue);
  27. _remoteWindowSize = (uint)random.Next(0, int.MaxValue);
  28. _remotePacketSize = (uint)random.Next(0, int.MaxValue);
  29. _onEofException = new SystemException();
  30. _channelExceptionRegister = new List<ExceptionEventArgs>();
  31. }
  32. protected override void SetupMocks()
  33. {
  34. }
  35. protected override void Arrange()
  36. {
  37. base.Arrange();
  38. _channel = new ChannelStub(SessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
  39. _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
  40. _channel.InitializeRemoteChannelInfo(_remoteChannelNumber, _remoteWindowSize, _remotePacketSize);
  41. _channel.SetIsOpen(true);
  42. _channel.OnEofException = _onEofException;
  43. }
  44. protected override void Act()
  45. {
  46. SessionMock.Raise(s => s.ChannelEofReceived += null,
  47. new MessageEventArgs<ChannelEofMessage>(new ChannelEofMessage(_localChannelNumber)));
  48. }
  49. [TestMethod]
  50. public void ExceptionEventShouldHaveFiredOnce()
  51. {
  52. Assert.AreEqual(1, _channelExceptionRegister.Count);
  53. Assert.AreSame(_onEofException, _channelExceptionRegister[0].Exception);
  54. }
  55. [TestMethod]
  56. public void OnErrorOccurredShouldBeInvokedOnce()
  57. {
  58. Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count);
  59. Assert.AreSame(_onEofException, _channel.OnErrorOccurredInvocations[0]);
  60. }
  61. }
  62. }