| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using Castle.DynamicProxy; |
| | | 6 | | |
| | | 7 | | namespace Azure.Core.TestFramework |
| | | 8 | | { |
| | | 9 | | internal class InstrumentClientInterceptor : IInterceptor |
| | | 10 | | { |
| | | 11 | | private readonly ClientTestBase _testBase; |
| | | 12 | | |
| | 61757 | 13 | | public InstrumentClientInterceptor(ClientTestBase testBase) |
| | | 14 | | { |
| | 61757 | 15 | | _testBase = testBase; |
| | 61757 | 16 | | } |
| | | 17 | | |
| | | 18 | | public void Intercept(IInvocation invocation) |
| | | 19 | | { |
| | 126734 | 20 | | invocation.Proceed(); |
| | | 21 | | |
| | 126713 | 22 | | var result = invocation.ReturnValue; |
| | 126713 | 23 | | if (result == null) |
| | | 24 | | { |
| | 12420 | 25 | | return; |
| | | 26 | | } |
| | | 27 | | |
| | 114293 | 28 | | var type = result.GetType(); |
| | 114293 | 29 | | if (type.Name.EndsWith("Client") || |
| | 114293 | 30 | | // Generated ARM clients will have a property containing the subclient that ends with Operations. |
| | 114293 | 31 | | (invocation.Method.Name.StartsWith("get_") && type.Name.EndsWith("Operations"))) |
| | | 32 | | { |
| | 40176 | 33 | | invocation.ReturnValue = _testBase.InstrumentClient(type, result, Array.Empty<IInterceptor>()); |
| | | 34 | | } |
| | 114293 | 35 | | } |
| | | 36 | | } |
| | | 37 | | } |