Skip to content

Commit

Permalink
update armclient to support extension mock (#39631)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcturusZhang committed Nov 1, 2023
1 parent 994cba6 commit 82a9481
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
8 changes: 2 additions & 6 deletions sdk/resourcemanager/Azure.ResourceManager/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# Release History

## 1.8.0-beta.1 (Unreleased)
## 1.8.0 (2023-11-02)

### Features Added

### Breaking Changes

### Bugs Fixed

### Other Changes
- Add a new method `GetCachedClient` in `ArmClient` class to unify the mocking experience.

## 1.7.0 (2023-07-13)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ protected ArmClient() { }
public ArmClient(Azure.Core.TokenCredential credential) { }
public ArmClient(Azure.Core.TokenCredential credential, string defaultSubscriptionId) { }
public ArmClient(Azure.Core.TokenCredential credential, string defaultSubscriptionId, Azure.ResourceManager.ArmClientOptions options) { }
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Never)]
public virtual T GetCachedClient<T>(System.Func<Azure.ResourceManager.ArmClient, T> clientFactory) where T : class { throw null; }
public virtual Azure.ResourceManager.Resources.DataPolicyManifestResource GetDataPolicyManifestResource(Azure.Core.ResourceIdentifier id) { throw null; }
public virtual Azure.ResourceManager.Resources.SubscriptionResource GetDefaultSubscription(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.ResourceManager.Resources.SubscriptionResource> GetDefaultSubscriptionAsync(System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
14 changes: 14 additions & 0 deletions sdk/resourcemanager/Azure.ResourceManager/src/ArmClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,5 +297,19 @@ public virtual T GetResourceClient<T>(Func<T> resourceFactory)
{
return resourceFactory();
}

private readonly ConcurrentDictionary<Type, object> _clientCache = new ConcurrentDictionary<Type, object>();

/// <summary>
/// Gets a cached client to use for extension methods.
/// </summary>
/// <typeparam name="T"> The type of client to get. </typeparam>
/// <param name="clientFactory"> The constructor factory for the client. </param>
[EditorBrowsable(EditorBrowsableState.Never)]
public virtual T GetCachedClient<T>(Func<ArmClient, T> clientFactory)
where T : class
{
return _clientCache.GetOrAdd(typeof(T), (type) => { return clientFactory(this); }) as T;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>1.8.0-beta.1</Version>
<Version>1.8.0</Version>
<!--The ApiCompatVersion is managed automatically and should not generally be modified manually.-->
<ApiCompatVersion>1.7.0</ApiCompatVersion>
<PackageId>Azure.ResourceManager</PackageId>
Expand Down

0 comments on commit 82a9481

Please sign in to comment.