~a-schlapsi/nunit-3.0/linux-makefile

« back to all changes in this revision

Viewing changes to src/tests/NUnit/Core/SuiteBuilderTests.cs

  • Committer: Andreas Schlapsi
  • Date: 2010-01-23 23:14:05 UTC
  • mfrom: (18.1.137 work)
  • Revision ID: a.schlapsi@gmx.at-20100123231405-17deqoh18nfnbq1j
Merged with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ***********************************************************************
2
 
// Copyright (c) 2007 Charlie Poole
3
 
//
4
 
// Permission is hereby granted, free of charge, to any person obtaining
5
 
// a copy of this software and associated documentation files (the
6
 
// "Software"), to deal in the Software without restriction, including
7
 
// without limitation the rights to use, copy, modify, merge, publish,
8
 
// distribute, sublicense, and/or sell copies of the Software, and to
9
 
// permit persons to whom the Software is furnished to do so, subject to
10
 
// the following conditions:
11
 
// 
12
 
// The above copyright notice and this permission notice shall be
13
 
// included in all copies or substantial portions of the Software.
14
 
// 
15
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
 
// ***********************************************************************
23
 
 
24
 
using System;
25
 
using System.IO;
26
 
using NUnit.Framework;
27
 
using NUnit.Core;
28
 
using NUnit.TestData.LegacySuiteData;
29
 
using NUnit.TestUtilities;
30
 
 
31
 
namespace NUnit.Core.Tests
32
 
{
33
 
        [TestFixture]
34
 
        public class SuiteBuilderTests
35
 
        {
36
 
                private string testsDll = "nunit.framework.tests.dll";
37
 
                private string testData = "test-assembly.dll";
38
 
                private string tempFile = "x.dll";
39
 
                private TestSuiteBuilder builder;
40
 
 
41
 
        [TestFixtureSetUp]
42
 
        public void InitializeBuilders()
43
 
        {
44
 
            if (!CoreExtensions.Host.Initialized)
45
 
                CoreExtensions.Host.Initialize();
46
 
        }
47
 
 
48
 
                [SetUp]
49
 
                public void CreateBuilder()
50
 
                {
51
 
                        builder = new TestSuiteBuilder();
52
 
                }
53
 
                [TearDown]
54
 
                public void TearDown()
55
 
                {
56
 
                        FileInfo info = new FileInfo(tempFile);
57
 
                        if(info.Exists) info.Delete();
58
 
                }
59
 
 
60
 
                [Test]
61
 
                public void LoadAssembly() 
62
 
                {
63
 
                        Test suite = builder.Build( new TestPackage( testsDll ) );
64
 
                        Assert.IsNotNull(suite, "Unable to build suite" );
65
 
                        Assert.AreEqual( 1, suite.Tests.Count );
66
 
                        Assert.AreEqual( "NUnit", ((ITest)suite.Tests[0]).TestName.Name );
67
 
                }
68
 
 
69
 
                [Test]
70
 
                public void LoadAssemblyWithoutNamespaces()
71
 
                {
72
 
                        TestPackage package = new TestPackage( testsDll );
73
 
                        package.Settings["AutoNamespaceSuites"] = false;
74
 
                        Test suite = builder.Build( package );
75
 
                        Assert.IsNotNull(suite, "Unable to build suite" );
76
 
                        Assert.Greater( suite.Tests.Count, 1 );
77
 
                        Assert.AreEqual( "NUnitTestFixture", ((ITest)suite.Tests[0]).TestType );
78
 
                }
79
 
 
80
 
                [Test]
81
 
                public void LoadFixture()
82
 
                {
83
 
                        TestPackage package = new TestPackage( testsDll );
84
 
                        package.TestName = this.GetType().FullName;
85
 
                        Test suite= builder.Build( package );
86
 
                        Assert.IsNotNull(suite, "Unable to build suite");
87
 
                }
88
 
 
89
 
                [Test]
90
 
                public void LoadSuite()
91
 
                {
92
 
                        TestPackage package = new TestPackage( testData );
93
 
                        package.TestName = typeof(LegacySuiteReturningFixtures).FullName;
94
 
                        Test suite= builder.Build( package );
95
 
                        Assert.IsNotNull(suite, "Unable to build suite");
96
 
            Assert.AreEqual(3, suite.Tests.Count);
97
 
            Assert.AreEqual(5, suite.TestCount);
98
 
        }
99
 
 
100
 
                [Test]
101
 
                public void LoadNamespaceAsSuite()
102
 
                {
103
 
                        TestPackage package = new TestPackage( testsDll );
104
 
                        package.TestName = "NUnit.Core.Tests";
105
 
                        Test suite= builder.Build( package );
106
 
                        Assert.IsNotNull( suite );
107
 
                        Assert.AreEqual( testsDll, suite.TestName.Name );
108
 
                        Assert.AreEqual( "NUnit", ((Test)suite.Tests[0]).TestName.Name );
109
 
                }
110
 
 
111
 
                [Test]
112
 
                public void DiscoverSuite()
113
 
                {
114
 
                        TestPackage package = new TestPackage( testData );
115
 
                        package.TestName = typeof(NUnit.TestData.LegacySuiteData.EmptySuite).FullName;
116
 
                        Test suite = builder.Build( package );
117
 
                        Assert.IsNotNull(suite, "Could not discover suite attribute");
118
 
                }
119
 
 
120
 
                [Test]
121
 
                public void WrongReturnTypeSuite()
122
 
                {
123
 
                        TestPackage package = new TestPackage( testData );
124
 
                        package.TestName = typeof(LegacySuiteWithInvalidPropertyType).FullName;
125
 
                        Test suite = builder.Build( package );
126
 
                        Assert.AreEqual(RunState.NotRunnable, suite.RunState);
127
 
                }
128
 
 
129
 
                [Test]
130
 
                [ExpectedException(typeof(FileNotFoundException))]
131
 
                public void FileNotFound()
132
 
                {
133
 
                        builder.Build( new TestPackage( "xxxx.dll" ) );
134
 
                }
135
 
 
136
 
                // Gives FileNotFoundException on Mono
137
 
                [Test, ExpectedException(typeof(BadImageFormatException))]
138
 
                public void InvalidAssembly()
139
 
                {
140
 
                        FileInfo file = new FileInfo( tempFile );
141
 
 
142
 
                        StreamWriter sw = file.AppendText();
143
 
 
144
 
                        sw.WriteLine("This is a new entry to add to the file");
145
 
                        sw.WriteLine("This is yet another line to add...");
146
 
                        sw.Flush();
147
 
                        sw.Close();
148
 
 
149
 
                        builder.Build( new TestPackage( tempFile ) );
150
 
                }
151
 
 
152
 
                [Test]
153
 
                public void FixtureNotFound()
154
 
                {
155
 
                        TestPackage package = new TestPackage( testsDll );
156
 
                        package.TestName = "NUnit.Tests.Junk";
157
 
                        Assert.IsNull( builder.Build( package ) );
158
 
                }
159
 
        }
160
 
}