TestMqttChannel.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System.IO;
  2. using System.Security.Cryptography.X509Certificates;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using MQTTnet.Channel;
  6. namespace MQTTnet.Internal
  7. {
  8. public class TestMqttChannel : IMqttChannel
  9. {
  10. private readonly MemoryStream _stream;
  11. public TestMqttChannel(MemoryStream stream)
  12. {
  13. _stream = stream;
  14. }
  15. public string Endpoint { get; } = "<Test channel>";
  16. public bool IsSecureConnection { get; } = false;
  17. public X509Certificate2 ClientCertificate { get; }
  18. public Task ConnectAsync(CancellationToken cancellationToken)
  19. {
  20. return Task.FromResult(0);
  21. }
  22. public Task DisconnectAsync(CancellationToken cancellationToken)
  23. {
  24. return Task.FromResult(0);
  25. }
  26. public Task<int> ReadAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
  27. {
  28. return _stream.ReadAsync(buffer, offset, count, cancellationToken);
  29. }
  30. public Task WriteAsync(byte[] buffer, int offset, int count, CancellationToken cancellationToken)
  31. {
  32. return _stream.WriteAsync(buffer, offset, count, cancellationToken);
  33. }
  34. public void Dispose()
  35. {
  36. }
  37. }
  38. }