-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update tests and framework to instrument all clients recursively (#19443
) * Framework changes * Azure.ResourceManager.Core changes to support client interceptors * Test changes * proto client changes * updates after merge * Address review comments * WIP * updates after WIP
- Loading branch information
Showing
149 changed files
with
166,684 additions
and
1,807 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
sdk/core/Azure.Core.TestFramework/src/AsyncPageableInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Castle.DynamicProxy; | ||
|
||
namespace Azure.Core.TestFramework | ||
{ | ||
public class AsyncPageableInterceptor<T> : IAsyncEnumerator<T> | ||
where T : class | ||
{ | ||
private ClientTestBase _testBase; | ||
private IAsyncEnumerator<T> _inner; | ||
|
||
public AsyncPageableInterceptor(ClientTestBase testBase, IAsyncEnumerator<T> inner) | ||
{ | ||
_testBase = testBase; | ||
_inner = inner; | ||
} | ||
|
||
public T Current => _testBase.InstrumentClient(typeof(T), _inner.Current, new IInterceptor[] { new ManagementInterceptor(_testBase) }) as T; | ||
|
||
public ValueTask<bool> MoveNextAsync() | ||
{ | ||
return _inner.MoveNextAsync(); | ||
} | ||
|
||
public ValueTask DisposeAsync() | ||
{ | ||
return _inner.DisposeAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
sdk/core/Azure.Core.TestFramework/src/ManagementInterceptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.Reflection; | ||
using System.Threading.Tasks; | ||
using Castle.DynamicProxy; | ||
|
||
namespace Azure.Core.TestFramework | ||
{ | ||
internal class ManagementInterceptor : IInterceptor | ||
{ | ||
private readonly ClientTestBase _testBase; | ||
private static readonly ProxyGenerator s_proxyGenerator = new ProxyGenerator(); | ||
|
||
public ManagementInterceptor(ClientTestBase testBase) | ||
{ | ||
_testBase = testBase; | ||
} | ||
|
||
public void Intercept(IInvocation invocation) | ||
{ | ||
invocation.Proceed(); | ||
|
||
var result = invocation.ReturnValue; | ||
if (result == null) | ||
{ | ||
return; | ||
} | ||
|
||
var type = result.GetType(); | ||
|
||
if (type.Name.StartsWith("Task")) | ||
{ | ||
var taskResultType = type.GetGenericArguments()[0]; | ||
if (taskResultType.Name.StartsWith("ArmResponse") || taskResultType.Name.StartsWith("ArmOperation")) | ||
{ | ||
var taskResult = result.GetType().GetProperty("Result").GetValue(result); | ||
var instrumentedResult = _testBase.InstrumentClient(taskResultType, taskResult, new IInterceptor[] { new ManagementInterceptor(_testBase) }); | ||
var method = typeof(Task).GetMethod("FromResult", BindingFlags.Public | BindingFlags.Static); | ||
var genericType = taskResultType.Name.StartsWith("Ph") ? taskResultType.BaseType : taskResultType; //TODO: remove after 5279 and 5284 | ||
var genericMethod = method.MakeGenericMethod(genericType); | ||
invocation.ReturnValue = genericMethod.Invoke(null, new object[] { instrumentedResult }); | ||
} | ||
} | ||
else if (invocation.Method.Name.EndsWith("Value") && type.BaseType.Name.EndsWith("Operations")) | ||
{ | ||
invocation.ReturnValue = _testBase.InstrumentClient(type, result, new IInterceptor[] { new ManagementInterceptor(_testBase) }); | ||
} | ||
else if (type.BaseType.Name.StartsWith("AsyncPageable")) | ||
{ | ||
invocation.ReturnValue = s_proxyGenerator.CreateClassProxyWithTarget(type, result, new IInterceptor[] { new ManagementInterceptor(_testBase) }); | ||
} | ||
else if (invocation.Method.Name.StartsWith("Get") && invocation.Method.Name.EndsWith("Enumerator")) | ||
{ | ||
var wrapperType = typeof(AsyncPageableInterceptor<>); | ||
var genericType = wrapperType.MakeGenericType(type.GetGenericArguments()[0]); | ||
var ctor = genericType.GetConstructor(new Type[] { typeof(ClientTestBase), result.GetType() }); | ||
invocation.ReturnValue = ctor.Invoke(new object[] { _testBase, result }); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.