diff --git a/Packages.Data.props b/Packages.Data.props
index bd40c7262bb..cf2dc549d01 100644
--- a/Packages.Data.props
+++ b/Packages.Data.props
@@ -29,7 +29,7 @@
-
+
diff --git a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupResource.cs b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupResource.cs
index 8ac34d5bbdb..f13e8fceceb 100644
--- a/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupResource.cs
+++ b/samples/Azure.ResourceManager.Sample/Generated/DedicatedHostGroupResource.cs
@@ -96,7 +96,7 @@ internal static void ValidateResourceId(ResourceIdentifier id)
/// An object representing collection of DedicatedHostResources and their operations over a DedicatedHostResource.
public virtual DedicatedHostCollection GetDedicatedHosts()
{
- return GetCachedClient(Client => new DedicatedHostCollection(Client, Id));
+ return GetCachedClient(client => new DedicatedHostCollection(client, Id));
}
///
@@ -115,8 +115,8 @@ public virtual DedicatedHostCollection GetDedicatedHosts()
/// The name of the dedicated host.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetDedicatedHostAsync(string hostName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
{
@@ -139,8 +139,8 @@ public virtual async Task> GetDedicatedHostAsync
/// The name of the dedicated host.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetDedicatedHost(string hostName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
{
diff --git a/samples/Azure.ResourceManager.Sample/Generated/Extensions/MockableSampleArmClient.cs b/samples/Azure.ResourceManager.Sample/Generated/Extensions/MockableSampleArmClient.cs
new file mode 100644
index 00000000000..dd6a198aa50
--- /dev/null
+++ b/samples/Azure.ResourceManager.Sample/Generated/Extensions/MockableSampleArmClient.cs
@@ -0,0 +1,207 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using Azure.Core;
+using Azure.ResourceManager;
+using Azure.ResourceManager.Sample;
+
+namespace Azure.ResourceManager.Sample.Mocking
+{
+ /// A class to add extension methods to ArmClient.
+ public partial class MockableSampleArmClient : ArmResource
+ {
+ /// Initializes a new instance of the class for mocking.
+ protected MockableSampleArmClient()
+ {
+ }
+
+ /// Initializes a new instance of the class.
+ /// The client parameters to use in these operations.
+ /// The identifier of the resource that is the target of operations.
+ internal MockableSampleArmClient(ArmClient client, ResourceIdentifier id) : base(client, id)
+ {
+ }
+
+ internal MockableSampleArmClient(ArmClient client) : this(client, ResourceIdentifier.Root)
+ {
+ }
+
+ private string GetApiVersionOrNull(ResourceType resourceType)
+ {
+ TryGetApiVersion(resourceType, out string apiVersion);
+ return apiVersion;
+ }
+
+ ///
+ /// Gets an object representing an along with the instance operations that can be performed on it but with no data.
+ /// You can use to create an from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual AvailabilitySetResource GetAvailabilitySetResource(ResourceIdentifier id)
+ {
+ AvailabilitySetResource.ValidateResourceId(id);
+ return new AvailabilitySetResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual ProximityPlacementGroupResource GetProximityPlacementGroupResource(ResourceIdentifier id)
+ {
+ ProximityPlacementGroupResource.ValidateResourceId(id);
+ return new ProximityPlacementGroupResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual DedicatedHostGroupResource GetDedicatedHostGroupResource(ResourceIdentifier id)
+ {
+ DedicatedHostGroupResource.ValidateResourceId(id);
+ return new DedicatedHostGroupResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual DedicatedHostResource GetDedicatedHostResource(ResourceIdentifier id)
+ {
+ DedicatedHostResource.ValidateResourceId(id);
+ return new DedicatedHostResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual SshPublicKeyResource GetSshPublicKeyResource(ResourceIdentifier id)
+ {
+ SshPublicKeyResource.ValidateResourceId(id);
+ return new SshPublicKeyResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual VirtualMachineExtensionImageResource GetVirtualMachineExtensionImageResource(ResourceIdentifier id)
+ {
+ VirtualMachineExtensionImageResource.ValidateResourceId(id);
+ return new VirtualMachineExtensionImageResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual VirtualMachineExtensionResource GetVirtualMachineExtensionResource(ResourceIdentifier id)
+ {
+ VirtualMachineExtensionResource.ValidateResourceId(id);
+ return new VirtualMachineExtensionResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual VirtualMachineScaleSetVirtualMachineExtensionResource GetVirtualMachineScaleSetVirtualMachineExtensionResource(ResourceIdentifier id)
+ {
+ VirtualMachineScaleSetVirtualMachineExtensionResource.ValidateResourceId(id);
+ return new VirtualMachineScaleSetVirtualMachineExtensionResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual VirtualMachineResource GetVirtualMachineResource(ResourceIdentifier id)
+ {
+ VirtualMachineResource.ValidateResourceId(id);
+ return new VirtualMachineResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing an along with the instance operations that can be performed on it but with no data.
+ /// You can use to create an from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual ImageResource GetImageResource(ResourceIdentifier id)
+ {
+ ImageResource.ValidateResourceId(id);
+ return new ImageResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual VirtualMachineScaleSetResource GetVirtualMachineScaleSetResource(ResourceIdentifier id)
+ {
+ VirtualMachineScaleSetResource.ValidateResourceId(id);
+ return new VirtualMachineScaleSetResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual VirtualMachineScaleSetExtensionResource GetVirtualMachineScaleSetExtensionResource(ResourceIdentifier id)
+ {
+ VirtualMachineScaleSetExtensionResource.ValidateResourceId(id);
+ return new VirtualMachineScaleSetExtensionResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual VirtualMachineScaleSetRollingUpgradeResource GetVirtualMachineScaleSetRollingUpgradeResource(ResourceIdentifier id)
+ {
+ VirtualMachineScaleSetRollingUpgradeResource.ValidateResourceId(id);
+ return new VirtualMachineScaleSetRollingUpgradeResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual VirtualMachineScaleSetVmResource GetVirtualMachineScaleSetVmResource(ResourceIdentifier id)
+ {
+ VirtualMachineScaleSetVmResource.ValidateResourceId(id);
+ return new VirtualMachineScaleSetVmResource(Client, id);
+ }
+ }
+}
diff --git a/samples/Azure.ResourceManager.Sample/Generated/Extensions/MockableSampleResourceGroupResource.cs b/samples/Azure.ResourceManager.Sample/Generated/Extensions/MockableSampleResourceGroupResource.cs
new file mode 100644
index 00000000000..590e0a149c6
--- /dev/null
+++ b/samples/Azure.ResourceManager.Sample/Generated/Extensions/MockableSampleResourceGroupResource.cs
@@ -0,0 +1,419 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Azure;
+using Azure.Core;
+using Azure.ResourceManager;
+using Azure.ResourceManager.Sample;
+using Azure.ResourceManager.Sample.Models;
+
+namespace Azure.ResourceManager.Sample.Mocking
+{
+ /// A class to add extension methods to ResourceGroupResource.
+ public partial class MockableSampleResourceGroupResource : ArmResource
+ {
+ /// Initializes a new instance of the class for mocking.
+ protected MockableSampleResourceGroupResource()
+ {
+ }
+
+ /// Initializes a new instance of the class.
+ /// The client parameters to use in these operations.
+ /// The identifier of the resource that is the target of operations.
+ internal MockableSampleResourceGroupResource(ArmClient client, ResourceIdentifier id) : base(client, id)
+ {
+ }
+
+ private string GetApiVersionOrNull(ResourceType resourceType)
+ {
+ TryGetApiVersion(resourceType, out string apiVersion);
+ return apiVersion;
+ }
+
+ /// Gets a collection of AvailabilitySetResources in the ResourceGroupResource.
+ /// An object representing collection of AvailabilitySetResources and their operations over a AvailabilitySetResource.
+ public virtual AvailabilitySetCollection GetAvailabilitySets()
+ {
+ return GetCachedClient(client => new AvailabilitySetCollection(client, Id));
+ }
+
+ ///
+ /// Retrieves information about an availability set.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}
+ ///
+ /// -
+ /// Operation Id
+ /// AvailabilitySets_Get
+ ///
+ ///
+ ///
+ /// The name of the availability set.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetAvailabilitySetAsync(string availabilitySetName, CancellationToken cancellationToken = default)
+ {
+ return await GetAvailabilitySets().GetAsync(availabilitySetName, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Retrieves information about an availability set.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/availabilitySets/{availabilitySetName}
+ ///
+ /// -
+ /// Operation Id
+ /// AvailabilitySets_Get
+ ///
+ ///
+ ///
+ /// The name of the availability set.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetAvailabilitySet(string availabilitySetName, CancellationToken cancellationToken = default)
+ {
+ return GetAvailabilitySets().Get(availabilitySetName, cancellationToken);
+ }
+
+ /// Gets a collection of ProximityPlacementGroupResources in the ResourceGroupResource.
+ /// An object representing collection of ProximityPlacementGroupResources and their operations over a ProximityPlacementGroupResource.
+ public virtual ProximityPlacementGroupCollection GetProximityPlacementGroups()
+ {
+ return GetCachedClient(client => new ProximityPlacementGroupCollection(client, Id));
+ }
+
+ ///
+ /// Retrieves information about a proximity placement group .
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/proximityPlacementGroups/{proximityPlacementGroupName}
+ ///
+ /// -
+ /// Operation Id
+ /// ProximityPlacementGroups_Get
+ ///
+ ///
+ ///
+ /// The name of the proximity placement group.
+ /// includeColocationStatus=true enables fetching the colocation status of all the resources in the proximity placement group.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetProximityPlacementGroupAsync(string proximityPlacementGroupName, string includeColocationStatus = null, CancellationToken cancellationToken = default)
+ {
+ return await GetProximityPlacementGroups().GetAsync(proximityPlacementGroupName, includeColocationStatus, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Retrieves information about a proximity placement group .
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/proximityPlacementGroups/{proximityPlacementGroupName}
+ ///
+ /// -
+ /// Operation Id
+ /// ProximityPlacementGroups_Get
+ ///
+ ///
+ ///
+ /// The name of the proximity placement group.
+ /// includeColocationStatus=true enables fetching the colocation status of all the resources in the proximity placement group.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetProximityPlacementGroup(string proximityPlacementGroupName, string includeColocationStatus = null, CancellationToken cancellationToken = default)
+ {
+ return GetProximityPlacementGroups().Get(proximityPlacementGroupName, includeColocationStatus, cancellationToken);
+ }
+
+ /// Gets a collection of DedicatedHostGroupResources in the ResourceGroupResource.
+ /// An object representing collection of DedicatedHostGroupResources and their operations over a DedicatedHostGroupResource.
+ public virtual DedicatedHostGroupCollection GetDedicatedHostGroups()
+ {
+ return GetCachedClient(client => new DedicatedHostGroupCollection(client, Id));
+ }
+
+ ///
+ /// Retrieves information about a dedicated host group.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/hostGroups/{hostGroupName}
+ ///
+ /// -
+ /// Operation Id
+ /// DedicatedHostGroups_Get
+ ///
+ ///
+ ///
+ /// The name of the dedicated host group.
+ /// The expand expression to apply on the operation. The response shows the list of instance view of the dedicated hosts under the dedicated host group.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetDedicatedHostGroupAsync(string hostGroupName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
+ {
+ return await GetDedicatedHostGroups().GetAsync(hostGroupName, expand, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Retrieves information about a dedicated host group.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/hostGroups/{hostGroupName}
+ ///
+ /// -
+ /// Operation Id
+ /// DedicatedHostGroups_Get
+ ///
+ ///
+ ///
+ /// The name of the dedicated host group.
+ /// The expand expression to apply on the operation. The response shows the list of instance view of the dedicated hosts under the dedicated host group.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetDedicatedHostGroup(string hostGroupName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
+ {
+ return GetDedicatedHostGroups().Get(hostGroupName, expand, cancellationToken);
+ }
+
+ /// Gets a collection of SshPublicKeyResources in the ResourceGroupResource.
+ /// An object representing collection of SshPublicKeyResources and their operations over a SshPublicKeyResource.
+ public virtual SshPublicKeyCollection GetSshPublicKeys()
+ {
+ return GetCachedClient(client => new SshPublicKeyCollection(client, Id));
+ }
+
+ ///
+ /// Retrieves information about an SSH public key.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/sshPublicKeys/{sshPublicKeyName}
+ ///
+ /// -
+ /// Operation Id
+ /// SshPublicKeys_Get
+ ///
+ ///
+ ///
+ /// The name of the SSH public key.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetSshPublicKeyAsync(string sshPublicKeyName, CancellationToken cancellationToken = default)
+ {
+ return await GetSshPublicKeys().GetAsync(sshPublicKeyName, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Retrieves information about an SSH public key.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/sshPublicKeys/{sshPublicKeyName}
+ ///
+ /// -
+ /// Operation Id
+ /// SshPublicKeys_Get
+ ///
+ ///
+ ///
+ /// The name of the SSH public key.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetSshPublicKey(string sshPublicKeyName, CancellationToken cancellationToken = default)
+ {
+ return GetSshPublicKeys().Get(sshPublicKeyName, cancellationToken);
+ }
+
+ /// Gets a collection of VirtualMachineResources in the ResourceGroupResource.
+ /// An object representing collection of VirtualMachineResources and their operations over a VirtualMachineResource.
+ public virtual VirtualMachineCollection GetVirtualMachines()
+ {
+ return GetCachedClient(client => new VirtualMachineCollection(client, Id));
+ }
+
+ ///
+ /// Retrieves information about the model view or the instance view of a virtual machine.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}
+ ///
+ /// -
+ /// Operation Id
+ /// VirtualMachines_Get
+ ///
+ ///
+ ///
+ /// The name of the virtual machine.
+ /// The expand expression to apply on the operation.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetVirtualMachineAsync(string vmName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
+ {
+ return await GetVirtualMachines().GetAsync(vmName, expand, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Retrieves information about the model view or the instance view of a virtual machine.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachines/{vmName}
+ ///
+ /// -
+ /// Operation Id
+ /// VirtualMachines_Get
+ ///
+ ///
+ ///
+ /// The name of the virtual machine.
+ /// The expand expression to apply on the operation.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetVirtualMachine(string vmName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
+ {
+ return GetVirtualMachines().Get(vmName, expand, cancellationToken);
+ }
+
+ /// Gets a collection of ImageResources in the ResourceGroupResource.
+ /// An object representing collection of ImageResources and their operations over a ImageResource.
+ public virtual ImageCollection GetImages()
+ {
+ return GetCachedClient(client => new ImageCollection(client, Id));
+ }
+
+ ///
+ /// Gets an image.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}
+ ///
+ /// -
+ /// Operation Id
+ /// Images_Get
+ ///
+ ///
+ ///
+ /// The name of the image.
+ /// The expand expression to apply on the operation.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetImageAsync(string imageName, string expand = null, CancellationToken cancellationToken = default)
+ {
+ return await GetImages().GetAsync(imageName, expand, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Gets an image.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/images/{imageName}
+ ///
+ /// -
+ /// Operation Id
+ /// Images_Get
+ ///
+ ///
+ ///
+ /// The name of the image.
+ /// The expand expression to apply on the operation.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetImage(string imageName, string expand = null, CancellationToken cancellationToken = default)
+ {
+ return GetImages().Get(imageName, expand, cancellationToken);
+ }
+
+ /// Gets a collection of VirtualMachineScaleSetResources in the ResourceGroupResource.
+ /// An object representing collection of VirtualMachineScaleSetResources and their operations over a VirtualMachineScaleSetResource.
+ public virtual VirtualMachineScaleSetCollection GetVirtualMachineScaleSets()
+ {
+ return GetCachedClient(client => new VirtualMachineScaleSetCollection(client, Id));
+ }
+
+ ///
+ /// Display information about a virtual machine scale set.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}
+ ///
+ /// -
+ /// Operation Id
+ /// VirtualMachineScaleSets_Get
+ ///
+ ///
+ ///
+ /// The name of the VM scale set.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetVirtualMachineScaleSetAsync(string vmScaleSetName, CancellationToken cancellationToken = default)
+ {
+ return await GetVirtualMachineScaleSets().GetAsync(vmScaleSetName, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Display information about a virtual machine scale set.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachineScaleSets/{vmScaleSetName}
+ ///
+ /// -
+ /// Operation Id
+ /// VirtualMachineScaleSets_Get
+ ///
+ ///
+ ///
+ /// The name of the VM scale set.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetVirtualMachineScaleSet(string vmScaleSetName, CancellationToken cancellationToken = default)
+ {
+ return GetVirtualMachineScaleSets().Get(vmScaleSetName, cancellationToken);
+ }
+ }
+}
diff --git a/samples/Azure.ResourceManager.Sample/Generated/Extensions/SubscriptionResourceExtensionClient.cs b/samples/Azure.ResourceManager.Sample/Generated/Extensions/MockableSampleSubscriptionResource.cs
similarity index 84%
rename from samples/Azure.ResourceManager.Sample/Generated/Extensions/SubscriptionResourceExtensionClient.cs
rename to samples/Azure.ResourceManager.Sample/Generated/Extensions/MockableSampleSubscriptionResource.cs
index b9525fc4b28..0fb45b9a8f8 100644
--- a/samples/Azure.ResourceManager.Sample/Generated/Extensions/SubscriptionResourceExtensionClient.cs
+++ b/samples/Azure.ResourceManager.Sample/Generated/Extensions/MockableSampleSubscriptionResource.cs
@@ -13,12 +13,13 @@
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.ResourceManager;
+using Azure.ResourceManager.Sample;
using Azure.ResourceManager.Sample.Models;
-namespace Azure.ResourceManager.Sample
+namespace Azure.ResourceManager.Sample.Mocking
{
/// A class to add extension methods to SubscriptionResource.
- internal partial class SubscriptionResourceExtensionClient : ArmResource
+ public partial class MockableSampleSubscriptionResource : ArmResource
{
private ClientDiagnostics _availabilitySetClientDiagnostics;
private AvailabilitySetsRestOperations _availabilitySetRestClient;
@@ -43,15 +44,15 @@ internal partial class SubscriptionResourceExtensionClient : ArmResource
private ClientDiagnostics _logAnalyticsClientDiagnostics;
private LogAnalyticsRestOperations _logAnalyticsRestClient;
- /// Initializes a new instance of the class for mocking.
- protected SubscriptionResourceExtensionClient()
+ /// Initializes a new instance of the class for mocking.
+ protected MockableSampleSubscriptionResource()
{
}
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
/// The client parameters to use in these operations.
/// The identifier of the resource that is the target of operations.
- internal SubscriptionResourceExtensionClient(ArmClient client, ResourceIdentifier id) : base(client, id)
+ internal MockableSampleSubscriptionResource(ArmClient client, ResourceIdentifier id) : base(client, id)
{
}
@@ -87,12 +88,66 @@ private string GetApiVersionOrNull(ResourceType resourceType)
/// Gets a collection of VirtualMachineExtensionImageResources in the SubscriptionResource.
/// The name of a supported Azure region.
/// The String to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
/// An object representing collection of VirtualMachineExtensionImageResources and their operations over a VirtualMachineExtensionImageResource.
public virtual VirtualMachineExtensionImageCollection GetVirtualMachineExtensionImages(AzureLocation location, string publisherName)
{
return new VirtualMachineExtensionImageCollection(Client, Id, location, publisherName);
}
+ ///
+ /// Gets a virtual machine extension image.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmextension/types/{type}/versions/{version}
+ ///
+ /// -
+ /// Operation Id
+ /// VirtualMachineExtensionImages_Get
+ ///
+ ///
+ ///
+ /// The name of a supported Azure region.
+ /// The String to use.
+ /// The String to use.
+ /// The String to use.
+ /// The cancellation token to use.
+ /// , or is null.
+ /// , or is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetVirtualMachineExtensionImageAsync(AzureLocation location, string publisherName, string type, string version, CancellationToken cancellationToken = default)
+ {
+ return await GetVirtualMachineExtensionImages(location, publisherName).GetAsync(type, version, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Gets a virtual machine extension image.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/providers/Microsoft.Compute/locations/{location}/publishers/{publisherName}/artifacttypes/vmextension/types/{type}/versions/{version}
+ ///
+ /// -
+ /// Operation Id
+ /// VirtualMachineExtensionImages_Get
+ ///
+ ///
+ ///
+ /// The name of a supported Azure region.
+ /// The String to use.
+ /// The String to use.
+ /// The String to use.
+ /// The cancellation token to use.
+ /// , or is null.
+ /// , or is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetVirtualMachineExtensionImage(AzureLocation location, string publisherName, string type, string version, CancellationToken cancellationToken = default)
+ {
+ return GetVirtualMachineExtensionImages(location, publisherName).Get(type, version, cancellationToken);
+ }
+
///
/// Lists all availability sets in a subscription.
///
@@ -113,7 +168,7 @@ public virtual AsyncPageable GetAvailabilitySetsAsync(s
{
HttpMessage FirstPageRequest(int? pageSizeHint) => AvailabilitySetRestClient.CreateListBySubscriptionRequest(Id.SubscriptionId, expand);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => AvailabilitySetRestClient.CreateListBySubscriptionNextPageRequest(nextLink, Id.SubscriptionId, expand);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new AvailabilitySetResource(Client, AvailabilitySetData.DeserializeAvailabilitySetData(e)), AvailabilitySetClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetAvailabilitySets", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new AvailabilitySetResource(Client, AvailabilitySetData.DeserializeAvailabilitySetData(e)), AvailabilitySetClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetAvailabilitySets", "value", "nextLink", cancellationToken);
}
///
@@ -136,7 +191,7 @@ public virtual Pageable GetAvailabilitySets(string expa
{
HttpMessage FirstPageRequest(int? pageSizeHint) => AvailabilitySetRestClient.CreateListBySubscriptionRequest(Id.SubscriptionId, expand);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => AvailabilitySetRestClient.CreateListBySubscriptionNextPageRequest(nextLink, Id.SubscriptionId, expand);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new AvailabilitySetResource(Client, AvailabilitySetData.DeserializeAvailabilitySetData(e)), AvailabilitySetClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetAvailabilitySets", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new AvailabilitySetResource(Client, AvailabilitySetData.DeserializeAvailabilitySetData(e)), AvailabilitySetClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetAvailabilitySets", "value", "nextLink", cancellationToken);
}
///
@@ -158,7 +213,7 @@ public virtual AsyncPageable GetProximityPlacem
{
HttpMessage FirstPageRequest(int? pageSizeHint) => ProximityPlacementGroupRestClient.CreateListBySubscriptionRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => ProximityPlacementGroupRestClient.CreateListBySubscriptionNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new ProximityPlacementGroupResource(Client, ProximityPlacementGroupData.DeserializeProximityPlacementGroupData(e)), ProximityPlacementGroupClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetProximityPlacementGroups", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new ProximityPlacementGroupResource(Client, ProximityPlacementGroupData.DeserializeProximityPlacementGroupData(e)), ProximityPlacementGroupClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetProximityPlacementGroups", "value", "nextLink", cancellationToken);
}
///
@@ -180,7 +235,7 @@ public virtual Pageable GetProximityPlacementGr
{
HttpMessage FirstPageRequest(int? pageSizeHint) => ProximityPlacementGroupRestClient.CreateListBySubscriptionRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => ProximityPlacementGroupRestClient.CreateListBySubscriptionNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new ProximityPlacementGroupResource(Client, ProximityPlacementGroupData.DeserializeProximityPlacementGroupData(e)), ProximityPlacementGroupClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetProximityPlacementGroups", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new ProximityPlacementGroupResource(Client, ProximityPlacementGroupData.DeserializeProximityPlacementGroupData(e)), ProximityPlacementGroupClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetProximityPlacementGroups", "value", "nextLink", cancellationToken);
}
///
@@ -202,7 +257,7 @@ public virtual AsyncPageable GetDedicatedHostGroupsA
{
HttpMessage FirstPageRequest(int? pageSizeHint) => DedicatedHostGroupRestClient.CreateListBySubscriptionRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => DedicatedHostGroupRestClient.CreateListBySubscriptionNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new DedicatedHostGroupResource(Client, DedicatedHostGroupData.DeserializeDedicatedHostGroupData(e)), DedicatedHostGroupClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetDedicatedHostGroups", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new DedicatedHostGroupResource(Client, DedicatedHostGroupData.DeserializeDedicatedHostGroupData(e)), DedicatedHostGroupClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetDedicatedHostGroups", "value", "nextLink", cancellationToken);
}
///
@@ -224,7 +279,7 @@ public virtual Pageable GetDedicatedHostGroups(Cance
{
HttpMessage FirstPageRequest(int? pageSizeHint) => DedicatedHostGroupRestClient.CreateListBySubscriptionRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => DedicatedHostGroupRestClient.CreateListBySubscriptionNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new DedicatedHostGroupResource(Client, DedicatedHostGroupData.DeserializeDedicatedHostGroupData(e)), DedicatedHostGroupClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetDedicatedHostGroups", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new DedicatedHostGroupResource(Client, DedicatedHostGroupData.DeserializeDedicatedHostGroupData(e)), DedicatedHostGroupClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetDedicatedHostGroups", "value", "nextLink", cancellationToken);
}
///
@@ -246,7 +301,7 @@ public virtual AsyncPageable GetSshPublicKeysAsync(Cancell
{
HttpMessage FirstPageRequest(int? pageSizeHint) => SshPublicKeyRestClient.CreateListBySubscriptionRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => SshPublicKeyRestClient.CreateListBySubscriptionNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new SshPublicKeyResource(Client, SshPublicKeyData.DeserializeSshPublicKeyData(e)), SshPublicKeyClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetSshPublicKeys", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new SshPublicKeyResource(Client, SshPublicKeyData.DeserializeSshPublicKeyData(e)), SshPublicKeyClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetSshPublicKeys", "value", "nextLink", cancellationToken);
}
///
@@ -268,7 +323,7 @@ public virtual Pageable GetSshPublicKeys(CancellationToken
{
HttpMessage FirstPageRequest(int? pageSizeHint) => SshPublicKeyRestClient.CreateListBySubscriptionRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => SshPublicKeyRestClient.CreateListBySubscriptionNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new SshPublicKeyResource(Client, SshPublicKeyData.DeserializeSshPublicKeyData(e)), SshPublicKeyClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetSshPublicKeys", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new SshPublicKeyResource(Client, SshPublicKeyData.DeserializeSshPublicKeyData(e)), SshPublicKeyClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetSshPublicKeys", "value", "nextLink", cancellationToken);
}
///
@@ -290,9 +345,16 @@ public virtual Pageable GetSshPublicKeys(CancellationToken
/// A valid image SKU.
/// A valid image SKU version.
/// The cancellation token to use.
+ /// , , or is an empty string, and was expected to be non-empty.
+ /// , , or is null.
public virtual async Task> GetVirtualMachineImageAsync(AzureLocation location, string publisherName, string offer, string skus, string version, CancellationToken cancellationToken = default)
{
- using var scope = VirtualMachineImagesClientDiagnostics.CreateScope("SubscriptionResourceExtensionClient.GetVirtualMachineImage");
+ Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
+ Argument.AssertNotNullOrEmpty(offer, nameof(offer));
+ Argument.AssertNotNullOrEmpty(skus, nameof(skus));
+ Argument.AssertNotNullOrEmpty(version, nameof(version));
+
+ using var scope = VirtualMachineImagesClientDiagnostics.CreateScope("MockableSampleSubscriptionResource.GetVirtualMachineImage");
scope.Start();
try
{
@@ -325,9 +387,16 @@ public virtual async Task> GetVirtualMachineImageA
/// A valid image SKU.
/// A valid image SKU version.
/// The cancellation token to use.
+ /// , , or is an empty string, and was expected to be non-empty.
+ /// , , or is null.
public virtual Response GetVirtualMachineImage(AzureLocation location, string publisherName, string offer, string skus, string version, CancellationToken cancellationToken = default)
{
- using var scope = VirtualMachineImagesClientDiagnostics.CreateScope("SubscriptionResourceExtensionClient.GetVirtualMachineImage");
+ Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
+ Argument.AssertNotNullOrEmpty(offer, nameof(offer));
+ Argument.AssertNotNullOrEmpty(skus, nameof(skus));
+ Argument.AssertNotNullOrEmpty(version, nameof(version));
+
+ using var scope = VirtualMachineImagesClientDiagnostics.CreateScope("MockableSampleSubscriptionResource.GetVirtualMachineImage");
scope.Start();
try
{
@@ -356,11 +425,14 @@ public virtual Response GetVirtualMachineImage(AzureLocatio
///
/// A property bag which contains all the parameters of this method except the LRO qualifier and request context parameter.
/// The cancellation token to use.
+ /// is null.
/// An async collection of that may take multiple service requests to iterate over.
public virtual AsyncPageable GetVirtualMachineImagesAsync(SubscriptionResourceGetVirtualMachineImagesOptions options, CancellationToken cancellationToken = default)
{
+ Argument.AssertNotNull(options, nameof(options));
+
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineImagesRestClient.CreateListRequest(Id.SubscriptionId, options.Location, options.PublisherName, options.Offer, options.Skus, options.Expand, options.Top, options.Orderby);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachineImages", "", null, cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachineImages", "", null, cancellationToken);
}
///
@@ -378,11 +450,14 @@ public virtual AsyncPageable GetVirtualMachineImage
///
/// A property bag which contains all the parameters of this method except the LRO qualifier and request context parameter.
/// The cancellation token to use.
+ /// is null.
/// A collection of that may take multiple service requests to iterate over.
public virtual Pageable GetVirtualMachineImages(SubscriptionResourceGetVirtualMachineImagesOptions options, CancellationToken cancellationToken = default)
{
+ Argument.AssertNotNull(options, nameof(options));
+
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineImagesRestClient.CreateListRequest(Id.SubscriptionId, options.Location, options.PublisherName, options.Offer, options.Skus, options.Expand, options.Top, options.Orderby);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachineImages", "", null, cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachineImages", "", null, cancellationToken);
}
///
@@ -401,11 +476,15 @@ public virtual Pageable GetVirtualMachineImages(Sub
/// The name of a supported Azure region.
/// A valid image publisher.
/// The cancellation token to use.
+ /// is an empty string, and was expected to be non-empty.
+ /// is null.
/// An async collection of that may take multiple service requests to iterate over.
public virtual AsyncPageable GetOffersVirtualMachineImagesAsync(AzureLocation location, string publisherName, CancellationToken cancellationToken = default)
{
+ Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
+
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineImagesRestClient.CreateListOffersRequest(Id.SubscriptionId, location, publisherName);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetOffersVirtualMachineImages", "", null, cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetOffersVirtualMachineImages", "", null, cancellationToken);
}
///
@@ -424,11 +503,15 @@ public virtual AsyncPageable GetOffersVirtualMachin
/// The name of a supported Azure region.
/// A valid image publisher.
/// The cancellation token to use.
+ /// is an empty string, and was expected to be non-empty.
+ /// is null.
/// A collection of that may take multiple service requests to iterate over.
public virtual Pageable GetOffersVirtualMachineImages(AzureLocation location, string publisherName, CancellationToken cancellationToken = default)
{
+ Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
+
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineImagesRestClient.CreateListOffersRequest(Id.SubscriptionId, location, publisherName);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetOffersVirtualMachineImages", "", null, cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetOffersVirtualMachineImages", "", null, cancellationToken);
}
///
@@ -450,7 +533,7 @@ public virtual Pageable GetOffersVirtualMachineImag
public virtual AsyncPageable GetPublishersVirtualMachineImagesAsync(AzureLocation location, CancellationToken cancellationToken = default)
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineImagesRestClient.CreateListPublishersRequest(Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetPublishersVirtualMachineImages", "", null, cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetPublishersVirtualMachineImages", "", null, cancellationToken);
}
///
@@ -472,7 +555,7 @@ public virtual AsyncPageable GetPublishersVirtualMa
public virtual Pageable GetPublishersVirtualMachineImages(AzureLocation location, CancellationToken cancellationToken = default)
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineImagesRestClient.CreateListPublishersRequest(Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetPublishersVirtualMachineImages", "", null, cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetPublishersVirtualMachineImages", "", null, cancellationToken);
}
///
@@ -492,11 +575,16 @@ public virtual Pageable GetPublishersVirtualMachine
/// A valid image publisher.
/// A valid image publisher offer.
/// The cancellation token to use.
+ /// or is an empty string, and was expected to be non-empty.
+ /// or is null.
/// An async collection of that may take multiple service requests to iterate over.
public virtual AsyncPageable GetSkusVirtualMachineImagesAsync(AzureLocation location, string publisherName, string offer, CancellationToken cancellationToken = default)
{
+ Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
+ Argument.AssertNotNullOrEmpty(offer, nameof(offer));
+
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineImagesRestClient.CreateListSkusRequest(Id.SubscriptionId, location, publisherName, offer);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetSkusVirtualMachineImages", "", null, cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetSkusVirtualMachineImages", "", null, cancellationToken);
}
///
@@ -516,11 +604,16 @@ public virtual AsyncPageable GetSkusVirtualMachineI
/// A valid image publisher.
/// A valid image publisher offer.
/// The cancellation token to use.
+ /// or is an empty string, and was expected to be non-empty.
+ /// or is null.
/// A collection of that may take multiple service requests to iterate over.
public virtual Pageable GetSkusVirtualMachineImages(AzureLocation location, string publisherName, string offer, CancellationToken cancellationToken = default)
{
+ Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
+ Argument.AssertNotNullOrEmpty(offer, nameof(offer));
+
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineImagesRestClient.CreateListSkusRequest(Id.SubscriptionId, location, publisherName, offer);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetSkusVirtualMachineImages", "", null, cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineImageResource.DeserializeVirtualMachineImageResource, VirtualMachineImagesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetSkusVirtualMachineImages", "", null, cancellationToken);
}
///
@@ -543,7 +636,7 @@ public virtual AsyncPageable GetUsagesAsync(AzureLocation location,
{
HttpMessage FirstPageRequest(int? pageSizeHint) => UsageRestClient.CreateListRequest(Id.SubscriptionId, location);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => UsageRestClient.CreateListNextPageRequest(nextLink, Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, SampleUsage.DeserializeSampleUsage, UsageClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetUsages", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, SampleUsage.DeserializeSampleUsage, UsageClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetUsages", "value", "nextLink", cancellationToken);
}
///
@@ -566,7 +659,7 @@ public virtual Pageable GetUsages(AzureLocation location, Cancellat
{
HttpMessage FirstPageRequest(int? pageSizeHint) => UsageRestClient.CreateListRequest(Id.SubscriptionId, location);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => UsageRestClient.CreateListNextPageRequest(nextLink, Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, SampleUsage.DeserializeSampleUsage, UsageClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetUsages", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, SampleUsage.DeserializeSampleUsage, UsageClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetUsages", "value", "nextLink", cancellationToken);
}
///
@@ -589,7 +682,7 @@ public virtual AsyncPageable GetVirtualMachinesByLocatio
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineRestClient.CreateListByLocationRequest(Id.SubscriptionId, location);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => VirtualMachineRestClient.CreateListByLocationNextPageRequest(nextLink, Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineResource(Client, VirtualMachineData.DeserializeVirtualMachineData(e)), VirtualMachineClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachinesByLocation", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineResource(Client, VirtualMachineData.DeserializeVirtualMachineData(e)), VirtualMachineClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachinesByLocation", "value", "nextLink", cancellationToken);
}
///
@@ -612,7 +705,7 @@ public virtual Pageable GetVirtualMachinesByLocation(Azu
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineRestClient.CreateListByLocationRequest(Id.SubscriptionId, location);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => VirtualMachineRestClient.CreateListByLocationNextPageRequest(nextLink, Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineResource(Client, VirtualMachineData.DeserializeVirtualMachineData(e)), VirtualMachineClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachinesByLocation", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineResource(Client, VirtualMachineData.DeserializeVirtualMachineData(e)), VirtualMachineClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachinesByLocation", "value", "nextLink", cancellationToken);
}
///
@@ -635,7 +728,7 @@ public virtual AsyncPageable GetVirtualMachinesAsync(str
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineRestClient.CreateListAllRequest(Id.SubscriptionId, statusOnly);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => VirtualMachineRestClient.CreateListAllNextPageRequest(nextLink, Id.SubscriptionId, statusOnly);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineResource(Client, VirtualMachineData.DeserializeVirtualMachineData(e)), VirtualMachineClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachines", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineResource(Client, VirtualMachineData.DeserializeVirtualMachineData(e)), VirtualMachineClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachines", "value", "nextLink", cancellationToken);
}
///
@@ -658,7 +751,7 @@ public virtual Pageable GetVirtualMachines(string status
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineRestClient.CreateListAllRequest(Id.SubscriptionId, statusOnly);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => VirtualMachineRestClient.CreateListAllNextPageRequest(nextLink, Id.SubscriptionId, statusOnly);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineResource(Client, VirtualMachineData.DeserializeVirtualMachineData(e)), VirtualMachineClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachines", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineResource(Client, VirtualMachineData.DeserializeVirtualMachineData(e)), VirtualMachineClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachines", "value", "nextLink", cancellationToken);
}
///
@@ -680,7 +773,7 @@ public virtual Pageable GetVirtualMachines(string status
public virtual AsyncPageable GetVirtualMachineSizesAsync(AzureLocation location, CancellationToken cancellationToken = default)
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineSizesRestClient.CreateListRequest(Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineSize.DeserializeVirtualMachineSize, VirtualMachineSizesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachineSizes", "value", null, cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, VirtualMachineSize.DeserializeVirtualMachineSize, VirtualMachineSizesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachineSizes", "value", null, cancellationToken);
}
///
@@ -702,7 +795,7 @@ public virtual AsyncPageable GetVirtualMachineSizesAsync(Azu
public virtual Pageable GetVirtualMachineSizes(AzureLocation location, CancellationToken cancellationToken = default)
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineSizesRestClient.CreateListRequest(Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineSize.DeserializeVirtualMachineSize, VirtualMachineSizesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachineSizes", "value", null, cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, VirtualMachineSize.DeserializeVirtualMachineSize, VirtualMachineSizesClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachineSizes", "value", null, cancellationToken);
}
///
@@ -724,7 +817,7 @@ public virtual AsyncPageable GetImagesAsync(CancellationToken can
{
HttpMessage FirstPageRequest(int? pageSizeHint) => ImageRestClient.CreateListRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => ImageRestClient.CreateListNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new ImageResource(Client, ImageData.DeserializeImageData(e)), ImageClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetImages", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new ImageResource(Client, ImageData.DeserializeImageData(e)), ImageClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetImages", "value", "nextLink", cancellationToken);
}
///
@@ -746,7 +839,7 @@ public virtual Pageable GetImages(CancellationToken cancellationT
{
HttpMessage FirstPageRequest(int? pageSizeHint) => ImageRestClient.CreateListRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => ImageRestClient.CreateListNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new ImageResource(Client, ImageData.DeserializeImageData(e)), ImageClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetImages", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new ImageResource(Client, ImageData.DeserializeImageData(e)), ImageClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetImages", "value", "nextLink", cancellationToken);
}
///
@@ -768,7 +861,7 @@ public virtual AsyncPageable GetVirtualMachineSc
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineScaleSetRestClient.CreateListAllRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => VirtualMachineScaleSetRestClient.CreateListAllNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineScaleSetResource(Client, VirtualMachineScaleSetData.DeserializeVirtualMachineScaleSetData(e)), VirtualMachineScaleSetClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachineScaleSets", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineScaleSetResource(Client, VirtualMachineScaleSetData.DeserializeVirtualMachineScaleSetData(e)), VirtualMachineScaleSetClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachineScaleSets", "value", "nextLink", cancellationToken);
}
///
@@ -790,7 +883,7 @@ public virtual Pageable GetVirtualMachineScaleSe
{
HttpMessage FirstPageRequest(int? pageSizeHint) => VirtualMachineScaleSetRestClient.CreateListAllRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => VirtualMachineScaleSetRestClient.CreateListAllNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineScaleSetResource(Client, VirtualMachineScaleSetData.DeserializeVirtualMachineScaleSetData(e)), VirtualMachineScaleSetClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetVirtualMachineScaleSets", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new VirtualMachineScaleSetResource(Client, VirtualMachineScaleSetData.DeserializeVirtualMachineScaleSetData(e)), VirtualMachineScaleSetClientDiagnostics, Pipeline, "MockableSampleSubscriptionResource.GetVirtualMachineScaleSets", "value", "nextLink", cancellationToken);
}
///
@@ -810,9 +903,12 @@ public virtual Pageable GetVirtualMachineScaleSe
/// The location upon which virtual-machine-sizes is queried.
/// Parameters supplied to the LogAnalytics getRequestRateByInterval Api.
/// The cancellation token to use.
+ /// is null.
public virtual async Task> ExportRequestRateByIntervalLogAnalyticAsync(WaitUntil waitUntil, AzureLocation location, RequestRateByIntervalContent content, CancellationToken cancellationToken = default)
{
- using var scope = LogAnalyticsClientDiagnostics.CreateScope("SubscriptionResourceExtensionClient.ExportRequestRateByIntervalLogAnalytic");
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = LogAnalyticsClientDiagnostics.CreateScope("MockableSampleSubscriptionResource.ExportRequestRateByIntervalLogAnalytic");
scope.Start();
try
{
@@ -846,9 +942,12 @@ public virtual async Task> ExportRequestRateByInterva
/// The location upon which virtual-machine-sizes is queried.
/// Parameters supplied to the LogAnalytics getRequestRateByInterval Api.
/// The cancellation token to use.
+ /// is null.
public virtual ArmOperation ExportRequestRateByIntervalLogAnalytic(WaitUntil waitUntil, AzureLocation location, RequestRateByIntervalContent content, CancellationToken cancellationToken = default)
{
- using var scope = LogAnalyticsClientDiagnostics.CreateScope("SubscriptionResourceExtensionClient.ExportRequestRateByIntervalLogAnalytic");
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = LogAnalyticsClientDiagnostics.CreateScope("MockableSampleSubscriptionResource.ExportRequestRateByIntervalLogAnalytic");
scope.Start();
try
{
@@ -882,9 +981,12 @@ public virtual ArmOperation ExportRequestRateByIntervalLogAnalytic
/// The location upon which virtual-machine-sizes is queried.
/// Parameters supplied to the LogAnalytics getThrottledRequests Api.
/// The cancellation token to use.
+ /// is null.
public virtual async Task> ExportThrottledRequestsLogAnalyticAsync(WaitUntil waitUntil, AzureLocation location, ThrottledRequestsContent content, CancellationToken cancellationToken = default)
{
- using var scope = LogAnalyticsClientDiagnostics.CreateScope("SubscriptionResourceExtensionClient.ExportThrottledRequestsLogAnalytic");
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = LogAnalyticsClientDiagnostics.CreateScope("MockableSampleSubscriptionResource.ExportThrottledRequestsLogAnalytic");
scope.Start();
try
{
@@ -918,9 +1020,12 @@ public virtual async Task> ExportThrottledRequestsLog
/// The location upon which virtual-machine-sizes is queried.
/// Parameters supplied to the LogAnalytics getThrottledRequests Api.
/// The cancellation token to use.
+ /// is null.
public virtual ArmOperation ExportThrottledRequestsLogAnalytic(WaitUntil waitUntil, AzureLocation location, ThrottledRequestsContent content, CancellationToken cancellationToken = default)
{
- using var scope = LogAnalyticsClientDiagnostics.CreateScope("SubscriptionResourceExtensionClient.ExportThrottledRequestsLogAnalytic");
+ Argument.AssertNotNull(content, nameof(content));
+
+ using var scope = LogAnalyticsClientDiagnostics.CreateScope("MockableSampleSubscriptionResource.ExportThrottledRequestsLogAnalytic");
scope.Start();
try
{
diff --git a/samples/Azure.ResourceManager.Sample/Generated/Extensions/ResourceGroupResourceExtensionClient.cs b/samples/Azure.ResourceManager.Sample/Generated/Extensions/ResourceGroupResourceExtensionClient.cs
deleted file mode 100644
index dbe9700070d..00000000000
--- a/samples/Azure.ResourceManager.Sample/Generated/Extensions/ResourceGroupResourceExtensionClient.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-//
-
-#nullable disable
-
-using Azure.Core;
-using Azure.ResourceManager;
-
-namespace Azure.ResourceManager.Sample
-{
- /// A class to add extension methods to ResourceGroupResource.
- internal partial class ResourceGroupResourceExtensionClient : ArmResource
- {
- /// Initializes a new instance of the class for mocking.
- protected ResourceGroupResourceExtensionClient()
- {
- }
-
- /// Initializes a new instance of the class.
- /// The client parameters to use in these operations.
- /// The identifier of the resource that is the target of operations.
- internal ResourceGroupResourceExtensionClient(ArmClient client, ResourceIdentifier id) : base(client, id)
- {
- }
-
- private string GetApiVersionOrNull(ResourceType resourceType)
- {
- TryGetApiVersion(resourceType, out string apiVersion);
- return apiVersion;
- }
-
- /// Gets a collection of AvailabilitySetResources in the ResourceGroupResource.
- /// An object representing collection of AvailabilitySetResources and their operations over a AvailabilitySetResource.
- public virtual AvailabilitySetCollection GetAvailabilitySets()
- {
- return GetCachedClient(Client => new AvailabilitySetCollection(Client, Id));
- }
-
- /// Gets a collection of ProximityPlacementGroupResources in the ResourceGroupResource.
- /// An object representing collection of ProximityPlacementGroupResources and their operations over a ProximityPlacementGroupResource.
- public virtual ProximityPlacementGroupCollection GetProximityPlacementGroups()
- {
- return GetCachedClient(Client => new ProximityPlacementGroupCollection(Client, Id));
- }
-
- /// Gets a collection of DedicatedHostGroupResources in the ResourceGroupResource.
- /// An object representing collection of DedicatedHostGroupResources and their operations over a DedicatedHostGroupResource.
- public virtual DedicatedHostGroupCollection GetDedicatedHostGroups()
- {
- return GetCachedClient(Client => new DedicatedHostGroupCollection(Client, Id));
- }
-
- /// Gets a collection of SshPublicKeyResources in the ResourceGroupResource.
- /// An object representing collection of SshPublicKeyResources and their operations over a SshPublicKeyResource.
- public virtual SshPublicKeyCollection GetSshPublicKeys()
- {
- return GetCachedClient(Client => new SshPublicKeyCollection(Client, Id));
- }
-
- /// Gets a collection of VirtualMachineResources in the ResourceGroupResource.
- /// An object representing collection of VirtualMachineResources and their operations over a VirtualMachineResource.
- public virtual VirtualMachineCollection GetVirtualMachines()
- {
- return GetCachedClient(Client => new VirtualMachineCollection(Client, Id));
- }
-
- /// Gets a collection of ImageResources in the ResourceGroupResource.
- /// An object representing collection of ImageResources and their operations over a ImageResource.
- public virtual ImageCollection GetImages()
- {
- return GetCachedClient(Client => new ImageCollection(Client, Id));
- }
-
- /// Gets a collection of VirtualMachineScaleSetResources in the ResourceGroupResource.
- /// An object representing collection of VirtualMachineScaleSetResources and their operations over a VirtualMachineScaleSetResource.
- public virtual VirtualMachineScaleSetCollection GetVirtualMachineScaleSets()
- {
- return GetCachedClient(Client => new VirtualMachineScaleSetCollection(Client, Id));
- }
- }
-}
diff --git a/samples/Azure.ResourceManager.Sample/Generated/Extensions/SampleExtensions.cs b/samples/Azure.ResourceManager.Sample/Generated/Extensions/SampleExtensions.cs
index a584b18d777..8b52543819a 100644
--- a/samples/Azure.ResourceManager.Sample/Generated/Extensions/SampleExtensions.cs
+++ b/samples/Azure.ResourceManager.Sample/Generated/Extensions/SampleExtensions.cs
@@ -12,6 +12,7 @@
using Azure.Core;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
+using Azure.ResourceManager.Sample.Mocking;
using Azure.ResourceManager.Sample.Models;
namespace Azure.ResourceManager.Sample
@@ -19,309 +20,257 @@ namespace Azure.ResourceManager.Sample
/// A class to add extension methods to Azure.ResourceManager.Sample.
public static partial class SampleExtensions
{
- private static ResourceGroupResourceExtensionClient GetResourceGroupResourceExtensionClient(ArmResource resource)
+ private static MockableSampleArmClient GetMockableSampleArmClient(ArmClient client)
{
- return resource.GetCachedClient(client =>
- {
- return new ResourceGroupResourceExtensionClient(client, resource.Id);
- });
+ return client.GetCachedClient(client0 => new MockableSampleArmClient(client0));
}
- private static ResourceGroupResourceExtensionClient GetResourceGroupResourceExtensionClient(ArmClient client, ResourceIdentifier scope)
+ private static MockableSampleResourceGroupResource GetMockableSampleResourceGroupResource(ArmResource resource)
{
- return client.GetResourceClient(() =>
- {
- return new ResourceGroupResourceExtensionClient(client, scope);
- });
+ return resource.GetCachedClient(client => new MockableSampleResourceGroupResource(client, resource.Id));
}
- private static SubscriptionResourceExtensionClient GetSubscriptionResourceExtensionClient(ArmResource resource)
+ private static MockableSampleSubscriptionResource GetMockableSampleSubscriptionResource(ArmResource resource)
{
- return resource.GetCachedClient(client =>
- {
- return new SubscriptionResourceExtensionClient(client, resource.Id);
- });
+ return resource.GetCachedClient(client => new MockableSampleSubscriptionResource(client, resource.Id));
}
- private static SubscriptionResourceExtensionClient GetSubscriptionResourceExtensionClient(ArmClient client, ResourceIdentifier scope)
- {
- return client.GetResourceClient(() =>
- {
- return new SubscriptionResourceExtensionClient(client, scope);
- });
- }
- #region AvailabilitySetResource
///
/// Gets an object representing an along with the instance operations that can be performed on it but with no data.
/// You can use to create an from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static AvailabilitySetResource GetAvailabilitySetResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- AvailabilitySetResource.ValidateResourceId(id);
- return new AvailabilitySetResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetAvailabilitySetResource(id);
}
- #endregion
- #region ProximityPlacementGroupResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static ProximityPlacementGroupResource GetProximityPlacementGroupResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- ProximityPlacementGroupResource.ValidateResourceId(id);
- return new ProximityPlacementGroupResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetProximityPlacementGroupResource(id);
}
- #endregion
- #region DedicatedHostGroupResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static DedicatedHostGroupResource GetDedicatedHostGroupResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- DedicatedHostGroupResource.ValidateResourceId(id);
- return new DedicatedHostGroupResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetDedicatedHostGroupResource(id);
}
- #endregion
- #region DedicatedHostResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static DedicatedHostResource GetDedicatedHostResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- DedicatedHostResource.ValidateResourceId(id);
- return new DedicatedHostResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetDedicatedHostResource(id);
}
- #endregion
- #region SshPublicKeyResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static SshPublicKeyResource GetSshPublicKeyResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- SshPublicKeyResource.ValidateResourceId(id);
- return new SshPublicKeyResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetSshPublicKeyResource(id);
}
- #endregion
- #region VirtualMachineExtensionImageResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static VirtualMachineExtensionImageResource GetVirtualMachineExtensionImageResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- VirtualMachineExtensionImageResource.ValidateResourceId(id);
- return new VirtualMachineExtensionImageResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetVirtualMachineExtensionImageResource(id);
}
- #endregion
- #region VirtualMachineExtensionResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static VirtualMachineExtensionResource GetVirtualMachineExtensionResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- VirtualMachineExtensionResource.ValidateResourceId(id);
- return new VirtualMachineExtensionResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetVirtualMachineExtensionResource(id);
}
- #endregion
- #region VirtualMachineScaleSetVirtualMachineExtensionResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static VirtualMachineScaleSetVirtualMachineExtensionResource GetVirtualMachineScaleSetVirtualMachineExtensionResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- VirtualMachineScaleSetVirtualMachineExtensionResource.ValidateResourceId(id);
- return new VirtualMachineScaleSetVirtualMachineExtensionResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetVirtualMachineScaleSetVirtualMachineExtensionResource(id);
}
- #endregion
- #region VirtualMachineResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static VirtualMachineResource GetVirtualMachineResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- VirtualMachineResource.ValidateResourceId(id);
- return new VirtualMachineResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetVirtualMachineResource(id);
}
- #endregion
- #region ImageResource
///
/// Gets an object representing an along with the instance operations that can be performed on it but with no data.
/// You can use to create an from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static ImageResource GetImageResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- ImageResource.ValidateResourceId(id);
- return new ImageResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetImageResource(id);
}
- #endregion
- #region VirtualMachineScaleSetResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static VirtualMachineScaleSetResource GetVirtualMachineScaleSetResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- VirtualMachineScaleSetResource.ValidateResourceId(id);
- return new VirtualMachineScaleSetResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetVirtualMachineScaleSetResource(id);
}
- #endregion
- #region VirtualMachineScaleSetExtensionResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static VirtualMachineScaleSetExtensionResource GetVirtualMachineScaleSetExtensionResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- VirtualMachineScaleSetExtensionResource.ValidateResourceId(id);
- return new VirtualMachineScaleSetExtensionResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetVirtualMachineScaleSetExtensionResource(id);
}
- #endregion
- #region VirtualMachineScaleSetRollingUpgradeResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static VirtualMachineScaleSetRollingUpgradeResource GetVirtualMachineScaleSetRollingUpgradeResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- VirtualMachineScaleSetRollingUpgradeResource.ValidateResourceId(id);
- return new VirtualMachineScaleSetRollingUpgradeResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetVirtualMachineScaleSetRollingUpgradeResource(id);
}
- #endregion
- #region VirtualMachineScaleSetVmResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static VirtualMachineScaleSetVmResource GetVirtualMachineScaleSetVmResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- VirtualMachineScaleSetVmResource.ValidateResourceId(id);
- return new VirtualMachineScaleSetVmResource(client, id);
- }
- );
+ return GetMockableSampleArmClient(client).GetVirtualMachineScaleSetVmResource(id);
}
- #endregion
- /// Gets a collection of AvailabilitySetResources in the ResourceGroupResource.
+ ///
+ /// Gets a collection of AvailabilitySetResources in the ResourceGroupResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// An object representing collection of AvailabilitySetResources and their operations over a AvailabilitySetResource.
public static AvailabilitySetCollection GetAvailabilitySets(this ResourceGroupResource resourceGroupResource)
{
- return GetResourceGroupResourceExtensionClient(resourceGroupResource).GetAvailabilitySets();
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetAvailabilitySets();
}
///
@@ -336,16 +285,20 @@ public static AvailabilitySetCollection GetAvailabilitySets(this ResourceGroupRe
/// AvailabilitySets_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the availability set.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetAvailabilitySetAsync(this ResourceGroupResource resourceGroupResource, string availabilitySetName, CancellationToken cancellationToken = default)
{
- return await resourceGroupResource.GetAvailabilitySets().GetAsync(availabilitySetName, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleResourceGroupResource(resourceGroupResource).GetAvailabilitySetAsync(availabilitySetName, cancellationToken).ConfigureAwait(false);
}
///
@@ -360,24 +313,34 @@ public static async Task> GetAvailabilitySetAs
/// AvailabilitySets_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the availability set.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetAvailabilitySet(this ResourceGroupResource resourceGroupResource, string availabilitySetName, CancellationToken cancellationToken = default)
{
- return resourceGroupResource.GetAvailabilitySets().Get(availabilitySetName, cancellationToken);
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetAvailabilitySet(availabilitySetName, cancellationToken);
}
- /// Gets a collection of ProximityPlacementGroupResources in the ResourceGroupResource.
+ ///
+ /// Gets a collection of ProximityPlacementGroupResources in the ResourceGroupResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// An object representing collection of ProximityPlacementGroupResources and their operations over a ProximityPlacementGroupResource.
public static ProximityPlacementGroupCollection GetProximityPlacementGroups(this ResourceGroupResource resourceGroupResource)
{
- return GetResourceGroupResourceExtensionClient(resourceGroupResource).GetProximityPlacementGroups();
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetProximityPlacementGroups();
}
///
@@ -392,17 +355,21 @@ public static ProximityPlacementGroupCollection GetProximityPlacementGroups(this
/// ProximityPlacementGroups_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the proximity placement group.
/// includeColocationStatus=true enables fetching the colocation status of all the resources in the proximity placement group.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetProximityPlacementGroupAsync(this ResourceGroupResource resourceGroupResource, string proximityPlacementGroupName, string includeColocationStatus = null, CancellationToken cancellationToken = default)
{
- return await resourceGroupResource.GetProximityPlacementGroups().GetAsync(proximityPlacementGroupName, includeColocationStatus, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleResourceGroupResource(resourceGroupResource).GetProximityPlacementGroupAsync(proximityPlacementGroupName, includeColocationStatus, cancellationToken).ConfigureAwait(false);
}
///
@@ -417,25 +384,35 @@ public static async Task> GetProximity
/// ProximityPlacementGroups_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the proximity placement group.
/// includeColocationStatus=true enables fetching the colocation status of all the resources in the proximity placement group.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetProximityPlacementGroup(this ResourceGroupResource resourceGroupResource, string proximityPlacementGroupName, string includeColocationStatus = null, CancellationToken cancellationToken = default)
{
- return resourceGroupResource.GetProximityPlacementGroups().Get(proximityPlacementGroupName, includeColocationStatus, cancellationToken);
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetProximityPlacementGroup(proximityPlacementGroupName, includeColocationStatus, cancellationToken);
}
- /// Gets a collection of DedicatedHostGroupResources in the ResourceGroupResource.
+ ///
+ /// Gets a collection of DedicatedHostGroupResources in the ResourceGroupResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// An object representing collection of DedicatedHostGroupResources and their operations over a DedicatedHostGroupResource.
public static DedicatedHostGroupCollection GetDedicatedHostGroups(this ResourceGroupResource resourceGroupResource)
{
- return GetResourceGroupResourceExtensionClient(resourceGroupResource).GetDedicatedHostGroups();
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetDedicatedHostGroups();
}
///
@@ -450,17 +427,21 @@ public static DedicatedHostGroupCollection GetDedicatedHostGroups(this ResourceG
/// DedicatedHostGroups_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the dedicated host group.
/// The expand expression to apply on the operation. The response shows the list of instance view of the dedicated hosts under the dedicated host group.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetDedicatedHostGroupAsync(this ResourceGroupResource resourceGroupResource, string hostGroupName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
{
- return await resourceGroupResource.GetDedicatedHostGroups().GetAsync(hostGroupName, expand, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleResourceGroupResource(resourceGroupResource).GetDedicatedHostGroupAsync(hostGroupName, expand, cancellationToken).ConfigureAwait(false);
}
///
@@ -475,25 +456,35 @@ public static async Task> GetDedicatedHostG
/// DedicatedHostGroups_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the dedicated host group.
/// The expand expression to apply on the operation. The response shows the list of instance view of the dedicated hosts under the dedicated host group.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetDedicatedHostGroup(this ResourceGroupResource resourceGroupResource, string hostGroupName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
{
- return resourceGroupResource.GetDedicatedHostGroups().Get(hostGroupName, expand, cancellationToken);
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetDedicatedHostGroup(hostGroupName, expand, cancellationToken);
}
- /// Gets a collection of SshPublicKeyResources in the ResourceGroupResource.
+ ///
+ /// Gets a collection of SshPublicKeyResources in the ResourceGroupResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// An object representing collection of SshPublicKeyResources and their operations over a SshPublicKeyResource.
public static SshPublicKeyCollection GetSshPublicKeys(this ResourceGroupResource resourceGroupResource)
{
- return GetResourceGroupResourceExtensionClient(resourceGroupResource).GetSshPublicKeys();
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetSshPublicKeys();
}
///
@@ -508,16 +499,20 @@ public static SshPublicKeyCollection GetSshPublicKeys(this ResourceGroupResource
/// SshPublicKeys_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the SSH public key.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetSshPublicKeyAsync(this ResourceGroupResource resourceGroupResource, string sshPublicKeyName, CancellationToken cancellationToken = default)
{
- return await resourceGroupResource.GetSshPublicKeys().GetAsync(sshPublicKeyName, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleResourceGroupResource(resourceGroupResource).GetSshPublicKeyAsync(sshPublicKeyName, cancellationToken).ConfigureAwait(false);
}
///
@@ -532,24 +527,34 @@ public static async Task> GetSshPublicKeyAsync(th
/// SshPublicKeys_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the SSH public key.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetSshPublicKey(this ResourceGroupResource resourceGroupResource, string sshPublicKeyName, CancellationToken cancellationToken = default)
{
- return resourceGroupResource.GetSshPublicKeys().Get(sshPublicKeyName, cancellationToken);
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetSshPublicKey(sshPublicKeyName, cancellationToken);
}
- /// Gets a collection of VirtualMachineResources in the ResourceGroupResource.
+ ///
+ /// Gets a collection of VirtualMachineResources in the ResourceGroupResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// An object representing collection of VirtualMachineResources and their operations over a VirtualMachineResource.
public static VirtualMachineCollection GetVirtualMachines(this ResourceGroupResource resourceGroupResource)
{
- return GetResourceGroupResourceExtensionClient(resourceGroupResource).GetVirtualMachines();
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetVirtualMachines();
}
///
@@ -564,17 +569,21 @@ public static VirtualMachineCollection GetVirtualMachines(this ResourceGroupReso
/// VirtualMachines_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the virtual machine.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetVirtualMachineAsync(this ResourceGroupResource resourceGroupResource, string vmName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
{
- return await resourceGroupResource.GetVirtualMachines().GetAsync(vmName, expand, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleResourceGroupResource(resourceGroupResource).GetVirtualMachineAsync(vmName, expand, cancellationToken).ConfigureAwait(false);
}
///
@@ -589,25 +598,35 @@ public static async Task> GetVirtualMachineAsyn
/// VirtualMachines_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the virtual machine.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetVirtualMachine(this ResourceGroupResource resourceGroupResource, string vmName, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
{
- return resourceGroupResource.GetVirtualMachines().Get(vmName, expand, cancellationToken);
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetVirtualMachine(vmName, expand, cancellationToken);
}
- /// Gets a collection of ImageResources in the ResourceGroupResource.
+ ///
+ /// Gets a collection of ImageResources in the ResourceGroupResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// An object representing collection of ImageResources and their operations over a ImageResource.
public static ImageCollection GetImages(this ResourceGroupResource resourceGroupResource)
{
- return GetResourceGroupResourceExtensionClient(resourceGroupResource).GetImages();
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetImages();
}
///
@@ -622,17 +641,21 @@ public static ImageCollection GetImages(this ResourceGroupResource resourceGroup
/// Images_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the image.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetImageAsync(this ResourceGroupResource resourceGroupResource, string imageName, string expand = null, CancellationToken cancellationToken = default)
{
- return await resourceGroupResource.GetImages().GetAsync(imageName, expand, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleResourceGroupResource(resourceGroupResource).GetImageAsync(imageName, expand, cancellationToken).ConfigureAwait(false);
}
///
@@ -647,25 +670,35 @@ public static async Task> GetImageAsync(this ResourceGro
/// Images_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the image.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetImage(this ResourceGroupResource resourceGroupResource, string imageName, string expand = null, CancellationToken cancellationToken = default)
{
- return resourceGroupResource.GetImages().Get(imageName, expand, cancellationToken);
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetImage(imageName, expand, cancellationToken);
}
- /// Gets a collection of VirtualMachineScaleSetResources in the ResourceGroupResource.
+ ///
+ /// Gets a collection of VirtualMachineScaleSetResources in the ResourceGroupResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// An object representing collection of VirtualMachineScaleSetResources and their operations over a VirtualMachineScaleSetResource.
public static VirtualMachineScaleSetCollection GetVirtualMachineScaleSets(this ResourceGroupResource resourceGroupResource)
{
- return GetResourceGroupResourceExtensionClient(resourceGroupResource).GetVirtualMachineScaleSets();
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetVirtualMachineScaleSets();
}
///
@@ -680,16 +713,20 @@ public static VirtualMachineScaleSetCollection GetVirtualMachineScaleSets(this R
/// VirtualMachineScaleSets_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the VM scale set.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetVirtualMachineScaleSetAsync(this ResourceGroupResource resourceGroupResource, string vmScaleSetName, CancellationToken cancellationToken = default)
{
- return await resourceGroupResource.GetVirtualMachineScaleSets().GetAsync(vmScaleSetName, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleResourceGroupResource(resourceGroupResource).GetVirtualMachineScaleSetAsync(vmScaleSetName, cancellationToken).ConfigureAwait(false);
}
///
@@ -704,30 +741,38 @@ public static async Task> GetVirtualMac
/// VirtualMachineScaleSets_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the VM scale set.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetVirtualMachineScaleSet(this ResourceGroupResource resourceGroupResource, string vmScaleSetName, CancellationToken cancellationToken = default)
{
- return resourceGroupResource.GetVirtualMachineScaleSets().Get(vmScaleSetName, cancellationToken);
+ return GetMockableSampleResourceGroupResource(resourceGroupResource).GetVirtualMachineScaleSet(vmScaleSetName, cancellationToken);
}
- /// Gets a collection of VirtualMachineExtensionImageResources in the SubscriptionResource.
+ ///
+ /// Gets a collection of VirtualMachineExtensionImageResources in the SubscriptionResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// The name of a supported Azure region.
/// The String to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
/// An object representing collection of VirtualMachineExtensionImageResources and their operations over a VirtualMachineExtensionImageResource.
public static VirtualMachineExtensionImageCollection GetVirtualMachineExtensionImages(this SubscriptionResource subscriptionResource, AzureLocation location, string publisherName)
{
- Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachineExtensionImages(location, publisherName);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineExtensionImages(location, publisherName);
}
///
@@ -742,6 +787,10 @@ public static VirtualMachineExtensionImageCollection GetVirtualMachineExtensionI
/// VirtualMachineExtensionImages_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -749,12 +798,12 @@ public static VirtualMachineExtensionImageCollection GetVirtualMachineExtensionI
/// The String to use.
/// The String to use.
/// The cancellation token to use.
- /// , or is an empty string, and was expected to be non-empty.
/// , or is null.
+ /// , or is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetVirtualMachineExtensionImageAsync(this SubscriptionResource subscriptionResource, AzureLocation location, string publisherName, string type, string version, CancellationToken cancellationToken = default)
{
- return await subscriptionResource.GetVirtualMachineExtensionImages(location, publisherName).GetAsync(type, version, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineExtensionImageAsync(location, publisherName, type, version, cancellationToken).ConfigureAwait(false);
}
///
@@ -769,6 +818,10 @@ public static async Task> GetVirt
/// VirtualMachineExtensionImages_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -776,12 +829,12 @@ public static async Task> GetVirt
/// The String to use.
/// The String to use.
/// The cancellation token to use.
- /// , or is an empty string, and was expected to be non-empty.
/// , or is null.
+ /// , or is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetVirtualMachineExtensionImage(this SubscriptionResource subscriptionResource, AzureLocation location, string publisherName, string type, string version, CancellationToken cancellationToken = default)
{
- return subscriptionResource.GetVirtualMachineExtensionImages(location, publisherName).Get(type, version, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineExtensionImage(location, publisherName, type, version, cancellationToken);
}
///
@@ -796,6 +849,10 @@ public static Response GetVirtualMachineEx
/// AvailabilitySets_ListBySubscription
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The expand expression to apply to the operation. Allowed values are 'instanceView'.
@@ -803,7 +860,7 @@ public static Response GetVirtualMachineEx
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetAvailabilitySetsAsync(this SubscriptionResource subscriptionResource, string expand = null, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetAvailabilitySetsAsync(expand, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetAvailabilitySetsAsync(expand, cancellationToken);
}
///
@@ -818,6 +875,10 @@ public static AsyncPageable GetAvailabilitySetsAsync(th
/// AvailabilitySets_ListBySubscription
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The expand expression to apply to the operation. Allowed values are 'instanceView'.
@@ -825,7 +886,7 @@ public static AsyncPageable GetAvailabilitySetsAsync(th
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetAvailabilitySets(this SubscriptionResource subscriptionResource, string expand = null, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetAvailabilitySets(expand, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetAvailabilitySets(expand, cancellationToken);
}
///
@@ -840,13 +901,17 @@ public static Pageable GetAvailabilitySets(this Subscri
/// ProximityPlacementGroups_ListBySubscription
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetProximityPlacementGroupsAsync(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetProximityPlacementGroupsAsync(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetProximityPlacementGroupsAsync(cancellationToken);
}
///
@@ -861,13 +926,17 @@ public static AsyncPageable GetProximityPlaceme
/// ProximityPlacementGroups_ListBySubscription
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetProximityPlacementGroups(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetProximityPlacementGroups(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetProximityPlacementGroups(cancellationToken);
}
///
@@ -882,13 +951,17 @@ public static Pageable GetProximityPlacementGro
/// DedicatedHostGroups_ListBySubscription
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetDedicatedHostGroupsAsync(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetDedicatedHostGroupsAsync(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetDedicatedHostGroupsAsync(cancellationToken);
}
///
@@ -903,13 +976,17 @@ public static AsyncPageable GetDedicatedHostGroupsAs
/// DedicatedHostGroups_ListBySubscription
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetDedicatedHostGroups(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetDedicatedHostGroups(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetDedicatedHostGroups(cancellationToken);
}
///
@@ -924,13 +1001,17 @@ public static Pageable GetDedicatedHostGroups(this S
/// SshPublicKeys_ListBySubscription
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetSshPublicKeysAsync(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetSshPublicKeysAsync(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetSshPublicKeysAsync(cancellationToken);
}
///
@@ -945,13 +1026,17 @@ public static AsyncPageable GetSshPublicKeysAsync(this Sub
/// SshPublicKeys_ListBySubscription
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetSshPublicKeys(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetSshPublicKeys(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetSshPublicKeys(cancellationToken);
}
///
@@ -966,6 +1051,10 @@ public static Pageable GetSshPublicKeys(this SubscriptionR
/// VirtualMachineImages_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -978,12 +1067,7 @@ public static Pageable GetSshPublicKeys(this SubscriptionR
/// , , or is null.
public static async Task> GetVirtualMachineImageAsync(this SubscriptionResource subscriptionResource, AzureLocation location, string publisherName, string offer, string skus, string version, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
- Argument.AssertNotNullOrEmpty(offer, nameof(offer));
- Argument.AssertNotNullOrEmpty(skus, nameof(skus));
- Argument.AssertNotNullOrEmpty(version, nameof(version));
-
- return await GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachineImageAsync(location, publisherName, offer, skus, version, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineImageAsync(location, publisherName, offer, skus, version, cancellationToken).ConfigureAwait(false);
}
///
@@ -998,6 +1082,10 @@ public static async Task> GetVirtualMachineImageAs
/// VirtualMachineImages_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -1010,12 +1098,7 @@ public static async Task> GetVirtualMachineImageAs
/// , , or is null.
public static Response GetVirtualMachineImage(this SubscriptionResource subscriptionResource, AzureLocation location, string publisherName, string offer, string skus, string version, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
- Argument.AssertNotNullOrEmpty(offer, nameof(offer));
- Argument.AssertNotNullOrEmpty(skus, nameof(skus));
- Argument.AssertNotNullOrEmpty(version, nameof(version));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachineImage(location, publisherName, offer, skus, version, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineImage(location, publisherName, offer, skus, version, cancellationToken);
}
///
@@ -1030,6 +1113,10 @@ public static Response GetVirtualMachineImage(this Subscrip
/// VirtualMachineImages_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// A property bag which contains all the parameters of this method except the LRO qualifier and request context parameter.
@@ -1038,9 +1125,7 @@ public static Response GetVirtualMachineImage(this Subscrip
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetVirtualMachineImagesAsync(this SubscriptionResource subscriptionResource, SubscriptionResourceGetVirtualMachineImagesOptions options, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNull(options, nameof(options));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachineImagesAsync(options, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineImagesAsync(options, cancellationToken);
}
///
@@ -1055,6 +1140,10 @@ public static AsyncPageable GetVirtualMachineImages
/// VirtualMachineImages_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// A property bag which contains all the parameters of this method except the LRO qualifier and request context parameter.
@@ -1063,9 +1152,7 @@ public static AsyncPageable GetVirtualMachineImages
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetVirtualMachineImages(this SubscriptionResource subscriptionResource, SubscriptionResourceGetVirtualMachineImagesOptions options, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNull(options, nameof(options));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachineImages(options, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineImages(options, cancellationToken);
}
///
@@ -1080,6 +1167,10 @@ public static Pageable GetVirtualMachineImages(this
/// VirtualMachineImages_ListOffers
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -1090,9 +1181,7 @@ public static Pageable GetVirtualMachineImages(this
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetOffersVirtualMachineImagesAsync(this SubscriptionResource subscriptionResource, AzureLocation location, string publisherName, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetOffersVirtualMachineImagesAsync(location, publisherName, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetOffersVirtualMachineImagesAsync(location, publisherName, cancellationToken);
}
///
@@ -1107,6 +1196,10 @@ public static AsyncPageable GetOffersVirtualMachine
/// VirtualMachineImages_ListOffers
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -1117,9 +1210,7 @@ public static AsyncPageable GetOffersVirtualMachine
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetOffersVirtualMachineImages(this SubscriptionResource subscriptionResource, AzureLocation location, string publisherName, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetOffersVirtualMachineImages(location, publisherName, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetOffersVirtualMachineImages(location, publisherName, cancellationToken);
}
///
@@ -1134,6 +1225,10 @@ public static Pageable GetOffersVirtualMachineImage
/// VirtualMachineImages_ListPublishers
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -1141,7 +1236,7 @@ public static Pageable GetOffersVirtualMachineImage
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetPublishersVirtualMachineImagesAsync(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetPublishersVirtualMachineImagesAsync(location, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetPublishersVirtualMachineImagesAsync(location, cancellationToken);
}
///
@@ -1156,6 +1251,10 @@ public static AsyncPageable GetPublishersVirtualMac
/// VirtualMachineImages_ListPublishers
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -1163,7 +1262,7 @@ public static AsyncPageable GetPublishersVirtualMac
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetPublishersVirtualMachineImages(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetPublishersVirtualMachineImages(location, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetPublishersVirtualMachineImages(location, cancellationToken);
}
///
@@ -1178,6 +1277,10 @@ public static Pageable GetPublishersVirtualMachineI
/// VirtualMachineImages_ListSkus
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -1189,10 +1292,7 @@ public static Pageable GetPublishersVirtualMachineI
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetSkusVirtualMachineImagesAsync(this SubscriptionResource subscriptionResource, AzureLocation location, string publisherName, string offer, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
- Argument.AssertNotNullOrEmpty(offer, nameof(offer));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetSkusVirtualMachineImagesAsync(location, publisherName, offer, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetSkusVirtualMachineImagesAsync(location, publisherName, offer, cancellationToken);
}
///
@@ -1207,6 +1307,10 @@ public static AsyncPageable GetSkusVirtualMachineIm
/// VirtualMachineImages_ListSkus
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of a supported Azure region.
@@ -1218,10 +1322,7 @@ public static AsyncPageable GetSkusVirtualMachineIm
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetSkusVirtualMachineImages(this SubscriptionResource subscriptionResource, AzureLocation location, string publisherName, string offer, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNullOrEmpty(publisherName, nameof(publisherName));
- Argument.AssertNotNullOrEmpty(offer, nameof(offer));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetSkusVirtualMachineImages(location, publisherName, offer, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetSkusVirtualMachineImages(location, publisherName, offer, cancellationToken);
}
///
@@ -1236,6 +1337,10 @@ public static Pageable GetSkusVirtualMachineImages(
/// Usage_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location for which resource usage is queried.
@@ -1243,7 +1348,7 @@ public static Pageable GetSkusVirtualMachineImages(
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetUsagesAsync(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetUsagesAsync(location, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetUsagesAsync(location, cancellationToken);
}
///
@@ -1258,6 +1363,10 @@ public static AsyncPageable GetUsagesAsync(this SubscriptionResourc
/// Usage_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location for which resource usage is queried.
@@ -1265,7 +1374,7 @@ public static AsyncPageable GetUsagesAsync(this SubscriptionResourc
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetUsages(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetUsages(location, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetUsages(location, cancellationToken);
}
///
@@ -1280,6 +1389,10 @@ public static Pageable GetUsages(this SubscriptionResource subscrip
/// VirtualMachines_ListByLocation
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location for which virtual machines under the subscription are queried.
@@ -1287,7 +1400,7 @@ public static Pageable GetUsages(this SubscriptionResource subscrip
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetVirtualMachinesByLocationAsync(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachinesByLocationAsync(location, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachinesByLocationAsync(location, cancellationToken);
}
///
@@ -1302,6 +1415,10 @@ public static AsyncPageable GetVirtualMachinesByLocation
/// VirtualMachines_ListByLocation
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location for which virtual machines under the subscription are queried.
@@ -1309,7 +1426,7 @@ public static AsyncPageable GetVirtualMachinesByLocation
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetVirtualMachinesByLocation(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachinesByLocation(location, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachinesByLocation(location, cancellationToken);
}
///
@@ -1324,6 +1441,10 @@ public static Pageable GetVirtualMachinesByLocation(this
/// VirtualMachines_ListAll
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// statusOnly=true enables fetching run time status of all Virtual Machines in the subscription.
@@ -1331,7 +1452,7 @@ public static Pageable GetVirtualMachinesByLocation(this
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetVirtualMachinesAsync(this SubscriptionResource subscriptionResource, string statusOnly = null, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachinesAsync(statusOnly, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachinesAsync(statusOnly, cancellationToken);
}
///
@@ -1346,6 +1467,10 @@ public static AsyncPageable GetVirtualMachinesAsync(this
/// VirtualMachines_ListAll
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// statusOnly=true enables fetching run time status of all Virtual Machines in the subscription.
@@ -1353,7 +1478,7 @@ public static AsyncPageable GetVirtualMachinesAsync(this
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetVirtualMachines(this SubscriptionResource subscriptionResource, string statusOnly = null, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachines(statusOnly, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachines(statusOnly, cancellationToken);
}
///
@@ -1368,6 +1493,10 @@ public static Pageable GetVirtualMachines(this Subscript
/// VirtualMachineSizes_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location upon which virtual-machine-sizes is queried.
@@ -1375,7 +1504,7 @@ public static Pageable GetVirtualMachines(this Subscript
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetVirtualMachineSizesAsync(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachineSizesAsync(location, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineSizesAsync(location, cancellationToken);
}
///
@@ -1390,6 +1519,10 @@ public static AsyncPageable GetVirtualMachineSizesAsync(this
/// VirtualMachineSizes_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location upon which virtual-machine-sizes is queried.
@@ -1397,7 +1530,7 @@ public static AsyncPageable GetVirtualMachineSizesAsync(this
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetVirtualMachineSizes(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachineSizes(location, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineSizes(location, cancellationToken);
}
///
@@ -1412,13 +1545,17 @@ public static Pageable GetVirtualMachineSizes(this Subscript
/// Images_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetImagesAsync(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetImagesAsync(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetImagesAsync(cancellationToken);
}
///
@@ -1433,13 +1570,17 @@ public static AsyncPageable GetImagesAsync(this SubscriptionResou
/// Images_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetImages(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetImages(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetImages(cancellationToken);
}
///
@@ -1454,13 +1595,17 @@ public static Pageable GetImages(this SubscriptionResource subscr
/// VirtualMachineScaleSets_ListAll
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetVirtualMachineScaleSetsAsync(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachineScaleSetsAsync(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineScaleSetsAsync(cancellationToken);
}
///
@@ -1475,13 +1620,17 @@ public static AsyncPageable GetVirtualMachineSca
/// VirtualMachineScaleSets_ListAll
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetVirtualMachineScaleSets(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetVirtualMachineScaleSets(cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).GetVirtualMachineScaleSets(cancellationToken);
}
///
@@ -1496,6 +1645,10 @@ public static Pageable GetVirtualMachineScaleSet
/// LogAnalytics_ExportRequestRateByInterval
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.
@@ -1505,9 +1658,7 @@ public static Pageable GetVirtualMachineScaleSet
/// is null.
public static async Task> ExportRequestRateByIntervalLogAnalyticAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, AzureLocation location, RequestRateByIntervalContent content, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNull(content, nameof(content));
-
- return await GetSubscriptionResourceExtensionClient(subscriptionResource).ExportRequestRateByIntervalLogAnalyticAsync(waitUntil, location, content, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleSubscriptionResource(subscriptionResource).ExportRequestRateByIntervalLogAnalyticAsync(waitUntil, location, content, cancellationToken).ConfigureAwait(false);
}
///
@@ -1522,6 +1673,10 @@ public static async Task> ExportRequestRateByInterval
/// LogAnalytics_ExportRequestRateByInterval
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.
@@ -1531,9 +1686,7 @@ public static async Task> ExportRequestRateByInterval
/// is null.
public static ArmOperation ExportRequestRateByIntervalLogAnalytic(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, AzureLocation location, RequestRateByIntervalContent content, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNull(content, nameof(content));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).ExportRequestRateByIntervalLogAnalytic(waitUntil, location, content, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).ExportRequestRateByIntervalLogAnalytic(waitUntil, location, content, cancellationToken);
}
///
@@ -1548,6 +1701,10 @@ public static ArmOperation ExportRequestRateByIntervalLogAnalytic(
/// LogAnalytics_ExportThrottledRequests
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.
@@ -1557,9 +1714,7 @@ public static ArmOperation ExportRequestRateByIntervalLogAnalytic(
/// is null.
public static async Task> ExportThrottledRequestsLogAnalyticAsync(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, AzureLocation location, ThrottledRequestsContent content, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNull(content, nameof(content));
-
- return await GetSubscriptionResourceExtensionClient(subscriptionResource).ExportThrottledRequestsLogAnalyticAsync(waitUntil, location, content, cancellationToken).ConfigureAwait(false);
+ return await GetMockableSampleSubscriptionResource(subscriptionResource).ExportThrottledRequestsLogAnalyticAsync(waitUntil, location, content, cancellationToken).ConfigureAwait(false);
}
///
@@ -1574,6 +1729,10 @@ public static async Task> ExportThrottledRequestsLogA
/// LogAnalytics_ExportThrottledRequests
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// if the method should wait to return until the long-running operation has completed on the service; if it should return after starting the operation. For more information on long-running operations, please see Azure.Core Long-Running Operation samples.
@@ -1583,9 +1742,7 @@ public static async Task> ExportThrottledRequestsLogA
/// is null.
public static ArmOperation ExportThrottledRequestsLogAnalytic(this SubscriptionResource subscriptionResource, WaitUntil waitUntil, AzureLocation location, ThrottledRequestsContent content, CancellationToken cancellationToken = default)
{
- Argument.AssertNotNull(content, nameof(content));
-
- return GetSubscriptionResourceExtensionClient(subscriptionResource).ExportThrottledRequestsLogAnalytic(waitUntil, location, content, cancellationToken);
+ return GetMockableSampleSubscriptionResource(subscriptionResource).ExportThrottledRequestsLogAnalytic(waitUntil, location, content, cancellationToken);
}
}
}
diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineResource.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineResource.cs
index ea262b19c4d..2106d063abe 100644
--- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineResource.cs
+++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineResource.cs
@@ -97,7 +97,7 @@ internal static void ValidateResourceId(ResourceIdentifier id)
/// An object representing collection of VirtualMachineExtensionResources and their operations over a VirtualMachineExtensionResource.
public virtual VirtualMachineExtensionCollection GetVirtualMachineExtensions()
{
- return GetCachedClient(Client => new VirtualMachineExtensionCollection(Client, Id));
+ return GetCachedClient(client => new VirtualMachineExtensionCollection(client, Id));
}
///
@@ -116,8 +116,8 @@ public virtual VirtualMachineExtensionCollection GetVirtualMachineExtensions()
/// The name of the virtual machine extension.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetVirtualMachineExtensionAsync(string vmExtensionName, string expand = null, CancellationToken cancellationToken = default)
{
@@ -140,8 +140,8 @@ public virtual async Task> GetVirtualM
/// The name of the virtual machine extension.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetVirtualMachineExtension(string vmExtensionName, string expand = null, CancellationToken cancellationToken = default)
{
diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetResource.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetResource.cs
index 443ff317fa1..40d423fa03f 100644
--- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetResource.cs
+++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetResource.cs
@@ -102,7 +102,7 @@ internal static void ValidateResourceId(ResourceIdentifier id)
/// An object representing collection of VirtualMachineScaleSetExtensionResources and their operations over a VirtualMachineScaleSetExtensionResource.
public virtual VirtualMachineScaleSetExtensionCollection GetVirtualMachineScaleSetExtensions()
{
- return GetCachedClient(Client => new VirtualMachineScaleSetExtensionCollection(Client, Id));
+ return GetCachedClient(client => new VirtualMachineScaleSetExtensionCollection(client, Id));
}
///
@@ -121,8 +121,8 @@ public virtual VirtualMachineScaleSetExtensionCollection GetVirtualMachineScaleS
/// The name of the VM scale set extension.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetVirtualMachineScaleSetExtensionAsync(string vmssExtensionName, string expand = null, CancellationToken cancellationToken = default)
{
@@ -145,8 +145,8 @@ public virtual async Task> Get
/// The name of the VM scale set extension.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetVirtualMachineScaleSetExtension(string vmssExtensionName, string expand = null, CancellationToken cancellationToken = default)
{
@@ -164,7 +164,7 @@ public virtual VirtualMachineScaleSetRollingUpgradeResource GetVirtualMachineSca
/// An object representing collection of VirtualMachineScaleSetVmResources and their operations over a VirtualMachineScaleSetVmResource.
public virtual VirtualMachineScaleSetVmCollection GetVirtualMachineScaleSetVms()
{
- return GetCachedClient(Client => new VirtualMachineScaleSetVmCollection(Client, Id));
+ return GetCachedClient(client => new VirtualMachineScaleSetVmCollection(client, Id));
}
///
@@ -183,8 +183,8 @@ public virtual VirtualMachineScaleSetVmCollection GetVirtualMachineScaleSetVms()
/// The instance ID of the virtual machine.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetVirtualMachineScaleSetVmAsync(string instanceId, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
{
@@ -207,8 +207,8 @@ public virtual async Task> GetVirtual
/// The instance ID of the virtual machine.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetVirtualMachineScaleSetVm(string instanceId, InstanceViewType? expand = null, CancellationToken cancellationToken = default)
{
diff --git a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVmResource.cs b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVmResource.cs
index b7e5086e8a4..20e2c47c6a0 100644
--- a/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVmResource.cs
+++ b/samples/Azure.ResourceManager.Sample/Generated/VirtualMachineScaleSetVmResource.cs
@@ -96,7 +96,7 @@ internal static void ValidateResourceId(ResourceIdentifier id)
/// An object representing collection of VirtualMachineScaleSetVirtualMachineExtensionResources and their operations over a VirtualMachineScaleSetVirtualMachineExtensionResource.
public virtual VirtualMachineScaleSetVirtualMachineExtensionCollection GetVirtualMachineScaleSetVirtualMachineExtensions()
{
- return GetCachedClient(Client => new VirtualMachineScaleSetVirtualMachineExtensionCollection(Client, Id));
+ return GetCachedClient(client => new VirtualMachineScaleSetVirtualMachineExtensionCollection(client, Id));
}
///
@@ -115,8 +115,8 @@ public virtual VirtualMachineScaleSetVirtualMachineExtensionCollection GetVirtua
/// The name of the virtual machine extension.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetVirtualMachineScaleSetVirtualMachineExtensionAsync(string vmExtensionName, string expand = null, CancellationToken cancellationToken = default)
{
@@ -139,8 +139,8 @@ public virtual async Task The name of the virtual machine extension.
/// The expand expression to apply on the operation.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetVirtualMachineScaleSetVirtualMachineExtension(string vmExtensionName, string expand = null, CancellationToken cancellationToken = default)
{
diff --git a/samples/Azure.ResourceManager.Storage/Generated/BlobServiceResource.cs b/samples/Azure.ResourceManager.Storage/Generated/BlobServiceResource.cs
index bdddb8932a8..85119b48ec3 100644
--- a/samples/Azure.ResourceManager.Storage/Generated/BlobServiceResource.cs
+++ b/samples/Azure.ResourceManager.Storage/Generated/BlobServiceResource.cs
@@ -93,7 +93,7 @@ internal static void ValidateResourceId(ResourceIdentifier id)
/// An object representing collection of BlobContainerResources and their operations over a BlobContainerResource.
public virtual BlobContainerCollection GetBlobContainers()
{
- return GetCachedClient(Client => new BlobContainerCollection(Client, Id));
+ return GetCachedClient(client => new BlobContainerCollection(client, Id));
}
///
@@ -111,8 +111,8 @@ public virtual BlobContainerCollection GetBlobContainers()
///
/// The name of the blob container within the specified storage account. Blob container names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetBlobContainerAsync(string containerName, CancellationToken cancellationToken = default)
{
@@ -134,8 +134,8 @@ public virtual async Task> GetBlobContainerAsync
///
/// The name of the blob container within the specified storage account. Blob container names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetBlobContainer(string containerName, CancellationToken cancellationToken = default)
{
diff --git a/samples/Azure.ResourceManager.Storage/Generated/Extensions/MockableStorageArmClient.cs b/samples/Azure.ResourceManager.Storage/Generated/Extensions/MockableStorageArmClient.cs
new file mode 100644
index 00000000000..9497463532e
--- /dev/null
+++ b/samples/Azure.ResourceManager.Storage/Generated/Extensions/MockableStorageArmClient.cs
@@ -0,0 +1,183 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using Azure.Core;
+using Azure.ResourceManager;
+using Azure.ResourceManager.Storage;
+
+namespace Azure.ResourceManager.Storage.Mocking
+{
+ /// A class to add extension methods to ArmClient.
+ public partial class MockableStorageArmClient : ArmResource
+ {
+ /// Initializes a new instance of the class for mocking.
+ protected MockableStorageArmClient()
+ {
+ }
+
+ /// Initializes a new instance of the class.
+ /// The client parameters to use in these operations.
+ /// The identifier of the resource that is the target of operations.
+ internal MockableStorageArmClient(ArmClient client, ResourceIdentifier id) : base(client, id)
+ {
+ }
+
+ internal MockableStorageArmClient(ArmClient client) : this(client, ResourceIdentifier.Root)
+ {
+ }
+
+ private string GetApiVersionOrNull(ResourceType resourceType)
+ {
+ TryGetApiVersion(resourceType, out string apiVersion);
+ return apiVersion;
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual BlobServiceResource GetBlobServiceResource(ResourceIdentifier id)
+ {
+ BlobServiceResource.ValidateResourceId(id);
+ return new BlobServiceResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual BlobContainerResource GetBlobContainerResource(ResourceIdentifier id)
+ {
+ BlobContainerResource.ValidateResourceId(id);
+ return new BlobContainerResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing an along with the instance operations that can be performed on it but with no data.
+ /// You can use to create an from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual ImmutabilityPolicyResource GetImmutabilityPolicyResource(ResourceIdentifier id)
+ {
+ ImmutabilityPolicyResource.ValidateResourceId(id);
+ return new ImmutabilityPolicyResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual FileServiceResource GetFileServiceResource(ResourceIdentifier id)
+ {
+ FileServiceResource.ValidateResourceId(id);
+ return new FileServiceResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual FileShareResource GetFileShareResource(ResourceIdentifier id)
+ {
+ FileShareResource.ValidateResourceId(id);
+ return new FileShareResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual StorageAccountResource GetStorageAccountResource(ResourceIdentifier id)
+ {
+ StorageAccountResource.ValidateResourceId(id);
+ return new StorageAccountResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual DeletedAccountResource GetDeletedAccountResource(ResourceIdentifier id)
+ {
+ DeletedAccountResource.ValidateResourceId(id);
+ return new DeletedAccountResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual ManagementPolicyResource GetManagementPolicyResource(ResourceIdentifier id)
+ {
+ ManagementPolicyResource.ValidateResourceId(id);
+ return new ManagementPolicyResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual BlobInventoryPolicyResource GetBlobInventoryPolicyResource(ResourceIdentifier id)
+ {
+ BlobInventoryPolicyResource.ValidateResourceId(id);
+ return new BlobInventoryPolicyResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing a along with the instance operations that can be performed on it but with no data.
+ /// You can use to create a from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual StoragePrivateEndpointConnectionResource GetStoragePrivateEndpointConnectionResource(ResourceIdentifier id)
+ {
+ StoragePrivateEndpointConnectionResource.ValidateResourceId(id);
+ return new StoragePrivateEndpointConnectionResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing an along with the instance operations that can be performed on it but with no data.
+ /// You can use to create an from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual ObjectReplicationPolicyResource GetObjectReplicationPolicyResource(ResourceIdentifier id)
+ {
+ ObjectReplicationPolicyResource.ValidateResourceId(id);
+ return new ObjectReplicationPolicyResource(Client, id);
+ }
+
+ ///
+ /// Gets an object representing an along with the instance operations that can be performed on it but with no data.
+ /// You can use to create an from its components.
+ ///
+ /// The resource ID of the resource to get.
+ /// Returns a object.
+ public virtual EncryptionScopeResource GetEncryptionScopeResource(ResourceIdentifier id)
+ {
+ EncryptionScopeResource.ValidateResourceId(id);
+ return new EncryptionScopeResource(Client, id);
+ }
+ }
+}
diff --git a/samples/Azure.ResourceManager.Storage/Generated/Extensions/MockableStorageResourceGroupResource.cs b/samples/Azure.ResourceManager.Storage/Generated/Extensions/MockableStorageResourceGroupResource.cs
new file mode 100644
index 00000000000..b68017e2f5c
--- /dev/null
+++ b/samples/Azure.ResourceManager.Storage/Generated/Extensions/MockableStorageResourceGroupResource.cs
@@ -0,0 +1,95 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License.
+
+//
+
+#nullable disable
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Azure;
+using Azure.Core;
+using Azure.ResourceManager;
+using Azure.ResourceManager.Storage;
+using Azure.ResourceManager.Storage.Models;
+
+namespace Azure.ResourceManager.Storage.Mocking
+{
+ /// A class to add extension methods to ResourceGroupResource.
+ public partial class MockableStorageResourceGroupResource : ArmResource
+ {
+ /// Initializes a new instance of the class for mocking.
+ protected MockableStorageResourceGroupResource()
+ {
+ }
+
+ /// Initializes a new instance of the class.
+ /// The client parameters to use in these operations.
+ /// The identifier of the resource that is the target of operations.
+ internal MockableStorageResourceGroupResource(ArmClient client, ResourceIdentifier id) : base(client, id)
+ {
+ }
+
+ private string GetApiVersionOrNull(ResourceType resourceType)
+ {
+ TryGetApiVersion(resourceType, out string apiVersion);
+ return apiVersion;
+ }
+
+ /// Gets a collection of StorageAccountResources in the ResourceGroupResource.
+ /// An object representing collection of StorageAccountResources and their operations over a StorageAccountResource.
+ public virtual StorageAccountCollection GetStorageAccounts()
+ {
+ return GetCachedClient(client => new StorageAccountCollection(client, Id));
+ }
+
+ ///
+ /// Returns the properties for the specified storage account including but not limited to name, SKU name, location, and account status. The ListKeys operation should be used to retrieve storage keys.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}
+ ///
+ /// -
+ /// Operation Id
+ /// StorageAccounts_GetProperties
+ ///
+ ///
+ ///
+ /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only.
+ /// May be used to expand the properties within account's properties. By default, data is not included when fetching properties. Currently we only support geoReplicationStats and blobRestoreStatus.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetStorageAccountAsync(string accountName, StorageAccountExpand? expand = null, CancellationToken cancellationToken = default)
+ {
+ return await GetStorageAccounts().GetAsync(accountName, expand, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Returns the properties for the specified storage account including but not limited to name, SKU name, location, and account status. The ListKeys operation should be used to retrieve storage keys.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}
+ ///
+ /// -
+ /// Operation Id
+ /// StorageAccounts_GetProperties
+ ///
+ ///
+ ///
+ /// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only.
+ /// May be used to expand the properties within account's properties. By default, data is not included when fetching properties. Currently we only support geoReplicationStats and blobRestoreStatus.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetStorageAccount(string accountName, StorageAccountExpand? expand = null, CancellationToken cancellationToken = default)
+ {
+ return GetStorageAccounts().Get(accountName, expand, cancellationToken);
+ }
+ }
+}
diff --git a/samples/Azure.ResourceManager.Storage/Generated/Extensions/SubscriptionResourceExtensionClient.cs b/samples/Azure.ResourceManager.Storage/Generated/Extensions/MockableStorageSubscriptionResource.cs
similarity index 72%
rename from samples/Azure.ResourceManager.Storage/Generated/Extensions/SubscriptionResourceExtensionClient.cs
rename to samples/Azure.ResourceManager.Storage/Generated/Extensions/MockableStorageSubscriptionResource.cs
index 9ea12adda55..de2b2379cca 100644
--- a/samples/Azure.ResourceManager.Storage/Generated/Extensions/SubscriptionResourceExtensionClient.cs
+++ b/samples/Azure.ResourceManager.Storage/Generated/Extensions/MockableStorageSubscriptionResource.cs
@@ -5,18 +5,21 @@
#nullable disable
+using System;
using System.Threading;
+using System.Threading.Tasks;
using Autorest.CSharp.Core;
using Azure;
using Azure.Core;
using Azure.Core.Pipeline;
using Azure.ResourceManager;
+using Azure.ResourceManager.Storage;
using Azure.ResourceManager.Storage.Models;
-namespace Azure.ResourceManager.Storage
+namespace Azure.ResourceManager.Storage.Mocking
{
/// A class to add extension methods to SubscriptionResource.
- internal partial class SubscriptionResourceExtensionClient : ArmResource
+ public partial class MockableStorageSubscriptionResource : ArmResource
{
private ClientDiagnostics _skusClientDiagnostics;
private SkusRestOperations _skusRestClient;
@@ -25,15 +28,15 @@ internal partial class SubscriptionResourceExtensionClient : ArmResource
private ClientDiagnostics _usagesClientDiagnostics;
private UsagesRestOperations _usagesRestClient;
- /// Initializes a new instance of the class for mocking.
- protected SubscriptionResourceExtensionClient()
+ /// Initializes a new instance of the class for mocking.
+ protected MockableStorageSubscriptionResource()
{
}
- /// Initializes a new instance of the class.
+ /// Initializes a new instance of the class.
/// The client parameters to use in these operations.
/// The identifier of the resource that is the target of operations.
- internal SubscriptionResourceExtensionClient(ArmClient client, ResourceIdentifier id) : base(client, id)
+ internal MockableStorageSubscriptionResource(ArmClient client, ResourceIdentifier id) : base(client, id)
{
}
@@ -54,7 +57,55 @@ private string GetApiVersionOrNull(ResourceType resourceType)
/// An object representing collection of DeletedAccountResources and their operations over a DeletedAccountResource.
public virtual DeletedAccountCollection GetDeletedAccounts()
{
- return GetCachedClient(Client => new DeletedAccountCollection(Client, Id));
+ return GetCachedClient(client => new DeletedAccountCollection(client, Id));
+ }
+
+ ///
+ /// Get properties of specified deleted account resource.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/providers/Microsoft.Storage/locations/{location}/deletedAccounts/{deletedAccountName}
+ ///
+ /// -
+ /// Operation Id
+ /// DeletedAccounts_Get
+ ///
+ ///
+ ///
+ /// The location of the deleted storage account.
+ /// Name of the deleted storage account.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual async Task> GetDeletedAccountAsync(AzureLocation location, string deletedAccountName, CancellationToken cancellationToken = default)
+ {
+ return await GetDeletedAccounts().GetAsync(location, deletedAccountName, cancellationToken).ConfigureAwait(false);
+ }
+
+ ///
+ /// Get properties of specified deleted account resource.
+ ///
+ /// -
+ /// Request Path
+ /// /subscriptions/{subscriptionId}/providers/Microsoft.Storage/locations/{location}/deletedAccounts/{deletedAccountName}
+ ///
+ /// -
+ /// Operation Id
+ /// DeletedAccounts_Get
+ ///
+ ///
+ ///
+ /// The location of the deleted storage account.
+ /// Name of the deleted storage account.
+ /// The cancellation token to use.
+ /// is null.
+ /// is an empty string, and was expected to be non-empty.
+ [ForwardsClientCalls]
+ public virtual Response GetDeletedAccount(AzureLocation location, string deletedAccountName, CancellationToken cancellationToken = default)
+ {
+ return GetDeletedAccounts().Get(location, deletedAccountName, cancellationToken);
}
///
@@ -75,7 +126,7 @@ public virtual DeletedAccountCollection GetDeletedAccounts()
public virtual AsyncPageable GetSkusAsync(CancellationToken cancellationToken = default)
{
HttpMessage FirstPageRequest(int? pageSizeHint) => SkusRestClient.CreateListRequest(Id.SubscriptionId);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, StorageSkuInformation.DeserializeStorageSkuInformation, SkusClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetSkus", "value", null, cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, StorageSkuInformation.DeserializeStorageSkuInformation, SkusClientDiagnostics, Pipeline, "MockableStorageSubscriptionResource.GetSkus", "value", null, cancellationToken);
}
///
@@ -96,7 +147,7 @@ public virtual AsyncPageable GetSkusAsync(CancellationTok
public virtual Pageable GetSkus(CancellationToken cancellationToken = default)
{
HttpMessage FirstPageRequest(int? pageSizeHint) => SkusRestClient.CreateListRequest(Id.SubscriptionId);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, StorageSkuInformation.DeserializeStorageSkuInformation, SkusClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetSkus", "value", null, cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, StorageSkuInformation.DeserializeStorageSkuInformation, SkusClientDiagnostics, Pipeline, "MockableStorageSubscriptionResource.GetSkus", "value", null, cancellationToken);
}
///
@@ -118,7 +169,7 @@ public virtual AsyncPageable GetStorageAccountsAsync(Can
{
HttpMessage FirstPageRequest(int? pageSizeHint) => StorageAccountRestClient.CreateListRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => StorageAccountRestClient.CreateListNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new StorageAccountResource(Client, StorageAccountData.DeserializeStorageAccountData(e)), StorageAccountClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetStorageAccounts", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, NextPageRequest, e => new StorageAccountResource(Client, StorageAccountData.DeserializeStorageAccountData(e)), StorageAccountClientDiagnostics, Pipeline, "MockableStorageSubscriptionResource.GetStorageAccounts", "value", "nextLink", cancellationToken);
}
///
@@ -140,7 +191,7 @@ public virtual Pageable GetStorageAccounts(CancellationT
{
HttpMessage FirstPageRequest(int? pageSizeHint) => StorageAccountRestClient.CreateListRequest(Id.SubscriptionId);
HttpMessage NextPageRequest(int? pageSizeHint, string nextLink) => StorageAccountRestClient.CreateListNextPageRequest(nextLink, Id.SubscriptionId);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new StorageAccountResource(Client, StorageAccountData.DeserializeStorageAccountData(e)), StorageAccountClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetStorageAccounts", "value", "nextLink", cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, NextPageRequest, e => new StorageAccountResource(Client, StorageAccountData.DeserializeStorageAccountData(e)), StorageAccountClientDiagnostics, Pipeline, "MockableStorageSubscriptionResource.GetStorageAccounts", "value", "nextLink", cancellationToken);
}
///
@@ -162,7 +213,7 @@ public virtual Pageable GetStorageAccounts(CancellationT
public virtual AsyncPageable GetUsagesByLocationAsync(AzureLocation location, CancellationToken cancellationToken = default)
{
HttpMessage FirstPageRequest(int? pageSizeHint) => UsagesRestClient.CreateListByLocationRequest(Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, StorageUsage.DeserializeStorageUsage, UsagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetUsagesByLocation", "value", null, cancellationToken);
+ return GeneratorPageableHelpers.CreateAsyncPageable(FirstPageRequest, null, StorageUsage.DeserializeStorageUsage, UsagesClientDiagnostics, Pipeline, "MockableStorageSubscriptionResource.GetUsagesByLocation", "value", null, cancellationToken);
}
///
@@ -184,7 +235,7 @@ public virtual AsyncPageable GetUsagesByLocationAsync(AzureLocatio
public virtual Pageable GetUsagesByLocation(AzureLocation location, CancellationToken cancellationToken = default)
{
HttpMessage FirstPageRequest(int? pageSizeHint) => UsagesRestClient.CreateListByLocationRequest(Id.SubscriptionId, location);
- return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, StorageUsage.DeserializeStorageUsage, UsagesClientDiagnostics, Pipeline, "SubscriptionResourceExtensionClient.GetUsagesByLocation", "value", null, cancellationToken);
+ return GeneratorPageableHelpers.CreatePageable(FirstPageRequest, null, StorageUsage.DeserializeStorageUsage, UsagesClientDiagnostics, Pipeline, "MockableStorageSubscriptionResource.GetUsagesByLocation", "value", null, cancellationToken);
}
}
}
diff --git a/samples/Azure.ResourceManager.Storage/Generated/Extensions/ResourceGroupResourceExtensionClient.cs b/samples/Azure.ResourceManager.Storage/Generated/Extensions/ResourceGroupResourceExtensionClient.cs
deleted file mode 100644
index 5283e341415..00000000000
--- a/samples/Azure.ResourceManager.Storage/Generated/Extensions/ResourceGroupResourceExtensionClient.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-//
-
-#nullable disable
-
-using Azure.Core;
-using Azure.ResourceManager;
-
-namespace Azure.ResourceManager.Storage
-{
- /// A class to add extension methods to ResourceGroupResource.
- internal partial class ResourceGroupResourceExtensionClient : ArmResource
- {
- /// Initializes a new instance of the class for mocking.
- protected ResourceGroupResourceExtensionClient()
- {
- }
-
- /// Initializes a new instance of the class.
- /// The client parameters to use in these operations.
- /// The identifier of the resource that is the target of operations.
- internal ResourceGroupResourceExtensionClient(ArmClient client, ResourceIdentifier id) : base(client, id)
- {
- }
-
- private string GetApiVersionOrNull(ResourceType resourceType)
- {
- TryGetApiVersion(resourceType, out string apiVersion);
- return apiVersion;
- }
-
- /// Gets a collection of StorageAccountResources in the ResourceGroupResource.
- /// An object representing collection of StorageAccountResources and their operations over a StorageAccountResource.
- public virtual StorageAccountCollection GetStorageAccounts()
- {
- return GetCachedClient(Client => new StorageAccountCollection(Client, Id));
- }
- }
-}
diff --git a/samples/Azure.ResourceManager.Storage/Generated/Extensions/StorageExtensions.cs b/samples/Azure.ResourceManager.Storage/Generated/Extensions/StorageExtensions.cs
index 455c578a0e4..7e710da0f03 100644
--- a/samples/Azure.ResourceManager.Storage/Generated/Extensions/StorageExtensions.cs
+++ b/samples/Azure.ResourceManager.Storage/Generated/Extensions/StorageExtensions.cs
@@ -12,6 +12,7 @@
using Azure.Core;
using Azure.ResourceManager;
using Azure.ResourceManager.Resources;
+using Azure.ResourceManager.Storage.Mocking;
using Azure.ResourceManager.Storage.Models;
namespace Azure.ResourceManager.Storage
@@ -19,271 +20,225 @@ namespace Azure.ResourceManager.Storage
/// A class to add extension methods to Azure.ResourceManager.Storage.
public static partial class StorageExtensions
{
- private static ResourceGroupResourceExtensionClient GetResourceGroupResourceExtensionClient(ArmResource resource)
+ private static MockableStorageArmClient GetMockableStorageArmClient(ArmClient client)
{
- return resource.GetCachedClient(client =>
- {
- return new ResourceGroupResourceExtensionClient(client, resource.Id);
- });
+ return client.GetCachedClient(client0 => new MockableStorageArmClient(client0));
}
- private static ResourceGroupResourceExtensionClient GetResourceGroupResourceExtensionClient(ArmClient client, ResourceIdentifier scope)
+ private static MockableStorageResourceGroupResource GetMockableStorageResourceGroupResource(ArmResource resource)
{
- return client.GetResourceClient(() =>
- {
- return new ResourceGroupResourceExtensionClient(client, scope);
- });
+ return resource.GetCachedClient(client => new MockableStorageResourceGroupResource(client, resource.Id));
}
- private static SubscriptionResourceExtensionClient GetSubscriptionResourceExtensionClient(ArmResource resource)
+ private static MockableStorageSubscriptionResource GetMockableStorageSubscriptionResource(ArmResource resource)
{
- return resource.GetCachedClient(client =>
- {
- return new SubscriptionResourceExtensionClient(client, resource.Id);
- });
+ return resource.GetCachedClient(client => new MockableStorageSubscriptionResource(client, resource.Id));
}
- private static SubscriptionResourceExtensionClient GetSubscriptionResourceExtensionClient(ArmClient client, ResourceIdentifier scope)
- {
- return client.GetResourceClient(() =>
- {
- return new SubscriptionResourceExtensionClient(client, scope);
- });
- }
- #region BlobServiceResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static BlobServiceResource GetBlobServiceResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- BlobServiceResource.ValidateResourceId(id);
- return new BlobServiceResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetBlobServiceResource(id);
}
- #endregion
- #region BlobContainerResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static BlobContainerResource GetBlobContainerResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- BlobContainerResource.ValidateResourceId(id);
- return new BlobContainerResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetBlobContainerResource(id);
}
- #endregion
- #region ImmutabilityPolicyResource
///
/// Gets an object representing an along with the instance operations that can be performed on it but with no data.
/// You can use to create an from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static ImmutabilityPolicyResource GetImmutabilityPolicyResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- ImmutabilityPolicyResource.ValidateResourceId(id);
- return new ImmutabilityPolicyResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetImmutabilityPolicyResource(id);
}
- #endregion
- #region FileServiceResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static FileServiceResource GetFileServiceResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- FileServiceResource.ValidateResourceId(id);
- return new FileServiceResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetFileServiceResource(id);
}
- #endregion
- #region FileShareResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static FileShareResource GetFileShareResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- FileShareResource.ValidateResourceId(id);
- return new FileShareResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetFileShareResource(id);
}
- #endregion
- #region StorageAccountResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static StorageAccountResource GetStorageAccountResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- StorageAccountResource.ValidateResourceId(id);
- return new StorageAccountResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetStorageAccountResource(id);
}
- #endregion
- #region DeletedAccountResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static DeletedAccountResource GetDeletedAccountResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- DeletedAccountResource.ValidateResourceId(id);
- return new DeletedAccountResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetDeletedAccountResource(id);
}
- #endregion
- #region ManagementPolicyResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static ManagementPolicyResource GetManagementPolicyResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- ManagementPolicyResource.ValidateResourceId(id);
- return new ManagementPolicyResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetManagementPolicyResource(id);
}
- #endregion
- #region BlobInventoryPolicyResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static BlobInventoryPolicyResource GetBlobInventoryPolicyResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- BlobInventoryPolicyResource.ValidateResourceId(id);
- return new BlobInventoryPolicyResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetBlobInventoryPolicyResource(id);
}
- #endregion
- #region StoragePrivateEndpointConnectionResource
///
/// Gets an object representing a along with the instance operations that can be performed on it but with no data.
/// You can use to create a from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static StoragePrivateEndpointConnectionResource GetStoragePrivateEndpointConnectionResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- StoragePrivateEndpointConnectionResource.ValidateResourceId(id);
- return new StoragePrivateEndpointConnectionResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetStoragePrivateEndpointConnectionResource(id);
}
- #endregion
- #region ObjectReplicationPolicyResource
///
/// Gets an object representing an along with the instance operations that can be performed on it but with no data.
/// You can use to create an from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static ObjectReplicationPolicyResource GetObjectReplicationPolicyResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- ObjectReplicationPolicyResource.ValidateResourceId(id);
- return new ObjectReplicationPolicyResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetObjectReplicationPolicyResource(id);
}
- #endregion
- #region EncryptionScopeResource
///
/// Gets an object representing an along with the instance operations that can be performed on it but with no data.
/// You can use to create an from its components.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The resource ID of the resource to get.
/// Returns a object.
public static EncryptionScopeResource GetEncryptionScopeResource(this ArmClient client, ResourceIdentifier id)
{
- return client.GetResourceClient(() =>
- {
- EncryptionScopeResource.ValidateResourceId(id);
- return new EncryptionScopeResource(client, id);
- }
- );
+ return GetMockableStorageArmClient(client).GetEncryptionScopeResource(id);
}
- #endregion
- /// Gets a collection of StorageAccountResources in the ResourceGroupResource.
+ ///
+ /// Gets a collection of StorageAccountResources in the ResourceGroupResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// An object representing collection of StorageAccountResources and their operations over a StorageAccountResource.
public static StorageAccountCollection GetStorageAccounts(this ResourceGroupResource resourceGroupResource)
{
- return GetResourceGroupResourceExtensionClient(resourceGroupResource).GetStorageAccounts();
+ return GetMockableStorageResourceGroupResource(resourceGroupResource).GetStorageAccounts();
}
///
@@ -298,17 +253,21 @@ public static StorageAccountCollection GetStorageAccounts(this ResourceGroupReso
/// StorageAccounts_GetProperties
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only.
/// May be used to expand the properties within account's properties. By default, data is not included when fetching properties. Currently we only support geoReplicationStats and blobRestoreStatus.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetStorageAccountAsync(this ResourceGroupResource resourceGroupResource, string accountName, StorageAccountExpand? expand = null, CancellationToken cancellationToken = default)
{
- return await resourceGroupResource.GetStorageAccounts().GetAsync(accountName, expand, cancellationToken).ConfigureAwait(false);
+ return await GetMockableStorageResourceGroupResource(resourceGroupResource).GetStorageAccountAsync(accountName, expand, cancellationToken).ConfigureAwait(false);
}
///
@@ -323,25 +282,35 @@ public static async Task> GetStorageAccountAsyn
/// StorageAccounts_GetProperties
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The name of the storage account within the specified resource group. Storage account names must be between 3 and 24 characters in length and use numbers and lower-case letters only.
/// May be used to expand the properties within account's properties. By default, data is not included when fetching properties. Currently we only support geoReplicationStats and blobRestoreStatus.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetStorageAccount(this ResourceGroupResource resourceGroupResource, string accountName, StorageAccountExpand? expand = null, CancellationToken cancellationToken = default)
{
- return resourceGroupResource.GetStorageAccounts().Get(accountName, expand, cancellationToken);
+ return GetMockableStorageResourceGroupResource(resourceGroupResource).GetStorageAccount(accountName, expand, cancellationToken);
}
- /// Gets a collection of DeletedAccountResources in the SubscriptionResource.
+ ///
+ /// Gets a collection of DeletedAccountResources in the SubscriptionResource.
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
+ ///
/// The instance the method will execute against.
/// An object representing collection of DeletedAccountResources and their operations over a DeletedAccountResource.
public static DeletedAccountCollection GetDeletedAccounts(this SubscriptionResource subscriptionResource)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetDeletedAccounts();
+ return GetMockableStorageSubscriptionResource(subscriptionResource).GetDeletedAccounts();
}
///
@@ -356,17 +325,21 @@ public static DeletedAccountCollection GetDeletedAccounts(this SubscriptionResou
/// DeletedAccounts_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location of the deleted storage account.
/// Name of the deleted storage account.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static async Task> GetDeletedAccountAsync(this SubscriptionResource subscriptionResource, AzureLocation location, string deletedAccountName, CancellationToken cancellationToken = default)
{
- return await subscriptionResource.GetDeletedAccounts().GetAsync(location, deletedAccountName, cancellationToken).ConfigureAwait(false);
+ return await GetMockableStorageSubscriptionResource(subscriptionResource).GetDeletedAccountAsync(location, deletedAccountName, cancellationToken).ConfigureAwait(false);
}
///
@@ -381,17 +354,21 @@ public static async Task> GetDeletedAccountAsyn
/// DeletedAccounts_Get
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location of the deleted storage account.
/// Name of the deleted storage account.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public static Response GetDeletedAccount(this SubscriptionResource subscriptionResource, AzureLocation location, string deletedAccountName, CancellationToken cancellationToken = default)
{
- return subscriptionResource.GetDeletedAccounts().Get(location, deletedAccountName, cancellationToken);
+ return GetMockableStorageSubscriptionResource(subscriptionResource).GetDeletedAccount(location, deletedAccountName, cancellationToken);
}
///
@@ -406,13 +383,17 @@ public static Response GetDeletedAccount(this Subscripti
/// Skus_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetSkusAsync(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetSkusAsync(cancellationToken);
+ return GetMockableStorageSubscriptionResource(subscriptionResource).GetSkusAsync(cancellationToken);
}
///
@@ -427,13 +408,17 @@ public static AsyncPageable GetSkusAsync(this Subscriptio
/// Skus_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetSkus(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetSkus(cancellationToken);
+ return GetMockableStorageSubscriptionResource(subscriptionResource).GetSkus(cancellationToken);
}
///
@@ -448,13 +433,17 @@ public static Pageable GetSkus(this SubscriptionResource
/// StorageAccounts_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetStorageAccountsAsync(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetStorageAccountsAsync(cancellationToken);
+ return GetMockableStorageSubscriptionResource(subscriptionResource).GetStorageAccountsAsync(cancellationToken);
}
///
@@ -469,13 +458,17 @@ public static AsyncPageable GetStorageAccountsAsync(this
/// StorageAccounts_List
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The cancellation token to use.
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetStorageAccounts(this SubscriptionResource subscriptionResource, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetStorageAccounts(cancellationToken);
+ return GetMockableStorageSubscriptionResource(subscriptionResource).GetStorageAccounts(cancellationToken);
}
///
@@ -490,6 +483,10 @@ public static Pageable GetStorageAccounts(this Subscript
/// Usages_ListByLocation
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location of the Azure Storage resource.
@@ -497,7 +494,7 @@ public static Pageable GetStorageAccounts(this Subscript
/// An async collection of that may take multiple service requests to iterate over.
public static AsyncPageable GetUsagesByLocationAsync(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetUsagesByLocationAsync(location, cancellationToken);
+ return GetMockableStorageSubscriptionResource(subscriptionResource).GetUsagesByLocationAsync(location, cancellationToken);
}
///
@@ -512,6 +509,10 @@ public static AsyncPageable GetUsagesByLocationAsync(this Subscrip
/// Usages_ListByLocation
///
///
+ /// -
+ /// Mocking
+ /// To mock this method, please mock instead.
+ ///
///
/// The instance the method will execute against.
/// The location of the Azure Storage resource.
@@ -519,7 +520,7 @@ public static AsyncPageable GetUsagesByLocationAsync(this Subscrip
/// A collection of that may take multiple service requests to iterate over.
public static Pageable GetUsagesByLocation(this SubscriptionResource subscriptionResource, AzureLocation location, CancellationToken cancellationToken = default)
{
- return GetSubscriptionResourceExtensionClient(subscriptionResource).GetUsagesByLocation(location, cancellationToken);
+ return GetMockableStorageSubscriptionResource(subscriptionResource).GetUsagesByLocation(location, cancellationToken);
}
}
}
diff --git a/samples/Azure.ResourceManager.Storage/Generated/FileServiceResource.cs b/samples/Azure.ResourceManager.Storage/Generated/FileServiceResource.cs
index 19da03b329c..43b229dca5e 100644
--- a/samples/Azure.ResourceManager.Storage/Generated/FileServiceResource.cs
+++ b/samples/Azure.ResourceManager.Storage/Generated/FileServiceResource.cs
@@ -93,7 +93,7 @@ internal static void ValidateResourceId(ResourceIdentifier id)
/// An object representing collection of FileShareResources and their operations over a FileShareResource.
public virtual FileShareCollection GetFileShares()
{
- return GetCachedClient(Client => new FileShareCollection(Client, Id));
+ return GetCachedClient(client => new FileShareCollection(client, Id));
}
///
@@ -113,8 +113,8 @@ public virtual FileShareCollection GetFileShares()
/// Optional, used to expand the properties within share's properties. Valid values are: stats. Should be passed as a string with delimiter ','.
/// Optional, used to retrieve properties of a snapshot.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetFileShareAsync(string shareName, string expand = null, string xMsSnapshot = null, CancellationToken cancellationToken = default)
{
@@ -138,8 +138,8 @@ public virtual async Task> GetFileShareAsync(string
/// Optional, used to expand the properties within share's properties. Valid values are: stats. Should be passed as a string with delimiter ','.
/// Optional, used to retrieve properties of a snapshot.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetFileShare(string shareName, string expand = null, string xMsSnapshot = null, CancellationToken cancellationToken = default)
{
diff --git a/samples/Azure.ResourceManager.Storage/Generated/StorageAccountResource.cs b/samples/Azure.ResourceManager.Storage/Generated/StorageAccountResource.cs
index 18f332e26d2..492967c4f96 100644
--- a/samples/Azure.ResourceManager.Storage/Generated/StorageAccountResource.cs
+++ b/samples/Azure.ResourceManager.Storage/Generated/StorageAccountResource.cs
@@ -122,7 +122,7 @@ public virtual ManagementPolicyResource GetManagementPolicy()
/// An object representing collection of BlobInventoryPolicyResources and their operations over a BlobInventoryPolicyResource.
public virtual BlobInventoryPolicyCollection GetBlobInventoryPolicies()
{
- return GetCachedClient(Client => new BlobInventoryPolicyCollection(Client, Id));
+ return GetCachedClient(client => new BlobInventoryPolicyCollection(client, Id));
}
///
@@ -171,7 +171,7 @@ public virtual Response GetBlobInventoryPolicy(Blob
/// An object representing collection of StoragePrivateEndpointConnectionResources and their operations over a StoragePrivateEndpointConnectionResource.
public virtual StoragePrivateEndpointConnectionCollection GetStoragePrivateEndpointConnections()
{
- return GetCachedClient(Client => new StoragePrivateEndpointConnectionCollection(Client, Id));
+ return GetCachedClient(client => new StoragePrivateEndpointConnectionCollection(client, Id));
}
///
@@ -189,8 +189,8 @@ public virtual StoragePrivateEndpointConnectionCollection GetStoragePrivateEndpo
///
/// The name of the private endpoint connection associated with the Azure resource.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetStoragePrivateEndpointConnectionAsync(string privateEndpointConnectionName, CancellationToken cancellationToken = default)
{
@@ -212,8 +212,8 @@ public virtual async Task> Ge
///
/// The name of the private endpoint connection associated with the Azure resource.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetStoragePrivateEndpointConnection(string privateEndpointConnectionName, CancellationToken cancellationToken = default)
{
@@ -224,7 +224,7 @@ public virtual Response GetStoragePriv
/// An object representing collection of ObjectReplicationPolicyResources and their operations over a ObjectReplicationPolicyResource.
public virtual ObjectReplicationPolicyCollection GetObjectReplicationPolicies()
{
- return GetCachedClient(Client => new ObjectReplicationPolicyCollection(Client, Id));
+ return GetCachedClient(client => new ObjectReplicationPolicyCollection(client, Id));
}
///
@@ -242,8 +242,8 @@ public virtual ObjectReplicationPolicyCollection GetObjectReplicationPolicies()
///
/// For the destination account, provide the value 'default'. Configure the policy on the destination account first. For the source account, provide the value of the policy ID that is returned when you download the policy that was defined on the destination account. The policy is downloaded as a JSON file.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetObjectReplicationPolicyAsync(string objectReplicationPolicyId, CancellationToken cancellationToken = default)
{
@@ -265,8 +265,8 @@ public virtual async Task> GetObjectRe
///
/// For the destination account, provide the value 'default'. Configure the policy on the destination account first. For the source account, provide the value of the policy ID that is returned when you download the policy that was defined on the destination account. The policy is downloaded as a JSON file.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetObjectReplicationPolicy(string objectReplicationPolicyId, CancellationToken cancellationToken = default)
{
@@ -277,7 +277,7 @@ public virtual Response GetObjectReplicationPol
/// An object representing collection of EncryptionScopeResources and their operations over a EncryptionScopeResource.
public virtual EncryptionScopeCollection GetEncryptionScopes()
{
- return GetCachedClient(Client => new EncryptionScopeCollection(Client, Id));
+ return GetCachedClient(client => new EncryptionScopeCollection(client, Id));
}
///
@@ -295,8 +295,8 @@ public virtual EncryptionScopeCollection GetEncryptionScopes()
///
/// The name of the encryption scope within the specified storage account. Encryption scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual async Task> GetEncryptionScopeAsync(string encryptionScopeName, CancellationToken cancellationToken = default)
{
@@ -318,8 +318,8 @@ public virtual async Task> GetEncryptionScopeA
///
/// The name of the encryption scope within the specified storage account. Encryption scope names must be between 3 and 63 characters in length and use numbers, lower-case letters and dash (-) only. Every dash (-) character must be immediately preceded and followed by a letter or number.
/// The cancellation token to use.
- /// is an empty string, and was expected to be non-empty.
/// is null.
+ /// is an empty string, and was expected to be non-empty.
[ForwardsClientCalls]
public virtual Response GetEncryptionScope(string encryptionScopeName, CancellationToken cancellationToken = default)
{
diff --git a/src/AutoRest.CSharp/Common/Generation/Writers/CodeWriterExtensions.cs b/src/AutoRest.CSharp/Common/Generation/Writers/CodeWriterExtensions.cs
index a08ddbfbbbf..9b985fa4dc3 100644
--- a/src/AutoRest.CSharp/Common/Generation/Writers/CodeWriterExtensions.cs
+++ b/src/AutoRest.CSharp/Common/Generation/Writers/CodeWriterExtensions.cs
@@ -628,10 +628,10 @@ public static IDisposable WriteCommonMethodWithoutValidation(this CodeWriter wri
return writer.WriteMethodDeclaration(signature.WithAsync(isAsync));
}
- public static IDisposable WriteCommonMethod(this CodeWriter writer, MethodSignature signature, FormattableString? returnDescription, bool isAsync, bool isPublicType)
+ public static IDisposable WriteCommonMethod(this CodeWriter writer, MethodSignature signature, FormattableString? returnDescription, bool isAsync, bool isPublicType, bool skipValidation = false)
{
var scope = WriteCommonMethodWithoutValidation(writer, signature, returnDescription, isAsync, isPublicType);
- if (isPublicType)
+ if (isPublicType && !skipValidation)
writer.WriteParametersValidation(signature.Parameters);
return scope;
diff --git a/src/AutoRest.CSharp/Common/Output/Expressions/KnownValueExpressions/BoolExpression.cs b/src/AutoRest.CSharp/Common/Output/Expressions/KnownValueExpressions/BoolExpression.cs
index b667c35e89d..e9cc9c1dc8f 100644
--- a/src/AutoRest.CSharp/Common/Output/Expressions/KnownValueExpressions/BoolExpression.cs
+++ b/src/AutoRest.CSharp/Common/Output/Expressions/KnownValueExpressions/BoolExpression.cs
@@ -7,5 +7,10 @@ namespace AutoRest.CSharp.Common.Output.Expressions.KnownValueExpressions
{
internal sealed record BoolExpression(ValueExpression Untyped) : TypedValueExpression(Untyped)
{
+ public BoolExpression Not() => new(new UnaryOperatorExpression("!", this, false));
+
+ public BoolExpression Or(ValueExpression other) => new(new BinaryOperatorExpression(" || ", this, other));
+
+ public BoolExpression And(ValueExpression other) => new(new BinaryOperatorExpression(" && ", this, other));
}
}
diff --git a/src/AutoRest.CSharp/Common/Output/Expressions/ValueExpressions/InvokeInstanceMethodExpression.cs b/src/AutoRest.CSharp/Common/Output/Expressions/ValueExpressions/InvokeInstanceMethodExpression.cs
index 1a2d54b6d3d..b5e7d88ab89 100644
--- a/src/AutoRest.CSharp/Common/Output/Expressions/ValueExpressions/InvokeInstanceMethodExpression.cs
+++ b/src/AutoRest.CSharp/Common/Output/Expressions/ValueExpressions/InvokeInstanceMethodExpression.cs
@@ -2,10 +2,17 @@
// Licensed under the MIT License. See License.txt in the project root for license information.
using System.Collections.Generic;
+using System.Linq;
using AutoRest.CSharp.Generation.Types;
+using AutoRest.CSharp.Output.Models;
namespace AutoRest.CSharp.Common.Output.Expressions.ValueExpressions
{
// [TODO]: AddConfigureAwaitFalse is needed only in docs. Consider removing.
- internal record InvokeInstanceMethodExpression(ValueExpression? InstanceReference, string MethodName, IReadOnlyList Arguments, IReadOnlyList? TypeArguments, bool CallAsAsync, bool AddConfigureAwaitFalse = true) : ValueExpression;
+ internal record InvokeInstanceMethodExpression(ValueExpression? InstanceReference, string MethodName, IReadOnlyList Arguments, IReadOnlyList? TypeArguments, bool CallAsAsync, bool AddConfigureAwaitFalse = true) : ValueExpression
+ {
+ public InvokeInstanceMethodExpression(ValueExpression? instanceReference, MethodSignature signature, IReadOnlyList arguments, bool addConfigureAwaitFalse = true) : this(instanceReference, signature.Name, arguments, signature.GenericArguments, signature.Modifiers.HasFlag(MethodSignatureModifiers.Async), addConfigureAwaitFalse) { }
+
+ public InvokeInstanceMethodExpression(ValueExpression? instanceReference, MethodSignature signature, bool addConfigureAwaitFalse = true) : this(instanceReference, signature, signature.Parameters.Select(p => (ValueExpression)p).ToArray(), addConfigureAwaitFalse) { }
+ }
}
diff --git a/src/AutoRest.CSharp/Common/Output/Expressions/ValueExpressions/ValueExpression.cs b/src/AutoRest.CSharp/Common/Output/Expressions/ValueExpressions/ValueExpression.cs
index 410aace5651..7e2e913242f 100644
--- a/src/AutoRest.CSharp/Common/Output/Expressions/ValueExpressions/ValueExpression.cs
+++ b/src/AutoRest.CSharp/Common/Output/Expressions/ValueExpressions/ValueExpression.cs
@@ -24,6 +24,8 @@ internal record ValueExpression
public ValueExpression NullableStructValue(CSharpType candidateType) => this is not ConstantExpression && candidateType is { IsNullable: true, IsValueType: true } ? new MemberExpression(this, nameof(Nullable.Value)) : this;
public StringExpression InvokeToString() => new(Invoke(nameof(ToString)));
+ public BoolExpression InvokeEquals(ValueExpression other) => new(Invoke(nameof(Equals), other));
+
public virtual ValueExpression Property(string propertyName)
=> new MemberExpression(this, propertyName);
diff --git a/src/AutoRest.CSharp/Common/Output/Models/MethodSignature.cs b/src/AutoRest.CSharp/Common/Output/Models/MethodSignature.cs
index 880b3ff9257..358226e1d60 100644
--- a/src/AutoRest.CSharp/Common/Output/Models/MethodSignature.cs
+++ b/src/AutoRest.CSharp/Common/Output/Models/MethodSignature.cs
@@ -4,10 +4,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Text;
using System.Threading.Tasks;
using AutoRest.CSharp.Generation.Types;
-using AutoRest.CSharp.Generation.Writers;
-using AutoRest.CSharp.Output.Models.Requests;
using AutoRest.CSharp.Output.Models.Shared;
using Azure;
using static AutoRest.CSharp.Output.Models.MethodSignatureModifiers;
@@ -96,5 +95,15 @@ private MethodSignature MakeSync()
: null
};
}
+
+ public string ToStringForDocs()
+ {
+ var builder = new StringBuilder(Name);
+ builder.Append("(");
+ var paramList = Parameters.Select(p => p.Type.ToStringForDocs());
+ builder.Append(string.Join(",", paramList));
+ builder.Append(")");
+ return builder.ToString();
+ }
}
}
diff --git a/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs b/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs
index 1c253a0cf99..4fa8de55c05 100644
--- a/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs
+++ b/src/AutoRest.CSharp/LowLevel/Generation/DpgClientWriter.cs
@@ -615,23 +615,13 @@ private void WriteSampleRefsIfNecessary(MethodSignature methodSignature, bool is
if (!samples.Any())
return;
- var docRef = GetMethodSignatureString(methodSignature);
+ var docRef = methodSignature.ToStringForDocs();
_writer.Line($"/// ");
_xmlDocWriter.AddMember(docRef);
_xmlDocWriter.AddExamples(samples);
}
- private static string GetMethodSignatureString(MethodSignature signature)
- {
- var builder = new StringBuilder(signature.Name);
- builder.Append("(");
- var paramList = signature.Parameters.Select(p => p.Type.ToStringForDocs());
- builder.Append(string.Join(",", paramList));
- builder.Append(")");
- return builder.ToString();
- }
-
private static void WriteProtocolMethodDocumentation(CodeWriter writer, LowLevelClientMethod clientMethod, bool isAsync)
{
var methodSignature = clientMethod.ProtocolMethodSignature.WithAsync(isAsync);
@@ -685,7 +675,7 @@ private static FormattableString BuildProtocolMethodSummary(MethodSignature meth
// we only append the relative convenience method information when the convenience method is public
if (clientMethod.ShouldGenerateConvenienceMethodRef())
{
- var convenienceDocRef = GetMethodSignatureString(clientMethod.ConvenienceMethod!.Signature.WithAsync(async));
+ var convenienceDocRef = clientMethod.ConvenienceMethod!.Signature.WithAsync(async).ToStringForDocs();
builder.AppendLine($"- {Environment.NewLine}{Environment.NewLine}Please try the simpler convenience overload with strongly typed models first.{Environment.NewLine}{Environment.NewLine}
");
}
builder.AppendLine($"");
diff --git a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs
index d142035d762..990c4d8692c 100644
--- a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs
+++ b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtOutputLibrary.cs
@@ -19,9 +19,6 @@
using AutoRest.CSharp.Output.Models.Requests;
using AutoRest.CSharp.Output.Models.Types;
using AutoRest.CSharp.Utilities;
-using Azure.ResourceManager;
-using Azure.ResourceManager.ManagementGroups;
-using Azure.ResourceManager.Resources;
using Humanizer.Inflections;
using static AutoRest.CSharp.Mgmt.Decorator.Transformer.PartialResourceResolver;
@@ -431,7 +428,7 @@ private bool ShouldGenerateChildrenForType(Type armCoreType)
=> !Configuration.MgmtConfiguration.IsArmCore || armCoreType.Namespace != MgmtContext.Context.DefaultNamespace;
public IEnumerable Extensions => ExtensionBuilder.Extensions;
- public IEnumerable ExtensionClients => ExtensionBuilder.ExtensionClients;
+ public IEnumerable MockableExtensions => ExtensionBuilder.MockableExtensions;
public MgmtExtensionWrapper ExtensionWrapper => ExtensionBuilder.ExtensionWrapper;
public MgmtExtension GetExtension(Type armCoreType) => ExtensionBuilder.GetExtension(armCoreType);
diff --git a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtTarget.cs b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtTarget.cs
index 8974ceb4262..5f78ee6bab2 100644
--- a/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtTarget.cs
+++ b/src/AutoRest.CSharp/Mgmt/AutoRest/MgmtTarget.cs
@@ -188,7 +188,7 @@ public static async Task ExecuteAsync(GeneratedCodeWorkspace project, CodeModel
}
// write extension class
- WriteExtensions(project, isArmCore, MgmtContext.Library.ExtensionWrapper, MgmtContext.Library.Extensions, MgmtContext.Library.ExtensionClients);
+ WriteExtensions(project, isArmCore, MgmtContext.Library.ExtensionWrapper, MgmtContext.Library.Extensions, MgmtContext.Library.MockableExtensions);
var lroWriter = new MgmtLongRunningOperationWriter(true);
lroWriter.Write();
@@ -232,7 +232,7 @@ public static async Task ExecuteAsync(GeneratedCodeWorkspace project, CodeModel
await project.PostProcessAsync(new MgmtPostProcessor(modelsToKeep, modelFactoryProvider?.FullName));
}
- private static void WriteExtensions(GeneratedCodeWorkspace project, bool isArmCore, MgmtExtensionWrapper extensionWrapper, IEnumerable extensions, IEnumerable extensionClients)
+ private static void WriteExtensions(GeneratedCodeWorkspace project, bool isArmCore, MgmtExtensionWrapper extensionWrapper, IEnumerable extensions, IEnumerable mockableExtensions)
{
if (isArmCore)
{
@@ -253,12 +253,12 @@ private static void WriteExtensions(GeneratedCodeWorkspace project, bool isArmCo
WriteExtensionFile(project, new MgmtExtensionWrapperWriter(extensionWrapper));
// and we write ExtensionClients
- foreach (var extensionClient in extensionClients)
+ foreach (var mockableExtension in mockableExtensions)
{
- if (!extensionClient.IsEmpty)
+ if (!mockableExtension.IsEmpty)
{
- MgmtReport.Instance.ExtensionSection.Add(extensionClient.ResourceName, new ExtensionItem(extensionClient, MgmtReport.Instance.TransformSection));
- WriteExtensionFile(project, new MgmtExtensionClientWriter(extensionClient));
+ MgmtReport.Instance.ExtensionSection.Add(mockableExtension.ResourceName, new ExtensionItem(mockableExtension, MgmtReport.Instance.TransformSection));
+ WriteExtensionFile(project, MgmtMockableExtensionResourceWriter.GetWriter(mockableExtension));
}
}
}
diff --git a/src/AutoRest.CSharp/Mgmt/Decorator/ParameterMappingBuilder.cs b/src/AutoRest.CSharp/Mgmt/Decorator/ParameterMappingBuilder.cs
index 07190b1a56a..1d5c3c6de60 100644
--- a/src/AutoRest.CSharp/Mgmt/Decorator/ParameterMappingBuilder.cs
+++ b/src/AutoRest.CSharp/Mgmt/Decorator/ParameterMappingBuilder.cs
@@ -29,17 +29,16 @@ internal static class ParameterMappingBuilder
/// method using their "value expression"s
///
/// The contextual path, which is usually the path creating a resource
- /// The
/// The variable name of the Id variable
///
- public static IEnumerable BuildContextualParameters(this RequestPath requestPath, string idVariableName)
+ public static IEnumerable BuildContextualParameters(this RequestPath requestPath, FormattableString idVariableName)
{
var stack = new Stack();
BuildContextualParameterMappingHierarchy(requestPath, stack, idVariableName);
return stack;
}
- private static void BuildContextualParameterMappingHierarchy(RequestPath current, Stack parameterMappingStack, string idVariableName = "Id", string invocationSuffix = "")
+ private static void BuildContextualParameterMappingHierarchy(RequestPath current, Stack parameterMappingStack, FormattableString idVariableName, string invocationSuffix = "")
{
// Check if the current path is a scope parameter
if (current.IsRawParameterizedScope())
diff --git a/src/AutoRest.CSharp/Mgmt/Decorator/ParentDetection.cs b/src/AutoRest.CSharp/Mgmt/Decorator/ParentDetection.cs
index ed5988e0943..3728e5b737d 100644
--- a/src/AutoRest.CSharp/Mgmt/Decorator/ParentDetection.cs
+++ b/src/AutoRest.CSharp/Mgmt/Decorator/ParentDetection.cs
@@ -28,7 +28,6 @@ internal static class ParentDetection
/// This is not initialized while the TypeProviders are constructing and can only be used in the writers.
///
///
- ///
///
public static IEnumerable GetParents(this Resource resource)
{
diff --git a/src/AutoRest.CSharp/Mgmt/Decorator/ResourceTypeBuilder.cs b/src/AutoRest.CSharp/Mgmt/Decorator/ResourceTypeBuilder.cs
index 1a07ad744e2..8ec807eb986 100644
--- a/src/AutoRest.CSharp/Mgmt/Decorator/ResourceTypeBuilder.cs
+++ b/src/AutoRest.CSharp/Mgmt/Decorator/ResourceTypeBuilder.cs
@@ -45,19 +45,12 @@ private static ResourceTypeSegment CalculateResourceType(RequestPath requestPath
return ResourceTypeSegment.ParseRequestPath(requestPath);
}
- public static ResourceTypeSegment GetResourceType(this IEnumerable requestPaths)
+ public static ICollection? GetScopeTypeStrings(IEnumerable? scopeTypes)
{
- var resourceTypes = requestPaths.Select(path => path.GetResourceType()).Distinct();
+ if (scopeTypes == null || !scopeTypes.Any() || scopeTypes.Contains(ResourceTypeSegment.Any))
+ return null;
- if (resourceTypes.Count() > 1)
- throw new InvalidOperationException($"Request path(s) {string.Join(", ", requestPaths)} contain multiple resource types in it ({string.Join(", ", resourceTypes)}), please double check and override it in `request-path-to-resource-type` section.");
-
- var resourceType = resourceTypes.First();
-
- if (resourceType == ResourceTypeSegment.Scope)
- throw new InvalidOperationException($"Request path(s) {string.Join(", ", requestPaths)} is a 'ById' resource, we cannot derive a resource type from its request path, please double check and override it in `request-path-to-resource-type` section.");
-
- return resourceType;
+ return scopeTypes.Select(type => (FormattableString)$"{type}").ToArray();
}
}
}
diff --git a/src/AutoRest.CSharp/Mgmt/Generation/ArmClientExtensionWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/ArmClientExtensionWriter.cs
index a5cc8fdf032..cc88f2e3a43 100644
--- a/src/AutoRest.CSharp/Mgmt/Generation/ArmClientExtensionWriter.cs
+++ b/src/AutoRest.CSharp/Mgmt/Generation/ArmClientExtensionWriter.cs
@@ -6,15 +6,15 @@
using AutoRest.CSharp.Generation.Writers;
using AutoRest.CSharp.Mgmt.AutoRest;
using AutoRest.CSharp.Mgmt.Decorator;
+using AutoRest.CSharp.Mgmt.Models;
using AutoRest.CSharp.Mgmt.Output;
-using AutoRest.CSharp.Utilities;
using Azure.Core;
namespace AutoRest.CSharp.Mgmt.Generation
{
internal sealed class ArmClientExtensionWriter : MgmtExtensionWriter
{
- private MgmtExtension This { get; }
+ private ArmClientExtension This { get; }
public ArmClientExtensionWriter(ArmClientExtension extension) : this(new CodeWriter(), extension)
{
@@ -27,13 +27,22 @@ public ArmClientExtensionWriter(CodeWriter writer, ArmClientExtension extension)
protected internal override void WriteImplementations()
{
- foreach (var resource in MgmtContext.Library.ArmResources)
+ base.WriteImplementations();
+
+ foreach (var method in This.ArmResourceMethods)
+ {
+ _writer.WriteMethodDocumentation(method.Signature);
+ _writer.WriteMethod(method);
+ }
+ }
+
+ protected override void WriteMethod(MgmtClientOperation clientOperation, bool isAsync)
+ {
+ using (_writer.WriteCommonMethod(clientOperation.MethodSignature, null, isAsync, This.Accessibility == "public", SkipParameterValidation))
{
- _writer.Line($"#region {resource.Type.Name}");
- WriteGetResourceFromIdMethod(resource);
- _writer.LineRaw("#endregion");
- _writer.Line();
+ WriteMethodBodyWrapper(clientOperation.MethodSignature, isAsync, clientOperation.IsPagingOperation);
}
+ _writer.Line();
}
private void WriteGetResourceFromIdMethod(Resource resource)
@@ -51,15 +60,12 @@ private void WriteGetResourceFromIdMethod(Resource resource)
_writer.WriteXmlDocumentationReturns($"Returns a object.");
var modifier = IsArmCore ? "virtual" : "static";
var instanceParameter = IsArmCore ? string.Empty : $"this {This.ExtensionParameter.Type.Name} {This.ExtensionParameter.Name}, ";
- using (_writer.Scope($"public {modifier} {resource.Type} Get{resource.Type.Name}({instanceParameter}{typeof(Azure.Core.ResourceIdentifier)} id)"))
+ using (_writer.Scope($"public {modifier} {resource.Type} Get{resource.Type.Name}({instanceParameter}{typeof(ResourceIdentifier)} id)"))
{
if (!IsArmCore)
{
- using (_writer.Scope($"return {This.ExtensionParameter.Name}.GetResourceClient<{resource.Type}>(() =>"))
- {
- WriteGetter(resource, $"{ArmClientReference.ToVariableName()}");
- }
- _writer.Line($");");
+ _writer.AppendRaw("return ")
+ .Append($"{This.MockableExtension.FactoryMethodName}({This.ExtensionParameter.Name}).Get{resource.Type.Name}(id);");
}
else
{
diff --git a/src/AutoRest.CSharp/Mgmt/Generation/ArmClientMockingExtensionWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/ArmClientMockingExtensionWriter.cs
new file mode 100644
index 00000000000..02753fcdb69
--- /dev/null
+++ b/src/AutoRest.CSharp/Mgmt/Generation/ArmClientMockingExtensionWriter.cs
@@ -0,0 +1,126 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using AutoRest.CSharp.Generation.Writers;
+using AutoRest.CSharp.Mgmt.AutoRest;
+using AutoRest.CSharp.Mgmt.Decorator;
+using AutoRest.CSharp.Mgmt.Models;
+using AutoRest.CSharp.Mgmt.Output;
+using AutoRest.CSharp.Output.Models.Shared;
+using Azure.Core;
+
+namespace AutoRest.CSharp.Mgmt.Generation
+{
+ internal sealed class ArmClientMockingExtensionWriter : MgmtMockableExtensionResourceWriter
+ {
+ private readonly Parameter _scopeParameter;
+ private MgmtMockableArmClient This { get; }
+
+ public ArmClientMockingExtensionWriter(MgmtMockableArmClient extensionClient) : base(extensionClient)
+ {
+ This = extensionClient;
+ _scopeParameter = new Parameter(
+ Name: "scope",
+ Description: $"The scope that the resource will apply against.",
+ Type: typeof(ResourceIdentifier),
+ DefaultValue: null,
+ Validation: ValidationType.None,
+ Initializer: null);
+ }
+
+ protected override void WriteCtors()
+ {
+ base.WriteCtors();
+
+ if (This.ArmClientCtor is { } armClientCtor)
+ {
+ // for ArmClientExtensionClient, we write an extra ctor that only takes ArmClient as parameter
+ var ctor = armClientCtor with
+ {
+ Parameters = new[] { MgmtTypeProvider.ArmClientParameter },
+ Initializer = new(false, new FormattableString[] { $"{MgmtTypeProvider.ArmClientParameter.Name:I}", $"{typeof(ResourceIdentifier)}.{nameof(ResourceIdentifier.Root)}" })
+ };
+
+ using (_writer.WriteMethodDeclaration(ctor))
+ {
+ // it does not need a body
+ }
+ }
+ }
+
+ protected internal override void WriteImplementations()
+ {
+ base.WriteImplementations();
+
+ foreach (var method in This.ArmResourceMethods)
+ {
+ _writer.WriteMethodDocumentation(method.Signature);
+ _writer.WriteMethod(method);
+ }
+ }
+
+ protected override IDisposable WriteCommonMethod(MgmtClientOperation clientOperation, bool isAsync)
+ {
+ var originalSignature = clientOperation.MethodSignature;
+ var signature = originalSignature with
+ {
+ Parameters = originalSignature.Parameters.Prepend(MgmtTypeProvider.ScopeParameter).ToArray()
+ };
+ _writer.Line();
+ var returnDescription = clientOperation.ReturnsDescription?.Invoke(isAsync);
+ return _writer.WriteCommonMethod(signature, returnDescription, isAsync, This.Accessibility == "public", SkipParameterValidation);
+ }
+
+ protected override WriteMethodDelegate GetMethodDelegate(bool isLongRunning, bool isPaging)
+ {
+ var writeBody = base.GetMethodDelegate(isLongRunning, isPaging);
+ return (clientOperation, diagnostic, isAsync) =>
+ {
+ var requestPaths = clientOperation.Select(restOperation => restOperation.RequestPath);
+ var scopeResourceTypes = requestPaths.Select(requestPath => requestPath.GetParameterizedScopeResourceTypes() ?? Enumerable.Empty()).SelectMany(types => types).Distinct();
+ var scopeTypes = ResourceTypeBuilder.GetScopeTypeStrings(scopeResourceTypes);
+
+ WriteScopeResourceTypesValidation(_scopeParameter.Name, scopeTypes);
+
+ writeBody(clientOperation, diagnostic, isAsync);
+ };
+ }
+
+ private void WriteScopeResourceTypesValidation(string parameterName, ICollection? types)
+ {
+ if (types == null)
+ return;
+ // validate the scope types
+ var typeAssertions = types.Select(type => (FormattableString)$"!{parameterName:I}.ResourceType.Equals(\"{type}\")").ToArray();
+ var assertion = typeAssertions.Join(" || ");
+ using (_writer.Scope($"if ({assertion})"))
+ {
+ _writer.Line($"throw new {typeof(ArgumentException)}({typeof(string)}.{nameof(string.Format)}(\"Invalid resource type {{0}} expected {types.Join(", ", " or ")}\", {parameterName:I}.ResourceType));");
+ }
+ }
+
+ private void WriteGetResourceFromIdMethod(Resource resource)
+ {
+ List lines = new List();
+ string an = resource.Type.Name.StartsWithVowel() ? "an" : "a";
+ lines.Add($"Gets an object representing {an} along with the instance operations that can be performed on it but with no data.");
+ lines.Add($"You can use to create {an} from its components.");
+ _writer.WriteXmlDocumentationSummary(FormattableStringHelpers.Join(lines, "\r\n"));
+ _writer.WriteXmlDocumentationParameter("id", $"The resource ID of the resource to get.");
+ _writer.WriteXmlDocumentationReturns($"Returns a object.");
+ using (_writer.Scope($"public virtual {resource.Type} Get{resource.Type.Name}({typeof(Azure.Core.ResourceIdentifier)} id)"))
+ {
+ WriteGetter(resource, "Client");
+ }
+ }
+
+ private void WriteGetter(Resource resource, string armVariable)
+ {
+ _writer.Line($"{resource.Type.Name}.ValidateResourceId(id);");
+ _writer.Line($"return new {resource.Type.Name}({armVariable}, id);");
+ }
+ }
+}
diff --git a/src/AutoRest.CSharp/Mgmt/Generation/ArmResourceExtensionWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/ArmResourceExtensionWriter.cs
deleted file mode 100644
index 444b62c1e0f..00000000000
--- a/src/AutoRest.CSharp/Mgmt/Generation/ArmResourceExtensionWriter.cs
+++ /dev/null
@@ -1,264 +0,0 @@
-// Copyright (c) Microsoft Corporation. All rights reserved.
-// Licensed under the MIT License.
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using AutoRest.CSharp.Common.Input;
-using AutoRest.CSharp.Generation.Writers;
-using AutoRest.CSharp.Input;
-using AutoRest.CSharp.Mgmt.Decorator;
-using AutoRest.CSharp.Mgmt.Models;
-using AutoRest.CSharp.Mgmt.Output;
-using AutoRest.CSharp.Output.Models;
-using AutoRest.CSharp.Output.Models.Shared;
-using AutoRest.CSharp.Utilities;
-using Azure.Core;
-using Azure.ResourceManager;
-
-namespace AutoRest.CSharp.Mgmt.Generation
-{
- ///
- /// The is writing the extension methods differently from
- /// The extension methods in ArmResourceExtension will have two versions:
- /// public static Response Foo(this ArmClient client, ResourceIdentifier scope)
- /// and
- /// public static Response Foo(this ArmResource armResource)
- /// The extending version is depending if we have the configuration set.
- /// Since the generated methods are different from regular extension classes, we have this writer to handle those methods.
- /// Because in Azure.ResourceManager (ArmCore) we will never generate extension method, instead we just generate instance method in partial classes, this class should be never used when IsArmCore is true
- ///
- internal sealed class ArmResourceExtensionWriter : MgmtExtensionWriter
- {
- private ArmResourceExtension This { get; }
-
- private readonly Parameter _armClientParameter;
- private readonly Parameter _scopeParameter;
-
- public ArmResourceExtensionWriter(CodeWriter writer, ArmResourceExtension extension)
- : base(writer, extension)
- {
- // we never use this class in ArmCore, see the description on this class for details
- Debug.Assert(!Configuration.MgmtConfiguration.IsArmCore);
-
- This = extension;
- _armClientParameter = This.ExtensionParameter with
- {
- Name = "client",
- Description = $"The instance the method will execute against.",
- Type = typeof(ArmClient),
- };
- _scopeParameter = new Parameter(
- Name: "scope",
- Description: $"The scope that the resource will apply against.",
- Type: typeof(ResourceIdentifier),
- DefaultValue: null,
- Validation: ValidationType.None,
- Initializer: null);
- }
-
- private static bool ShouldGenerateArmResourceExtensionMethod(IEnumerable requestPaths)
- => requestPaths.Any(ShouldGenerateArmResourceExtensionMethod);
-
- private static bool ShouldGenerateArmResourceExtensionMethod(RequestPath requestPath)
- => Configuration.MgmtConfiguration.GenerateArmResourceExtensions.Contains(requestPath);
-
- protected override void WriteMethod(MgmtClientOperation clientOperation, bool isAsync)
- {
- var requestPaths = clientOperation.Select(restOperation => restOperation.RequestPath);
- if (ShouldGenerateArmResourceExtensionMethod(requestPaths))
- {
- base.WriteMethod(clientOperation, isAsync);
- _writer.Line();
- }
-
- var scopeResourceTypes = requestPaths.Select(requestPath => requestPath.GetParameterizedScopeResourceTypes() ?? Enumerable.Empty()).SelectMany(types => types).Distinct();
- var scopeTypes = GetScopeTypeStrings(scopeResourceTypes);
- var originalSignature = clientOperation.MethodSignature;
- var signature = new MethodSignature(
- originalSignature.Name,
- originalSignature.Summary,
- originalSignature.Description,
- originalSignature.Modifiers,
- originalSignature.ReturnType,
- originalSignature.ReturnDescription,
- GetScopeVersionMethodParameters(originalSignature.Parameters.Skip(1), scopeTypes),
- originalSignature.Attributes);
- using (_writer.WriteCommonMethod(signature, null, isAsync, This.Accessibility == "public"))
- {
- WriteMethodBodyWrapper(signature, isAsync, clientOperation.IsPagingOperation, scopeTypes);
- }
- _writer.Line();
- }
-
- protected override void WriteSingletonResourceGetMethod(Resource resource)
- {
- if (ShouldGenerateArmResourceExtensionMethod(resource.RequestPath))
- {
- base.WriteSingletonResourceGetMethod(resource);
- _writer.Line();
- }
-
- var scopeTypes = GetScopeTypeStrings(resource.RequestPath.GetParameterizedScopeResourceTypes());
- var signature = new MethodSignature(
- $"Get{resource.ResourceName}",
- null,
- $"Gets an object representing a {resource.Type.Name} along with the instance operations that can be performed on it in the {This.ResourceName}.",
- GetMethodModifiers(),
- resource.Type,
- $"Returns a object.",
- GetParametersForSingletonEntry(scopeTypes));
- using (_writer.WriteCommonMethod(signature, null, false, This.Accessibility == "public"))
- {
- WriteMethodBodyWrapper(signature, false, false, scopeTypes);
- }
- }
-
- protected override void WriteResourceCollectionGetMethod(Resource resource)
- {
- if (ShouldGenerateArmResourceExtensionMethod(resource.RequestPath))
- {
- base.WriteResourceCollectionGetMethod(resource);
- _writer.Line();
- }
-
- var scopeTypes = GetScopeTypeStrings(resource.RequestPath.GetParameterizedScopeResourceTypes());
- var resourceCollection = resource.ResourceCollection!;
- var signature = new MethodSignature(
- $"{GetResourceCollectionMethodName(resourceCollection)}",
- null,
- $"Gets a collection of {resource.Type.Name.LastWordToPlural()} in the {This.ResourceName}.",
- GetMethodModifiers(),
- resourceCollection.Type,
- $"An object representing collection of {resource.Type.Name.LastWordToPlural()} and their operations over a {resource.Type.Name}.",
- GetParametersForCollectionEntry(resourceCollection, scopeTypes));
- using (_writer.WriteCommonMethod(signature, null, false, This.Accessibility == "public"))
- {
- WriteMethodBodyWrapper(signature, false, false, scopeTypes);
- }
- }
-
- protected override void WriteChildResourceGetMethod(ResourceCollection resourceCollection, bool isAsync)
- {
- if (ShouldGenerateArmResourceExtensionMethod(resourceCollection.Resource.RequestPath))
- {
- base.WriteChildResourceGetMethod(resourceCollection, isAsync);
- _writer.Line();
- }
-
- var scopeTypes = GetScopeTypeStrings(resourceCollection.RequestPath.GetParameterizedScopeResourceTypes());
- var getOperation = resourceCollection.GetOperation;
- // Copy the original method signature with changes in name and modifier (e.g. when adding into extension class, the modifier should be static)
- var methodSignature = getOperation.MethodSignature with
- {
- // name after `Get{ResourceName}`
- Name = $"{getOperation.MethodSignature.Name}{resourceCollection.Resource.ResourceName}",
- Modifiers = GetMethodModifiers(),
- // There could be parameters to get resource collection
- Parameters = GetParametersForCollectionEntry(resourceCollection, scopeTypes).Concat(GetParametersForResourceEntry(resourceCollection)).ToArray(),
- Attributes = new[] { new CSharpAttribute(typeof(ForwardsClientCallsAttribute)) }
- };
-
- _writer.Line();
- using (_writer.WriteCommonMethodWithoutValidation(methodSignature, getOperation.ReturnsDescription != null ? getOperation.ReturnsDescription(isAsync) : null, isAsync, This.Accessibility == "public"))
- {
- WriteResourceEntry(resourceCollection, isAsync, scopeTypes);
- }
- }
-
- private void WriteResourceEntry(ResourceCollection resourceCollection, bool isAsync, ICollection? types)
- {
- WriteScopeResourceTypesValidation(_scopeParameter.Name, types);
- var operation = resourceCollection.GetOperation;
- string configureAwait = isAsync & !operation.IsPagingOperation ? ".ConfigureAwait(false)" : string.Empty;
-
- _writer.AppendRaw("return ")
- .AppendRawIf("await ", isAsync && !operation.IsPagingOperation)
- .Append($"{GetResourceCollectionMethodName(resourceCollection)}(");
- foreach (var parameter in GetParametersForCollectionEntry(resourceCollection, types))
- {
- _writer.Append($"{parameter.Name:I},");
- }
- _writer.RemoveTrailingComma();
- _writer.Append($").{operation.MethodSignature.WithAsync(isAsync).Name}(");
- foreach (var parameter in operation.MethodSignature.Parameters)
- {
- _writer.Append($"{parameter.Name},");
- }
-
- _writer.RemoveTrailingComma();
- _writer.AppendRaw(")")
- .AppendRawIf(".ConfigureAwait(false)", isAsync && !operation.IsPagingOperation)
- .LineRaw(";");
- }
-
- private void WriteMethodBodyWrapper(MethodSignature signature, bool isAsync, bool isPaging, ICollection? scopeTypes)
- {
- WriteScopeResourceTypesValidation(_scopeParameter.Name, scopeTypes);
-
- var extensionClient = This.GetExtensionClient(null);
-
- _writer.AppendRaw("return ")
- .AppendRawIf("await ", isAsync && !isPaging)
- .Append($"{extensionClient.FactoryMethodName}({_armClientParameter.Name}, {_scopeParameter.Name}).{CreateMethodName(signature.Name, isAsync)}(");
-
- foreach (var parameter in signature.Parameters.Skip(2))
- {
- _writer.Append($"{parameter.Name},");
- }
-
- _writer.RemoveTrailingComma();
- _writer.AppendRaw(")")
- .AppendRawIf(".ConfigureAwait(false)", isAsync && !isPaging)
- .LineRaw(";");
- }
-
- private ICollection? GetScopeTypeStrings(IEnumerable? scopeTypes)
- {
- if (scopeTypes == null || scopeTypes.Contains(ResourceTypeSegment.Any))
- return null;
-
- return scopeTypes.Select(type => (FormattableString)$"{type}").ToArray();
- }
-
- private void WriteScopeResourceTypesValidation(string parameterName, ICollection? types)
- {
- if (types == null)
- return;
- // validate the scope types
- var typeAssertions = types.Select(type => (FormattableString)$"!{parameterName:I}.ResourceType.Equals(\"{type}\")").ToArray();
- var assertion = typeAssertions.Join(" || ");
- using (_writer.Scope($"if ({assertion})"))
- {
- _writer.Line($"throw new {typeof(ArgumentException)}({typeof(string)}.{nameof(string.Format)}(\"Invalid resource type {{0}} expected {types.Join(", ", " or ")}\", {parameterName:I}.ResourceType));");
- }
- }
-
- ///
- /// Returns the parameters by the specific scope
- ///
- ///
- ///
- private Parameter[] GetScopeVersionMethodParameters(IEnumerable parameters, ICollection? types)
- {
- var scopeParameter = GetScopeParameter(types);
- return parameters.Prepend(scopeParameter).Prepend(_armClientParameter).ToArray();
- }
-
- private Parameter[] GetParametersForSingletonEntry(ICollection? types) => GetScopeVersionMethodParameters(Enumerable.Empty(), types);
-
- private Parameter[] GetParametersForCollectionEntry(ResourceCollection resourceCollection, ICollection? types) => GetScopeVersionMethodParameters(resourceCollection.ExtraConstructorParameters, types);
-
- private Parameter GetScopeParameter(ICollection? types)
- {
- if (types == null)
- return _scopeParameter;
-
- return _scopeParameter with
- {
- Description = $"{_scopeParameter.Description} Expected resource type includes the following: {types.Join(", ", " or ")}"
- };
- }
- }
-}
diff --git a/src/AutoRest.CSharp/Mgmt/Generation/MgmtClientBaseWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/MgmtClientBaseWriter.cs
index 3e1005c7dd9..beb62fc7d9d 100644
--- a/src/AutoRest.CSharp/Mgmt/Generation/MgmtClientBaseWriter.cs
+++ b/src/AutoRest.CSharp/Mgmt/Generation/MgmtClientBaseWriter.cs
@@ -15,7 +15,6 @@
using AutoRest.CSharp.Mgmt.Models;
using AutoRest.CSharp.Mgmt.Output;
using AutoRest.CSharp.Mgmt.Output.Models;
-using AutoRest.CSharp.Output.Models;
using AutoRest.CSharp.Output.Models.Requests;
using AutoRest.CSharp.Output.Models.Shared;
using AutoRest.CSharp.Utilities;
@@ -24,7 +23,6 @@
using Azure.ResourceManager.ManagementGroups;
using Azure.ResourceManager.Resources;
using static AutoRest.CSharp.Mgmt.Decorator.ParameterMappingBuilder;
-using static AutoRest.CSharp.Output.Models.MethodSignatureModifiers;
namespace AutoRest.CSharp.Mgmt.Generation
{
@@ -43,6 +41,8 @@ internal abstract class MgmtClientBaseWriter : ClientWriter
protected virtual bool UseField => true;
+ protected virtual bool SkipParameterValidation => false;
+
public string FileName { get; }
protected MgmtClientBaseWriter(CodeWriter writer, MgmtTypeProvider provider)
@@ -78,7 +78,12 @@ protected internal virtual void WriteImplementations()
WritePrivateHelpers();
- WriteChildResourceEntries();
+ _writer.Line(); // TODO -- add this here to minimize the amount of code changes, this could be removed after future refactor
+ foreach (var method in This.ChildResourceEntryMethods)
+ {
+ _writer.WriteMethodDocumentation(method.Signature);
+ _writer.WriteMethod(method);
+ }
WriteOperations();
@@ -244,144 +249,6 @@ private void WriteRestClientConstructorPair(MgmtRestClient restClient, Resource?
return null;
}
- protected virtual void WriteChildResourceEntries()
- {
- foreach (var resource in This.ChildResources)
- {
- _writer.Line();
- if (resource.IsSingleton)
- {
- WriteSingletonResourceGetMethod(resource);
- }
- else if (resource.ResourceCollection is not null)
- {
- WriteResourceCollectionGetMethod(resource);
-
- if (This.HasChildResourceGetMethods)
- {
- WriteChildResourceGetMethod(resource.ResourceCollection, true);
- WriteChildResourceGetMethod(resource.ResourceCollection, false);
- }
- }
- }
- _writer.Line();
- }
-
- protected virtual void WriteSingletonResourceGetMethod(Resource resource)
- {
- var signature = new MethodSignature(
- $"Get{resource.ResourceName}",
- null,
- $"Gets an object representing a {resource.Type.Name} along with the instance operations that can be performed on it in the {This.ResourceName}.",
- GetMethodModifiers(),
- resource.Type,
- $"Returns a object.",
- GetParametersForSingletonEntry());
- using (_writer.WriteCommonMethod(signature, null, false, This.Accessibility == "public"))
- {
- WriteSingletonResourceEntry(resource, resource.SingletonResourceIdSuffix!, signature);
- }
- }
-
- protected virtual void WriteResourceCollectionGetMethod(Resource resource)
- {
- var resourceCollection = resource.ResourceCollection!;
- var signature = new MethodSignature(
- $"{GetResourceCollectionMethodName(resourceCollection)}",
- null,
- $"Gets a collection of {resource.Type.Name.LastWordToPlural()} in the {This.ResourceName}.",
- GetMethodModifiers(),
- resourceCollection.Type,
- $"An object representing collection of {resource.Type.Name.LastWordToPlural()} and their operations over a {resource.Type.Name}.",
- GetParametersForCollectionEntry(resourceCollection));
- using (_writer.WriteCommonMethod(signature, null, false, This.Accessibility == "public"))
- {
- WriteResourceCollectionEntry(resourceCollection, signature);
- }
- }
-
- protected virtual void WriteChildResourceGetMethod(ResourceCollection resourceCollection, bool isAsync)
- {
- var getOperation = resourceCollection.GetOperation;
- // Copy the original method signature with changes in name and modifier (e.g. when adding into extension class, the modifier should be static)
- var methodSignature = getOperation.MethodSignature with
- {
- // name after `Get{ResourceName}`
- Name = $"{getOperation.MethodSignature.Name}{resourceCollection.Resource.ResourceName}",
- Modifiers = GetMethodModifiers(),
- // There could be parameters to get resource collection
- Parameters = GetParametersForCollectionEntry(resourceCollection).Concat(GetParametersForResourceEntry(resourceCollection)).Distinct().ToArray(),
- Attributes = new[] { new CSharpAttribute(typeof(ForwardsClientCallsAttribute)) }
- };
-
- _writer.Line();
- using (_writer.WriteCommonMethodWithoutValidation(methodSignature, getOperation.ReturnsDescription?.Invoke(isAsync), isAsync, This.Accessibility == "public"))
- {
- WriteResourceEntry(resourceCollection, isAsync);
- }
- }
-
- protected virtual void WriteResourceEntry(ResourceCollection resourceCollection, bool isAsync)
- {
- var operation = resourceCollection.GetOperation;
- string awaitText = isAsync & !operation.IsPagingOperation ? " await" : string.Empty;
- string configureAwait = isAsync & !operation.IsPagingOperation ? ".ConfigureAwait(false)" : string.Empty;
- var arguments = string.Join(", ", operation.MethodSignature.Parameters.Select(p => p.Name));
- _writer.Line($"return{awaitText} {GetResourceCollectionMethodName(resourceCollection)}({GetResourceCollectionMethodArgumentList(resourceCollection)}).{operation.MethodSignature.WithAsync(isAsync).Name}({arguments}){configureAwait};");
- }
-
- protected string GetResourceCollectionMethodName(ResourceCollection resourceCollection)
- {
- return $"Get{resourceCollection.Resource.ResourceName.ResourceNameToPlural()}";
- }
-
- protected string GetResourceCollectionMethodArgumentList(ResourceCollection resourceCollection)
- {
- return string.Join(", ", GetParametersForCollectionEntry(resourceCollection).Select(p => p.Name));
- }
-
- protected virtual void WriteSingletonResourceEntry(Resource resource, SingletonResourceSuffix singletonResourceIdSuffix, MethodSignature signature)
- {
- // we cannot guarantee that the singleResourceSuffix can only have two segments (it has many different cases),
- // therefore instead of using the extension method of ResourceIdentifier, we are just concatting this as a string
- _writer.UseNamespace(typeof(ResourceIdentifier).Namespace!);
- _writer.Line($"return new {resource.Type.Name}({ArmClientReference}, {singletonResourceIdSuffix.BuildResourceIdentifier($"Id")});");
- }
-
- protected virtual MethodSignatureModifiers GetMethodModifiers() => Public | Virtual;
-
- protected virtual Parameter[] GetParametersForSingletonEntry() => Array.Empty();
-
- protected virtual Parameter[] GetParametersForCollectionEntry(ResourceCollection resourceCollection)
- {
- return resourceCollection.ExtraConstructorParameters.ToArray();
- }
-
- protected Parameter[] GetParametersForResourceEntry(ResourceCollection resourceCollection)
- {
- return resourceCollection.GetOperation.MethodSignature.Parameters.ToArray();
- }
-
- protected virtual void WriteResourceCollectionEntry(ResourceCollection resourceCollection, MethodSignature signature)
- {
- // TODO: can we cache collection with extra constructor parameters
- if (resourceCollection.ExtraConstructorParameters.Any())
- {
- _writer.Append($"return new {resourceCollection.Type.Name}({ArmClientReference}, Id, ");
- foreach (var parameter in resourceCollection.ExtraConstructorParameters)
- {
- _writer.Append($"{parameter.Name}, ");
- }
- _writer.RemoveTrailingComma();
- _writer.Line($");");
- }
- else
- {
- // for collections without extra constructor parameter, we can return a cached instance
- _writer.Line($"return GetCachedClient({ArmClientReference} => new {resourceCollection.Type.Name}({ArmClientReference}, Id));");
- }
- }
-
protected void WriteStaticValidate(FormattableString validResourceType)
{
using (_writer.Scope($"internal static void ValidateResourceId({typeof(Azure.Core.ResourceIdentifier)} id)"))
@@ -417,7 +284,7 @@ protected FormattableString GetProviderNamespaceFromReturnType(FormattableString
protected FormattableString ConstructClientDiagnostic(CodeWriter writer, FormattableString providerNamespace, string diagnosticsOptionsVariable)
{
- return $"new {Configuration.ApiTypes.ClientDiagnosticsType}(\"{This.Type.Namespace}\", {providerNamespace}, {diagnosticsOptionsVariable})";
+ return $"new {Configuration.ApiTypes.ClientDiagnosticsType}(\"{This.DiagnosticNamespace}\", {providerNamespace}, {diagnosticsOptionsVariable})";
}
protected FormattableString GetRestConstructorString(MgmtRestClient restClient, FormattableString? apiVersionExpression)
@@ -538,11 +405,11 @@ private void WritePagingLROMethodBody(MgmtClientOperation clientOperation, Diagn
throw new NotImplementedException($"Pageable LRO is not implemented yet, please use `remove-operation` directive to remove the following operationIds: {string.Join(", ", clientOperation.Select(o => o.OperationId))}");
}
- protected IDisposable WriteCommonMethod(MgmtClientOperation clientOperation, bool isAsync)
+ protected virtual IDisposable WriteCommonMethod(MgmtClientOperation clientOperation, bool isAsync)
{
_writer.Line();
var returnDescription = clientOperation.ReturnsDescription?.Invoke(isAsync);
- return _writer.WriteCommonMethod(clientOperation.MethodSignature, returnDescription, isAsync, This.Accessibility == "public");
+ return _writer.WriteCommonMethod(clientOperation.MethodSignature, returnDescription, isAsync, This.Accessibility == "public", SkipParameterValidation);
}
#region PagingMethod
diff --git a/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionWrapperWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionWrapperWriter.cs
index 710d339e7cb..f299f804c40 100644
--- a/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionWrapperWriter.cs
+++ b/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionWrapperWriter.cs
@@ -1,12 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
-using System;
-using System.Collections.Generic;
-using System.Text;
using AutoRest.CSharp.Generation.Writers;
using AutoRest.CSharp.Mgmt.Output;
-using Azure.ResourceManager;
namespace AutoRest.CSharp.Mgmt.Generation
{
@@ -21,20 +17,14 @@ public MgmtExtensionWrapperWriter(MgmtExtensionWrapper extensionWrapper) : base(
protected override void WritePrivateHelpers()
{
- foreach (var extensionClient in This.ExtensionClients)
+ foreach (var extension in This.Extensions)
{
- if (extensionClient.IsEmpty)
+ if (extension.IsEmpty)
continue;
- foreach (var method in extensionClient.FactoryMethods)
- {
- _writer.Line();
+ _writer.Line();
- using (_writer.WriteMethodDeclaration(method.Signature))
- {
- method.MethodBodyImplementation(_writer);
- }
- }
+ _writer.WriteMethod(extension.MockingExtensionFactoryMethod);
}
base.WritePrivateHelpers();
diff --git a/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionWriter.cs
index 36960c1d314..69adc3a1547 100644
--- a/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionWriter.cs
+++ b/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionWriter.cs
@@ -21,16 +21,15 @@ internal class MgmtExtensionWriter : MgmtClientBaseWriter
public static MgmtExtensionWriter GetWriter(CodeWriter writer, MgmtExtension extension) => extension switch
{
ArmClientExtension armClientExtension => new ArmClientExtensionWriter(writer, armClientExtension),
- // the class ArmResourceExtensionWriter is created to handle scope resources, but in ArmCore we do not have that problem, therefore for ArmCore we just let the regular MgmtExtension class handle that
- ArmResourceExtension armResourceExtension when !Configuration.MgmtConfiguration.IsArmCore => new ArmResourceExtensionWriter(writer, armResourceExtension),
_ => new MgmtExtensionWriter(writer, extension)
};
+ protected override bool SkipParameterValidation => true;
+
private MgmtExtension This { get; }
protected delegate void WriteResourceGetBody(MethodSignature signature, bool isAsync, bool isPaging);
- public MgmtExtensionWriter(MgmtExtension extensions)
- : this(new CodeWriter(), extensions)
+ public MgmtExtensionWriter(MgmtExtension extensions) : this(new CodeWriter(), extensions)
{
This = extensions;
}
@@ -46,13 +45,11 @@ protected override WriteMethodDelegate GetMethodDelegate(bool isLongRunning, boo
private void GetMethodWrapperImpl(MgmtClientOperation clientOperation, Diagnostic diagnostic, bool isAsync)
=> WriteMethodBodyWrapper(clientOperation.MethodSignature, isAsync, clientOperation.IsPagingOperation);
- private void WriteMethodBodyWrapper(MethodSignature signature, bool isAsync, bool isPaging)
+ protected void WriteMethodBodyWrapper(MethodSignature signature, bool isAsync, bool isPaging)
{
- var extensionClient = This.GetExtensionClient(null);
-
_writer.AppendRaw("return ")
.AppendRawIf("await ", isAsync && !isPaging)
- .Append($"{extensionClient.FactoryMethodName}({This.ExtensionParameter.Name}).{CreateMethodName(signature.Name, isAsync)}(");
+ .Append($"{This.MockableExtension.FactoryMethodName}({This.ExtensionParameter.Name}).{CreateMethodName(signature.Name, isAsync)}(");
foreach (var parameter in signature.Parameters.Skip(1))
{
@@ -64,60 +61,5 @@ private void WriteMethodBodyWrapper(MethodSignature signature, bool isAsync, boo
.AppendRawIf(".ConfigureAwait(false)", isAsync && !isPaging)
.LineRaw(";");
}
-
- protected override void WriteResourceCollectionEntry(ResourceCollection resourceCollection, MethodSignature signature)
- {
- if (IsArmCore)
- {
- base.WriteResourceCollectionEntry(resourceCollection, signature);
- }
- else
- {
- WriteMethodBodyWrapper(signature, false, false);
- }
- }
-
- protected override void WriteSingletonResourceEntry(Resource resource, SingletonResourceSuffix singletonResourceSuffix, MethodSignature signature)
- {
- _writer.UseNamespace(typeof(ResourceIdentifier).Namespace!);
- if (IsArmCore)
- {
- base.WriteSingletonResourceEntry(resource, singletonResourceSuffix, signature);
- }
- else
- {
- WriteMethodBodyWrapper(signature, false, false);
- }
- }
-
- protected override void WriteResourceEntry(ResourceCollection resourceCollection, bool isAsync)
- {
- if (IsArmCore)
- {
- base.WriteResourceEntry(resourceCollection, isAsync);
- }
- else
- {
- var operation = resourceCollection.GetOperation;
- string awaitText = isAsync & !operation.IsPagingOperation ? " await" : string.Empty;
- string configureAwait = isAsync & !operation.IsPagingOperation ? ".ConfigureAwait(false)" : string.Empty;
- _writer.Append($"return{awaitText} {GetResourceCollectionMethodName(resourceCollection)}({GetResourceCollectionMethodArgumentList(resourceCollection)}).{operation.MethodSignature.WithAsync(isAsync).Name}(");
-
- foreach (var parameter in operation.MethodSignature.Parameters)
- {
- _writer.Append($"{parameter.Name},");
- }
-
- _writer.RemoveTrailingComma();
- _writer.Line($"){configureAwait};");
- }
- }
-
- protected override MethodSignatureModifiers GetMethodModifiers() => IsArmCore ? base.GetMethodModifiers() : Public | Static | Extension;
-
- protected override Parameter[] GetParametersForSingletonEntry() => IsArmCore ? base.GetParametersForSingletonEntry() : new[] { This.ExtensionParameter };
-
- protected override Parameter[] GetParametersForCollectionEntry(ResourceCollection resourceCollection)
- => IsArmCore ? base.GetParametersForCollectionEntry(resourceCollection) : resourceCollection.ExtraConstructorParameters.Prepend(This.ExtensionParameter).ToArray();
}
}
diff --git a/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionClientWriter.cs b/src/AutoRest.CSharp/Mgmt/Generation/MgmtMockableExtensionResourceWriter.cs
similarity index 76%
rename from src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionClientWriter.cs
rename to src/AutoRest.CSharp/Mgmt/Generation/MgmtMockableExtensionResourceWriter.cs
index 0e7d3967710..49bc70ef7ba 100644
--- a/src/AutoRest.CSharp/Mgmt/Generation/MgmtExtensionClientWriter.cs
+++ b/src/AutoRest.CSharp/Mgmt/Generation/MgmtMockableExtensionResourceWriter.cs
@@ -9,14 +9,19 @@
namespace AutoRest.CSharp.Mgmt.Generation
{
- internal sealed class MgmtExtensionClientWriter : MgmtClientBaseWriter
+ internal class MgmtMockableExtensionResourceWriter : MgmtClientBaseWriter
{
+ public static MgmtMockableExtensionResourceWriter GetWriter(MgmtMockableExtension extensionClient) => extensionClient switch
+ {
+ MgmtMockableArmClient armClientExtensionClient => new ArmClientMockingExtensionWriter(armClientExtensionClient),
+ _ => new MgmtMockableExtensionResourceWriter(extensionClient)
+ };
+
protected override bool UseField => false;
- private MgmtExtensionClient This { get; }
+ private MgmtMockableExtension This { get; }
- public MgmtExtensionClientWriter(MgmtExtensionClient extensions)
- : base(new CodeWriter(), extensions)
+ public MgmtMockableExtensionResourceWriter(MgmtMockableExtension extensions) : base(new CodeWriter(), extensions)
{
This = extensions;
}
diff --git a/src/AutoRest.CSharp/Mgmt/Models/MgmtClientOperation.cs b/src/AutoRest.CSharp/Mgmt/Models/MgmtClientOperation.cs
index ce1f44b85ce..052d970ddce 100644
--- a/src/AutoRest.CSharp/Mgmt/Models/MgmtClientOperation.cs
+++ b/src/AutoRest.CSharp/Mgmt/Models/MgmtClientOperation.cs
@@ -5,8 +5,10 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
+using System.Text;
using AutoRest.CSharp.Generation.Types;
using AutoRest.CSharp.Generation.Writers;
+using AutoRest.CSharp.Mgmt.AutoRest;
using AutoRest.CSharp.Mgmt.Decorator;
using AutoRest.CSharp.Mgmt.Output;
using AutoRest.CSharp.Output.Models;
@@ -27,18 +29,29 @@ namespace AutoRest.CSharp.Mgmt.Models
internal class MgmtClientOperation : IReadOnlyList
{
private const int PropertyBagThreshold = 5;
- private const string IdVariableName = "Id";
private readonly Parameter? _extensionParameter;
- public static MgmtClientOperation? FromOperations(IReadOnlyList operations)
+ public static MgmtClientOperation? FromOperations(IReadOnlyList operations, FormattableString idVariableName, Parameter? extensionParameter = null, bool isConvenientOperation = false)
{
if (operations.Count > 0)
{
- return new MgmtClientOperation(operations.OrderBy(operation => operation.Name).ToArray(), null);
+ return new MgmtClientOperation(operations.OrderBy(operation => operation.Name).ToArray(), idVariableName, extensionParameter, isConvenientOperation);
}
return null;
}
+ public static MgmtClientOperation FromOperation(MgmtRestOperation operation, FormattableString idVariableName, Parameter? extensionParameter = null, bool isConvenientOperation = false)
+ {
+ return new MgmtClientOperation(new List { operation }, idVariableName, extensionParameter, isConvenientOperation);
+ }
+
+ public static MgmtClientOperation FromClientOperation(MgmtClientOperation other, FormattableString idVariableName, Parameter? extensionParameter = null, bool isConvenientOperation = false, IReadOnlyList? parameterOverride = null)
+ {
+ return new MgmtClientOperation(other._operations, idVariableName, extensionParameter, isConvenientOperation, parameterOverride);
+ }
+
+ internal FormattableString IdVariableName { get; }
+
public Func? ReturnsDescription => _operations.First().ReturnsDescription;
private IReadOnlyDictionary? _operationMappings;
@@ -51,20 +64,22 @@ internal class MgmtClientOperation : IReadOnlyList
public IReadOnlyList MethodParameters => _methodParameters ??= EnsureMethodParameters();
public IReadOnlyList PropertyBagUnderlyingParameters => IsPropertyBagOperation ? _passThroughParams : Array.Empty();
- public static MgmtClientOperation FromOperation(MgmtRestOperation operation, Parameter? extensionParameter = null, bool isConvenientOperation = false)
- {
- return new MgmtClientOperation(new List { operation }, extensionParameter, isConvenientOperation);
- }
private readonly IReadOnlyList _operations;
- private MgmtClientOperation(IReadOnlyList operations, Parameter? extensionParameter, bool isConvenientOperation = false)
+ private MgmtClientOperation(IReadOnlyList operations, FormattableString idVariableName, Parameter? extensionParameter, bool isConvenientOperation = false)
{
_operations = operations;
_extensionParameter = extensionParameter;
+ IdVariableName = idVariableName;
IsConvenientOperation = isConvenientOperation;
}
+ private MgmtClientOperation(IReadOnlyList operations, FormattableString idVariableName, Parameter? extensionParameter, bool isConvenientOperation = false, IReadOnlyList? parameterOverride = null) : this(operations, idVariableName, extensionParameter, isConvenientOperation)
+ {
+ _methodParameters = parameterOverride;
+ }
+
public bool IsConvenientOperation { get; }
public MgmtRestOperation this[int index] => _operations[index];
@@ -104,10 +119,35 @@ private FormattableString BuildDescription()
pathInformation = $@"
{pathInformation}
";
+ FormattableString? mockingInformation;
+ if (_extensionParameter == null)
+ {
+ mockingInformation = null;
+ }
+ else
+ {
+ // find the corresponding extension of this method
+ var extendType = _extensionParameter.Type;
+ var mockingExtensionTypeName = MgmtMockableExtension.GetMockableExtensionDefaultName(extendType.Name);
+ // construct the cref name
+ var builder = new StringBuilder(Name);
+ builder.Append("(");
+ var paramList = MethodParameters.Skip(1).Select(p => p.Type.ToStringForDocs());
+ builder.Append(string.Join(",", paramList));
+ builder.Append(")");
+ var methodRef = builder.ToString();
+
+ mockingInformation = $@"-
+Mocking
+To mock this method, please mock instead.
+
";
+ }
+
+ FormattableString extraInformation = mockingInformation != null ? $"{pathInformation}{Environment.NewLine}{mockingInformation}" : pathInformation;
var descriptionOfOperation = _operations.First().Description;
if (descriptionOfOperation != null)
- return $"{descriptionOfOperation}\n{pathInformation}";
- return pathInformation;
+ return $"{descriptionOfOperation}{Environment.NewLine}{extraInformation}";
+ return extraInformation;
}
// TODO -- we need a better way to get this
diff --git a/src/AutoRest.CSharp/Mgmt/Models/SingletonResourceSuffix.cs b/src/AutoRest.CSharp/Mgmt/Models/SingletonResourceSuffix.cs
index 130fd3d540e..6353ca891e2 100644
--- a/src/AutoRest.CSharp/Mgmt/Models/SingletonResourceSuffix.cs
+++ b/src/AutoRest.CSharp/Mgmt/Models/SingletonResourceSuffix.cs
@@ -4,8 +4,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions;
using AutoRest.CSharp.Generation.Writers;
using Azure.Core;
+using static AutoRest.CSharp.Common.Output.Models.Snippets;
namespace AutoRest.CSharp.Mgmt.Models
{
@@ -30,29 +32,36 @@ private SingletonResourceSuffix(IReadOnlyList<(string Key, string Value)> pairs)
_pairs = pairs;
}
- public FormattableString BuildResourceIdentifier(FormattableString originalId)
+ public ValueExpression BuildResourceIdentifier(ValueExpression originalId)
{
- var list = new List() { originalId };
+ var result = originalId;
for (int i = 0; i < _pairs.Count; i++)
{
- var key = _pairs[i].Key;
- var value = _pairs[i].Value;
+ var (key, value) = _pairs[i];
if (key == Segment.Providers)
{
- // when we have a providers, we must have a next pair
+ // when we have a providers segment, we must have a next pair
i++;
- var nextKey = _pairs[i].Key;
- var nextValue = _pairs[i].Value;
- list.Add($"{nameof(ResourceIdentifier.AppendProviderResource)}({value:L}, {nextKey:L}, {nextValue:L})");
+ var (nextKey, nextValue) = _pairs[i];
+ // build expression: => .AppendProviderResource(value, nextKey, nextValue)
+ result = new InvokeStaticMethodExpression(
+ typeof(ResourceIdentifier),
+ nameof(ResourceIdentifier.AppendProviderResource),
+ new[] { result, Literal(value), Literal(nextKey), Literal(nextValue) },
+ CallAsExtension: true);
}
else
{
// if not, we just call the method to append this pair
- list.Add($"{nameof(ResourceIdentifier.AppendChildResource)}({key:L}, {value:L})");
+ result = new InvokeStaticMethodExpression(
+ typeof(ResourceIdentifier),
+ nameof(ResourceIdentifier.AppendChildResource),
+ new[] { result, Literal(key), Literal(value) },
+ CallAsExtension: true);
}
}
- return list.Join(".");
+ return result;
}
public override string ToString()
diff --git a/src/AutoRest.CSharp/Mgmt/Output/ArmClientExtension.cs b/src/AutoRest.CSharp/Mgmt/Output/ArmClientExtension.cs
index c5bba11c845..ce36d9950b4 100644
--- a/src/AutoRest.CSharp/Mgmt/Output/ArmClientExtension.cs
+++ b/src/AutoRest.CSharp/Mgmt/Output/ArmClientExtension.cs
@@ -1,25 +1,229 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License
+using System;
using System.Collections.Generic;
using System.Linq;
+using AutoRest.CSharp.Common.Output.Expressions.Statements;
+using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions;
+using AutoRest.CSharp.Common.Output.Models;
+using AutoRest.CSharp.Generation.Writers;
using AutoRest.CSharp.Common.Input;
using AutoRest.CSharp.Input;
using AutoRest.CSharp.Mgmt.AutoRest;
+using AutoRest.CSharp.Mgmt.Decorator;
using AutoRest.CSharp.Mgmt.Models;
+using AutoRest.CSharp.Output.Models;
+using AutoRest.CSharp.Output.Models.Shared;
+using Azure.Core;
using Azure.ResourceManager;
namespace AutoRest.CSharp.Mgmt.Output
{
internal class ArmClientExtension : MgmtExtension
{
- public ArmClientExtension(IEnumerable allOperations)
- : base(allOperations, Enumerable.Empty(), typeof(ArmClient), RequestPath.Tenant)
+ private readonly List _extensions;
+ private readonly ArmResourceExtension _armResourceExtensionForChildResources;
+ public ArmClientExtension(IReadOnlyDictionary> armResourceExtensionOperations, IEnumerable extensionClients, ArmResourceExtension armResourceExtensionForChildResources)
+ : base(Enumerable.Empty(), extensionClients, typeof(ArmClient), RequestPath.Tenant)
{
+ _armResourceExtensionForChildResources = armResourceExtensionForChildResources;
+ _extensions = new();
+ foreach (var (parentRequestPath, operations) in armResourceExtensionOperations)
+ {
+ _extensions.Add(new(operations, extensionClients, typeof(ArmResource), parentRequestPath));
+ }
}
- public override bool IsEmpty => !MgmtContext.Library.ArmResources.Any();
+ public override bool IsEmpty => !MgmtContext.Library.ArmResources.Any() && base.IsEmpty;
protected override string VariableName => Configuration.MgmtConfiguration.IsArmCore ? "this" : "client";
+
+ public override FormattableString IdVariableName => $"scope";
+ public override FormattableString BranchIdVariableName => $"scope";
+
+ protected override IEnumerable EnsureClientOperations()
+ {
+ var extensionParamToUse = Configuration.MgmtConfiguration.IsArmCore ? null : ExtensionParameter;
+ foreach (var extension in _extensions)
+ {
+ foreach (var clientOperation in extension.ClientOperations)
+ {
+ var requestPaths = clientOperation.Select(restOperation => restOperation.RequestPath);
+ var scopeResourceTypes = requestPaths.Select(requestPath => requestPath.GetParameterizedScopeResourceTypes() ?? Enumerable.Empty()).SelectMany(types => types).Distinct();
+ var scopeTypes = ResourceTypeBuilder.GetScopeTypeStrings(scopeResourceTypes);
+ var parameterOverride = clientOperation.MethodParameters.Skip(1).Prepend(GetScopeParameter(scopeTypes)).Prepend(ExtensionParameter).ToArray();
+ var newOp = MgmtClientOperation.FromClientOperation(clientOperation, IdVariableName, extensionParameter: extensionParamToUse, parameterOverride: parameterOverride);
+ yield return newOp;
+ }
+ }
+ }
+
+ // only when in usual packages other than arm core, we need to generate the ArmClient, scope pattern for those scope resources
+ public override IEnumerable ChildResources => Configuration.MgmtConfiguration.IsArmCore ? Enumerable.Empty() : _armResourceExtensionForChildResources.AllChildResources;
+
+ private readonly Parameter _scopeParameter = new Parameter(
+ Name: "scope",
+ Description: $"The scope that the resource will apply against.",
+ Type: typeof(ResourceIdentifier),
+ DefaultValue: null,
+ Validation: ValidationType.None,
+ Initializer: null);
+
+ private Parameter GetScopeParameter(ICollection? types)
+ {
+ if (types == null)
+ return _scopeParameter;
+
+ return _scopeParameter with
+ {
+ Description = $"{_scopeParameter.Description} Expected resource type includes the following: {types.Join(", ", " or ")}"
+ };
+ }
+
+ protected override Method BuildMockableExtensionFactoryMethod()
+ {
+ var signature = new MethodSignature(
+ MockableExtension.FactoryMethodName,
+ null,
+ null,
+ MethodSignatureModifiers.Private | MethodSignatureModifiers.Static,
+ MockableExtension.Type,
+ null,
+ new[] { ArmClientParameter });
+
+ var extensionVariable = (ValueExpression)ArmClientParameter;
+ var clientVariable = new VariableReference(typeof(ArmClient), "client");
+ var body = Snippets.Return(
+ extensionVariable.Invoke(nameof(ArmClient.GetCachedClient),
+ new FuncExpression(new[] { clientVariable.Declaration }, Snippets.New.Instance(MockableExtension.Type, clientVariable))
+ ));
+ return new(signature, body);
+ }
+
+ protected override Method BuildGetSingletonResourceMethod(Resource resource)
+ {
+ var originalMethod = base.BuildGetSingletonResourceMethod(resource);
+ if (IsArmCore)
+ return originalMethod;
+
+ // we need to add a scope parameter inside the method signature
+ var originalSignature = (MethodSignature)originalMethod.Signature;
+ var scopeTypes = ResourceTypeBuilder.GetScopeTypeStrings(resource.RequestPath.GetParameterizedScopeResourceTypes());
+ var parameters = new List()
+ {
+ // add the first parameter, which is the extension parameter
+ originalSignature.Parameters[0],
+ // then we add the scope parameter
+ GetScopeParameter(scopeTypes)
+ };
+ parameters.AddRange(originalSignature.Parameters.Skip(1)); // add all remaining parameters
+ var signatureOnMockingExtension = originalSignature with
+ {
+ Modifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Virtual,
+ Parameters = parameters.Skip(1).ToArray()
+ };
+ var signature = originalSignature with
+ {
+ Description = $"{BuildDescriptionForSingletonResource(resource)}{Environment.NewLine}{BuildMockingExtraDescription(signatureOnMockingExtension)}",
+ Parameters = parameters
+ };
+
+ return BuildRedirectCallToMockingExtension(signature, signatureOnMockingExtension);
+ }
+
+ protected override Method BuildGetChildCollectionMethod(ResourceCollection collection)
+ {
+ var originalMethod = base.BuildGetChildCollectionMethod(collection);
+ if (IsArmCore)
+ return originalMethod;
+
+ // we need to add a scope parameter inside the method signature
+ var originalSignature = (MethodSignature)originalMethod.Signature;
+ var scopeTypes = ResourceTypeBuilder.GetScopeTypeStrings(collection.RequestPath.GetParameterizedScopeResourceTypes());
+ var parameters = new List()
+ {
+ // add the first parameter, which is the extension parameter
+ originalSignature.Parameters[0],
+ // then we add the scope parameter
+ GetScopeParameter(scopeTypes)
+ };
+ parameters.AddRange(originalSignature.Parameters.Skip(1)); // add all remaining parameters
+ var signatureOnMockingExtension = originalSignature with
+ {
+ Modifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Virtual,
+ Parameters = parameters.Skip(1).ToArray()
+ };
+ var signature = originalSignature with
+ {
+ Description = $"{BuildDescriptionForChildCollection(collection)}{Environment.NewLine}{BuildMockingExtraDescription(signatureOnMockingExtension)}",
+ Parameters = parameters
+ };
+
+ return BuildRedirectCallToMockingExtension(signature, signatureOnMockingExtension);
+ }
+
+ private IEnumerable? _armResourceMethods;
+ public IEnumerable ArmResourceMethods => _armResourceMethods ??= BuildArmResourceMethods();
+
+ private IEnumerable BuildArmResourceMethods()
+ {
+ foreach (var resource in MgmtContext.Library.ArmResources)
+ {
+ yield return BuildArmResourceMethod(resource);
+ }
+ }
+
+ private Method BuildArmResourceMethod(Resource resource)
+ {
+ var lines = new List();
+ string an = resource.Type.Name.StartsWithVowel() ? "an" : "a";
+ lines.Add($"Gets an object representing {an} along with the instance operations that can be performed on it but with no data.");
+ lines.Add($"You can use to create {an} from its components.");
+ var description = FormattableStringHelpers.Join(lines, Environment.NewLine);
+
+ var parameters = new List
+ {
+ _resourceIdParameter
+ };
+
+ var signatureOnMockingExtension = new MethodSignature(
+ $"Get{resource.Type.Name}",
+ null,
+ description,
+ MethodSignatureModifiers.Public | MethodSignatureModifiers.Virtual,
+ resource.Type,
+ $"Returns a object.",
+ parameters);
+
+ if (IsArmCore)
+ {
+ var methodBody = new MethodBodyStatement[]{
+ new InvokeStaticMethodStatement(resource.Type, "ValidateResourceId", _resourceIdParameter),
+ Snippets.Return(Snippets.New.Instance(resource.Type, Snippets.This, _resourceIdParameter))
+ };
+
+ return new(signatureOnMockingExtension, methodBody);
+ }
+ else
+ {
+ var signature = signatureOnMockingExtension with
+ {
+ Description = $"{description}{Environment.NewLine}{BuildMockingExtraDescription(signatureOnMockingExtension)}",
+ Modifiers = MethodModifiers,
+ Parameters = parameters.Prepend(ExtensionParameter).ToArray()
+ };
+
+ return BuildRedirectCallToMockingExtension(signature, signatureOnMockingExtension);
+ }
+ }
+
+ private readonly Parameter _resourceIdParameter = new(
+ Name: "id",
+ Description: $"The resource ID of the resource to get.",
+ Type: typeof(ResourceIdentifier),
+ DefaultValue: null,
+ Validation: ValidationType.None,
+ Initializer: null);
}
}
diff --git a/src/AutoRest.CSharp/Mgmt/Output/ArmResourceExtension.cs b/src/AutoRest.CSharp/Mgmt/Output/ArmResourceExtension.cs
index b56147ec75e..4640f2fa359 100644
--- a/src/AutoRest.CSharp/Mgmt/Output/ArmResourceExtension.cs
+++ b/src/AutoRest.CSharp/Mgmt/Output/ArmResourceExtension.cs
@@ -4,8 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
+using AutoRest.CSharp.Common.Input;
using AutoRest.CSharp.Input;
using AutoRest.CSharp.Mgmt.Models;
using Azure.ResourceManager;
@@ -15,7 +14,7 @@ namespace AutoRest.CSharp.Mgmt.Output
internal class ArmResourceExtension : MgmtExtension
{
private readonly List _extensions;
- public ArmResourceExtension(IReadOnlyDictionary> armResourceExtensionOperations, IEnumerable extensionClients) : base(Enumerable.Empty(), extensionClients, typeof(ArmResource), RequestPath.Any)
+ public ArmResourceExtension(IReadOnlyDictionary> armResourceExtensionOperations, IEnumerable extensionClients) : base(Enumerable.Empty(), extensionClients, typeof(ArmResource), RequestPath.Any)
{
_extensions = new();
foreach (var (parentRequestPath, operations) in armResourceExtensionOperations)
@@ -28,8 +27,42 @@ protected override IEnumerable EnsureClientOperations()
{
foreach (var extension in _extensions)
{
- foreach (var operation in extension.ClientOperations)
- yield return operation;
+ foreach (var clientOperation in extension.ClientOperations)
+ {
+ var requestPaths = clientOperation.Select(restOperation => restOperation.RequestPath);
+ if (ShouldGenerateArmResourceExtensionMethod(requestPaths))
+ yield return clientOperation;
+ }
+ }
+ }
+
+ private static bool ShouldGenerateArmResourceExtensionMethod(IEnumerable requestPaths)
+ => requestPaths.Any(ShouldGenerateArmResourceExtensionMethod);
+
+ private static bool ShouldGenerateArmResourceExtensionMethod(RequestPath requestPath)
+ => Configuration.MgmtConfiguration.GenerateArmResourceExtensions.Contains(requestPath);
+
+ ///
+ /// This tracks all resources with a parent of ArmResource
+ /// We need this to keep the original data of all possible child resources of ArmResource and we will use it again in ArmClientExtension
+ ///
+ internal IEnumerable AllChildResources => base.ChildResources;
+
+ private IEnumerable? _filteredArmResourceChildResource;
+ ///
+ /// We need to filter out some resources here
+ /// because in the design of generated code for ArmResourceExtension, we usually do not generate an extension method that extends ArmResource type
+ /// instead we generate an extension method of ArmClient with a scope instead to avoid that the extension method shows up on every resource
+ /// because in real life it is not quite possible.
+ ///
+ public override IEnumerable ChildResources => _filteredArmResourceChildResource ??= EnsureArmResourceExtensionChildResources();
+
+ private IEnumerable EnsureArmResourceExtensionChildResources()
+ {
+ foreach (var resource in AllChildResources)
+ {
+ if (ShouldGenerateArmResourceExtensionMethod(resource.RequestPath))
+ yield return resource;
}
}
}
diff --git a/src/AutoRest.CSharp/Mgmt/Output/MgmtExtension.cs b/src/AutoRest.CSharp/Mgmt/Output/MgmtExtension.cs
index e70b9b9682d..97fa791b86d 100644
--- a/src/AutoRest.CSharp/Mgmt/Output/MgmtExtension.cs
+++ b/src/AutoRest.CSharp/Mgmt/Output/MgmtExtension.cs
@@ -4,6 +4,8 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions;
+using AutoRest.CSharp.Common.Output.Models;
using AutoRest.CSharp.Common.Input;
using AutoRest.CSharp.Generation.Types;
using AutoRest.CSharp.Input;
@@ -13,6 +15,8 @@
using AutoRest.CSharp.Output.Models;
using AutoRest.CSharp.Output.Models.Shared;
using AutoRest.CSharp.Utilities;
+using Azure.ResourceManager;
+using Humanizer.Localisation;
namespace AutoRest.CSharp.Mgmt.Output
{
@@ -22,11 +26,11 @@ internal class MgmtExtension : MgmtTypeProvider
private readonly IEnumerable _allRawOperations;
- public MgmtExtension(IEnumerable allRawOperations, IEnumerable extensionClients, Type armCoreType, RequestPath? contextualPath = null)
+ public MgmtExtension(IEnumerable allRawOperations, IEnumerable mockingExtensions, Type armCoreType, RequestPath? contextualPath = null)
: base(armCoreType.Name)
{
_allRawOperations = allRawOperations;
- _extensionClients = extensionClients; // this property is populated later
+ _mockingExtensions = mockingExtensions; // this property is populated later
ArmCoreType = armCoreType;
DefaultName = Configuration.MgmtConfiguration.IsArmCore ? ResourceName : $"{ResourceName}Extensions";
DefaultNamespace = Configuration.MgmtConfiguration.IsArmCore ? ArmCoreType.Namespace! : base.DefaultNamespace;
@@ -34,6 +38,17 @@ public MgmtExtension(IEnumerable allRawOperations, IEnumerable();
+ ExtensionParameter = new Parameter(
+ VariableName,
+ $"The instance the method will execute against.",
+ ArmCoreType,
+ null,
+ ValidationType.None,
+ null);
+
+ MethodModifiers = IsArmCore ?
+ MethodSignatureModifiers.Public | MethodSignatureModifiers.Virtual :
+ MethodSignatureModifiers.Public | MethodSignatureModifiers.Static | MethodSignatureModifiers.Extension;
}
protected override ConstructorSignature? EnsureMockingCtor()
@@ -41,20 +56,9 @@ public MgmtExtension(IEnumerable allRawOperations, IEnumerable $"{ExtensionParameter.Name}.Id";
+ public override FormattableString BranchIdVariableName => $"{ExtensionParameter.Name}.Id";
- private Parameter? _extensionParameter;
- public Parameter ExtensionParameter => _extensionParameter ??= EnsureExtensionParameter();
- private Parameter EnsureExtensionParameter()
- {
- return new Parameter(
- VariableName,
- $"The instance the method will execute against.",
- ArmCoreType,
- null,
- ValidationType.None,
- null);
- }
+ public Parameter ExtensionParameter { get; }
protected virtual string VariableName => Configuration.MgmtConfiguration.IsArmCore ? "this" : ArmCoreType.Name.ToVariableName();
@@ -99,6 +103,7 @@ protected override IEnumerable EnsureClientOperations()
ContextualPath,
operationName,
propertyBagName: ResourceName),
+ BranchIdVariableName,
extensionParamToUse);
});
}
@@ -158,19 +163,138 @@ private IEnumerable GetExtraLayers(RequestPath requestPath, Resource re
return null;
}
- public MgmtExtensionClient GetExtensionClient(CSharpType? resourceType)
+
+ private Method? _mockingExtensionFactoryMethod;
+ public Method MockingExtensionFactoryMethod => _mockingExtensionFactoryMethod ??= BuildMockableExtensionFactoryMethod();
+
+ protected virtual Method BuildMockableExtensionFactoryMethod()
{
- if (resourceType != null && Cache.TryGetValue(resourceType, out var extensionClient))
- return extensionClient;
+ var signature = new MethodSignature(
+ MockableExtension.FactoryMethodName,
+ null,
+ null,
+ MethodSignatureModifiers.Private | MethodSignatureModifiers.Static,
+ MockableExtension.Type,
+ null,
+ new[] { _generalExtensionParameter });
+
+ var extensionVariable = (ValueExpression)_generalExtensionParameter;
+ var clientVariable = new VariableReference(typeof(ArmClient), "client");
+ var body = Snippets.Return(
+ extensionVariable.Invoke(
+ nameof(ArmResource.GetCachedClient),
+ new FuncExpression(new[] { clientVariable.Declaration }, Snippets.New.Instance(MockableExtension.Type, clientVariable, extensionVariable.Property(nameof(ArmResource.Id))))
+ ));
- return Cache[ArmCoreType];
+ return new(signature, body);
}
- private readonly IEnumerable _extensionClients;
+ private readonly Parameter _generalExtensionParameter = new Parameter(
+ "resource",
+ $"The resource parameters to use in these operations.",
+ typeof(ArmResource),
+ null,
+ ValidationType.None,
+ null);
- private Dictionary? _cache;
- private Dictionary Cache => _cache ??= _extensionClients.ToDictionary(
+ public MgmtMockableExtension MockableExtension => Cache[ArmCoreType];
+
+ private readonly IEnumerable _mockingExtensions;
+
+ private Dictionary? _cache;
+ private Dictionary Cache => _cache ??= _mockingExtensions.ToDictionary(
extensionClient => extensionClient.ExtendedResourceType,
extensionClient => extensionClient);
+
+ ///
+ /// Build the implementation of methods in the extension.
+ /// It calls the factory method of the mocking extension first, and then calls the method wtih the same name and parameter list on the mocking extension
+ ///
+ ///
+ ///
+ ///
+ ///
+ protected Method BuildRedirectCallToMockingExtension(MethodSignature signature, MethodSignature signatureOnMockingExtension)
+ {
+ var callFactoryMethod = new InvokeInstanceMethodExpression(null, (MethodSignature)MockingExtensionFactoryMethod.Signature, new[] { (ValueExpression)signature.Parameters[0] }, false);
+
+ var callMethodOnMockingExtension = callFactoryMethod.Invoke(signatureOnMockingExtension);
+
+ var methodBody = Snippets.Return(callMethodOnMockingExtension);
+
+ return new(signature, methodBody);
+ }
+
+ protected FormattableString BuildMockingExtraDescription(MethodSignature signatureOnMockingExtension)
+ {
+ var methodRef = signatureOnMockingExtension.ToStringForDocs();
+ return $@"-
+Mocking
+To mock this method, please mock instead.
+
";
+ }
+
+ protected override Method BuildGetSingletonResourceMethod(Resource resource)
+ {
+ var originalMethod = base.BuildGetSingletonResourceMethod(resource);
+ if (IsArmCore)
+ return originalMethod;
+
+ // if it not arm core, we should generate these methods in a static extension way
+ var originalSignature = (MethodSignature)originalMethod.Signature;
+ var signatureOnMockingExtension = originalSignature with
+ {
+ Modifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Virtual
+ };
+ var signature = originalSignature with
+ {
+ Description = $"{BuildDescriptionForSingletonResource(resource)}{Environment.NewLine}{BuildMockingExtraDescription(signatureOnMockingExtension)}",
+ Parameters = originalSignature.Parameters.Prepend(ExtensionParameter).ToArray()
+ };
+
+ return BuildRedirectCallToMockingExtension(signature, signatureOnMockingExtension);
+ }
+
+ protected override Method BuildGetChildCollectionMethod(ResourceCollection collection)
+ {
+ var originalMethod = base.BuildGetChildCollectionMethod(collection);
+ if (IsArmCore)
+ return originalMethod;
+
+ // if it not arm core, we should generate these methods in a static extension way
+ var originalSignature = (MethodSignature)originalMethod.Signature;
+ var signatureOnMockingExtension = originalSignature with
+ {
+ Modifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Virtual
+ };
+ var signature = originalSignature with
+ {
+ Description = $"{BuildDescriptionForChildCollection(collection)}{Environment.NewLine}{BuildMockingExtraDescription(signatureOnMockingExtension)}",
+ Parameters = originalSignature.Parameters.Prepend(ExtensionParameter).ToArray()
+ };
+
+ return BuildRedirectCallToMockingExtension(signature, signatureOnMockingExtension);
+ }
+
+ protected override Method BuildGetChildResourceMethod(ResourceCollection collection, MethodSignatureBase getCollectionMethodSignature, bool isAsync)
+ {
+ var originalMethod = base.BuildGetChildResourceMethod(collection, getCollectionMethodSignature, isAsync);
+ if (IsArmCore)
+ return originalMethod;
+
+ var originalSignature = (MethodSignature)originalMethod.Signature;
+ var signatureOnMockingExtension = (originalSignature.WithAsync(false) with
+ {
+ Modifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Virtual,
+ Parameters = originalSignature.Parameters.Skip(1).ToArray()
+ }).WithAsync(isAsync);
+ var signature = originalSignature with
+ {
+ Description = $"{BuildDescriptionForChildResource(collection)}{Environment.NewLine}{BuildMockingExtraDescription(signatureOnMockingExtension)}"
+ };
+
+ // if it not arm core, we should generate these methods in a static extension way
+ return BuildRedirectCallToMockingExtension(signature, signatureOnMockingExtension);
+ }
}
}
diff --git a/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionBuilder.cs b/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionBuilder.cs
index acee0b6e955..dcef4668013 100644
--- a/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionBuilder.cs
+++ b/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionBuilder.cs
@@ -8,19 +8,18 @@
using AutoRest.CSharp.Mgmt.Models;
using AutoRest.CSharp.Utilities;
using Azure.ResourceManager;
-using Azure.ResourceManager.Resources;
namespace AutoRest.CSharp.Mgmt.Output
{
internal class MgmtExtensionBuilder
{
- private record MgmtExtensionInfo(IReadOnlyDictionary ExtensionDict, IEnumerable ExtensionClients)
+ private record MgmtExtensionInfo(IReadOnlyDictionary ExtensionDict, IEnumerable MockableExtensions)
{
private IEnumerable? _extensions;
public IEnumerable Extensions => _extensions ??= ExtensionDict.Values;
private MgmtExtensionWrapper? _extensionWrapper;
- public MgmtExtensionWrapper ExtensionWrapper => _extensionWrapper ??= new MgmtExtensionWrapper(Extensions, ExtensionClients);
+ public MgmtExtensionWrapper ExtensionWrapper => _extensionWrapper ??= new MgmtExtensionWrapper(Extensions, MockableExtensions);
}
private readonly IReadOnlyDictionary> _extensionOperations;
@@ -36,7 +35,7 @@ public MgmtExtensionBuilder(Dictionary> extensionOp
public IEnumerable Extensions => ExtensionInfo.Extensions;
- public IEnumerable ExtensionClients => ExtensionInfo.ExtensionClients;
+ public IEnumerable MockableExtensions => ExtensionInfo.MockableExtensions;
public MgmtExtension GetExtension(Type armCoreType)
{
@@ -50,26 +49,25 @@ private MgmtExtensionInfo EnsureMgmtExtensionInfo()
{
// we use a SortedDictionary or SortedSet here to make sure the order of extensions or extension clients is deterministic
var extensionDict = new SortedDictionary(new CSharpTypeNameComparer());
- var extensionClients = new SortedSet(new MgmtExtensionClientComparer());
+ var mockingExtensions = new SortedSet(new MgmtExtensionClientComparer());
// create the extensions
foreach (var (type, operations) in _extensionOperations)
{
- var extension = new MgmtExtension(operations, extensionClients, type);
+ var extension = new MgmtExtension(operations, mockingExtensions, type);
extensionDict.Add(type, extension);
}
// add ArmResourceExtension methods
- extensionDict.Add(typeof(ArmResource), new ArmResourceExtension(_armResourceExtensionOperations, extensionClients));
- // add the ArmClientExtension
- extensionDict.Add(typeof(ArmClient), new ArmClientExtension(_extensionOperations[typeof(TenantResource)]));
+ var armResourceExtension = new ArmResourceExtension(_armResourceExtensionOperations, mockingExtensions);
+ // add ArmClientExtension methods (which is also the TenantResource extension methods)
+ var armClientExtension = new ArmClientExtension(_armResourceExtensionOperations, mockingExtensions, armResourceExtension);
+ extensionDict.Add(typeof(ArmResource), armResourceExtension);
+ extensionDict.Add(typeof(ArmClient), armClientExtension);
// construct all possible extension clients
// first we collection all possible combinations of the resource on operations
var resourceToOperationsDict = new Dictionary>();
foreach (var (type, extension) in extensionDict)
{
- // explicitly skip ArmClient because it should not have an extension client
- if (type.Equals(typeof(ArmClient)))
- continue;
// we add an empty list for the type to ensure that the corresponding extension client will always be constructed, even empty
resourceToOperationsDict.Add(type, new());
foreach (var operation in extension.AllOperations)
@@ -82,10 +80,13 @@ private MgmtExtensionInfo EnsureMgmtExtensionInfo()
{
// find the extension if the resource type here is a framework type (when it is ResourceGroupResource, SubscriptionResource, etc) to ensure the ExtensionClient could property have the child resources
extensionDict.TryGetValue(resourceType, out var extensionForChildResources);
- extensionClients.Add(new MgmtExtensionClient(resourceType, operations, extensionForChildResources));
+ var extensionClient = resourceType.Equals(typeof(ArmClient)) ?
+ new MgmtMockableArmClient(resourceType, operations, extensionForChildResources) :
+ new MgmtMockableExtension(resourceType, operations, extensionForChildResources);
+ mockingExtensions.Add(extensionClient);
}
- return new(extensionDict, extensionClients);
+ return new(extensionDict, mockingExtensions);
}
private struct CSharpTypeNameComparer : IComparer
@@ -96,9 +97,9 @@ public int Compare(CSharpType? x, CSharpType? y)
}
}
- private struct MgmtExtensionClientComparer : IComparer
+ private struct MgmtExtensionClientComparer : IComparer
{
- public int Compare(MgmtExtensionClient? x, MgmtExtensionClient? y)
+ public int Compare(MgmtMockableExtension? x, MgmtMockableExtension? y)
{
return string.Compare(x?.Declaration.Name, y?.Declaration.Name);
}
diff --git a/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionWrapper.cs b/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionWrapper.cs
index f7c5ab556fb..cc1cd4253c4 100644
--- a/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionWrapper.cs
+++ b/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionWrapper.cs
@@ -20,18 +20,18 @@ internal class MgmtExtensionWrapper : MgmtTypeProvider
{
public IEnumerable Extensions { get; }
- public IEnumerable ExtensionClients { get; }
+ public IEnumerable MockingExtensions { get; }
public override bool IsStatic => true;
public bool IsEmpty => Extensions.All(extension => extension.IsEmpty);
- public MgmtExtensionWrapper(IEnumerable extensions, IEnumerable extensionClients) : base(MgmtContext.RPName)
+ public MgmtExtensionWrapper(IEnumerable extensions, IEnumerable mockingExtensions) : base(MgmtContext.RPName)
{
DefaultName = $"{ResourceName}Extensions";
Description = Configuration.MgmtConfiguration.IsArmCore ? (FormattableString)$"" : $"A class to add extension methods to {MgmtContext.Context.DefaultNamespace}.";
Extensions = extensions;
- ExtensionClients = extensionClients;
+ MockingExtensions = mockingExtensions;
}
public override CSharpType? BaseType => null;
diff --git a/src/AutoRest.CSharp/Mgmt/Output/MgmtMockableArmClient.cs b/src/AutoRest.CSharp/Mgmt/Output/MgmtMockableArmClient.cs
new file mode 100644
index 00000000000..5f1c652e332
--- /dev/null
+++ b/src/AutoRest.CSharp/Mgmt/Output/MgmtMockableArmClient.cs
@@ -0,0 +1,179 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT License
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using AutoRest.CSharp.Common.Output.Expressions.KnownValueExpressions;
+using AutoRest.CSharp.Common.Output.Expressions.Statements;
+using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions;
+using AutoRest.CSharp.Common.Output.Models;
+using AutoRest.CSharp.Generation.Types;
+using AutoRest.CSharp.Generation.Writers;
+using AutoRest.CSharp.Mgmt.AutoRest;
+using AutoRest.CSharp.Mgmt.Decorator;
+using AutoRest.CSharp.Mgmt.Models;
+using AutoRest.CSharp.Output.Models;
+using AutoRest.CSharp.Output.Models.Shared;
+using Azure.Core;
+
+namespace AutoRest.CSharp.Mgmt.Output
+{
+ internal class MgmtMockableArmClient : MgmtMockableExtension
+ {
+ public MgmtMockableArmClient(CSharpType resourceType, IEnumerable operations, MgmtExtension? extensionForChildResources) : base(resourceType, operations, extensionForChildResources)
+ {
+ }
+
+ public override FormattableString IdVariableName => $"scope";
+
+ public override FormattableString BranchIdVariableName => $"scope";
+
+ public override bool IsEmpty => !ClientOperations.Any() && !MgmtContext.Library.ArmResources.Any();
+
+ protected override Method BuildGetSingletonResourceMethod(Resource resource)
+ {
+ var originalMethod = base.BuildGetSingletonResourceMethod(resource);
+ if (IsArmCore)
+ return originalMethod;
+
+ // we need to add a scope parameter inside the method signature
+ var originalSignature = (MethodSignature)originalMethod.Signature;
+ var signature = originalSignature with
+ {
+ Parameters = originalSignature.Parameters.Prepend(_scopeParameter).ToArray()
+ };
+
+ var scopeTypes = resource.RequestPath.GetParameterizedScopeResourceTypes();
+ var methodBody = new MethodBodyStatement[]
+ {
+ BuildScopeResourceTypeValidations(scopeTypes),
+ Snippets.Return(
+ Snippets.New.Instance(resource.Type, ArmClientProperty, resource.SingletonResourceIdSuffix!.BuildResourceIdentifier(_scopeParameter)))
+ };
+
+ return new(signature, methodBody);
+ }
+
+ protected override Method BuildGetChildCollectionMethod(ResourceCollection collection)
+ {
+ var originalMethod = base.BuildGetChildCollectionMethod(collection);
+ if (IsArmCore)
+ return originalMethod;
+
+ // we need to add a scope parameter inside the method signature
+ var originalSignature = (MethodSignature)originalMethod.Signature;
+ var signature = originalSignature with
+ {
+ Parameters = originalSignature.Parameters.Prepend(_scopeParameter).ToArray()
+ };
+
+ var scopeTypes = collection.RequestPath.GetParameterizedScopeResourceTypes();
+ var ctorArguments = new List
+ {
+ ArmClientProperty,
+ _scopeParameter
+ };
+ ctorArguments.AddRange(originalSignature.Parameters.Select(p => (ValueExpression)p));
+ var methodBody = new MethodBodyStatement[]
+ {
+ BuildScopeResourceTypeValidations(scopeTypes),
+ Snippets.Return(
+ Snippets.New.Instance(collection.Type, ctorArguments.ToArray()))
+ };
+
+ return new(signature, methodBody);
+ }
+
+ private MethodBodyStatement BuildScopeResourceTypeValidations(ResourceTypeSegment[]? scopeTypes)
+ {
+ if (scopeTypes is null || !scopeTypes.Any() || scopeTypes.Contains(ResourceTypeSegment.Any))
+ return MethodBodyStatement.Empty;
+
+ var scopeVariable = (ValueExpression)_scopeParameter;
+ var resourceTypeVariable = new ResourceIdentifierExpression(_scopeParameter).ResourceType;
+ var conditions = new List();
+ var resourceTypeStrings = new List();
+ foreach (var type in scopeTypes)
+ {
+ // here we have an expression of `!scope.ResourceType.Equals("")`
+ conditions.Add(
+ resourceTypeVariable.InvokeEquals(Snippets.Literal(type.ToString())).Not()
+ );
+ resourceTypeStrings.Add($"{type}");
+ }
+
+ // here we aggregate them together using or operator || and get: scope.ResourceType.Equals("") || scope.ResourceType.Equals("")
+ var condition = conditions.Aggregate((a, b) => a.Or(b));
+ var errorMessageFormat = $"Invalid resource type {{0}}, expected {resourceTypeStrings.Join(", ", " or ")}";
+ return new IfStatement(condition)
+ {
+ Snippets.Throw(
+ Snippets.New.Instance(
+ typeof(ArgumentException),
+ new InvokeStaticMethodExpression(
+ typeof(string),
+ nameof(string.Format),
+ new ValueExpression[] { Snippets.Literal(errorMessageFormat), resourceTypeVariable })
+ ))
+ };
+ }
+
+ private IEnumerable? _armResourceMethods;
+ public IEnumerable ArmResourceMethods => _armResourceMethods ??= BuildArmResourceMethods();
+
+ private IEnumerable BuildArmResourceMethods()
+ {
+ foreach (var resource in MgmtContext.Library.ArmResources)
+ {
+ yield return BuildArmResourceMethod(resource);
+ }
+ }
+
+ private Method BuildArmResourceMethod(Resource resource)
+ {
+ var lines = new List();
+ string an = resource.Type.Name.StartsWithVowel() ? "an" : "a";
+ lines.Add($"Gets an object representing {an} along with the instance operations that can be performed on it but with no data.");
+ lines.Add($"You can use to create {an} from its components.");
+ var description = FormattableStringHelpers.Join(lines, Environment.NewLine);
+
+ var parameters = new List
+ {
+ _resourceIdParameter
+ };
+
+ var signature = new MethodSignature(
+ $"Get{resource.Type.Name}",
+ null,
+ description,
+ MethodModifiers,
+ resource.Type,
+ $"Returns a object.",
+ parameters);
+
+ var methodBody = new MethodBodyStatement[]{
+ new InvokeStaticMethodStatement(resource.Type, "ValidateResourceId", _resourceIdParameter),
+ Snippets.Return(Snippets.New.Instance(resource.Type, ArmClientProperty, _resourceIdParameter))
+ };
+
+ return new(signature, methodBody);
+ }
+
+ private readonly Parameter _resourceIdParameter = new(
+ Name: "id",
+ Description: $"The resource ID of the resource to get.",
+ Type: typeof(ResourceIdentifier),
+ DefaultValue: null,
+ Validation: ValidationType.None,
+ Initializer: null);
+
+ private readonly Parameter _scopeParameter = new Parameter(
+ Name: "scope",
+ Description: $"The scope that the resource will apply against.",
+ Type: typeof(ResourceIdentifier),
+ DefaultValue: null,
+ Validation: ValidationType.None,
+ Initializer: null);
+ }
+}
diff --git a/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionClient.cs b/src/AutoRest.CSharp/Mgmt/Output/MgmtMockableExtension.cs
similarity index 56%
rename from src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionClient.cs
rename to src/AutoRest.CSharp/Mgmt/Output/MgmtMockableExtension.cs
index 662d9dd039a..70f26d9c64f 100644
--- a/src/AutoRest.CSharp/Mgmt/Output/MgmtExtensionClient.cs
+++ b/src/AutoRest.CSharp/Mgmt/Output/MgmtMockableExtension.cs
@@ -6,35 +6,35 @@
using System.Linq;
using System.Text;
using AutoRest.CSharp.Generation.Types;
-using AutoRest.CSharp.Generation.Writers;
+using AutoRest.CSharp.Mgmt.AutoRest;
using AutoRest.CSharp.Mgmt.Decorator;
using AutoRest.CSharp.Mgmt.Models;
using AutoRest.CSharp.Output.Models;
-using AutoRest.CSharp.Output.Models.Shared;
using AutoRest.CSharp.Utilities;
-using Azure.Core;
using Azure.ResourceManager;
using static AutoRest.CSharp.Output.Models.MethodSignatureModifiers;
namespace AutoRest.CSharp.Mgmt.Output
{
- internal class MgmtExtensionClient : MgmtTypeProvider
+ internal class MgmtMockableExtension : MgmtTypeProvider
{
private readonly IEnumerable _operations;
private readonly MgmtExtension? _extensionForChildResources;
- public MgmtExtensionClient(CSharpType resourceType, IEnumerable operations, MgmtExtension? extensionForChildResources)
+ public MgmtMockableExtension(CSharpType resourceType, IEnumerable operations, MgmtExtension? extensionForChildResources)
: base(resourceType.Name)
{
_operations = operations;
_extensionForChildResources = extensionForChildResources;
ExtendedResourceType = resourceType;
- DefaultName = $"{ResourceName}ExtensionClient";
+ // name of this class is like "MockableComputeResourceGroupResource"
+ DefaultName = GetMockableExtensionDefaultName(resourceType.Name);
}
- public override bool IsInitializedByProperties => true;
+ internal static string GetMockableExtensionDefaultName(string resourceName)
+ => $"Mockable{MgmtContext.RPName}{resourceName}";
- public override bool HasChildResourceGetMethods => false;
+ public override bool IsInitializedByProperties => true;
protected override ConstructorSignature? EnsureArmClientCtor()
{
@@ -52,64 +52,6 @@ public MgmtExtensionClient(CSharpType resourceType, IEnumerable _factoryMethodName ??= $"Get{Declaration.Name}";
- private IEnumerable? _factoryMethods;
- public IEnumerable FactoryMethods => _factoryMethods ??= EnsureFactoryMethods();
-
- private IEnumerable EnsureFactoryMethods()
- {
- var resourceExtensionMethod = new MethodSignature(
- FactoryMethodName,
- null,
- null,
- Private | Static,
- Type,
- null,
- new[] { _generalExtensionParameter });
- Action resourceExtensionMethodBody = writer =>
- {
- using (writer.Scope($"return {_generalExtensionParameter.Name}.GetCachedClient(client =>", newLine: false))
- {
- writer.Line($"return new {Type}(client, {_generalExtensionParameter.Name}.Id);");
- }
- writer.LineRaw(");");
- };
- yield return new(resourceExtensionMethod, resourceExtensionMethodBody);
-
- var scopeExtensionMethod = new MethodSignature(
- FactoryMethodName,
- null,
- null,
- Private | Static,
- Type,
- null,
- new[] { ArmClientParameter, _scopeParameter });
- Action