1
// ***********************************************************************
2
// Copyright (c) 2007 Charlie Poole
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:
12
// The above copyright notice and this permission notice shall be
13
// included in all copies or substantial portions of the Software.
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
// ***********************************************************************
26
using NUnit.Framework;
28
using NUnit.TestData.LegacySuiteData;
29
using NUnit.TestUtilities;
31
namespace NUnit.Core.Tests
34
public class SuiteBuilderTests
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;
42
public void InitializeBuilders()
44
if (!CoreExtensions.Host.Initialized)
45
CoreExtensions.Host.Initialize();
49
public void CreateBuilder()
51
builder = new TestSuiteBuilder();
54
public void TearDown()
56
FileInfo info = new FileInfo(tempFile);
57
if(info.Exists) info.Delete();
61
public void LoadAssembly()
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 );
70
public void LoadAssemblyWithoutNamespaces()
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 );
81
public void LoadFixture()
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");
90
public void LoadSuite()
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);
101
public void LoadNamespaceAsSuite()
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 );
112
public void DiscoverSuite()
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");
121
public void WrongReturnTypeSuite()
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);
130
[ExpectedException(typeof(FileNotFoundException))]
131
public void FileNotFound()
133
builder.Build( new TestPackage( "xxxx.dll" ) );
136
// Gives FileNotFoundException on Mono
137
[Test, ExpectedException(typeof(BadImageFormatException))]
138
public void InvalidAssembly()
140
FileInfo file = new FileInfo( tempFile );
142
StreamWriter sw = file.AppendText();
144
sw.WriteLine("This is a new entry to add to the file");
145
sw.WriteLine("This is yet another line to add...");
149
builder.Build( new TestPackage( tempFile ) );
153
public void FixtureNotFound()
155
TestPackage package = new TestPackage( testsDll );
156
package.TestName = "NUnit.Tests.Junk";
157
Assert.IsNull( builder.Build( package ) );