ChannelTest_OnSessionDisconnected_OnDisconnected_Exception.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_OnDisconnected_Exception : ChannelTestBase
  9. {
  10. private uint _localWindowSize;
  11. private uint _localPacketSize;
  12. private uint _localChannelNumber;
  13. private ChannelStub _channel;
  14. private IList<ExceptionEventArgs> _channelExceptionRegister;
  15. private Exception _onDisconnectedException;
  16. protected override void SetupData()
  17. {
  18. var random = new Random();
  19. _localWindowSize = (uint)random.Next(1000, int.MaxValue);
  20. _localPacketSize = _localWindowSize - 1;
  21. _localChannelNumber = (uint)random.Next(0, int.MaxValue);
  22. _onDisconnectedException = new SystemException();
  23. _channelExceptionRegister = new List<ExceptionEventArgs>();
  24. }
  25. protected override void SetupMocks()
  26. {
  27. }
  28. protected override void Arrange()
  29. {
  30. base.Arrange();
  31. _channel = new ChannelStub(SessionMock.Object, _localChannelNumber, _localWindowSize, _localPacketSize);
  32. _channel.Exception += (sender, args) => _channelExceptionRegister.Add(args);
  33. _channel.OnDisconnectedException = _onDisconnectedException;
  34. }
  35. protected override void Act()
  36. {
  37. SessionMock.Raise(s => s.Disconnected += null, EventArgs.Empty);
  38. }
  39. [TestMethod]
  40. public void ExceptionEventShouldHaveFiredOnce()
  41. {
  42. Assert.AreEqual(1, _channelExceptionRegister.Count);
  43. Assert.AreSame(_onDisconnectedException, _channelExceptionRegister[0].Exception);
  44. }
  45. [TestMethod]
  46. public void OnErrorOccurredShouldBeInvokedOnce()
  47. {
  48. Assert.AreEqual(1, _channel.OnErrorOccurredInvocations.Count);
  49. Assert.AreSame(_onDisconnectedException, _channel.OnErrorOccurredInvocations[0]);
  50. }
  51. }
  52. }