protected override void Run()
        {
            // If either of the static memories has changed, we need to shut down the VM
            // before and reboot afterwards. The user has already been warned about this.
            bool reboot = needReboot;
            XenAPI.Host vmHost = null;
            if (reboot)
            {
                vmHost = VM.Home();
                AsyncAction action = null;
                if (VM.allowed_operations.Contains(XenAPI.vm_operations.clean_shutdown))
                    action = new VMCleanShutdown(VM);
                else
                    action = new VMHardShutdown(VM);
                action.RunExternal(Session);
            }

            // Now save the memory settings. We can't use VM.SaveChanges() for this,
            // because we have to do the operations simultaneously or we will
            // violate the memory ordering constraints.
            try
            {
                if (staticChanged)
                    XenAPI.VM.set_memory_limits(Session, VM.opaque_ref, static_min, static_max, dynamic_min, dynamic_max);
                else
                    XenAPI.VM.set_memory_dynamic_range(Session, VM.opaque_ref, dynamic_min, dynamic_max);
            }

            // Reboot the VM, even if we failed to change the memory settings
            finally
            {
                if (reboot)
                {
                    var action = new VMStartOnAction(VM, vmHost, _warningDialogHAInvalidConfig, _startDiagnosticForm);
                    action.RunExternal(Session);
                }
            }

            Description = string.Format(Messages.ACTION_CHANGE_MEMORY_SETTINGS_DONE, VM.Name);
        }
        public void ShutdownVMPureAsyncActionTest()
        {

            mockProxy.Setup(x => x.async_vm_clean_shutdown(It.IsAny<string>(), It.IsAny<string>())).Returns(new Response<string>(""));
            VM vm = GetVM();
            SetupPureAsyncAction(vm);
            ExtraAsyncMethodsSetup();
            vm.power_state = vm_power_state.Halted;
            var action = new VMCleanShutdown(vm);
            action.Completed += action_Completed;
            action.RunAsync();
            _autoResetEvent.WaitOne();
            Assert.True(action.Succeeded);
            mockProxy.VerifyAll();
        }