public GetAutoscaleSettingCommandTests()
        {
            insightsAutoscaleOperationsMock = new Mock <IAutoscaleOperations>();
            insightsManagementClientMock    = new Mock <InsightsManagementClient>();
            commandRuntimeMock = new Mock <ICommandRuntime>();
            cmdlet             = new GetAutoscaleSettingCommand()
            {
                CommandRuntime           = commandRuntimeMock.Object,
                InsightsManagementClient = insightsManagementClientMock.Object
            };

            response = new AutoscaleSettingGetResponse()
            {
                RequestId  = Guid.NewGuid().ToString(),
                StatusCode = HttpStatusCode.OK,
                Id         = "",
                Location   = "",
                Name       = "",
                Properties = null,
                Tags       = null,
            };

            responseList = new AutoscaleSettingListResponse()
            {
                RequestId  = Guid.NewGuid().ToString(),
                StatusCode = HttpStatusCode.OK,
                AutoscaleSettingResourceCollection = new AutoscaleSettingResourceCollection()
                {
                    Value = new List <AutoscaleSettingResource>()
                    {
                        new AutoscaleSettingResource()
                        {
                            Id         = "",
                            Location   = "",
                            Name       = "",
                            Properties = null,
                            Tags       = null,
                        },
                    }
                }
            };

            insightsAutoscaleOperationsMock.Setup(f => f.GetSettingAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <AutoscaleSettingGetResponse>(response))
            .Callback((string resourceGrp, string settingNm, CancellationToken t) =>
            {
                resourceGroup = resourceGrp;
                settingName   = settingNm;
            });

            insightsAutoscaleOperationsMock.Setup(f => f.ListSettingsAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult <AutoscaleSettingListResponse>(responseList))
            .Callback((string resourceGrp, string targetResourceId, CancellationToken t) =>
            {
                resourceGroup     = resourceGrp;
                targetResourceUri = targetResourceId;
            });

            insightsManagementClientMock.SetupGet(f => f.AutoscaleOperations).Returns(this.insightsAutoscaleOperationsMock.Object);
        }
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        protected override void ExecuteCmdletInternal()
        {
            if (string.IsNullOrWhiteSpace(this.Name))
            {
                // Retrieve all the Autoscale settings for a resource group
                AutoscaleSettingListResponse result = this.InsightsManagementClient.AutoscaleOperations.ListSettingsAsync(resourceGroupName: this.ResourceGroup, targetResourceUri: null).Result;

                var records = result.AutoscaleSettingResourceCollection.Value.Select(e => this.DetailedOutput.IsPresent ? new PSAutoscaleSetting(e) : e);
                WriteObject(sendToPipeline: records, enumerateCollection: true);
            }
            else
            {
                // Retrieve a single Autoscale setting determined by the resource group and the rule name
                AutoscaleSettingGetResponse result = this.InsightsManagementClient.AutoscaleOperations.GetSettingAsync(resourceGroupName: this.ResourceGroup, autoscaleSettingName: this.Name).Result;
                WriteObject(sendToPipeline: this.DetailedOutput.IsPresent ? new PSAutoscaleSetting(result) : result.ToAutoscaleSettingGetResponse());
            }
        }
Пример #3
0
        /// <summary>
        /// Execute the cmdlet
        /// </summary>
        protected override void ProcessRecordInternal()
        {
            WriteWarning("This cmdlet is being modified to enable better experience and may contain breaking changes in a future release.");

            if (string.IsNullOrWhiteSpace(this.Name))
            {
                // Retrieve all the Autoscale settings for a resource group
                AutoscaleSettingListResponse result = this.InsightsManagementClient.AutoscaleOperations.ListSettingsAsync(resourceGroupName: this.ResourceGroup, targetResourceUri: null).Result;

                var records = result.AutoscaleSettingResourceCollection.Value.Select(e => this.DetailedOutput.IsPresent ? new PSAutoscaleSetting(e) : e);
                WriteObject(sendToPipeline: records, enumerateCollection: true);
            }
            else
            {
                // Retrieve a single Autoscale setting determined by the resource group and the rule name
                AutoscaleSettingGetResponse result = this.InsightsManagementClient.AutoscaleOperations.GetSettingAsync(resourceGroupName: this.ResourceGroup, autoscaleSettingName: this.Name).Result;

                WriteObject(sendToPipeline: this.DetailedOutput.IsPresent ? new PSAutoscaleSetting(result) : result.ToAutoscaleSettingGetResponse());
            }
        }