SubsystemSessionStub.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading;
  5. using Renci.SshNet.Common;
  6. namespace Renci.SshNet.Tests.Classes
  7. {
  8. internal class SubsystemSessionStub : SubsystemSession
  9. {
  10. private int _onChannelOpenInvocationCount;
  11. public SubsystemSessionStub(ISession session, string subsystemName, TimeSpan operationTimeout, Encoding encoding) : base(session, subsystemName, operationTimeout, encoding)
  12. {
  13. OnDataReceivedInvocations = new List<ChannelDataEventArgs>();
  14. }
  15. public int OnChannelOpenInvocationCount
  16. {
  17. get { return _onChannelOpenInvocationCount; }
  18. }
  19. public IList<ChannelDataEventArgs> OnDataReceivedInvocations { get; private set; }
  20. public Exception OnChannelOpenException { get; set; }
  21. public Exception OnDataReceivedException { get; set; }
  22. protected override void OnChannelOpen()
  23. {
  24. Interlocked.Increment(ref _onChannelOpenInvocationCount);
  25. if (OnChannelOpenException != null)
  26. throw OnChannelOpenException;
  27. }
  28. protected override void OnDataReceived(byte[] data)
  29. {
  30. OnDataReceivedInvocations.Add(new ChannelDataEventArgs(0, data));
  31. if (OnDataReceivedException != null)
  32. throw OnDataReceivedException;
  33. }
  34. }
  35. }