/// <summary> /// Begins an asynchronous call to create or update a user account on the compute node. /// </summary> /// <param name="addOrUpdate">Selects the type of commit operation to perform.</param> /// <param name="additionalBehaviors">A collection of BatchClientBehavior instances that are applied after the CustomBehaviors on the current object.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param> /// <returns>A <see cref="System.Threading.Tasks.Task"/> object that represents the asynchronous operation.</returns> public Task CommitAsync( ComputeNodeUserCommitSemantics addOrUpdate = ComputeNodeUserCommitSemantics.AddUser, IEnumerable <BatchClientBehavior> additionalBehaviors = null, CancellationToken cancellationToken = default(CancellationToken)) { // create the behavior managaer BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors); Task asyncTask; if (ComputeNodeUserCommitSemantics.AddUser == addOrUpdate) { Models.ComputeNodeUser protoUser = new Models.ComputeNodeUser() { Name = this.Name, Password = this.Password, }; protoUser.ExpiryTime = this.ExpiryTime; protoUser.IsAdmin = this.IsAdmin; protoUser.SshPublicKey = this.SshPublicKey; // begin the adduser call asyncTask = this.parentBatchClient.ProtocolLayer.AddComputeNodeUser(this.parentPoolId, this.parentNodeId, protoUser, bhMgr, cancellationToken); } else { // begin the update call asyncTask = this.parentBatchClient.ProtocolLayer.UpdateComputeNodeUser( this.parentPoolId, this.parentNodeId, this.Name, this.Password, this.ExpiryTime, this.SshPublicKey, bhMgr, cancellationToken); } return(asyncTask); }
public void NewBatchComputeNodeUserParametersGetPassedToRequestTest() { BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "computeNode1"; cmdlet.Name = "user"; cmdlet.Password = "******"; cmdlet.IsAdmin = true; cmdlet.ExpiryTime = DateTime.Now.AddDays(30); ProxyModels.ComputeNodeUser requestParameters = null; // Store the request parameters RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeUser, ProxyModels.ComputeNodeAddUserOptions, AzureOperationHeaderResponse <ProxyModels.ComputeNodeAddUserHeaders> >(requestAction: (r) => { requestParameters = r.Parameters; }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; cmdlet.ExecuteCmdlet(); // Verify the request parameters match the cmdlet parameters Assert.Equal(cmdlet.Name, requestParameters.Name); Assert.Equal(cmdlet.Password, requestParameters.Password); Assert.Equal(cmdlet.IsAdmin, requestParameters.IsAdmin); Assert.Equal(cmdlet.ExpiryTime, requestParameters.ExpiryTime); }