Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 0.4 #68

Merged
merged 23 commits into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);


}
}
}