Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update arm response types to match current Azure.Core pattern #20738

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0f3f806
WIP
m-nash Mar 22, 2021
0f52a38
wip
m-nash Mar 24, 2021
10f6ad0
Change the accessbility to virtual for Resource.Id
YalinLi0312 Mar 24, 2021
1f81d59
merge from feature/mgmt-track2
Mar 30, 2021
c192698
update strawman for operation changes
Apr 1, 2021
ccc17c7
merge from usptream
Apr 5, 2021
5060f5c
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash Apr 12, 2021
795c706
merge from mgmt-track2
m-nash Apr 14, 2021
2f90c91
finalize changes before testing
m-nash Apr 14, 2021
d0407f6
update ph overloads
m-nash Apr 14, 2021
c7305e8
move pipeline creation into armoperation
m-nash Apr 14, 2021
30e529d
wip
m-nash Apr 21, 2021
e358938
merge
m-nash Apr 26, 2021
7db165a
updates based on new OperationInternals
m-nash Apr 28, 2021
a4e5bae
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash Apr 28, 2021
ec173e7
address PR comments
m-nash Apr 29, 2021
5a9fff2
update test classes to use new pattern
m-nash Apr 30, 2021
381cc03
merge from upstream
m-nash Apr 30, 2021
a6217d6
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash May 4, 2021
d7c8171
Merge branch 'feature/mgmt-track2' of https://github.com/Azure/azure-…
m-nash May 5, 2021
cd712bb
final fixes for arm core tests
m-nash May 5, 2021
8649b18
use mock response instead of null
m-nash May 5, 2021
09bb02b
updates to proto code
m-nash May 5, 2021
f888e32
add null check around basetype
m-nash May 5, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void Intercept(IInvocation invocation)

if (
// Generated ARM clients will have a property containing the sub-client that ends with Operations.
(invocation.Method.Name.StartsWith("get_") && (type.Name.EndsWith("Operations") || type.BaseType.Name.EndsWith("Operations"))) ||
(invocation.Method.Name.StartsWith("get_") && (type.Name.EndsWith("Operations") || (type.BaseType != null && type.BaseType.Name.EndsWith("Operations")))) ||
pakrym marked this conversation as resolved.
Show resolved Hide resolved
// Instrument the container construction methods inside Operations objects
(invocation.Method.Name.StartsWith("Get") && type.Name.EndsWith("Container")) ||
// Instrument the operations construction methods inside Operations objects
Expand Down
1 change: 1 addition & 0 deletions sdk/core/Azure.Core/tests/Azure.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<TargetFrameworks>$(RequiredTargetFrameworks)</TargetFrameworks>
<DefineConstants>$(DefineConstants);HAS_INTERNALS_VISIBLE_CORE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IncludeGeneratorSharedCode>true</IncludeGeneratorSharedCode>
</PropertyGroup>

<ItemGroup>
Expand Down
47 changes: 22 additions & 25 deletions sdk/core/Azure.Core/tests/TestClients/ArmOperationTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,66 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core.TestFramework;
using Azure.ResourceManager.Core;

namespace Azure.Core.Tests
{
public class ArmOperationTest<T> : ArmOperation<T>
where T : class
public class ArmOperationTest : ArmOperation<TestResource>, IOperationSource<TestResource>
{
private T _value;
private TestResource _value;
private bool _exceptionOnWait;
private OperationOrResponseInternals<TestResource> _operationHelper;

protected ArmOperationTest()
{
}

public ArmOperationTest(T value, bool exceptionOnWait = false)
public ArmOperationTest(TestResource value, bool exceptionOnWait = false)
{
_value = value;
_exceptionOnWait = exceptionOnWait;
_operationHelper = new OperationOrResponseInternals<TestResource>(Response.FromValue(value, new MockResponse(200)));
}

public override string Id => "testId";

public override T Value => _value;
public override TestResource Value => _operationHelper.Value;

public override bool HasCompleted => true;
public override bool HasCompleted => _operationHelper.HasCompleted;

public override bool HasValue => true;
public override bool HasValue => _operationHelper.HasValue;

public override Response GetRawResponse()
{
return Response.FromValue(_value, null) as Response;
}
public override Response GetRawResponse() => _operationHelper.GetRawResponse();

public override ValueTask<Response<T>> WaitForCompletionAsync(CancellationToken cancellationToken = default)
public override ValueTask<Response<TestResource>> WaitForCompletionAsync(CancellationToken cancellationToken = default)
{
if (_exceptionOnWait)
throw new ArgumentException("FakeArg");

return new ValueTask<Response<T>>(Response.FromValue(_value, null));
return new ValueTask<Response<TestResource>>(Response.FromValue(_value, new MockResponse(200)));
}

public override ValueTask<Response<T>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken)
public override ValueTask<Response<TestResource>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken)
{
if (_exceptionOnWait)
throw new ArgumentException("FakeArg");

return new ValueTask<Response<T>>(Response.FromValue(_value, null));
return new ValueTask<Response<TestResource>>(Response.FromValue(_value, new MockResponse(200)));
}

public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default)
{
if (_exceptionOnWait)
throw new ArgumentException("FakeArg");
public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatusAsync(cancellationToken);

return new ValueTask<Response>(Response.FromValue(_value, null) as Response);
}
public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatus(cancellationToken);

public override Response UpdateStatus(CancellationToken cancellationToken = default)
public TestResource CreateResult(Response response, CancellationToken cancellationToken)
{
if (_exceptionOnWait)
throw new ArgumentException("FakeArg");
return _value;
}

return Response.FromValue(_value, null) as Response;
public ValueTask<TestResource> CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return new ValueTask<TestResource>(_value);
}
}
}
31 changes: 29 additions & 2 deletions sdk/core/Azure.Core/tests/TestClients/PhArmOperationTest.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,44 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using System;
using System.Threading;
using System.Threading.Tasks;
using Azure.Core.TestFramework;
using Azure.ResourceManager.Core;

namespace Azure.Core.Tests
{
public class PhArmOperationTest<T> : ArmOperationTest<T>
public class PhArmOperationTest<T> : ArmOperation<T>
where T : class
{
private OperationOrResponseInternals<T> _operationHelper;

public override T Value => _operationHelper.Value;

public override bool HasValue => _operationHelper.HasValue;

public override string Id => "MyId";

public override bool HasCompleted => _operationHelper.HasCompleted;

protected PhArmOperationTest()
{
}

public PhArmOperationTest(T value) : base(value)
public PhArmOperationTest(T value)
{
_operationHelper = new OperationOrResponseInternals<T>(Response.FromValue(value, new MockResponse(200)));
}

public override ValueTask<Response<T>> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _operationHelper.WaitForCompletionAsync(cancellationToken);

public override ValueTask<Response<T>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken) => _operationHelper.WaitForCompletionAsync(pollingInterval, cancellationToken);

public override Response GetRawResponse() => _operationHelper.GetRawResponse();

public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatusAsync(cancellationToken);

public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operationHelper.UpdateStatus(cancellationToken);
}
}
19 changes: 10 additions & 9 deletions sdk/core/Azure.Core/tests/TestClients/TestResourceOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using Azure.Core.Pipeline;
using Azure.ResourceManager.Core;

namespace Azure.Core.Tests
{
Expand All @@ -17,14 +18,14 @@ public virtual TestResourceOperations GetAnotherOperations()
return new TestResource();
}

public virtual ArmOperationTest<TestResource> GetArmOperation(bool exceptionOnWait = false, CancellationToken cancellationToken = default)
public virtual ArmOperationTest GetArmOperation(bool exceptionOnWait = false, CancellationToken cancellationToken = default)
{
using var scope = _diagnostic.CreateScope("TestResourceOperations.GetArmOperation");
scope.Start();

try
{
return new ArmOperationTest<TestResource>(new TestResource(), exceptionOnWait);
return new ArmOperationTest(new TestResource(), exceptionOnWait);
}
catch (Exception e)
{
Expand All @@ -33,14 +34,14 @@ public virtual ArmOperationTest<TestResource> GetArmOperation(bool exceptionOnWa
}
}

public virtual Task<ArmOperationTest<TestResource>> GetArmOperationAsync(bool exceptionOnWait = false, CancellationToken cancellationToken = default)
public virtual Task<ArmOperationTest> GetArmOperationAsync(bool exceptionOnWait = false, CancellationToken cancellationToken = default)
{
using var scope = _diagnostic.CreateScope("TestResourceOperations.GetArmOperation");
scope.Start();

try
{
return Task.FromResult(new ArmOperationTest<TestResource>(new TestResource(), exceptionOnWait));
return Task.FromResult(new ArmOperationTest(new TestResource(), exceptionOnWait));
}
catch (Exception e)
{
Expand Down Expand Up @@ -81,7 +82,7 @@ public virtual Task<ArmResponseTest<TestResource>> GetArmResponseAsync(Cancellat
}
}

public virtual ArmOperationTest<TestResource> GetPhArmOperation(CancellationToken cancellationToken = default)
public virtual ArmOperation<TestResource> GetPhArmOperation(CancellationToken cancellationToken = default)
{
using var scope = _diagnostic.CreateScope("TestResourceOperations.GetPhArmOperation");
scope.Start();
Expand All @@ -97,14 +98,14 @@ public virtual ArmOperationTest<TestResource> GetPhArmOperation(CancellationToke
}
}

public virtual Task<ArmOperationTest<TestResource>> GetPhArmOperationAsync(CancellationToken cancellationToken = default)
public virtual Task<ArmOperation<TestResource>> GetPhArmOperationAsync(CancellationToken cancellationToken = default)
{
using var scope = _diagnostic.CreateScope("TestResourceOperations.GetPhArmOperation");
scope.Start();

try
{
return Task.FromResult<ArmOperationTest<TestResource>>(new PhArmOperationTest<TestResource>(new TestResource()));
return Task.FromResult<ArmOperation<TestResource>>(new PhArmOperationTest<TestResource>(new TestResource()));
}
catch (Exception e)
{
Expand Down Expand Up @@ -177,7 +178,7 @@ public virtual Task<ArmResponseTest<TestResource>> GetArmResponseExceptionAsync(
}
}

public virtual ArmOperationTest<TestResource> GetArmOperationException(CancellationToken cancellationToken = default)
public virtual ArmOperationTest GetArmOperationException(CancellationToken cancellationToken = default)
{
using var scope = _diagnostic.CreateScope("TestResourceOperations.GetArmOperationException");
scope.Start();
Expand All @@ -193,7 +194,7 @@ public virtual ArmOperationTest<TestResource> GetArmOperationException(Cancellat
}
}

public virtual Task<ArmOperationTest<TestResource>> GetArmOperationExceptionAsync(CancellationToken cancellationToken = default)
public virtual Task<ArmOperationTest> GetArmOperationExceptionAsync(CancellationToken cancellationToken = default)
{
using var scope = _diagnostic.CreateScope("TestResourceOperations.GetArmOperationException");
scope.Start();
Expand Down
83 changes: 0 additions & 83 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmOperation.cs

This file was deleted.

46 changes: 0 additions & 46 deletions sdk/resourcemanager/Azure.ResourceManager.Core/src/ArmResponse.cs

This file was deleted.

Loading