/// <summary> /// Removes a given test case group from the model. /// </summary> /// <param name="parent">The parent to the test case group.</param> /// <param name="testCase">The test case group to remove.</param> public bool RemoveTestCaseGroup(TestCaseGroup parent, TestCaseGroup testCase) { Directory.Delete(Path.Combine(testCase.Path, testCase.Name), true); CountTestCaseGroups--; return(RemoveTestCaseBase(parent, testCase)); }
// ======================================================================== // Con- / Destructors #region === Con- / Destructors /// <summary> /// Initializes a new instance of the <see cref="TestCase"/> class. /// </summary> /// <param name="parent">The parent of this test case or group.</param> /// <param name="name">The name of the test case.</param> public TestCase(TestCaseGroup parent, string name) : base(parent) { State = TestCaseState.Unknown; Dirty = false; this.name = name; Messages = new ObservableCollection <Message>(); }
/// <summary> /// Moves a test case group to a new group. /// </summary> /// <param name="testCaseGroup">The test case group to move.</param> /// <param name="destGroup">The destination of the operation.</param> public void MoveTestCaseGroup(TestCaseGroup testCaseGroup, TestCaseGroup destGroup) { Directory.Move(testCaseGroup.Directory, Path.Combine(destGroup.Directory, testCaseGroup.Name)); testCaseGroup.Parent.TestCases.Remove(testCaseGroup); destGroup.TestCases.Add(testCaseGroup); testCaseGroup.Parent = destGroup; }
/// <summary> /// Fires the <see cref="TestCaseRemoved"/> event. /// </summary> /// <param name="parent">The test case group the test case is located in.</param> /// <param name="testCaseBase">The removed test case.</param> protected void OnTestCaseRemoved(TestCaseGroup parent, TestCaseBase testCaseBase) { if (TestCaseRemoved != null) { TestCaseRemoved(this, new TestCaseEventArgs(parent, testCaseBase)); } }
/// <summary> /// Removes a given test case from the model. /// </summary> /// <param name="parent">The paret to the test case.</param> /// <param name="testCase">The test case to remove.</param> public bool RemoveTestCase(TestCaseGroup parent, TestCase testCase) { File.Delete(Path.Combine(testCase.Path, testCase.Name + ".cs")); CountTestCases--; return(RemoveTestCaseBase(parent, testCase)); }
/// <summary> /// Moves a test case or group to a new position. /// </summary> /// <param name="node">The moved node.</param> /// <param name="destNode">The destination.</param> public void MoveTestCase(TreeNodeAdv node, TreeNodeAdv destNode) { TestCaseGroup destGroup = destNode.Tag as TestCaseGroup; if (destNode.Tag == null) { // Move to root destGroup = CoreData.Instance.TestCaseModel.Root; } if (destGroup == null) { return; } TreePath oldPath = treeView.GetPath(node.Parent); if (node.Tag is TestCase) { CoreData.Instance.TestCaseModel.MoveTestCase(node.Tag as TestCase, destGroup); } else if (node.Tag is TestCaseGroup) { CoreData.Instance.TestCaseModel.MoveTestCaseGroup(node.Tag as TestCaseGroup, destGroup); } OnNodesRemoved(new TreeModelEventArgs(oldPath, new[] { node.Tag })); OnNodesInserted(new TreeModelEventArgs(treeView.GetPath(destNode), new[] { node.Tag })); }
/// <summary> /// Removes a given test case base from the model. /// </summary> /// <param name="parent">The parent to the item to remove.</param> /// <param name="testCaseBase">The test case base to remove.</param> private bool RemoveTestCaseBase(TestCaseGroup parent, TestCaseBase testCaseBase) { bool result = parent.TestCases.Remove(testCaseBase); OnTestCaseRemoved(parent, testCaseBase); return(result); }
// ======================================================================== // Methods #region === Methods /// <summary> /// Gets an enumerator for all testcases within the given <see cref="TestCaseGroup"/>. /// </summary> /// <param name="testCaseGroup">The <see cref="TestCaseGroup"/> to search for <see cref="TestCase"/>es.</param> /// <returns>An enumerator.</returns> public IEnumerable <TestCase> GetChildTestCases(TestCaseGroup testCaseGroup) { IEnumerable <TestCase> result = from testCase in testCaseGroup.TestCases where testCase is TestCase select testCase as TestCase; result = testCaseGroup.TestCases.OfType <TestCaseGroup>() .Aggregate(result, (current, testCaseBase) => current.Concat(GetChildTestCases(testCaseBase))); return(result); }
/// <summary> /// Adds a new test case to the model. /// </summary> /// <param name="parent">The parent to add the test case to.</param> /// <param name="name">The name of the new test case to add.</param> public TestCase AddTestCase(TestCaseGroup parent, string name) { File.Create(Path.Combine(parent.Directory, name)).Close(); TestCase newTestCase = new TestCase(parent, name); parent.TestCases.Add(newTestCase); CountTestCases++; OnTestCaseAdded(parent, newTestCase); return(newTestCase); }
/// <summary> /// Adds a new test case group to the model. /// </summary> /// <param name="parent">The parent to add the test case group to.</param> /// <param name="name">The name of the new test case to add.</param> public TestCaseGroup AddTestCaseGroup(TestCaseGroup parent, string name) { Directory.CreateDirectory(Path.Combine(parent.Directory, name)); TestCaseGroup newGroup = new TestCaseGroup(parent, name); parent.TestCases.Add(newGroup); CountTestCaseGroups++; OnTestCaseAdded(parent, newGroup); return(newGroup); }
public TreeNodeAdv AddNewTestCaseGroup(TreeNodeAdv parentNode) { TestCaseGroup parentGroup = null; if (parentNode != null) { parentGroup = parentNode.Tag as TestCaseGroup ?? parentNode.Parent.Tag as TestCaseGroup; } if (parentGroup == null) { parentGroup = CoreData.Instance.TestCaseModel.Root; } TestCaseGroup newTestCaseGroup = CoreData.Instance.TestCaseModel.AddTestCaseGroup(parentGroup, "NewGroup"); return(treeView.FindNodeByTag(newTestCaseGroup)); }
/// <summary> /// Moves a test case to a new group. /// </summary> /// <param name="testCase">The test case to move.</param> /// <param name="destGroup">The destination of the operation.</param> public void MoveTestCase(TestCase testCase, TestCaseGroup destGroup) { File.Move(testCase.FullPath, Path.Combine(destGroup.Directory, testCase.FileName)); if (testCase.ExpectedObjectFile != null) { if (File.Exists(testCase.ExpectedObjectFile)) { string fileName = Path.GetFileName(testCase.ExpectedObjectFile); if (fileName != null) { File.Move(testCase.ExpectedObjectFile, Path.Combine(destGroup.Directory, fileName)); } } } testCase.Parent.TestCases.Remove(testCase); destGroup.TestCases.Add(testCase); testCase.Parent = destGroup; }
// ======================================================================== // Properties #region === Properties #endregion // ======================================================================== // Methods #region === Methods public override IEnumerable GetChildren(TreePath treePath) { if (treePath.IsEmpty()) { if (CoreData.Instance.TestCaseModel.Root == null) { return(null); } return(CoreData.Instance.TestCaseModel.Root.TestCases); } TestCaseGroup testCaseGroup = treePath.LastNode as TestCaseGroup; if (testCaseGroup != null) { return(testCaseGroup.TestCases); } return(new List <TestCaseBase>()); }
public void RemoveTestCase(TreeNodeAdv node) { TestCaseGroup parentGroup = null; if (node != null) { parentGroup = node.Parent.Tag as TestCaseGroup; } if (parentGroup == null) { parentGroup = CoreData.Instance.TestCaseModel.Root; } if (node != null && node.Tag is TestCase) { CoreData.Instance.TestCaseModel.RemoveTestCase(parentGroup, node.Tag as TestCase); } else if (node != null && node.Tag is TestCaseGroup) { CoreData.Instance.TestCaseModel.RemoveTestCaseGroup(parentGroup, node.Tag as TestCaseGroup); } }
/// <summary> /// Loads the test cases within the specified directory and its subdirectories. /// </summary> /// <param name="testCaseDirectory">The directory to search for test cases.</param> public void LoadTestCases(string testCaseDirectory) { CoreData.Instance.Messages.Add(new Message(MessageSeverity.Info, "Loading test cases...")); try { if (!Directory.Exists(testCaseDirectory)) { throw new FileNotFoundException("Directory '" + testCaseDirectory + "' does not exist."); } Root = new TestCaseGroup(null, testCaseDirectory); CountTestCases = 0; CountTestCaseGroups = 0; LoadTestCases(testCaseDirectory, Root); OnTestCasesLoaded(); CoreData.Instance.Messages.Add(new Message(MessageSeverity.Info, "Loading test cases successful. Loaded " + CountTestCases + " test cases in " + CountTestCaseGroups + " groups.")); } catch (Exception ex) { CoreData.Instance.Messages.Add(new Message(MessageSeverity.Error, "Loading test cases failed: " + ex.Message)); } }
/// <summary> /// Loads the test cases within the specified directory and its subdirectories /// and places them into the parent group. /// </summary> /// <param name="path">The directory to search for test cases.</param> /// <param name="parent">A list to add the test cases to.</param> private void LoadTestCases(string path, TestCaseGroup parent) { // Get sub-dirs... string[] directories = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly); foreach (string directory in directories) { TestCaseGroup testCaseGroup = new TestCaseGroup(parent, Path.GetFileName(directory)); LoadTestCases(directory, testCaseGroup); parent.TestCases.Add(testCaseGroup); CountTestCaseGroups++; } // Get files... List <string> files = new List <string>(); files.AddRange(Directory.GetFiles(path, "*.cs", SearchOption.TopDirectoryOnly)); files.AddRange(Directory.GetFiles(path, "*.dll", SearchOption.TopDirectoryOnly)); files.AddRange(Directory.GetFiles(path, "*.exe", SearchOption.TopDirectoryOnly)); foreach (string file in files) { TestCase testCase; if (file.EndsWith(".cs")) { testCase = new TestCaseCSharp(parent, Path.GetFileName(file)); } else { testCase = new TestCaseAssembly(parent, Path.GetFileName(file)); } testCase.Load(); parent.TestCases.Add(testCase); CountTestCases++; } }
// ======================================================================== // Con- / Destructors #region === Con- / Destructors /// <summary> /// Initializes a new instance of the <see cref="TestCaseBase"/> class. /// </summary> /// <param name="parent">The parent of this test case or group.</param> protected TestCaseBase(TestCaseGroup parent) { Parent = parent; }
// ======================================================================== // Con- / Destructors #region === Con- / Destructors /// <summary> /// Initializes a new instance of <see cref="TestCaseGroup"/>. /// </summary> /// <param name="parent">The parent of this test case or group.</param> /// <param name="name">The name of the test case.</param> public TestCaseGroup(TestCaseGroup parent, string name) : base(parent) { TestCases = new ObservableCollection <TestCaseBase>(); this.name = name; }
// ======================================================================== // Con- / Destructors #region === Con- / Destructors /// <summary> /// Initializes a new instance of <see cref="TestCaseCSharp"/>. /// </summary> /// <param name="parent">The parent of this test case or group.</param> /// <param name="name">The name of the test case.</param> public TestCaseCSharp(TestCaseGroup parent, string name) : base(parent, name) { }
// ======================================================================== // Con- / Destructors #region === Con- / Destructors /// <summary> /// Initializes a new instance of the <see cref="TestCaseEventArgs"/> class. /// </summary> /// <param name="parent">The test case group the test case is located in.</param> /// <param name="testCaseBase">The test case base in question.</param> public TestCaseEventArgs(TestCaseGroup parent, TestCaseBase testCaseBase) { TestCaseBase = testCaseBase; Parent = parent; }