Пример #1
0
        [TestMethod] public void ListVms_Props_Consistent()
        {
            if (VBox.VBoxManagePath == null)
            {
                Assert.Inconclusive("Unable to test if Has_VMs without VBoxManage"); return;
            }

            var vms = VBox.ListVms().ToList();

            if (vms.Count == 0)
            {
                Assert.Inconclusive("Unable to test if Has_VMs without VBoxManage"); return;
            }

            foreach (var vm in vms)
            {
                var vmProps = VBox.VmInfoDictionary(vm);
                Assert.IsTrue(vmProps.ContainsKey("name"), "VM properties should include 'name' field");
                Assert.IsTrue(vmProps.ContainsKey("chipset"), "VM properties should include 'chipset' field");
                Assert.IsTrue(vmProps.ContainsKey("ostype"), "VM properties should include 'ostype' field");

                Assert.IsFalse(vmProps.ContainsKey("nonexistant"), "VM properties shouldn't include 'nonexistant' field");
                Assert.IsFalse(vmProps.ContainsKey(""), "VM properties shouldn't include blank keys");

                Assert.AreEqual(vm.Name, vmProps["name"], "VM name property should match name from parsed list");
                Assert.AreEqual(vm.Guid.TrimStart('{').TrimEnd('}'), vmProps["UUID"], "VM UUID property should match guid from parsed list (minus {}s)");
            }
        }
        [TestMethod] public void Clone_Delete_VMs()
        {
            if (VBox.VBoxManagePath == null)
            {
                Assert.Inconclusive("Unable to test without VBoxManage"); return;
            }

            var vms = VBox.ListVms().ToList();

            if (vms.Count == 0)
            {
                Assert.Inconclusive("Unable to test without VMs"); return;
            }

            bool foundVmToTest = false;

            foreach (var original in vms)
            {
                string desc;
                if (!VBox.VmInfoDictionary(original).TryGetValue("description", out desc) || !desc.Contains("clone testing vm"))
                {
                    continue;
                }
                foundVmToTest = true;

                var clone = VBox.CloneVm(original);
                try {
                    Guid g;
                    Assert.IsTrue(clone.Name.StartsWith("Clone of "), "Cloned VMs should be named as such");
                    Assert.IsTrue(Guid.TryParse(clone.Guid, out g), "Cloned VMs should have sane GUIDs");
                    Assert.AreNotEqual(original.Guid, clone.Guid, "Cloned VMs should have new unique GUIDs");
                }
                finally { Assert.IsTrue(VBox.TryDeleteVm(clone)); }
            }

            if (!foundVmToTest)
            {
                Assert.Inconclusive("Unable to test:  No VMs tagged 'clone testing vm' in their descriptions.");
            }
        }
Пример #3
0
        [TestMethod] public void ModifyVm_NatForward_Delete()
        {
            if (VBox.VBoxManagePath == null)
            {
                Assert.Inconclusive("Unable to test without VBoxManage"); return;
            }
            var vms = VBox.ListVms().ToList();

            if (vms.Count == 0)
            {
                Assert.Inconclusive("Unable to test without VMs"); return;
            }

            bool foundVmToTest = false;

            foreach (var original in vms)
            {
                string desc;
                if (!VBox.VmInfoDictionary(original).TryGetValue("description", out desc) || !desc.Contains("clone testing vm"))
                {
                    continue;
                }
                foundVmToTest = true;

                var clone = VBox.CloneVm(original);
                Assert.IsFalse(clone.IsNull);
                try {
                    VBox.ModifyVmNatPortForward(clone, 1, "ssh", VirtualBox.PortType.Tcp, "127.0.0.2", 3022, null, 22);
                    try {
                        VBox.ModifyVmNatPortForward(clone, 1, "ssh", VirtualBox.PortType.Tcp, "127.0.0.2", 3022, null, 22);
                        Assert.Fail("Rule collision should've thrown");
                    } catch (VmManagementException) { }

                    VBox.ModifyVmDeleteNatPortForward(clone, 1, "ssh");
                    try {
                        VBox.ModifyVmDeleteNatPortForward(clone, 1, "ssh");
                        Assert.Fail("Rule should've already been deleted");
                    } catch (VmManagementException) { }
                }
                finally { Assert.IsTrue(VBox.TryDeleteVm(clone)); }
            }

            if (!foundVmToTest)
            {
                Assert.Inconclusive("Unable to test:  No VMs tagged 'clone testing vm' in their descriptions.");
            }
        }