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.

ManagedMqttClientTests.cs 1.8 KiB

пре 6 година
пре 6 година
пре 6 година
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System.Threading.Tasks;
  2. using Microsoft.VisualStudio.TestTools.UnitTesting;
  3. using MQTTnet.Extensions.ManagedClient;
  4. using MQTTnet.Server;
  5. namespace MQTTnet.Tests
  6. {
  7. [TestClass]
  8. public class ManagedMqttClientTests
  9. {
  10. [TestMethod]
  11. public async Task Drop_New_Messages_On_Full_Queue()
  12. {
  13. var factory = new MqttFactory();
  14. var managedClient = factory.CreateManagedMqttClient();
  15. try
  16. {
  17. var clientOptions = new ManagedMqttClientOptionsBuilder()
  18. .WithMaxPendingMessages(5)
  19. .WithPendingMessagesOverflowStrategy(MqttPendingMessagesOverflowStrategy.DropNewMessage);
  20. clientOptions.WithClientOptions(o => o.WithTcpServer("localhost"));
  21. await managedClient.StartAsync(clientOptions.Build());
  22. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "1" });
  23. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "2" });
  24. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "3" });
  25. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "4" });
  26. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "5" });
  27. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "6" });
  28. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "7" });
  29. await managedClient.PublishAsync(new MqttApplicationMessage { Topic = "8" });
  30. Assert.AreEqual(5, managedClient.PendingApplicationMessagesCount);
  31. }
  32. finally
  33. {
  34. await managedClient.StopAsync();
  35. }
  36. }
  37. }
  38. }