~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Analysis/UnitTesting/Test/Project/TwoProjectRootNamespacesTestFixture.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 ICSharpCode.SharpDevelop.Dom;
 
5
using ICSharpCode.SharpDevelop.Project;
 
6
using ICSharpCode.UnitTesting;
 
7
using NUnit.Framework;
 
8
using System;
 
9
using UnitTesting.Tests.Utils;
 
10
 
 
11
namespace UnitTesting.Tests.Project
 
12
{
 
13
        [TestFixture]
 
14
        public class TwoRootNamespacesTestFixture
 
15
        {
 
16
                TestProject testProject;
 
17
                MockProjectContent projectContent;
 
18
                MockTestFrameworksWithNUnitFrameworkSupport testFrameworks;
 
19
                
 
20
                [SetUp]
 
21
                public void Init()
 
22
                {
 
23
                        // Create a project to display in the test tree view.
 
24
                        IProject project = new MockCSharpProject();
 
25
                        project.Name = "TestProject";
 
26
                        ReferenceProjectItem nunitFrameworkReferenceItem = new ReferenceProjectItem(project);
 
27
                        nunitFrameworkReferenceItem.Include = "NUnit.Framework";
 
28
                        ProjectService.AddProjectItem(project, nunitFrameworkReferenceItem);
 
29
                        
 
30
                        // Add a test class with a TestFixture attributes.
 
31
                        projectContent = new MockProjectContent();
 
32
                        projectContent.Language = LanguageProperties.None;
 
33
                        MockClass c = new MockClass(projectContent, "RootNamespace1.MyTestFixture1");
 
34
                        c.Attributes.Add(new MockAttribute("TestFixture"));
 
35
                        projectContent.Classes.Add(c);
 
36
                        
 
37
                        // Add a second class with a different root namespace.
 
38
                        c = new MockClass(projectContent, "RootNamespace2.MyTestFixture2");
 
39
                        c.Attributes.Add(new MockAttribute("TestFixture"));
 
40
                        projectContent.Classes.Add(c);
 
41
                        
 
42
                        testFrameworks = new MockTestFrameworksWithNUnitFrameworkSupport();
 
43
                        testProject = new TestProject(project, projectContent, testFrameworks);
 
44
                }
 
45
                
 
46
                [Test]
 
47
                public void TwoRootNamespaces()
 
48
                {
 
49
                        Assert.AreEqual(2, testProject.RootNamespaces.Count);
 
50
                }
 
51
                
 
52
                [Test]
 
53
                public void RootNamespace1()
 
54
                {
 
55
                        Assert.AreEqual("RootNamespace1", testProject.RootNamespaces[0]);
 
56
                }
 
57
                
 
58
                [Test]
 
59
                public void RootNamespace2()
 
60
                {
 
61
                        Assert.AreEqual("RootNamespace2", testProject.RootNamespaces[1]);
 
62
                }
 
63
                
 
64
                [Test]
 
65
                public void OneClassInNamespace1()
 
66
                {
 
67
                        Assert.AreEqual(1, testProject.GetTestClasses("RootNamespace1").Length);
 
68
                }
 
69
                
 
70
                [Test]
 
71
                public void ClassNameInNamespace1()
 
72
                {
 
73
                        TestClass[] classes = testProject.GetTestClasses("RootNamespace1");
 
74
                        Assert.AreEqual("MyTestFixture1", classes[0].Name);
 
75
                }
 
76
                
 
77
                [Test]
 
78
                public void OneClassInNamespace2()
 
79
                {
 
80
                        Assert.AreEqual(1, testProject.GetTestClasses("RootNamespace2").Length);
 
81
                }
 
82
                
 
83
                [Test]
 
84
                public void ClassNameInNamespace2()
 
85
                {
 
86
                        TestClass[] classes = testProject.GetTestClasses("RootNamespace2");
 
87
                        Assert.AreEqual("MyTestFixture2", classes[0].Name);
 
88
                }
 
89
                
 
90
                [Test]
 
91
                public void TwoClassesStartWithRootNamespace()
 
92
                {
 
93
                        TestClass[] classes = testProject.GetAllTestClasses("RootNamespace");
 
94
                        Assert.AreEqual(2, classes.Length);
 
95
                        Assert.AreEqual("MyTestFixture1", classes[0].Name);
 
96
                        Assert.AreEqual("MyTestFixture2", classes[1].Name);
 
97
                }
 
98
                
 
99
                [Test]
 
100
                public void NoChildNamespaces()
 
101
                {
 
102
                        Assert.AreEqual(0, testProject.GetChildNamespaces("RootNamespace").Length);
 
103
                }
 
104
                
 
105
                [Test]
 
106
                public void TwoChildNamespacesForEmptyNamespace()
 
107
                {
 
108
                        string[] namespaces = testProject.GetChildNamespaces(String.Empty);
 
109
                        Assert.AreEqual(2, namespaces.Length);
 
110
                        Assert.AreEqual("RootNamespace1", namespaces[0]);
 
111
                        Assert.AreEqual("RootNamespace2", namespaces[1]);
 
112
                }
 
113
                
 
114
                /// <summary>
 
115
                /// Makes sure that the fully qualified class name is used
 
116
                /// when working out the overall test result in the 
 
117
                /// TestClassCollection.
 
118
                /// </summary>
 
119
                [Test]
 
120
                public void DuplicateClassName()
 
121
                {
 
122
                        MockClass c = new MockClass(projectContent, "RootNamespace1.MyTestFixture2");
 
123
                        c.Attributes.Add(new MockAttribute("TestFixture"));
 
124
                        
 
125
                        TestClass testClass = new TestClass(c, testFrameworks);
 
126
                        testProject.TestClasses.Add(testClass);
 
127
                        
 
128
                        testClass.Result = TestResultType.Failure;
 
129
                        TestClass testClass2 = testProject.TestClasses["RootNamespace2.MyTestFixture2"];
 
130
                        testClass2.Result = TestResultType.Failure;
 
131
                        
 
132
                        Assert.AreEqual(TestResultType.Failure, testProject.TestClasses.Result);
 
133
                }
 
134
        }
 
135
}