~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Analysis/UnitTesting/Src/TestClassTreeNode.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using ICSharpCode.SharpDevelop.Dom;
 
6
using ICSharpCode.SharpDevelop.Gui;
 
7
using ICSharpCode.SharpDevelop.Project;
 
8
 
 
9
namespace ICSharpCode.UnitTesting
 
10
{
 
11
        /// <summary>
 
12
        /// Represents a class that has the [TestFixture] attribute 
 
13
        /// associated with it.
 
14
        /// </summary>
 
15
        public class TestClassTreeNode : TestTreeNode
 
16
        {
 
17
                TestClass testClass;
 
18
                                
 
19
                public TestClassTreeNode(TestProject project, TestClass testClass)
 
20
                        : base(project, testClass.Name)
 
21
                {
 
22
                        this.testClass = testClass;
 
23
                        testClass.ResultChanged += TestClassResultChanged;
 
24
                        Nodes.Add(new ExtTreeNode());
 
25
                        UpdateImageListIndex(testClass.Result);
 
26
                }
 
27
                
 
28
                /// <summary>
 
29
                /// Gets the underlying IClass for this test class.
 
30
                /// </summary>
 
31
                public IClass Class {
 
32
                        get {
 
33
                                return testClass.Class;
 
34
                        }
 
35
                }
 
36
                
 
37
                public override void Dispose()
 
38
                {
 
39
                        if (!IsDisposed) {
 
40
                                testClass.ResultChanged -= TestClassResultChanged;
 
41
                                testClass.TestMethods.TestMethodAdded -= TestMethodAdded;
 
42
                                testClass.TestMethods.TestMethodRemoved -= TestMethodRemoved;
 
43
                        }
 
44
                        base.Dispose();
 
45
                }
 
46
                
 
47
                protected override void Initialize()
 
48
                {
 
49
                        Nodes.Clear();
 
50
                        
 
51
                        foreach (TestMethod method in testClass.TestMethods) {
 
52
                                AddTestMethodTreeNode(method);
 
53
                        }
 
54
                        testClass.TestMethods.TestMethodAdded += TestMethodAdded;
 
55
                        testClass.TestMethods.TestMethodRemoved += TestMethodRemoved;
 
56
                }
 
57
                
 
58
                /// <summary>
 
59
                /// Adds a new TestMethodTreeNode to this node.
 
60
                /// </summary>
 
61
                void AddTestMethodTreeNode(TestMethod method)
 
62
                {
 
63
                        TestMethodTreeNode node = new TestMethodTreeNode(TestProject, method);
 
64
                        node.AddTo(this);
 
65
                }
 
66
                
 
67
                /// <summary>
 
68
                /// Updates the node's icon based on the test class test result.
 
69
                /// </summary>
 
70
                void TestClassResultChanged(object source, EventArgs e)
 
71
                {
 
72
                        UpdateImageListIndex(testClass.Result);
 
73
                }
 
74
                
 
75
                /// <summary>
 
76
                /// Adds a new test method tree node to this class node after a new
 
77
                /// TestMethod has been added to the TestClass.
 
78
                /// </summary>
 
79
                void TestMethodAdded(object source, TestMethodEventArgs e)
 
80
                {
 
81
                        AddTestMethodTreeNode(e.TestMethod);
 
82
                        SortChildNodes();
 
83
                }
 
84
                
 
85
                /// <summary>
 
86
                /// Removes the corresponding test method node after it has been
 
87
                /// removed from the TestClass.
 
88
                /// </summary>
 
89
                void TestMethodRemoved(object source, TestMethodEventArgs e)
 
90
                {
 
91
                        foreach (TestMethodTreeNode methodNode in Nodes) {
 
92
                                if (methodNode.Text == e.TestMethod.Name) {
 
93
                                        Nodes.Remove(methodNode);
 
94
                                        methodNode.Dispose();
 
95
                                        break;
 
96
                                }
 
97
                        }
 
98
                }
 
99
        }
 
100
}