/// <summary> /// Creates an empty test project. /// </summary> public TestProjectData() { testPackage = new TestPackageData(); testFilters = new List <FilterInfo>(); testRunnerExtensions = new List <string>(); reportNameFormat = TestProject.DefaultReportNameFormat; reportDirectory = TestProject.DefaultReportDirectoryRelativePath; }
public bool Initialize(TestPackageData testPackage, bool scheduled, int operatingSystemID) { mScheduled = scheduled; mOperatingSystemID = operatingSystemID; if (mScheduled == false) { SchedulingGB.Visibility = Visibility.Hidden; } try { mPackage = testPackage; PackageNameLabel.Content = mPackage.TestPackageName; // Get all license keys if (string.IsNullOrEmpty(mPackage.LicenseKey)) { var result = LicenseKeyData.Select(); foreach (var key in result) { ComboBoxItem item = new ComboBoxItem(); item.Content = key.Name; item.Tag = key.LicenseKeyString; item.ToolTip = key.Description; LicenseKeyCB.Items.Add(item); } } else { ComboBoxItem item = new ComboBoxItem(); item.Content = mPackage.LicenseKey; item.Tag = mPackage.LicenseKey; item.ToolTip = "From TestPackage.json"; LicenseKeyCB.Items.Add(item); LicenseKeyCB.SelectedItem = item; } var DownloadLinks = DownloadLinkData.Select(mOperatingSystemID); foreach (var DownloadLink in DownloadLinks) { DownloadLinkCB.Items.Add(new ComboBoxItem() { Content = DownloadLink.DownloadLink, Tag = DownloadLink.DownloadLink, ToolTip = DownloadLink.DownloadLinkDescription }); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); return(false); } return(true); }
public void GetAndSetPackageConfig() { Report report = new Report(); Assert.IsNull(report.TestModel); TestPackageData value = new TestPackageData(); report.TestPackage = value; Assert.AreSame(value, report.TestPackage); }
public static void AreEqual(TestPackageData expected, TestPackageData actual) { if (expected == null) { Assert.IsNull(actual); return; } Assert.AreElementsEqual(expected.Files, actual.Files); Assert.AreElementsEqual(expected.HintDirectories, actual.HintDirectories); // TODO: Compare HostSetup objects. }
/// <summary> /// Copies the contents of a test project. /// </summary> /// <param name="source">The source test project.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="source"/> is null.</exception> public TestProjectData(TestProject source) : this() { if (source == null) { throw new ArgumentNullException("source"); } testPackage = new TestPackageData(source.TestPackage); GenericCollectionUtils.ConvertAndAddAll(source.TestFilters, testFilters, x => x.Copy()); testRunnerExtensions.AddRange(source.TestRunnerExtensionSpecifications); reportNameFormat = source.ReportNameFormat; reportDirectory = source.ReportDirectory; }
public void Refresh() { try { mOriginalData.Clear(); var result = TestPackageData.Select(mOperatingSystemID, mLabID, null); mOriginalData.AddRange(result); SortData(); UpdateList(); } catch (Exception ex) { System.Windows.MessageBox.Show("Exception: " + ex); } }
private void HandleTestSuiteCreate(bool scheduled) { if (PackagesList.SelectedItem == null) { System.Windows.MessageBox.Show("Please select a package to start a test suite from."); return; } CreateTestSuite suite = new CreateTestSuite(); TestPackageData item = PackagesList.SelectedItem as TestPackageData; if (item != null) { var result = suite.Initialize(item, scheduled, mOperatingSystemID); if (result == true) { suite.Show(); } } else { System.Windows.MessageBox.Show("Select item is null."); } }
private void UploadButton_Click(object sender, RoutedEventArgs e) { FolderBrowserDialog dialog = new FolderBrowserDialog(); dialog.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); dialog.RootFolder = Environment.SpecialFolder.MyComputer; dialog.Description = "Select the directory containing the packages to upload."; dialog.ShowNewFolderButton = false; DialogResult result = dialog.ShowDialog(); if (result == DialogResult.Cancel) { return; } if (dialog.SelectedPath.StartsWith("C:\\TestPackages") == true) { System.Windows.MessageBox.Show("TestPackages cannot be stored under C:\\TestPackages."); return; } string path = string.Empty; string[] jsonFiles = null; try { jsonFiles = Directory.GetFiles(dialog.SelectedPath, "*.json"); } catch { System.Windows.MessageBox.Show("No test package found."); return; } if (jsonFiles == null || jsonFiles.Length == 0) { System.Windows.MessageBox.Show("No json files found."); return; } if (jsonFiles.Length > 1) { PackageJsonSelect jsonSelect = new PackageJsonSelect(); jsonSelect.Initialize(jsonFiles); jsonSelect.ShowDialog(); path = jsonSelect.SelectedFile(); } else { path = jsonFiles[0]; } if (string.IsNullOrEmpty(path)) { return; } if (File.Exists(path) == false) { System.Windows.MessageBox.Show("The file '" + path + "' was not found."); return; } TestPackageJson package = null; StreamReader reader = null; // Parse the json file try { DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(TestPackageJson)); reader = new StreamReader(path); package = (TestPackageJson)serializer.ReadObject(reader.BaseStream); reader.Close(); } catch (Exception ex) { System.Windows.MessageBox.Show("Failure when parsing '" + path + "': " + ex); return; } if (reader != null) { reader.Close(); } if (string.IsNullOrEmpty(package.ServerGroup) == true) { System.Windows.MessageBox.Show("Please specify a ServerGroup for this test package to use."); return; } int serverGroupID = GetServerGroupID(package.ServerGroup); if (serverGroupID == -1) { System.Windows.MessageBox.Show("Unknown server group: " + package.ServerGroup); return; } if (string.IsNullOrEmpty(package.Lab) == true) { System.Windows.MessageBox.Show("Please specify the Production or Development lab for this test package"); return; } int labID = GetLabID(package.Lab); if (labID == -1) { System.Windows.MessageBox.Show("Unknown lab environment: " + package.Lab); return; } try { // Locate all entry points; verify snapshots Dictionary <string, int> snapshots = new Dictionary <string, int>(); foreach (var command in package.Commands) { string[] results = command.Split(new char[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries); if (command.ToLower().StartsWith("entrypoint=")) { if (results.Length < 2) { System.Windows.MessageBox.Show("Invalid format for EntryPoint: " + command); return; } path = System.IO.Path.Combine(dialog.SelectedPath, results[results.Length - 1]); if (File.Exists(path) == false) { System.Windows.MessageBox.Show("Did not find entrypoint '" + results[1] + "'."); return; } } else if (command.ToLower().StartsWith("createsnapshot")) { if (results.Length < 2) { System.Windows.MessageBox.Show("Invalid format for CreateSnapshot: " + command); return; } snapshots.Add(results[1], 0); } else if (command.ToLower().StartsWith("rollback")) { if (results.Length > 1) { if (snapshots.ContainsKey(results[1]) == false) { System.Windows.MessageBox.Show("Rolling back to non-existing snapshot: " + command); return; } else { snapshots[results[1]]++; } } } else if (command.ToLower().StartsWith("installapp") == true) { if (results.Length > 1) { bool filePresent = FileInPackage(dialog.SelectedPath, results[1]); if (filePresent == false) { System.Windows.MessageBox.Show("The command '" + command + "' refers to a file that is not part of the package."); return; } } } else if (command.ToLower().StartsWith("stoponerror") == true) { bool stopOnError = false; if (bool.TryParse(results[1], out stopOnError) == false) { System.Windows.MessageBox.Show("Invalid value for StopOnError: " + command); return; } } else if (command.ToLower().StartsWith("reboot") == true) { // OK } else if (command.ToLower().StartsWith("timeout") == true) { if (results.Length > 1) { int timeout = 0; if (int.TryParse(results[1], out timeout) == false) { System.Windows.MessageBox.Show("Invalid value for Timeout: " + results[1]); return; } } else { System.Windows.MessageBox.Show("No value specified for Timeout."); return; } } else { System.Windows.MessageBox.Show("Invalid command: " + command); return; } } foreach (KeyValuePair <string, int> kvp in snapshots) { if (kvp.Value == 0) { System.Windows.MessageBox.Show("Snapshot with name '" + kvp.Key + "' is created but never used."); return; } } } catch (Exception ex) { System.Windows.MessageBox.Show("Error when parsing package json: " + ex); return; } try { // Upload to database path = "C:\\TestPackages\\" + package.Name; // dialog.SelectedPath.Replace("C:\\", string.Empty); int testPackageID = TestPackageData.Create(package.Name, package.Description, path.Replace("C:\\", string.Empty), package.LicenseKey, serverGroupID, mOperatingSystemID, labID); TestPackageVersionData testPackageVersion = TestPackageVersionData.Select(testPackageID); int executionOrder = 0; // Handle all commands foreach (string command in package.Commands) { TestPackageCommand.Create(testPackageID, command, executionOrder); executionOrder++; } if (Directory.Exists(path) == false) { Directory.CreateDirectory(path); } path = path + "\\" + testPackageVersion.TestPackageVersionID; System.Windows.MessageBox.Show("Renaming " + dialog.SelectedPath + " to " + path); Directory.Move(dialog.SelectedPath, path); DirectorySecurity sec = Directory.GetAccessControl(path); // Using this instead of the "Everyone" string means we work on non-English systems. SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null); sec.AddAccessRule(new FileSystemAccessRule(everyone, FileSystemRights.FullControl | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow)); Directory.SetAccessControl(path, sec); } catch (Exception ex) { System.Windows.MessageBox.Show("Exception: " + ex); } Refresh(); }