public void Pool_WhenReturnedFromServer_HasExpectedBoundProperties() { const string cloudPoolId = "id-123"; const string cloudPoolDisplayName = "pool-display-name-test"; MetadataItem metadataItem = new MetadataItem("foo", "bar"); using (BatchClient client = ClientUnitTestCommon.CreateDummyClient()) { Models.CloudPool protoPool = new Models.CloudPool(id: cloudPoolId, displayName: cloudPoolDisplayName, metadata: new[] { new Models.MetadataItem { Name = metadataItem.Name, Value = metadataItem.Value } }); CloudPool boundPool = client.PoolOperations.GetPool(string.Empty, additionalBehaviors: InterceptorFactory.CreateGetPoolRequestInterceptor(protoPool)); // Cannot change these bound properties. Assert.Throws <InvalidOperationException>(() => boundPool.DisplayName = "cannot-change-display-name"); Assert.Throws <InvalidOperationException>(() => boundPool.Id = "cannot-change-id"); Assert.Throws <InvalidOperationException>(() => boundPool.TargetDedicatedComputeNodes = 1); Assert.Throws <InvalidOperationException>(() => boundPool.VirtualMachineSize = "cannot-change-1"); // Swap the value with the name and the name with the value. boundPool.Metadata = new[] { new MetadataItem(metadataItem.Value, metadataItem.Name) }; Assert.Equal(metadataItem.Name, boundPool.Metadata.First().Value); Assert.Equal(metadataItem.Value, boundPool.Metadata.First().Name); } }
internal CloudPool( BatchClient parentBatchClient, Models.CloudPool protocolObject, IEnumerable <BatchClientBehavior> baseBehaviors) { this.parentBatchClient = parentBatchClient; InheritUtil.InheritClientBehaviorsAndSetPublicProperty(this, baseBehaviors); this.propertyContainer = new PropertyContainer(protocolObject); }
/// <summary> /// Builds a CloudPoolGetResponse object /// </summary> public static ProxyModels.CloudPoolGetResponse CreateCloudPoolGetResponse(string poolId) { ProxyModels.CloudPoolGetResponse response = new ProxyModels.CloudPoolGetResponse(); response.StatusCode = HttpStatusCode.OK; ProxyModels.CloudPool pool = new ProxyModels.CloudPool(); pool.Id = poolId; response.Pool = pool; return(response); }
/// <summary> /// Builds a CloudPoolGetResponse object /// </summary> public static AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> CreateCloudPoolGetResponse(string poolId) { var response = new AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders>(); response.Response = new HttpResponseMessage(HttpStatusCode.OK); ProxyModels.CloudPool pool = new ProxyModels.CloudPool(); pool.Id = poolId; response.Body = pool; return(response); }
/// <summary> /// Builds a CloudPoolListResponse object /// </summary> public static ProxyModels.CloudPoolListResponse CreateCloudPoolListResponse(IEnumerable <string> poolIds) { ProxyModels.CloudPoolListResponse response = new ProxyModels.CloudPoolListResponse(); response.StatusCode = HttpStatusCode.OK; List <ProxyModels.CloudPool> pools = new List <ProxyModels.CloudPool>(); foreach (string id in poolIds) { ProxyModels.CloudPool pool = new ProxyModels.CloudPool(); pool.Id = id; pools.Add(pool); } response.Pools = pools; return(response); }
/// <summary> /// Builds a CloudPoolListResponse object /// </summary> public static AzureOperationResponse <IPage <ProxyModels.CloudPool>, ProxyModels.PoolListHeaders> CreateCloudPoolListResponse(IEnumerable <string> poolIds) { var response = new AzureOperationResponse <IPage <ProxyModels.CloudPool>, ProxyModels.PoolListHeaders>(); response.Response = new HttpResponseMessage(HttpStatusCode.OK); List <ProxyModels.CloudPool> pools = new List <ProxyModels.CloudPool>(); foreach (string id in poolIds) { ProxyModels.CloudPool pool = new ProxyModels.CloudPool(); pool.Id = id; pools.Add(pool); } response.Body = new MockPagedEnumerable <ProxyModels.CloudPool>(pools); return(response); }
public void GetBatchPoolTest() { // Setup cmdlet to get a pool by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Id = "testPool"; cmdlet.Filter = null; // Pool returned in the response ProxyModels.CloudPool pool = new ProxyModels.CloudPool(); pool.Id = cmdlet.Id; pool.TaskSlotsPerNode = 16; // Build a CloudPool instead of querying the service on a Get CloudPool call AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> response = BatchTestHelpers.CreateCloudPoolGetResponse(pool); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.PoolGetOptions, AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCloudPool> pipeline = new List <PSCloudPool>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudPool>())).Callback <object>(p => pipeline.Add((PSCloudPool)p)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the pool returned from the OM to the pipeline Assert.Single(pipeline); Assert.Equal(cmdlet.Id, pipeline[0].Id); Assert.Equal(16, pipeline[0].TaskSlotsPerNode); }
public PropertyContainer(Models.CloudPool protocolObject) : base(BindingState.Bound) { this.AllocationStateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.AllocationState, Common.AllocationState>(protocolObject.AllocationState), nameof(AllocationState), BindingAccess.Read); this.AllocationStateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.AllocationStateTransitionTime, nameof(AllocationStateTransitionTime), BindingAccess.Read); this.ApplicationLicensesProperty = this.CreatePropertyAccessor( UtilitiesInternal.CollectionToThreadSafeCollection(protocolObject.ApplicationLicenses, o => o), nameof(ApplicationLicenses), BindingAccess.Read); this.ApplicationPackageReferencesProperty = this.CreatePropertyAccessor( ApplicationPackageReference.ConvertFromProtocolCollection(protocolObject.ApplicationPackageReferences), nameof(ApplicationPackageReferences), BindingAccess.Read | BindingAccess.Write); this.AutoScaleEnabledProperty = this.CreatePropertyAccessor( protocolObject.EnableAutoScale, nameof(AutoScaleEnabled), BindingAccess.Read); this.AutoScaleEvaluationIntervalProperty = this.CreatePropertyAccessor( protocolObject.AutoScaleEvaluationInterval, nameof(AutoScaleEvaluationInterval), BindingAccess.Read); this.AutoScaleFormulaProperty = this.CreatePropertyAccessor( protocolObject.AutoScaleFormula, nameof(AutoScaleFormula), BindingAccess.Read); this.AutoScaleRunProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.AutoScaleRun, o => new AutoScaleRun(o).Freeze()), nameof(AutoScaleRun), BindingAccess.Read); this.CertificateReferencesProperty = this.CreatePropertyAccessor( CertificateReference.ConvertFromProtocolCollection(protocolObject.CertificateReferences), nameof(CertificateReferences), BindingAccess.Read | BindingAccess.Write); this.CloudServiceConfigurationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.CloudServiceConfiguration, o => new CloudServiceConfiguration(o).Freeze()), nameof(CloudServiceConfiguration), BindingAccess.Read); this.CreationTimeProperty = this.CreatePropertyAccessor( protocolObject.CreationTime, nameof(CreationTime), BindingAccess.Read); this.CurrentDedicatedComputeNodesProperty = this.CreatePropertyAccessor( protocolObject.CurrentDedicatedNodes, nameof(CurrentDedicatedComputeNodes), BindingAccess.Read); this.CurrentLowPriorityComputeNodesProperty = this.CreatePropertyAccessor( protocolObject.CurrentLowPriorityNodes, nameof(CurrentLowPriorityComputeNodes), BindingAccess.Read); this.DisplayNameProperty = this.CreatePropertyAccessor( protocolObject.DisplayName, nameof(DisplayName), BindingAccess.Read); this.ETagProperty = this.CreatePropertyAccessor( protocolObject.ETag, nameof(ETag), BindingAccess.Read); this.IdProperty = this.CreatePropertyAccessor( protocolObject.Id, nameof(Id), BindingAccess.Read); this.IdentityProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Identity, o => new BatchPoolIdentity(o)), nameof(Identity), BindingAccess.Read | BindingAccess.Write); this.InterComputeNodeCommunicationEnabledProperty = this.CreatePropertyAccessor( protocolObject.EnableInterNodeCommunication, nameof(InterComputeNodeCommunicationEnabled), BindingAccess.Read); this.LastModifiedProperty = this.CreatePropertyAccessor( protocolObject.LastModified, nameof(LastModified), BindingAccess.Read); this.MetadataProperty = this.CreatePropertyAccessor( MetadataItem.ConvertFromProtocolCollection(protocolObject.Metadata), nameof(Metadata), BindingAccess.Read | BindingAccess.Write); this.MountConfigurationProperty = this.CreatePropertyAccessor( Batch.MountConfiguration.ConvertFromProtocolCollectionAndFreeze(protocolObject.MountConfiguration), nameof(MountConfiguration), BindingAccess.Read); this.NetworkConfigurationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.NetworkConfiguration, o => new NetworkConfiguration(o).Freeze()), nameof(NetworkConfiguration), BindingAccess.Read); this.ResizeErrorsProperty = this.CreatePropertyAccessor( ResizeError.ConvertFromProtocolCollectionReadOnly(protocolObject.ResizeErrors), nameof(ResizeErrors), BindingAccess.Read); this.ResizeTimeoutProperty = this.CreatePropertyAccessor( protocolObject.ResizeTimeout, nameof(ResizeTimeout), BindingAccess.Read); this.StartTaskProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.StartTask, o => new StartTask(o)), nameof(StartTask), BindingAccess.Read | BindingAccess.Write); this.StateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.PoolState, Common.PoolState>(protocolObject.State), nameof(State), BindingAccess.Read); this.StateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.StateTransitionTime, nameof(StateTransitionTime), BindingAccess.Read); this.StatisticsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Stats, o => new PoolStatistics(o).Freeze()), nameof(Statistics), BindingAccess.Read); this.TargetDedicatedComputeNodesProperty = this.CreatePropertyAccessor( protocolObject.TargetDedicatedNodes, nameof(TargetDedicatedComputeNodes), BindingAccess.Read); this.TargetLowPriorityComputeNodesProperty = this.CreatePropertyAccessor( protocolObject.TargetLowPriorityNodes, nameof(TargetLowPriorityComputeNodes), BindingAccess.Read); this.TaskSchedulingPolicyProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.TaskSchedulingPolicy, o => new TaskSchedulingPolicy(o).Freeze()), nameof(TaskSchedulingPolicy), BindingAccess.Read); this.TaskSlotsPerNodeProperty = this.CreatePropertyAccessor( protocolObject.TaskSlotsPerNode, nameof(TaskSlotsPerNode), BindingAccess.Read); this.UrlProperty = this.CreatePropertyAccessor( protocolObject.Url, nameof(Url), BindingAccess.Read); this.UserAccountsProperty = this.CreatePropertyAccessor( UserAccount.ConvertFromProtocolCollectionAndFreeze(protocolObject.UserAccounts), nameof(UserAccounts), BindingAccess.Read); this.VirtualMachineConfigurationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.VirtualMachineConfiguration, o => new VirtualMachineConfiguration(o).Freeze()), nameof(VirtualMachineConfiguration), BindingAccess.Read); this.VirtualMachineSizeProperty = this.CreatePropertyAccessor( protocolObject.VmSize, nameof(VirtualMachineSize), BindingAccess.Read); }
public static IEnumerable <Protocol.RequestInterceptor> CreateGetPoolRequestInterceptor(Protocol.Models.CloudPool poolToReturn) { return(CreateGetRequestInterceptor <Protocol.Models.PoolGetOptions, Protocol.Models.CloudPool, Protocol.Models.PoolGetHeaders>(poolToReturn)); }
public PropertyContainer(Models.CloudPool protocolObject) : base(BindingState.Bound) { this.AllocationStateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.AllocationState, Common.AllocationState>(protocolObject.AllocationState), "AllocationState", BindingAccess.Read); this.AllocationStateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.AllocationStateTransitionTime, "AllocationStateTransitionTime", BindingAccess.Read); this.ApplicationPackageReferencesProperty = this.CreatePropertyAccessor( ApplicationPackageReference.ConvertFromProtocolCollection(protocolObject.ApplicationPackageReferences), "ApplicationPackageReferences", BindingAccess.Read | BindingAccess.Write); this.AutoScaleEnabledProperty = this.CreatePropertyAccessor( protocolObject.EnableAutoScale, "AutoScaleEnabled", BindingAccess.Read); this.AutoScaleEvaluationIntervalProperty = this.CreatePropertyAccessor( protocolObject.AutoScaleEvaluationInterval, "AutoScaleEvaluationInterval", BindingAccess.Read); this.AutoScaleFormulaProperty = this.CreatePropertyAccessor( protocolObject.AutoScaleFormula, "AutoScaleFormula", BindingAccess.Read); this.AutoScaleRunProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.AutoScaleRun, o => new AutoScaleRun(o).Freeze()), "AutoScaleRun", BindingAccess.Read); this.CertificateReferencesProperty = this.CreatePropertyAccessor( CertificateReference.ConvertFromProtocolCollection(protocolObject.CertificateReferences), "CertificateReferences", BindingAccess.Read | BindingAccess.Write); this.CloudServiceConfigurationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.CloudServiceConfiguration, o => new CloudServiceConfiguration(o).Freeze()), "CloudServiceConfiguration", BindingAccess.Read); this.CreationTimeProperty = this.CreatePropertyAccessor( protocolObject.CreationTime, "CreationTime", BindingAccess.Read); this.CurrentDedicatedProperty = this.CreatePropertyAccessor( protocolObject.CurrentDedicated, "CurrentDedicated", BindingAccess.Read); this.DisplayNameProperty = this.CreatePropertyAccessor( protocolObject.DisplayName, "DisplayName", BindingAccess.Read); this.ETagProperty = this.CreatePropertyAccessor( protocolObject.ETag, "ETag", BindingAccess.Read); this.IdProperty = this.CreatePropertyAccessor( protocolObject.Id, "Id", BindingAccess.Read); this.InterComputeNodeCommunicationEnabledProperty = this.CreatePropertyAccessor( protocolObject.EnableInterNodeCommunication, "InterComputeNodeCommunicationEnabled", BindingAccess.Read); this.LastModifiedProperty = this.CreatePropertyAccessor( protocolObject.LastModified, "LastModified", BindingAccess.Read); this.MaxTasksPerComputeNodeProperty = this.CreatePropertyAccessor( protocolObject.MaxTasksPerNode, "MaxTasksPerComputeNode", BindingAccess.Read); this.MetadataProperty = this.CreatePropertyAccessor( MetadataItem.ConvertFromProtocolCollection(protocolObject.Metadata), "Metadata", BindingAccess.Read | BindingAccess.Write); this.NetworkConfigurationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.NetworkConfiguration, o => new NetworkConfiguration(o).Freeze()), "NetworkConfiguration", BindingAccess.Read); this.ResizeErrorProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ResizeError, o => new ResizeError(o).Freeze()), "ResizeError", BindingAccess.Read); this.ResizeTimeoutProperty = this.CreatePropertyAccessor( protocolObject.ResizeTimeout, "ResizeTimeout", BindingAccess.Read); this.StartTaskProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.StartTask, o => new StartTask(o)), "StartTask", BindingAccess.Read | BindingAccess.Write); this.StateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum <Models.PoolState, Common.PoolState>(protocolObject.State), "State", BindingAccess.Read); this.StateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.StateTransitionTime, "StateTransitionTime", BindingAccess.Read); this.StatisticsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Stats, o => new PoolStatistics(o).Freeze()), "Statistics", BindingAccess.Read); this.TargetDedicatedProperty = this.CreatePropertyAccessor( protocolObject.TargetDedicated, "TargetDedicated", BindingAccess.Read); this.TaskSchedulingPolicyProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.TaskSchedulingPolicy, o => new TaskSchedulingPolicy(o).Freeze()), "TaskSchedulingPolicy", BindingAccess.Read); this.UrlProperty = this.CreatePropertyAccessor( protocolObject.Url, "Url", BindingAccess.Read); this.VirtualMachineConfigurationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.VirtualMachineConfiguration, o => new VirtualMachineConfiguration(o).Freeze()), "VirtualMachineConfiguration", BindingAccess.Read); this.VirtualMachineSizeProperty = this.CreatePropertyAccessor( protocolObject.VmSize, "VirtualMachineSize", BindingAccess.Read); }
/// <summary> /// Builds a CloudPoolListResponse object /// </summary> public static ProxyModels.CloudPoolListResponse CreateCloudPoolListResponse(IEnumerable<string> poolIds) { ProxyModels.CloudPoolListResponse response = new ProxyModels.CloudPoolListResponse(); response.StatusCode = HttpStatusCode.OK; List<ProxyModels.CloudPool> pools = new List<ProxyModels.CloudPool>(); foreach (string id in poolIds) { ProxyModels.CloudPool pool = new ProxyModels.CloudPool(); pool.Id = id; pools.Add(pool); } response.Pools = pools; return response; }
/// <summary> /// Builds a CloudPoolGetResponse object /// </summary> public static ProxyModels.CloudPoolGetResponse CreateCloudPoolGetResponse(string poolId) { ProxyModels.CloudPoolGetResponse response = new ProxyModels.CloudPoolGetResponse(); response.StatusCode = HttpStatusCode.OK; ProxyModels.CloudPool pool = new ProxyModels.CloudPool(); pool.Id = poolId; response.Pool = pool; return response; }