ChannelTest_OnSessionErrorOccurred_OnErrorOccurred_Exception.cs 2.2 KB

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