public void VirtualMachineCreatePostValid()
        {
            // Arrange
            var mockVmRepo = new Mock<IVirtualMachineRepository>();
            var mockConfigRepo = new Mock<IConfigurationRepository>();

            var vm = new VirtualMachine();

            mockVmRepo.Setup(v => v.CreateVirtualMachine(vm, ""));

            var projects = new List<ProjectViewModel>();
            projects.Add(new ProjectViewModel());
            projects.Add(new ProjectViewModel());

            var controller = new VirtualMachineController(mockVmRepo.Object, mockConfigRepo.Object);

            // Act
            var result = controller.Create() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            var model = result.ViewData.Model as IList<ProjectViewModel>;
            Assert.AreEqual(3, model.Count);
            mockVmRepo.Verify();
        }
        public VirtualMachineFormViewModel(VirtualMachine vm, string projectName)
        {
            ProjectName = projectName;
            MachineName = vm.MachineName;
            BaseImageFile = vm.BaseImageFullPhysicalPath;

            IP = vm.IP;
            IsAutoStarted = vm.IsAutoStarted;
        }
예제 #3
0
        public VirtualMachineViewModel(VirtualMachine vm)
        {
            VirtualMachineId = vm.VirtualMachineId;
            ImagePathName = vm.ImagePathName;
            //BaseImageName = vm.BaseImageFullPhysicalPath;
            MachineName = vm.MachineName;
            IP = vm.IP;
            CreatedTime = vm.CreatedTime.ToString();
            LastStopped = vm.LastStopped.ToString();
            LastStarted = vm.LastStarted.ToString();
            LastArchived = vm.LastArchived.ToString();
            LastBackuped = vm.LastBackuped.ToString();

            switch (vm.Status)
            {
                case VirtualMachine.STOPPED:
                    Status = "stopped";
                    break;
                case VirtualMachine.PAUSED:
                    Status = "paused";
                    break;
                case VirtualMachine.SUSPENDED:
                    Status = "suspended";
                    break;
                case VirtualMachine.RUNNING:
                    Status = "running";
                    break;
                case VirtualMachine.POWERINGON:
                    Status = "powering-on";
                    break;
                case VirtualMachine.POWERINGOFF:
                    Status = "powering-off";
                    break;
                case VirtualMachine.PENDING:
                    Status = "pending";
                    break;
                case VirtualMachine.ARCHIVED:
                    Status = "archived";
                    break;
            }
            BaseImageName = System.IO.Path.GetFileNameWithoutExtension(vm.BaseImageFullPhysicalPath);

            //todo doesn't work
            if (vm.BaseImageFullPhysicalPath == "Windows 7")
                OperatingSystemIcon = "~/Content/themes/images/logo_windows-7.png";
            else if (vm.BaseImageFullPhysicalPath == "Windows Server 2008")
                OperatingSystemIcon = "~/Content/themes/images/logo_windows-server-2008.png";
            else
                OperatingSystemIcon = "~/Content/themes/images/logo_windows-7.png";
        }
예제 #4
0
        public ActionResult Create(VirtualMachineFormViewModel vmForm)
        {
            if (vmRepo.GetAllRegisteredVirtualMachines().Count < configRepo.GetMaxVmCount() ||
                configRepo.GetMaxVmCount() <= 0)
            {
                if (ModelState.IsValid)
                {
                    var vm = new VirtualMachine(vmForm, configRepo.GetVmCreationTime());
                    vmRepo.CreateVirtualMachine(vm, vmForm.ProjectName);

                    return RedirectToAction("Index");
                }
            }
            //TODO: Add comments to what this does
            var projectName = new SelectList(vmRepo.GetAllProjects(),
                "ProjectName", "ProjectName");

            ViewBag.ProjectName = projectName;
            ViewBag.BaseImageFile = new SelectList(
                VMAT.Services.RegisteredVirtualMachineService.GetBaseImageFiles());
            ViewBag.Hostname = AppConfiguration.GetVMHostName();
            vmForm.IP = vmRepo.GetNextAvailableIP().ToString();

            return View(vmForm);
        }
 public VirtualMachineFormViewModel(VirtualMachine vm)
 {
     MachineName = vm.MachineName;
     IP = vm.IP;
     IsAutoStarted = vm.IsAutoStarted;
 }
 public CreateVirtualMachineService(VirtualMachine vm)
 {
     VM = vm;
 }