Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
abhipsaMisra committed Jun 3, 2021
1 parent 9eea8de commit 2f2494d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
34 changes: 18 additions & 16 deletions e2e/test/iothub/properties/PropertiesE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Client;
using Microsoft.Azure.Devices.Client.Exceptions;
Expand All @@ -21,7 +20,7 @@ public class PropertiesE2ETests : E2EMsTestBase
{
private readonly string _devicePrefix = $"E2E_{nameof(PropertiesE2ETests)}_";

private static readonly RegistryManager _registryManager = RegistryManager.CreateFromConnectionString(Configuration.IoTHub.ConnectionString);
private static readonly RegistryManager s_registryManager = RegistryManager.CreateFromConnectionString(Configuration.IoTHub.ConnectionString);

private static readonly List<object> s_listOfPropertyValues = new List<object>
{
Expand Down Expand Up @@ -207,29 +206,29 @@ private async Task Properties_DeviceSetsPropertyArrayAndGetsItBackSingleDeviceAs

public static async Task Properties_DeviceSetsPropertyAndGetsItBackAsync<T>(DeviceClient deviceClient, string deviceId, T propValue, MsTestLogger logger)
{
var propName = Guid.NewGuid().ToString();
string propName = Guid.NewGuid().ToString();

logger.Trace($"{nameof(Properties_DeviceSetsPropertyAndGetsItBackAsync)}: name={propName}, value={propValue}");

var props = new ClientPropertyCollection();
props[propName] = propValue;
props.AddRootProperty(propName, propValue);
await deviceClient.UpdateClientPropertiesAsync(props).ConfigureAwait(false);

// Validate the updated twin from the device-client
ClientProperties deviceTwin = await deviceClient.GetClientPropertiesAsync().ConfigureAwait(false);
if (deviceTwin.TryGetValue<T>(propName, out var propFromCollection))
ClientProperties clientProperties = await deviceClient.GetClientPropertiesAsync().ConfigureAwait(false);
if (clientProperties.TryGetValue<T>(propName, out T propFromCollection))
{
Assert.AreEqual(JsonConvert.SerializeObject(propFromCollection), JsonConvert.SerializeObject(propValue));
Assert.AreEqual(propFromCollection, propValue);
}
else
{
Assert.Fail($"The property {propName} was not found in the collection");
}

// Validate the updated twin from the service-client
Twin completeTwin = await _registryManager.GetTwinAsync(deviceId).ConfigureAwait(false);
var actualProp = completeTwin.Properties.Reported[propName];
Assert.AreEqual(JsonConvert.SerializeObject(actualProp), JsonConvert.SerializeObject(propValue));
Twin completeTwin = await s_registryManager.GetTwinAsync(deviceId).ConfigureAwait(false);
dynamic actualProp = completeTwin.Properties.Reported[propName];
Assert.AreEqual(actualProp, propValue);
}

public static async Task<Task> SetClientPropertyUpdateCallbackHandlerAsync<T>(DeviceClient deviceClient, string expectedPropName, T expectedPropValue, MsTestLogger logger)
Expand All @@ -248,7 +247,8 @@ await deviceClient
if (patch.TryGetValue<T>(expectedPropName, out var propertyFromCollection))
{
Assert.AreEqual(JsonConvert.SerializeObject(expectedPropValue), JsonConvert.SerializeObject(propertyFromCollection));
} else
}
else
{
Assert.Fail("Property was not found in the collection.");
}
Expand Down Expand Up @@ -278,7 +278,7 @@ public static async Task RegistryManagerUpdateWritablePropertyAsync<T>(string de
var twinPatch = new Twin();
if (propValue is List<object>)
{
twinPatch.Properties.Desired[propName] = (Newtonsoft.Json.Linq.JToken)(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(propValue)));
twinPatch.Properties.Desired[propName] = (Newtonsoft.Json.Linq.JToken)JsonConvert.DeserializeObject(JsonConvert.SerializeObject(propValue));
}
else
{
Expand Down Expand Up @@ -344,13 +344,14 @@ await Task.WhenAll(
if (deviceTwin.Writable.TryGetValue<T>(propName, out var propFromCollection))
{
Assert.AreEqual(JsonConvert.SerializeObject(propFromCollection), JsonConvert.SerializeObject(propValue));
} else
}
else
{
Assert.Fail($"The property {propName} was not found in the Writable collection");
}

// Validate the updated twin from the service-client
Twin completeTwin = await _registryManager.GetTwinAsync(testDevice.Id).ConfigureAwait(false);
Twin completeTwin = await s_registryManager.GetTwinAsync(testDevice.Id).ConfigureAwait(false);
var actualProp = completeTwin.Properties.Desired[propName];
Assert.AreEqual(JsonConvert.SerializeObject(actualProp), JsonConvert.SerializeObject(propValue));

Expand All @@ -375,7 +376,8 @@ private async Task Properties_ServiceSetsWritablePropertyAndDeviceReceivesItOnNe
if (deviceTwin.Writable.TryGetValue(propName, out string propFromCollection))
{
Assert.AreEqual<string>(propFromCollection, propValue);
} else
}
else
{
Assert.Fail("Property not found in ClientProperties");
}
Expand Down
8 changes: 8 additions & 0 deletions iothub/device/src/PayloadCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public abstract class PayloadCollection : IEnumerable<object>
/// <remarks>
/// This accessor is best used to access and cast to simple types.
/// It is recommended to use <see cref="TryGetValue"/> to deserialize to a complex type.
/// <para>
/// <remarks>
/// For setting component-level property values see <see cref="ClientPropertyCollection.AddComponentProperty(string, string, object)"/>
/// and <see cref="ClientPropertyCollection.AddComponentProperties(string, IDictionary{string, object})"/>instead.
/// These convenience methods ensure that component-level properties include the component identifier markers { "__t": "c" }.
/// For more information see <see href="https://docs.microsoft.com/en-us/azure/iot-pnp/concepts-convention#sample-multiple-components-read-only-property"/>.
/// </remarks>
/// </para>
/// </remarks>
/// <param name="key">Key of value.</param>
/// <returns>The specified property.</returns>
Expand Down

0 comments on commit 2f2494d

Please sign in to comment.