Skip to content

Commit 5f9e928

Browse files
authored
combine resource and resource operations classes (Azure#23205)
* update simple resources to no longer have operations rename ResourceOperations to ArmResource rename ResourceContainer to ArmContainer * combine genericResource and genericResourceExpanded add test case to validate the expand deserializes properly * combine managementGroupInfo and manageGroup * update core tests after changes * update fields to be consistent with autorest * update after test interceptor changes * update to take resourceidentifier differentiate between a tenant provider and a subscription provider add overloads to get generic resource list to take string and resource identifier * update api after changes * add test case to validate bad sub id being passed into armclient * temporarily use alpha version of core * remove unused overload * add recording so test can be played back in ci * use testenv creds
1 parent b227271 commit 5f9e928

File tree

138 files changed

+6576
-63602
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+6576
-63602
lines changed

common/ManagementTestShared/Redesign/ManagementRecordedTestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ protected void CleanupResourceGroups()
117117
{
118118
try
119119
{
120-
_cleanupClient.GetManagementGroupOperations(mgmtGroupId).StartDelete();
120+
_cleanupClient.GetManagementGroup(mgmtGroupId).StartDelete();
121121
}
122122
catch (RequestFailedException e) when (e.Status == 404 || e.Status == 403)
123123
{
@@ -206,7 +206,7 @@ public void OneTimeCleanupResourceGroups()
206206
});
207207
Parallel.ForEach(OneTimeManagementGroupCleanupPolicy.ManagementGroupsCreated, mgmtGroupId =>
208208
{
209-
_cleanupClient.GetManagementGroupOperations(mgmtGroupId).StartDelete();
209+
_cleanupClient.GetManagementGroup(mgmtGroupId).StartDelete();
210210
});
211211
}
212212

eng/Directory.Build.Common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
</ItemGroup>
127127

128128
<ItemGroup Condition="'$(IsMgmtLibrary)' == 'true'">
129-
<PackageReference Include="Azure.Core" />
129+
<PackageReference Include="Azure.Core" VersionOverride="1.18.0-alpha.20210810.5"/>
130130
<PackageReference Include="System.Text.Json" />
131131
</ItemGroup>
132132

sdk/core/Azure.Core.TestFramework/src/Instrumentation/InstrumentResultInterceptor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void Intercept(IInvocation invocation)
3030
// We don't want to instrument generated rest clients.
3131
if ((type.Name.EndsWith("Client") && !type.Name.EndsWith("RestClient")) ||
3232
// Generated ARM clients will have a property containing the sub-client that ends with Operations.
33+
//TODO: remove after all track2 .net mgmt libraries are updated to the new generation
3334
(invocation.Method.Name.StartsWith("get_") && type.Name.EndsWith("Operations")))
3435
{
3536
if (IsNullResult(invocation))
@@ -41,11 +42,10 @@ public void Intercept(IInvocation invocation)
4142

4243
if (
4344
// Generated ARM clients will have a property containing the sub-client that ends with Operations.
44-
(invocation.Method.Name.StartsWith("get_") && (type.Name.EndsWith("Operations") || (type.BaseType != null && type.BaseType.Name.EndsWith("Operations")))) ||
45+
(invocation.Method.Name.StartsWith("get_") && ManagementInterceptor.InheritsFromArmResource(type)) ||
4546
// Instrument the container construction methods inside Operations objects
46-
(invocation.Method.Name.StartsWith("Get") && type.Name.EndsWith("Container")) ||
4747
// Instrument the operations construction methods inside Operations objects
48-
(invocation.Method.Name.StartsWith("Get") && type.Name.EndsWith("Operations")))
48+
(invocation.Method.Name.StartsWith("Get") && ManagementInterceptor.InheritsFromArmResource(type)))
4949
{
5050
if (IsNullResult(invocation))
5151
return;

sdk/core/Azure.Core.TestFramework/src/Instrumentation/ManagementInterceptor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void Intercept(IInvocation invocation)
6161
}
6262
}
6363
}
64-
else if (invocation.Method.Name.EndsWith("Value") && type.BaseType.Name.EndsWith("Operations"))
64+
else if (invocation.Method.Name.EndsWith("Value") && InheritsFromArmResource(type))
6565
{
6666
invocation.ReturnValue = _testBase.InstrumentClient(type, result, new IInterceptor[] { new ManagementInterceptor(_testBase) });
6767
}
@@ -72,7 +72,7 @@ public void Intercept(IInvocation invocation)
7272
else if (invocation.Method.Name.StartsWith("Get") &&
7373
invocation.Method.Name.EndsWith("Enumerator") &&
7474
type.IsGenericType &&
75-
InheritsFromOperationBase(type.GetGenericArguments().First()))
75+
InheritsFromArmResource(type.GetGenericArguments().First()))
7676
{
7777
var wrapperType = typeof(AsyncPageableInterceptor<>);
7878
var genericType = wrapperType.MakeGenericType(type.GetGenericArguments()[0]);
@@ -81,18 +81,18 @@ public void Intercept(IInvocation invocation)
8181
}
8282
}
8383

84-
private bool InheritsFromOperationBase(Type elementType)
84+
internal static bool InheritsFromArmResource(Type elementType)
8585
{
8686
if (elementType.BaseType == null)
8787
return false;
8888

8989
if (elementType.BaseType == typeof(object))
9090
return false;
9191

92-
if (elementType.BaseType.Name == "ResourceOperations")
92+
if (elementType.BaseType.Name == "ArmResource")
9393
return true;
9494

95-
return InheritsFromOperationBase(elementType.BaseType);
95+
return InheritsFromArmResource(elementType.BaseType);
9696
}
9797

9898
private object GetValueFromOther(Type taskResultType, object instrumentedResult)

sdk/core/Azure.Core/tests/ManagementPipelineBuilderTests.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,24 @@
77
using System.Threading;
88
using Azure.Core.Pipeline;
99
using Azure.Core.TestFramework;
10+
using Azure.Identity;
1011
using Azure.ResourceManager;
1112
using NUnit.Framework;
13+
using static Azure.Core.Tests.Management.ManagementPipelineBuilderTests;
1214

1315
namespace Azure.Core.Tests.Management
1416
{
15-
public class ManagementPipelineBuilderTests
17+
internal class ManagementPipelineBuilderTests : RecordedTestBase<MgmtPipelineTestEnvironment>
1618
{
19+
internal class MgmtPipelineTestEnvironment : TestEnvironment { }
20+
21+
public ManagementPipelineBuilderTests(bool isAsync)
22+
: base(isAsync)//, RecordedTestMode.Record)
23+
{
24+
}
25+
1726
[TestCase]
27+
[SyncOnly]
1828
public void AddPerCallPolicy()
1929
{
2030
var options = new ArmClientOptions();
@@ -27,13 +37,14 @@ public void AddPerCallPolicy()
2737
Assert.IsNotNull(policies.ToArray().FirstOrDefault(p => p.GetType() == typeof(DummyPolicy)));
2838
}
2939

30-
[TestCase]
40+
[RecordedTest]
41+
[SyncOnly]
3142
public void AddPerCallPolicyViaClient()
3243
{
33-
var options = new ArmClientOptions();
44+
var options = InstrumentClientOptions(new ArmClientOptions());
3445
var dummyPolicy = new DummyPolicy();
3546
options.AddPolicy(dummyPolicy, HttpPipelinePosition.PerCall);
36-
var client = new ArmClient(Guid.NewGuid().ToString(), new MockCredential(), options);
47+
var client = InstrumentClient(new ArmClient(TestEnvironment.Credential, options));
3748

3849
var pipelineProperty = client.GetType().GetProperty("Pipeline", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty);
3950
var pipeline = pipelineProperty.GetValue(client) as HttpPipeline;

sdk/core/Azure.Core/tests/ManagementRecordedTestBaseTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public async Task ValidateInstrumentArmOperation()
4848
{
4949
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
5050
var sub = client.DefaultSubscription;
51-
var operation = (await sub.GetArmOperationAsync()).Value;
51+
var operation = (await sub.GetLroAsync()).Value;
5252
var result = operation.Method();
5353

5454
Assert.AreEqual("TestResourceProxy", operation.GetType().Name);
@@ -60,7 +60,7 @@ public async Task ValidateInstrumentArmResponse()
6060
{
6161
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
6262
var sub = client.DefaultSubscription;
63-
var response = (await sub.GetArmOperationAsync()).Value;
63+
var response = (await sub.GetLroAsync()).Value;
6464
var result = response.Method();
6565

6666
Assert.AreEqual("TestResourceProxy", response.GetType().Name);
@@ -83,9 +83,9 @@ public void ValidateInstrumentGetContainer()
8383
public void ValidateInstrumentGetOperations()
8484
{
8585
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
86-
var testResource = client.GetTestResourceOperations();
86+
var testResource = client.GetTestResource();
8787

88-
Assert.AreEqual("TestResourceOperationsProxy", testResource.GetType().Name);
88+
Assert.AreEqual("TestResourceProxy", testResource.GetType().Name);
8989
Assert.AreEqual("success", testResource.Method());
9090
}
9191

@@ -105,8 +105,8 @@ public async Task ValidateInstrumentPageable()
105105
public async Task ValidateWaitForCompletion()
106106
{
107107
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
108-
TestResourceOperations rgOp = client.GetTestResourceOperations();
109-
var testResourceOp = await rgOp.GetArmOperationAsync();
108+
TestResource rgOp = client.GetTestResource();
109+
var testResourceOp = await rgOp.GetLroAsync();
110110
TestResource testResource = await testResourceOp.WaitForCompletionAsync();
111111
Assert.AreEqual("TestResourceProxy", testResource.GetType().Name);
112112
Assert.AreEqual("success", testResource.Method());
@@ -116,32 +116,32 @@ public async Task ValidateWaitForCompletion()
116116
public void ValidateExceptionResponse()
117117
{
118118
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
119-
TestResourceOperations rgOp = client.GetTestResourceOperations();
119+
TestResource rgOp = client.GetTestResource();
120120
Assert.ThrowsAsync(typeof(ArgumentException), async () => await rgOp.GetResponseExceptionAsync());
121121
}
122122

123123
[Test]
124124
public void ValidateExceptionOperation()
125125
{
126126
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
127-
TestResourceOperations rgOp = client.GetTestResourceOperations();
128-
Assert.ThrowsAsync(typeof(ArgumentException), async () => await rgOp.GetArmOperationExceptionAsync());
127+
TestResource rgOp = client.GetTestResource();
128+
Assert.ThrowsAsync(typeof(ArgumentException), async () => await rgOp.GetLroExceptionAsync());
129129
}
130130

131131
[Test]
132132
public async Task ValidateExceptionOperationWaitForCompletion()
133133
{
134134
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
135-
TestResourceOperations rgOp = client.GetTestResourceOperations();
136-
var testResourceOp = await rgOp.GetArmOperationAsync(true);
135+
TestResource rgOp = client.GetTestResource();
136+
var testResourceOp = await rgOp.GetLroAsync(true);
137137
Assert.ThrowsAsync(typeof(ArgumentException), async () => await testResourceOp.WaitForCompletionAsync());
138138
}
139139

140140
[Test]
141141
public async Task ValidateLroWrapper()
142142
{
143143
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
144-
TestResourceOperations rgOp = client.GetTestResourceOperations();
144+
TestResource rgOp = client.GetTestResource();
145145
TestResource testResource = await rgOp.LroWrapperAsync();
146146
Assert.AreEqual("TestResourceProxy", testResource.GetType().Name);
147147
Assert.AreEqual("success", testResource.Method());
@@ -151,7 +151,7 @@ public async Task ValidateLroWrapper()
151151
public async Task ValidateStartLroWrapper()
152152
{
153153
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
154-
TestResourceOperations rgOp = client.GetTestResourceOperations();
154+
TestResource rgOp = client.GetTestResource();
155155
var testResourceOp = await rgOp.StartLroWrapperAsync();
156156
TestResource testResource = await testResourceOp.WaitForCompletionAsync();
157157
Assert.AreEqual("TestResourceProxy", testResource.GetType().Name);
@@ -162,7 +162,7 @@ public async Task ValidateStartLroWrapper()
162162
public async Task ValidateSkipWait()
163163
{
164164
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
165-
TestResourceOperations rgOp = client.GetTestResourceOperations();
165+
TestResource rgOp = client.GetTestResource();
166166
Stopwatch timer = Stopwatch.StartNew();
167167
TestResource testResource = await rgOp.LroWrapperAsync();
168168
timer.Stop();
@@ -174,7 +174,7 @@ public async Task ValidateSkipWait()
174174
public async Task ValidateStartSkipWait()
175175
{
176176
ManagementTestClient client = InstrumentClient(new ManagementTestClient());
177-
TestResourceOperations rgOp = client.GetTestResourceOperations();
177+
TestResource rgOp = client.GetTestResource();
178178
var testResourceOp = await rgOp.StartLroWrapperAsync();
179179
Stopwatch timer = Stopwatch.StartNew();
180180
TestResource testResource = await testResourceOp.WaitForCompletionAsync();

sdk/core/Azure.Core/tests/SessionRecords/ManagementPipelineBuilderTests/AddPerCallPolicyViaClient.json

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/core/Azure.Core/tests/TestClients/ManagementTestClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ public ManagementTestClient(TestClientOptions options)
1919
_diagnostics = new ClientDiagnostics(options);
2020
}
2121

22-
public virtual TestResourceOperations GetTestResourceOperations()
22+
public virtual TestResource GetTestResource()
2323
{
24-
return new TestResourceOperations();
24+
return new TestResource();
2525
}
2626

2727
public virtual TestResourceContainer GetTestResourceContainer()

sdk/core/Azure.Core/tests/TestClients/ArmOperationTest.cs renamed to sdk/core/Azure.Core/tests/TestClients/TestLroOperation.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88

99
namespace Azure.Core.Tests
1010
{
11-
public class ArmOperationTest : Operation<TestResource>, IOperationSource<TestResource>
11+
public class TestLroOperation : Operation<TestResource>, IOperationSource<TestResource>
1212
{
1313
private TestResource _value;
1414
private bool _exceptionOnWait;
1515
private OperationOrResponseInternals<TestResource> _operationHelper;
1616
private int _delaySteps = 0;
1717

18-
protected ArmOperationTest()
18+
protected TestLroOperation()
1919
{
2020
}
2121

22-
public ArmOperationTest(TestResource value, bool exceptionOnWait = false, int delaySteps = 0)
22+
public TestLroOperation(TestResource value, bool exceptionOnWait = false, int delaySteps = 0)
2323
{
2424
_value = value;
2525
_exceptionOnWait = exceptionOnWait;

0 commit comments

Comments
 (0)