You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MqttConnectionContextTest.cs 963 B

6 years ago
1234567891011121314151617181920212223242526272829
  1. using Microsoft.AspNetCore.Connections;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using MQTTnet.AspNetCore.Tests.Mockups;
  4. using MQTTnet.Exceptions;
  5. using MQTTnet.Serializer;
  6. using System;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. namespace MQTTnet.AspNetCore.Tests
  10. {
  11. [TestClass]
  12. public class MqttConnectionContextTest
  13. {
  14. [TestMethod]
  15. public async Task TestReceivePacketAsyncThrowsWhenReaderCompleted()
  16. {
  17. var serializer = new MqttPacketSerializer {};
  18. var pipe = new DuplexPipeMockup();
  19. var connection = new DefaultConnectionContext();
  20. connection.Transport = pipe;
  21. var ctx = new MqttConnectionContext(serializer, connection);
  22. pipe.Receive.Writer.Complete();
  23. await Assert.ThrowsExceptionAsync<MqttCommunicationException>(() => ctx.ReceivePacketAsync(TimeSpan.FromSeconds(1), CancellationToken.None));
  24. }
  25. }
  26. }