SubsystemSessionStub.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using Renci.SshNet.Common;
  5. namespace Renci.SshNet.Tests.Classes
  6. {
  7. internal class SubsystemSessionStub : SubsystemSession
  8. {
  9. private int _onChannelOpenInvocationCount;
  10. public SubsystemSessionStub(ISession session, string subsystemName, int operationTimeout)
  11. : base(session, subsystemName, operationTimeout)
  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. {
  27. throw OnChannelOpenException;
  28. }
  29. }
  30. protected override void OnDataReceived(ArraySegment<byte> data)
  31. {
  32. OnDataReceivedInvocations.Add(new ChannelDataEventArgs(0, data));
  33. if (OnDataReceivedException != null)
  34. {
  35. throw OnDataReceivedException;
  36. }
  37. }
  38. }
  39. }