From 650138584b9c57e1798bdd98c4e3fe3a8ac5ebe5 Mon Sep 17 00:00:00 2001 From: Rido Date: Fri, 30 Sep 2022 14:57:14 -0700 Subject: [PATCH] Release 0.4 (#68) * Prep 0.4 (#62) * squash big refactor * clean TwinInitializer * review tests * add payload sample * add avro * add memmon proto * sync with ux * upd links for ux * samples not packagable * review packable * clean up * clean pnp comments * fix unit tests * fix cmd response binder * add proto unit tests * review generic ack * Validate 0.4 (#64) * review packable * clean up * clean pnp comments * fix unit tests * fix cmd response binder * add proto unit tests * review generic ack * clean ns * init properties * rm cert keys * run integration tests in ci * review ack versions * resolve protos * add default version to hub wp * add unit test for wp version init value * add default version to hub wp * add unit test for wp version init value --- .../WritableProperty.cs | 2 +- .../HubWritablePropertyUTFJsonFixture.cs | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/MQTTnet.Extensions.MultiCloud.AzureIoTClient/WritableProperty.cs b/src/MQTTnet.Extensions.MultiCloud.AzureIoTClient/WritableProperty.cs index 8d1ed0d..48384ab 100644 --- a/src/MQTTnet.Extensions.MultiCloud.AzureIoTClient/WritableProperty.cs +++ b/src/MQTTnet.Extensions.MultiCloud.AzureIoTClient/WritableProperty.cs @@ -8,7 +8,7 @@ public class WritableProperty : CloudToDeviceBinder>, IWritableProp readonly IMqttClient _connection; readonly string _name; public T? Value { get; set; } - public int? Version { get; set; } + public int? Version { get; set; } = -1; public WritableProperty(IMqttClient c, string name) : base(c, name) diff --git a/tests/MQTTnet.Extensions.MultiCloud.UnitTests/HubClient/HubWritablePropertyUTFJsonFixture.cs b/tests/MQTTnet.Extensions.MultiCloud.UnitTests/HubClient/HubWritablePropertyUTFJsonFixture.cs index 845cf72..6e803a5 100644 --- a/tests/MQTTnet.Extensions.MultiCloud.UnitTests/HubClient/HubWritablePropertyUTFJsonFixture.cs +++ b/tests/MQTTnet.Extensions.MultiCloud.UnitTests/HubClient/HubWritablePropertyUTFJsonFixture.cs @@ -1,4 +1,5 @@ using MQTTnet.Extensions.MultiCloud.AzureIoTClient; +using MQTTnet.Extensions.MultiCloud.Serializers; using System.Collections.Generic; using System.Threading.Tasks; using Xunit; @@ -46,5 +47,47 @@ public void DesiredPropGetsTriggeredAndIsReportedBackWithAck() }); Assert.Equal(expected, mqttClient.payloadReceived); } + + [Fact] + public void ReceiveWPWithVersion() + { + MockMqttClient mockMqtt = new MockMqttClient(); + WritableProperty wp = new WritableProperty(mockMqtt, "aStringProp"); + Assert.Equal(-1, wp.Version); + Assert.Null(wp.Value); + bool propReceived = false; + wp.OnMessage = async (message) => + { + propReceived = true; + wp.Value = message; + wp.Version++; + return await Task.FromResult( + new Ack + { + Value = message, + Version = wp.Version, + Status = 200 + }); + }; + + mockMqtt.SimulateNewBinaryMessage("$iothub/twin/PATCH/properties/desired/?$rid=1&$version=3", + new UTF8JsonSerializer().ToBytes(new { aStringProp = "string value" } )); + Assert.True(propReceived); + Assert.Equal(4, wp.Version); + Assert.Equal("string value", wp.Value); + Assert.Equal($"$iothub/twin/PATCH/properties/reported/?$rid=1&$version=3", mockMqtt.topicRecceived); + Assert.Equal("{\"aStringProp\":{\"av\":4,\"ac\":200,\"value\":\"string value\"}}", mockMqtt.payloadReceived); + + propReceived = false; + mockMqtt.SimulateNewBinaryMessage("$iothub/twin/PATCH/properties/desired/?$rid=1&$version=4", + new UTF8JsonSerializer().ToBytes(new { aStringProp = "second string value" })); + Assert.True(propReceived); + Assert.Equal(5, wp.Version); + Assert.Equal("second string value", wp.Value); + Assert.Equal($"$iothub/twin/PATCH/properties/reported/?$rid=1&$version=4", mockMqtt.topicRecceived); + Assert.Equal("{\"aStringProp\":{\"av\":5,\"ac\":200,\"value\":\"second string value\"}}", mockMqtt.payloadReceived); + + + } } }