[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."); } }
[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."); } }