Skip to content

Commit 0989f0c

Browse files
mryanloCopilot
andauthored
[Azure Device Registry] - add support for GA stable release api version 2025-10-01 (Azure#53386)
* update autorest.md * first draft of tests * fix tests * update assets.json to get latest test recordings * fix device and discovered device tests by creating custom delete logic to allow 200 status codes * Apply suggestions from code review Co-authored-by: Copilot <[email protected]> * push new test run * add migration test, add wrapping for 200 http status code, remove custom logic * update assets.json --------- Co-authored-by: Copilot <[email protected]>
1 parent 6f87c8f commit 0989f0c

8 files changed

+916
-5
lines changed

sdk/deviceregistry/Azure.ResourceManager.DeviceRegistry/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/deviceregistry/Azure.ResourceManager.DeviceRegistry",
5-
"Tag": "net/deviceregistry/Azure.ResourceManager.DeviceRegistry_79d9723834"
5+
"Tag": "net/deviceregistry/Azure.ResourceManager.DeviceRegistry_70e6f194a3"
66
}

sdk/deviceregistry/Azure.ResourceManager.DeviceRegistry/src/autorest.md.bak

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ azure-arm: true
77
csharp: true
88
library-name: DeviceRegistry
99
namespace: Azure.ResourceManager.DeviceRegistry
10-
require: https://github.com/Azure/azure-rest-api-specs/blob/b440cf2c8cffa273a680b49b082faef69a4bee13/specification/deviceregistry/resource-manager/readme.md
11-
tag: package-preview-2024-09
10+
require: https://github.com/Azure/azure-rest-api-specs/blob/52fc376d009c4d96b89cfc410c11a38358a18f5b/specification/deviceregistry/resource-manager/readme.md
11+
tag: package-2025-10
1212
output-folder: $(this-folder)/Generated
1313
clear-output-folder: true
1414
sample-gen:
@@ -25,8 +25,11 @@ use-model-reader-writer: true
2525
prepend-rp-prefix:
2626
- Asset
2727
- AssetEndpointProfile
28-
- DiscoveredAsset
29-
- DiscoveredAssetEndpointProfile
28+
- Namespace
29+
- NamespaceAsset
30+
- NamespaceDevice
31+
- NamespaceDiscoveredAsset
32+
- NamespaceDiscoveredDevice
3033
- SchemaRegistry
3134
- Schema
3235
- SchemaVersion
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Azure.Core;
9+
using Azure.Core.TestFramework;
10+
using Azure.ResourceManager.DeviceRegistry.Models;
11+
using NUnit.Framework;
12+
13+
namespace Azure.ResourceManager.DeviceRegistry.Tests.Scenario
14+
{
15+
public class DeviceRegistryNamespaceAssetsOperationsTest : DeviceRegistryManagementTestBase
16+
{
17+
private readonly string _subscriptionId = "8c64812d-6e59-4e65-96b3-14a7cdb1a4e4";
18+
private readonly string _resourceGroupNamePrefix = "adr-test-sdk-rg-ns-assets";
19+
private readonly string _namespaceNamePrefix = "adr-namespace-test";
20+
private readonly string _assetNamePrefix = "deviceregistry-test-asset-sdk";
21+
private readonly string _extendedLocationName = "/subscriptions/8c64812d-6e59-4e65-96b3-14a7cdb1a4e4/resourceGroups/adr-sdk-test-rg/providers/Microsoft.ExtendedLocation/customLocations/adr-sdk-test-cluster-cl";
22+
23+
public DeviceRegistryNamespaceAssetsOperationsTest(bool isAsync) : base(isAsync)
24+
{
25+
}
26+
27+
[RecordedTest]
28+
public async Task NamespaceAssetsCrudOperationsTest()
29+
{
30+
var resourceGroupName = Recording.GenerateAssetName(_resourceGroupNamePrefix);
31+
var namespaceName = Recording.GenerateAssetName(_namespaceNamePrefix);
32+
var assetName = Recording.GenerateAssetName(_assetNamePrefix);
33+
34+
var subscription = Client.GetSubscriptionResource(new ResourceIdentifier($"/subscriptions/{_subscriptionId}"));
35+
var rg = await CreateResourceGroup(subscription, resourceGroupName, AzureLocation.WestUS);
36+
var extendedLocation = new DeviceRegistryExtendedLocation() { ExtendedLocationType = "CustomLocation", Name = _extendedLocationName };
37+
38+
// Create the parent namespace resource
39+
var namespacesCollection = rg.GetDeviceRegistryNamespaces();
40+
var namespaceData = new DeviceRegistryNamespaceData(AzureLocation.WestUS)
41+
{
42+
Properties = new()
43+
{
44+
MessagingEndpoints =
45+
{
46+
["myendpoint1"] = new MessagingEndpoint("https://myendpoint1.westeurope-1.iothub.azure.net")
47+
{
48+
EndpointType = "Microsoft.Devices/IoTHubs",
49+
ResourceId = "/subscriptions/8c64812d-6e59-4e65-96b3-14a7cdb1a4e4/resourceGroups/adr-sdk-test-rg/providers/Microsoft.IotHub/namespaces/contoso-hub-namespace1"
50+
}
51+
}
52+
}
53+
};
54+
var namespaceCreateOrUpdateResponse = await namespacesCollection.CreateOrUpdateAsync(WaitUntil.Completed, namespaceName, namespaceData, CancellationToken.None);
55+
var namespaceResource = namespaceCreateOrUpdateResponse.Value;
56+
var assetsCollection = namespaceResource.GetDeviceRegistryNamespaceAssets();
57+
58+
// Create DeviceRegistry Asset
59+
var deviceRef = new DeviceRef()
60+
{
61+
DeviceName = "device1",
62+
EndpointName = "endpoint1"
63+
};
64+
var assetData = new DeviceRegistryNamespaceAssetData(AzureLocation.WestUS, extendedLocation)
65+
{
66+
Properties = new(deviceRef)
67+
{
68+
Description = "This is an asset."
69+
}
70+
};
71+
var assetCreateOrUpdateResponse = await assetsCollection.CreateOrUpdateAsync(WaitUntil.Completed, assetName, assetData, CancellationToken.None);
72+
Assert.IsNotNull(assetCreateOrUpdateResponse.Value);
73+
Assert.IsTrue(Guid.TryParse(assetCreateOrUpdateResponse.Value.Data.Properties.Uuid, out _));
74+
Assert.AreEqual(assetCreateOrUpdateResponse.Value.Data.Properties.ExternalAssetId, assetCreateOrUpdateResponse.Value.Data.Properties.Uuid);
75+
Assert.AreEqual(assetCreateOrUpdateResponse.Value.Data.Properties.DeviceRef.DeviceName, assetData.Properties.DeviceRef.DeviceName);
76+
Assert.AreEqual(assetCreateOrUpdateResponse.Value.Data.Properties.DeviceRef.EndpointName, assetData.Properties.DeviceRef.EndpointName);
77+
Assert.AreEqual(assetCreateOrUpdateResponse.Value.Data.Properties.DisplayName, assetCreateOrUpdateResponse.Value.Data.Name);
78+
Assert.AreEqual(assetCreateOrUpdateResponse.Value.Data.Properties.Description, assetData.Properties.Description);
79+
Assert.AreEqual(assetCreateOrUpdateResponse.Value.Data.Properties.Enabled, true);
80+
81+
// Read DeviceRegistry Asset
82+
var assetReadResponse = await assetsCollection.GetAsync(assetName, CancellationToken.None);
83+
Assert.IsNotNull(assetReadResponse.Value);
84+
Assert.IsTrue(Guid.TryParse(assetReadResponse.Value.Data.Properties.Uuid, out _));
85+
Assert.AreEqual(assetReadResponse.Value.Data.Properties.ExternalAssetId, assetReadResponse.Value.Data.Properties.Uuid);
86+
Assert.AreEqual(assetReadResponse.Value.Data.Properties.DeviceRef.DeviceName, assetData.Properties.DeviceRef.DeviceName);
87+
Assert.AreEqual(assetReadResponse.Value.Data.Properties.DeviceRef.EndpointName, assetData.Properties.DeviceRef.EndpointName);
88+
Assert.AreEqual(assetReadResponse.Value.Data.Properties.DisplayName, assetReadResponse.Value.Data.Name);
89+
Assert.AreEqual(assetReadResponse.Value.Data.Properties.Enabled, true);
90+
91+
// List DeviceRegistry Asset by Resource Group
92+
var assetResourcesListByResourceGroup = new List<DeviceRegistryNamespaceAssetResource>();
93+
var assetResourceListByResourceGroupAsyncIteratorPage = assetsCollection.GetAllAsync(CancellationToken.None).AsPages(null, 5);
94+
await foreach (var assetEntryPage in assetResourceListByResourceGroupAsyncIteratorPage)
95+
{
96+
assetResourcesListByResourceGroup.AddRange(assetEntryPage.Values);
97+
break; // limit to the the first page of results
98+
}
99+
Assert.IsNotEmpty(assetResourcesListByResourceGroup);
100+
Assert.GreaterOrEqual(assetResourcesListByResourceGroup.Count, 1);
101+
102+
// Update DeviceRegistry Asset
103+
var asset = assetReadResponse.Value;
104+
var assetPatchData = new DeviceRegistryNamespaceAssetPatch
105+
{
106+
Properties = new()
107+
{
108+
Description = "This is a patched Asset."
109+
}
110+
};
111+
var assetUpdateResponse = await asset.UpdateAsync(WaitUntil.Completed, assetPatchData, CancellationToken.None);
112+
Assert.IsNotNull(assetUpdateResponse.Value);
113+
Assert.IsTrue(Guid.TryParse(assetUpdateResponse.Value.Data.Properties.Uuid, out _));
114+
Assert.AreEqual(assetUpdateResponse.Value.Data.Properties.ExternalAssetId, assetUpdateResponse.Value.Data.Properties.Uuid);
115+
Assert.AreEqual(assetUpdateResponse.Value.Data.Properties.DeviceRef.DeviceName, assetData.Properties.DeviceRef.DeviceName);
116+
Assert.AreEqual(assetUpdateResponse.Value.Data.Properties.DeviceRef.EndpointName, assetData.Properties.DeviceRef.EndpointName);
117+
Assert.AreEqual(assetUpdateResponse.Value.Data.Properties.DisplayName, assetUpdateResponse.Value.Data.Name);
118+
Assert.AreEqual(assetUpdateResponse.Value.Data.Properties.Description, assetPatchData.Properties.Description);
119+
Assert.AreEqual(assetUpdateResponse.Value.Data.Properties.Enabled, true);
120+
121+
// Delete DeviceRegistry Asset
122+
await asset.DeleteAsync(WaitUntil.Completed, CancellationToken.None);
123+
}
124+
}
125+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Azure.Core;
9+
using Azure.Core.TestFramework;
10+
using Azure.ResourceManager.DeviceRegistry.Models;
11+
using NUnit.Framework;
12+
13+
namespace Azure.ResourceManager.DeviceRegistry.Tests.Scenario
14+
{
15+
public class DeviceRegistryNamespaceDevicesOperationsTest : DeviceRegistryManagementTestBase
16+
{
17+
private readonly string _subscriptionId = "8c64812d-6e59-4e65-96b3-14a7cdb1a4e4";
18+
private readonly string _namespaceRgName = "adr-sdk-test-rg";
19+
private readonly string _namespaceName = "adr-namespace";
20+
private readonly string _deviceNamePrefix = "deviceregistry-test-device-sdk";
21+
private readonly string _extendedLocationName = "/subscriptions/8c64812d-6e59-4e65-96b3-14a7cdb1a4e4/resourceGroups/adr-sdk-test-rg/providers/Microsoft.ExtendedLocation/customLocations/adr-sdk-test-cluster-cl";
22+
23+
public DeviceRegistryNamespaceDevicesOperationsTest(bool isAsync) : base(isAsync)
24+
{
25+
}
26+
27+
[RecordedTest]
28+
public async Task NamespaceDevicesCrudOperationsTest()
29+
{
30+
var deviceName = Recording.GenerateAssetName(_deviceNamePrefix);
31+
32+
var subscription = Client.GetSubscriptionResource(new ResourceIdentifier($"/subscriptions/{_subscriptionId}"));
33+
var extendedLocation = new DeviceRegistryExtendedLocation() { ExtendedLocationType = "CustomLocation", Name = _extendedLocationName };
34+
35+
var namespaceRg = await subscription.GetResourceGroupAsync(_namespaceRgName);
36+
var namespacesCollection = namespaceRg.Value.GetDeviceRegistryNamespaces();
37+
var namespaceResource = await namespacesCollection.GetAsync(_namespaceName);
38+
var devicesCollection = namespaceResource.Value.GetDeviceRegistryNamespaceDevices();
39+
40+
// Create DeviceRegistry Device
41+
var deviceData = new DeviceRegistryNamespaceDeviceData(AzureLocation.WestUS2)
42+
{
43+
Properties = new()
44+
{
45+
Manufacturer = "Contoso",
46+
Model = "Model 5000",
47+
OperatingSystem = "Linux",
48+
OperatingSystemVersion = "18.04",
49+
Endpoints = new MessagingEndpoints(),
50+
}
51+
};
52+
deviceData.Properties.Endpoints.Inbound.Add("myendpoint1", new InboundEndpoints()
53+
{
54+
Address = "https://myendpoint1.westeurope-1.iothub.azure.net",
55+
EndpointType = "Microsoft.Devices/IoTHubs"
56+
});
57+
var deviceCreateOrUpdateResponse = await devicesCollection.CreateOrUpdateAsync(WaitUntil.Completed, deviceName, deviceData, CancellationToken.None);
58+
Assert.IsNotNull(deviceCreateOrUpdateResponse.Value);
59+
Assert.IsTrue(Guid.TryParse(deviceCreateOrUpdateResponse.Value.Data.Properties.Uuid, out _));
60+
Assert.AreEqual(deviceCreateOrUpdateResponse.Value.Data.Properties.ExternalDeviceId, deviceCreateOrUpdateResponse.Value.Data.Properties.Uuid);
61+
Assert.AreEqual(deviceCreateOrUpdateResponse.Value.Data.Properties.Manufacturer, deviceData.Properties.Manufacturer);
62+
Assert.AreEqual(deviceCreateOrUpdateResponse.Value.Data.Properties.Model, deviceData.Properties.Model);
63+
Assert.AreEqual(deviceCreateOrUpdateResponse.Value.Data.Properties.OperatingSystem, deviceData.Properties.OperatingSystem);
64+
Assert.AreEqual(deviceCreateOrUpdateResponse.Value.Data.Properties.OperatingSystemVersion, deviceData.Properties.OperatingSystemVersion);
65+
Assert.AreEqual(deviceCreateOrUpdateResponse.Value.Data.Properties.Endpoints.Inbound["myendpoint1"].Address, deviceData.Properties.Endpoints.Inbound["myendpoint1"].Address);
66+
Assert.AreEqual(deviceCreateOrUpdateResponse.Value.Data.Properties.Endpoints.Inbound["myendpoint1"].EndpointType, deviceData.Properties.Endpoints.Inbound["myendpoint1"].EndpointType);
67+
Assert.AreEqual(deviceCreateOrUpdateResponse.Value.Data.Properties.Version, 1);
68+
69+
// Read DeviceRegistry Device
70+
var deviceReadResponse = await devicesCollection.GetAsync(deviceName, CancellationToken.None);
71+
Assert.IsNotNull(deviceReadResponse.Value);
72+
Assert.IsTrue(Guid.TryParse(deviceReadResponse.Value.Data.Properties.Uuid, out _));
73+
Assert.AreEqual(deviceReadResponse.Value.Data.Properties.ExternalDeviceId, deviceReadResponse.Value.Data.Properties.Uuid);
74+
Assert.AreEqual(deviceReadResponse.Value.Data.Properties.Manufacturer, deviceData.Properties.Manufacturer);
75+
Assert.AreEqual(deviceReadResponse.Value.Data.Properties.Model, deviceData.Properties.Model);
76+
Assert.AreEqual(deviceReadResponse.Value.Data.Properties.OperatingSystem, deviceData.Properties.OperatingSystem);
77+
Assert.AreEqual(deviceReadResponse.Value.Data.Properties.OperatingSystemVersion, deviceData.Properties.OperatingSystemVersion);
78+
Assert.AreEqual(deviceReadResponse.Value.Data.Properties.Endpoints.Inbound["myendpoint1"].Address, deviceData.Properties.Endpoints.Inbound["myendpoint1"].Address);
79+
Assert.AreEqual(deviceReadResponse.Value.Data.Properties.Endpoints.Inbound["myendpoint1"].EndpointType, deviceData.Properties.Endpoints.Inbound["myendpoint1"].EndpointType);
80+
Assert.AreEqual(deviceReadResponse.Value.Data.Properties.Version, 1);
81+
82+
// List DeviceRegistry Device by Resource Group
83+
var deviceResourcesListByResourceGroup = new List<DeviceRegistryNamespaceDeviceResource>();
84+
var deviceResourceListByResourceGroupAsyncIteratorPage = devicesCollection.GetAllAsync(CancellationToken.None).AsPages(null, 5);
85+
await foreach (var deviceEntryPage in deviceResourceListByResourceGroupAsyncIteratorPage)
86+
{
87+
deviceResourcesListByResourceGroup.AddRange(deviceEntryPage.Values);
88+
break; // limit to the the first page of results
89+
}
90+
Assert.IsNotEmpty(deviceResourcesListByResourceGroup);
91+
Assert.GreaterOrEqual(deviceResourcesListByResourceGroup.Count, 1);
92+
93+
// Update DeviceRegistry Device
94+
var device = deviceReadResponse.Value;
95+
var devicePatchData = new DeviceRegistryNamespaceDevicePatch
96+
{
97+
Properties = new()
98+
{
99+
OperatingSystemVersion = "20.04",
100+
}
101+
};
102+
var deviceUpdateResponse = await device.UpdateAsync(WaitUntil.Completed, devicePatchData, CancellationToken.None);
103+
Assert.IsNotNull(deviceUpdateResponse.Value);
104+
Assert.IsTrue(Guid.TryParse(deviceUpdateResponse.Value.Data.Properties.Uuid, out _));
105+
Assert.AreEqual(deviceUpdateResponse.Value.Data.Properties.ExternalDeviceId, deviceUpdateResponse.Value.Data.Properties.Uuid);
106+
Assert.AreEqual(deviceUpdateResponse.Value.Data.Properties.Manufacturer, deviceData.Properties.Manufacturer);
107+
Assert.AreEqual(deviceUpdateResponse.Value.Data.Properties.Model, deviceData.Properties.Model);
108+
Assert.AreEqual(deviceUpdateResponse.Value.Data.Properties.OperatingSystem, deviceData.Properties.OperatingSystem);
109+
Assert.AreEqual(deviceUpdateResponse.Value.Data.Properties.OperatingSystemVersion, devicePatchData.Properties.OperatingSystemVersion);
110+
Assert.AreEqual(deviceUpdateResponse.Value.Data.Properties.Endpoints.Inbound["myendpoint1"].Address, deviceData.Properties.Endpoints.Inbound["myendpoint1"].Address);
111+
Assert.AreEqual(deviceUpdateResponse.Value.Data.Properties.Endpoints.Inbound["myendpoint1"].EndpointType, deviceData.Properties.Endpoints.Inbound["myendpoint1"].EndpointType);
112+
Assert.AreEqual(deviceUpdateResponse.Value.Data.Properties.Version, 2);
113+
114+
// Delete DeviceRegistry Device
115+
try
116+
{
117+
await device.DeleteAsync(WaitUntil.Completed, CancellationToken.None);
118+
}
119+
catch (RequestFailedException ex)
120+
{
121+
// Delete temporary returns 200 since async operation is defined for the resource but not implemented in RP
122+
if (ex.Status != 200)
123+
{
124+
throw;
125+
}
126+
}
127+
}
128+
}
129+
}

0 commit comments

Comments
 (0)