Exemplo n.º 1
0
        /// <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));
        }
Exemplo n.º 2
0
        // ========================================================================
        // 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>();
        }
Exemplo n.º 3
0
 /// <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;
 }
Exemplo n.º 4
0
 /// <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));
     }
 }
Exemplo n.º 5
0
        /// <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));
        }
Exemplo n.º 6
0
        /// <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 }));
        }
Exemplo n.º 7
0
        /// <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);
        }
Exemplo n.º 8
0
        // ========================================================================
        // 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);
        }
Exemplo n.º 9
0
        /// <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);
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
 /// <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;
 }
Exemplo n.º 13
0
        // ========================================================================
        // 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>());
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        /// <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));
            }
        }
Exemplo n.º 16
0
        /// <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++;
            }
        }
Exemplo n.º 17
0
        // ========================================================================
        // 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;
        }
Exemplo n.º 18
0
        // ========================================================================
        // 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;
        }
Exemplo n.º 19
0
        // ========================================================================
        // 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)
        {
        }
Exemplo n.º 20
0
        // ========================================================================
        // 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;
        }