Skip to content

Commit

Permalink
Release 0.4 (#68)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
ridomin authored Sep 30, 2022
1 parent 79a45af commit 6501385
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class WritableProperty<T> : CloudToDeviceBinder<T, Ack<T>>, 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)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MQTTnet.Extensions.MultiCloud.AzureIoTClient;
using MQTTnet.Extensions.MultiCloud.Serializers;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;
Expand Down Expand Up @@ -46,5 +47,47 @@ public void DesiredPropGetsTriggeredAndIsReportedBackWithAck()
});
Assert.Equal(expected, mqttClient.payloadReceived);
}

[Fact]
public void ReceiveWPWithVersion()
{
MockMqttClient mockMqtt = new MockMqttClient();
WritableProperty<string> wp = new WritableProperty<string>(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<string>
{
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);


}
}
}

0 comments on commit 6501385

Please sign in to comment.