示例#1
0
        public override void ExecuteCmdlet()
        {
            var  virtualMachineOperations = new VirtualMachineOperations(this.WebClientFactory);
            Guid?jobId = null;

            ConfirmAction(
                Force.IsPresent,
                string.Format(Resources.RemoveVMConfirmationMessage, VM.Name),
                string.Format(Resources.RemoveVMMessage),
                VM.Name,
                () =>
            {
                virtualMachineOperations.Delete(VM.ID, out jobId);

                if (!jobId.HasValue)
                {
                    throw new WAPackOperationException(String.Format(Resources.OperationFailedErrorMessage, Resources.Delete, VM.ID));
                }
                var jobInfo = WaitForJobCompletion(jobId);

                if (PassThru)
                {
                    WriteObject(jobInfo.jobStatus != JobStatusEnum.Failed);
                }
            });
        }
        protected override void ExecuteCommand()
        {
            var virtualMachineOperations = new VirtualMachineOperations(this.WebClientFactory);
            Guid? jobId = null;

            ConfirmAction(
                        Force.IsPresent,
                        string.Format(Resources.RemoveVMConfirmationMessage, VM.Name),
                        string.Format(Resources.RemoveVMMessage),
                        VM.Name,
                        () =>
                        {
                            virtualMachineOperations.Delete(VM.ID, out jobId);

                            if (!jobId.HasValue)
                            {
                                throw new WAPackOperationException(String.Format(Resources.OperationFailedErrorMessage, Resources.Delete, VM.ID));
                            }

                            var jobInfo = new JobOperations(this.WebClientFactory).WaitOnJob(jobId.Value);
                            if (jobInfo.jobStatus == JobStatusEnum.Failed)
                            {
                                this.WriteErrorDetails(new Exception(jobInfo.errorMessage));
                            }

                            if (PassThru)
                            {
                                WriteObject(jobInfo.jobStatus != JobStatusEnum.Failed);
                            }

                        });
        }
示例#3
0
        public void DeleteVM()
        {
            var sub     = new Subscription();
            var channel = new MockRequestChannel();

            //Response to client getting /Clouds (client needs stampId, gets it from clouds)
            var testCloud = new Cloud {
                ID = Guid.NewGuid(), StampId = Guid.NewGuid()
            };

            channel.AddReturnObject(testCloud);

            //Response to the DELETE
            channel.AddReturnObject(null, new WebHeaderCollection {
                "x-ms-request-id:" + Guid.NewGuid()
            });

            var vmOps = new VirtualMachineOperations(new WebClientFactory(sub, channel));

            Guid toDelete = Guid.NewGuid();
            Guid?jobOut;

            vmOps.Delete(toDelete, out jobOut);

            //Check the requests the client generated
            Assert.Equal(channel.ClientRequests.Count, 2);
            Assert.Equal(channel.ClientRequests[1].Item1.Method, HttpMethod.Delete.ToString());
        }
        public void DeleteVM()
        {
            var sub = new Subscription();
            var channel = new MockRequestChannel();

            //Response to client getting /Clouds (client needs stampId, gets it from clouds)
            var testCloud = new Cloud { ID = Guid.NewGuid(), StampId = Guid.NewGuid() };
            channel.AddReturnObject(testCloud);

            //Response to the DELETE
            channel.AddReturnObject(null, new WebHeaderCollection {"x-ms-request-id:" + Guid.NewGuid()});

            var vmOps = new VirtualMachineOperations(new WebClientFactory(sub, channel));

            Guid toDelete = Guid.NewGuid();
            Guid? jobOut;

            vmOps.Delete(toDelete, out jobOut);

            //Check the requests the client generated
            Assert.AreEqual(channel.ClientRequests.Count, 2);
            Assert.AreEqual(channel.ClientRequests[1].Item1.Method, HttpMethod.Delete.ToString());
        }