public async Task SerializeAsJson_Action_PayloadSerialized() { var message = new TestEventOne { Content = "Hello MQTT!" }; var serializer = new JsonMessageSerializer <TestEventOne> { Options = new JsonSerializerOptions { WriteIndented = true } }; var messageBytes = (await serializer.SerializeAsync( message, new MessageHeaderCollection(), MessageSerializationContext.Empty)).ReadAll(); var builder = new MqttLastWillMessageBuilder(); builder .ProduceTo("testaments") .SerializeAsJson( serializerBuilder => serializerBuilder .WithOptions( new JsonSerializerOptions { WriteIndented = true })) .Message(message); var willMessage = builder.Build(); willMessage.Payload.Should().NotBeNullOrEmpty(); willMessage.Payload.Should().BeEquivalentTo(messageBytes); }
public async Task SerializeUsing_NewtonsoftJsonSerializer_PayloadSerialized() { var message = new TestEventOne { Content = "Hello MQTT!" }; var serializer = new NewtonsoftJsonMessageSerializer <TestEventOne> { Encoding = MessageEncoding.Unicode, Settings = new JsonSerializerSettings { Formatting = Formatting.Indented } }; var messageBytes = (await serializer.SerializeAsync( message, new MessageHeaderCollection(), MessageSerializationContext.Empty)).ReadAll(); var builder = new MqttLastWillMessageBuilder(); builder .ProduceTo("testaments") .SerializeUsing(serializer) .Message(message); var willMessage = builder.Build(); willMessage.Payload.Should().NotBeNullOrEmpty(); willMessage.Payload.Should().BeEquivalentTo(messageBytes); }
public void WithDelay_TimeSpam_DelaySet() { var builder = new MqttLastWillMessageBuilder(); builder .ProduceTo("testaments") .WithDelay(TimeSpan.FromSeconds(42)); builder.Delay.Should().Be(42); }
public void ProduceTo_TopicName_TopicSet() { var builder = new MqttLastWillMessageBuilder(); builder.ProduceTo("testaments"); var willMessage = builder.Build(); willMessage.Topic.Should().Be("testaments"); }
public void WithAtMostOnceQoS_QosLevelSet() { var builder = new MqttLastWillMessageBuilder(); builder .ProduceTo("testaments") .WithAtMostOnceQoS(); var willMessage = builder.Build(); willMessage.QualityOfServiceLevel.Should().Be(MqttQualityOfServiceLevel.AtMostOnce); }
public void WithRetain_RetainFlagSet() { var builder = new MqttLastWillMessageBuilder(); builder .ProduceTo("testaments") .Retain(); var willMessage = builder.Build(); willMessage.Retain.Should().BeTrue(); }
public async Task Message_SomeMessage_PayloadSet() { var message = new TestEventOne { Content = "Hello MQTT!" }; var builder = new MqttLastWillMessageBuilder(); builder .ProduceTo("testaments") .Message(message); var willMessage = builder.Build(); willMessage.Payload.Should().NotBeNullOrEmpty(); (object?deserializedMessage, Type _) = await new JsonMessageSerializer <TestEventOne>().DeserializeAsync( new MemoryStream(willMessage.Payload), new MessageHeaderCollection(), MessageSerializationContext.Empty); deserializedMessage.Should().BeEquivalentTo(message); }