From 10f6ad0c6416ee7b84427b30a3068fec2005e6aa Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Wed, 24 Mar 2021 16:18:02 -0700 Subject: [PATCH 1/4] Change the accessbility to virtual for Resource.Id --- .../Azure.ResourceManager.Core/src/Resources/Resource.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs index 86a35ac05cf77..a8638d1c689be 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Resources/Resource.cs @@ -14,7 +14,7 @@ public abstract class Resource : IEquatable, IEquatable, IComp /// /// Gets or sets the resource identifier. /// - public abstract ResourceIdentifier Id { get; protected set; } + public virtual ResourceIdentifier Id { get; protected set; } /// /// Gets the name. From bdaa65aa54b57b9cdb04cf2f1178ae1361f591b9 Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Wed, 30 Jun 2021 16:14:55 -0700 Subject: [PATCH 2/4] WIP --- .../tests/Scenario/ResponseExtensionsTests.cs | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResponseExtensionsTests.cs diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResponseExtensionsTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResponseExtensionsTests.cs new file mode 100644 index 0000000000000..e087536c19d36 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResponseExtensionsTests.cs @@ -0,0 +1,42 @@ +using System; +using System.Net.Http; +using System.Threading.Tasks; +using Azure.Core; +using Azure.Core.TestFramework; +using NUnit.Framework; + +namespace Azure.ResourceManager.Core.Tests +{ + public class ResponseExtensionsTests : ResourceManagerTestBase + { + public ResponseExtensionsTests(bool isAsync) + : base(isAsync)//, RecordedTestMode.Record) + { + } + + [TestCase] + [RecordedTest] + public async Task GetCorrelationId() + { + var correlationId = Guid.NewGuid().ToString(); + var pipeline = Client.DefaultSubscription.Pipeline; + var endpoint = new Uri("https://management.azure.com"); + var message = pipeline.CreateMessage(); + var request = message.Request; + request.Method = RequestMethod.Get; + var uri = new RawRequestUriBuilder(); + uri.Reset(endpoint); + uri.AppendPath("/subscriptions/", false); + uri.AppendPath(TestEnvironment.SubscriptionId, true); + uri.AppendQuery("api-version", "2019-11-01", true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("x-ms-correlation-id", correlationId); + + await pipeline.SendAsync(message, default).ConfigureAwait(false); + + var response = message.Response; + Assert.AreEqual(correlationId, ResponseExtensions.GetCorrelationId(response)); + } + } +} From 9dd1525a5c6816c18c4d6778dcd89f5876f6474d Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Thu, 8 Jul 2021 17:19:26 -0700 Subject: [PATCH 3/4] Update a typo --- .../src/Extensions/ResponseExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Extensions/ResponseExtensions.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Extensions/ResponseExtensions.cs index 1de63e0891a5e..8ec18d3531757 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/src/Extensions/ResponseExtensions.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/src/Extensions/ResponseExtensions.cs @@ -14,7 +14,7 @@ public static class ResponseExtensions public static string GetCorrelationId(this Response response) { string correlationId = null; - response.Headers.TryGetValue("x-ms-correlation-id", out correlationId); + response.Headers.TryGetValue("x-ms-correlation-request-id", out correlationId); return correlationId; } } From 46e5ba85afe872d092ca0305cf6e3316baa2d53e Mon Sep 17 00:00:00 2001 From: YalinLi0312 Date: Thu, 8 Jul 2021 17:20:03 -0700 Subject: [PATCH 4/4] Update tests based on the typo --- .../tests/Scenario/ResponseExtensionsTests.cs | 5 +- .../GetCorrelationId().json | 99 +++++++++++++++++++ .../GetCorrelationId()Async.json | 99 +++++++++++++++++++ 3 files changed, 200 insertions(+), 3 deletions(-) create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/tests/SessionRecords/ResponseExtensionsTests/GetCorrelationId().json create mode 100644 sdk/resourcemanager/Azure.ResourceManager.Core/tests/SessionRecords/ResponseExtensionsTests/GetCorrelationId()Async.json diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResponseExtensionsTests.cs b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResponseExtensionsTests.cs index e087536c19d36..5cd4d894f69c9 100644 --- a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResponseExtensionsTests.cs +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/Scenario/ResponseExtensionsTests.cs @@ -18,7 +18,7 @@ public ResponseExtensionsTests(bool isAsync) [RecordedTest] public async Task GetCorrelationId() { - var correlationId = Guid.NewGuid().ToString(); + var correlationId = "0a98bb8b-ec3e-4f68-a8c1-a7705554a980"; var pipeline = Client.DefaultSubscription.Pipeline; var endpoint = new Uri("https://management.azure.com"); var message = pipeline.CreateMessage(); @@ -31,10 +31,9 @@ public async Task GetCorrelationId() uri.AppendQuery("api-version", "2019-11-01", true); request.Uri = uri; request.Headers.Add("Accept", "application/json"); - request.Headers.Add("x-ms-correlation-id", correlationId); + request.Headers.Add("x-ms-correlation-request-id", correlationId); await pipeline.SendAsync(message, default).ConfigureAwait(false); - var response = message.Response; Assert.AreEqual(correlationId, ResponseExtensions.GetCorrelationId(response)); } diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/SessionRecords/ResponseExtensionsTests/GetCorrelationId().json b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/SessionRecords/ResponseExtensionsTests/GetCorrelationId().json new file mode 100644 index 0000000000000..39cdad4b65362 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/SessionRecords/ResponseExtensionsTests/GetCorrelationId().json @@ -0,0 +1,99 @@ +{ + "Entries": [ + { + "RequestUri": "https://management.azure.com/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c?api-version=2019-11-01", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "User-Agent": "azsdk-net-ResourceManager.Core/1.0.0-alpha.20210708.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19043 )", + "x-ms-client-request-id": "25c4321654833f35fc7ed90c51f70388", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Cache-Control": "no-cache", + "Content-Length": "450", + "Content-Type": "application/json; charset=utf-8", + "Date": "Fri, 09 Jul 2021 00:16:18 GMT", + "Expires": "-1", + "Pragma": "no-cache", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "X-Content-Type-Options": "nosniff", + "x-ms-correlation-request-id": "eace7458-fdd1-443f-8696-52efa1806b24", + "x-ms-ratelimit-remaining-subscription-reads": "11998", + "x-ms-request-id": "eace7458-fdd1-443f-8696-52efa1806b24", + "x-ms-routing-request-id": "WESTUS2:20210709T001618Z:eace7458-fdd1-443f-8696-52efa1806b24" + }, + "ResponseBody": { + "id": "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c", + "authorizationSource": "RoleBased", + "managedByTenants": [], + "tags": { + "tagKey1": "tagValue1", + "tagKey2": "tagValue2" + }, + "subscriptionId": "db1ab6f0-4769-4b27-930e-01e2ef9c123c", + "tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47", + "displayName": "Azure SDK sandbox", + "state": "Enabled", + "subscriptionPolicies": { + "locationPlacementId": "Internal_2014-09-01", + "quotaId": "Internal_2014-09-01", + "spendingLimit": "Off" + } + } + }, + { + "RequestUri": "https://management.azure.com/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c?api-version=2019-11-01", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "User-Agent": "azsdk-net-ResourceManager.Core/1.0.0-alpha.20210708.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19043 )", + "x-ms-client-request-id": "9fd7c2cd3cb6714d542b181699e6381a", + "x-ms-correlation-request-id": "0a98bb8b-ec3e-4f68-a8c1-a7705554a980", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Cache-Control": "no-cache", + "Content-Length": "450", + "Content-Type": "application/json; charset=utf-8", + "Date": "Fri, 09 Jul 2021 00:16:18 GMT", + "Expires": "-1", + "Pragma": "no-cache", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "X-Content-Type-Options": "nosniff", + "x-ms-correlation-request-id": "0a98bb8b-ec3e-4f68-a8c1-a7705554a980", + "x-ms-ratelimit-remaining-subscription-reads": "11997", + "x-ms-request-id": "85f8bd21-d2a4-40b5-8302-ef59258d949d", + "x-ms-routing-request-id": "WESTUS2:20210709T001618Z:85f8bd21-d2a4-40b5-8302-ef59258d949d" + }, + "ResponseBody": { + "id": "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c", + "authorizationSource": "RoleBased", + "managedByTenants": [], + "tags": { + "tagKey1": "tagValue1", + "tagKey2": "tagValue2" + }, + "subscriptionId": "db1ab6f0-4769-4b27-930e-01e2ef9c123c", + "tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47", + "displayName": "Azure SDK sandbox", + "state": "Enabled", + "subscriptionPolicies": { + "locationPlacementId": "Internal_2014-09-01", + "quotaId": "Internal_2014-09-01", + "spendingLimit": "Off" + } + } + } + ], + "Variables": { + "RandomSeed": "1582208049", + "SUBSCRIPTION_ID": "db1ab6f0-4769-4b27-930e-01e2ef9c123c" + } +} \ No newline at end of file diff --git a/sdk/resourcemanager/Azure.ResourceManager.Core/tests/SessionRecords/ResponseExtensionsTests/GetCorrelationId()Async.json b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/SessionRecords/ResponseExtensionsTests/GetCorrelationId()Async.json new file mode 100644 index 0000000000000..bd65de44474e5 --- /dev/null +++ b/sdk/resourcemanager/Azure.ResourceManager.Core/tests/SessionRecords/ResponseExtensionsTests/GetCorrelationId()Async.json @@ -0,0 +1,99 @@ +{ + "Entries": [ + { + "RequestUri": "https://management.azure.com/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c?api-version=2019-11-01", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "User-Agent": "azsdk-net-ResourceManager.Core/1.0.0-alpha.20210708.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19043 )", + "x-ms-client-request-id": "484ea1bdf82f5b04c8e56838974d2a51", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Cache-Control": "no-cache", + "Content-Length": "450", + "Content-Type": "application/json; charset=utf-8", + "Date": "Fri, 09 Jul 2021 00:16:18 GMT", + "Expires": "-1", + "Pragma": "no-cache", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "X-Content-Type-Options": "nosniff", + "x-ms-correlation-request-id": "cb34a47c-b3b9-4365-bf85-301afbdd31a0", + "x-ms-ratelimit-remaining-subscription-reads": "11998", + "x-ms-request-id": "cb34a47c-b3b9-4365-bf85-301afbdd31a0", + "x-ms-routing-request-id": "WESTUS2:20210709T001618Z:cb34a47c-b3b9-4365-bf85-301afbdd31a0" + }, + "ResponseBody": { + "id": "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c", + "authorizationSource": "RoleBased", + "managedByTenants": [], + "tags": { + "tagKey1": "tagValue1", + "tagKey2": "tagValue2" + }, + "subscriptionId": "db1ab6f0-4769-4b27-930e-01e2ef9c123c", + "tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47", + "displayName": "Azure SDK sandbox", + "state": "Enabled", + "subscriptionPolicies": { + "locationPlacementId": "Internal_2014-09-01", + "quotaId": "Internal_2014-09-01", + "spendingLimit": "Off" + } + } + }, + { + "RequestUri": "https://management.azure.com/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c?api-version=2019-11-01", + "RequestMethod": "GET", + "RequestHeaders": { + "Accept": "application/json", + "Authorization": "Sanitized", + "User-Agent": "azsdk-net-ResourceManager.Core/1.0.0-alpha.20210708.1 (.NET Framework 4.8.4300.0; Microsoft Windows 10.0.19043 )", + "x-ms-client-request-id": "e5708f1c6583f5f6670cffe4bc65604b", + "x-ms-correlation-request-id": "0a98bb8b-ec3e-4f68-a8c1-a7705554a980", + "x-ms-return-client-request-id": "true" + }, + "RequestBody": null, + "StatusCode": 200, + "ResponseHeaders": { + "Cache-Control": "no-cache", + "Content-Length": "450", + "Content-Type": "application/json; charset=utf-8", + "Date": "Fri, 09 Jul 2021 00:16:18 GMT", + "Expires": "-1", + "Pragma": "no-cache", + "Strict-Transport-Security": "max-age=31536000; includeSubDomains", + "X-Content-Type-Options": "nosniff", + "x-ms-correlation-request-id": "0a98bb8b-ec3e-4f68-a8c1-a7705554a980", + "x-ms-ratelimit-remaining-subscription-reads": "11997", + "x-ms-request-id": "3541cbae-404a-4664-8b43-4572fbe053f7", + "x-ms-routing-request-id": "WESTUS2:20210709T001618Z:3541cbae-404a-4664-8b43-4572fbe053f7" + }, + "ResponseBody": { + "id": "/subscriptions/db1ab6f0-4769-4b27-930e-01e2ef9c123c", + "authorizationSource": "RoleBased", + "managedByTenants": [], + "tags": { + "tagKey1": "tagValue1", + "tagKey2": "tagValue2" + }, + "subscriptionId": "db1ab6f0-4769-4b27-930e-01e2ef9c123c", + "tenantId": "72f988bf-86f1-41af-91ab-2d7cd011db47", + "displayName": "Azure SDK sandbox", + "state": "Enabled", + "subscriptionPolicies": { + "locationPlacementId": "Internal_2014-09-01", + "quotaId": "Internal_2014-09-01", + "spendingLimit": "Off" + } + } + } + ], + "Variables": { + "RandomSeed": "205252330", + "SUBSCRIPTION_ID": "db1ab6f0-4769-4b27-930e-01e2ef9c123c" + } +} \ No newline at end of file