diff --git a/e2e/test/iothub/service/RegistryManagerE2ETests.cs b/e2e/test/iothub/service/RegistryManagerE2ETests.cs index 0e4c681fcb..c8a1550281 100644 --- a/e2e/test/iothub/service/RegistryManagerE2ETests.cs +++ b/e2e/test/iothub/service/RegistryManagerE2ETests.cs @@ -121,7 +121,10 @@ public async Task RegistryManager_BulkLifecycle() var devices = new List(); for (int i = 0; i < bulkCount; i++) { - devices.Add(new Device(_devicePrefix + Guid.NewGuid())); + var device = new Device(_devicePrefix + Guid.NewGuid()); + device.Scope = "someScope" + Guid.NewGuid(); + device.ParentScopes.Add("someParentScope" + Guid.NewGuid()); + devices.Add(device); } using RegistryManager registryManager = RegistryManager.CreateFromConnectionString(TestConfiguration.IoTHub.ConnectionString); @@ -133,7 +136,11 @@ public async Task RegistryManager_BulkLifecycle() foreach (Device device in devices) { // After a bulk add, every device should be able to be retrieved - Assert.IsNotNull(await registryManager.GetDeviceAsync(device.Id).ConfigureAwait(false)); + Device retrievedDevice = await registryManager.GetDeviceAsync(device.Id).ConfigureAwait(false); + Assert.IsNotNull(retrievedDevice.Id); + Assert.AreEqual(device.Scope, retrievedDevice.Scope); + Assert.AreEqual(1, retrievedDevice.ParentScopes.Count); + Assert.AreEqual(device.ParentScopes.ElementAt(0), retrievedDevice.ParentScopes.ElementAt(0)); } var twins = new List(); diff --git a/iothub/service/src/ExportImportDevice.cs b/iothub/service/src/ExportImportDevice.cs index eacfc12b6d..79d1a60a9e 100644 --- a/iothub/service/src/ExportImportDevice.cs +++ b/iothub/service/src/ExportImportDevice.cs @@ -5,6 +5,7 @@ // --------------------------------------------------------------- using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using Microsoft.Azure.Devices.Shared; using Newtonsoft.Json; @@ -64,6 +65,8 @@ public ExportImportDevice(Device device, ImportMode importmode) StatusReason = device.StatusReason; Authentication = device.Authentication; Capabilities = device.Capabilities; + DeviceScope = device.Scope; + ParentScopes = device.ParentScopes; } /// @@ -152,6 +155,21 @@ public string TwinETag [JsonProperty(PropertyName = "deviceScope", NullValueHandling = NullValueHandling.Include)] public string DeviceScope { get; set; } + /// + /// The scopes of the upper level edge devices if applicable. + /// + /// + /// For edge devices, the value to set a parent edge device can be retrieved from the parent edge device's property. + /// + /// For leaf devices, this could be set to the same value as or left for the service to copy over. + /// + /// For now, this list can only have 1 element in the collection. + /// + /// For more information, see . + /// + [JsonProperty(PropertyName = "parentScopes", NullValueHandling = NullValueHandling.Ignore)] + public IList ParentScopes { get; internal set; } = new List(); + private static string SanitizeETag(string eTag) { if (!string.IsNullOrWhiteSpace(eTag))