~ubuntu-branches/debian/sid/nunit/sid

« back to all changes in this revision

Viewing changes to src/tests/test-utilities/TestBuilder.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2014-09-16 13:43:36 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20140916134336-kjxz48tty6lx2ja5
Tags: 2.6.3+dfsg-1
* [c7bd1b5] Imported Upstream version 2.6.3+dfsg
* [bcb4bf8] Move nunit-console-runner to GAC-installed libnunit2.6, 
  don't treat it as a private lib. This lib is signed, and treated 
  as a GAC lib by consumers such as MonoDevelop.
* [7f08e99] Bump version to 2.6.3 as required
* [84535eb] Refreshed patches
* [8479f61] Split package up into per-assembly packages. This makes 
  ABI tracking easier in the future, as we can meaningfully have GAC 
  policy for cases where ABI isn't truly bumped, and no policy for 
  cases where it is. For example, if nunit.framework bumps ABI but 
  nunit.core does not, previously we would need to rebuild everything 
  using NUnit, but under the new split packaging, that rebuild would 
  not be needed for apps only using nunit.core.
* [17a7dc7] Add missing nunit.mocks.dll to nunit.pc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// ****************************************************************
2
 
// Copyright 2007, Charlie Poole
3
 
// This is free software licensed under the NUnit license. You may
4
 
// obtain a copy of the license at http://nunit.org
5
 
// ****************************************************************
6
 
 
7
 
using System;
8
 
using System.Reflection;
9
 
using NUnit.Framework;
10
 
using NUnit.Core;
11
 
using NUnit.Core.Builders;
12
 
using NUnit.Core.Extensibility;
13
 
 
14
 
namespace NUnit.TestUtilities
15
 
{
16
 
        /// <summary>
17
 
        /// Utility Class used to build NUnit tests for use as test data
18
 
        /// </summary>
19
 
        public class TestBuilder
20
 
        {
21
 
                private static ISuiteBuilder suiteBuilder = (ISuiteBuilder)CoreExtensions.Host.GetExtensionPoint("SuiteBuilders");
22
 
        private static ITestCaseBuilder testBuilder = (ITestCaseBuilder)CoreExtensions.Host.GetExtensionPoint("TestCaseBuilders");
23
 
 
24
 
                public static TestSuite MakeFixture( Type type )
25
 
                {
26
 
                        return (TestSuite)suiteBuilder.BuildFrom( type );
27
 
                }
28
 
 
29
 
                public static TestSuite MakeFixture( object fixture )
30
 
                {
31
 
                        TestSuite suite = (TestSuite)suiteBuilder.BuildFrom( fixture.GetType() );
32
 
                        suite.Fixture = fixture;
33
 
                        return suite;
34
 
                }
35
 
 
36
 
                public static Test MakeTestCase( Type type, string methodName )
37
 
                {
38
 
            MethodInfo method = Reflect.GetNamedMethod(type, methodName);
39
 
            if (method == null)
40
 
                Assert.Fail("Method not found: " + methodName);
41
 
            return testBuilder.BuildFrom(method);
42
 
        }
43
 
 
44
 
                public static Test MakeTestCase( object fixture, string methodName )
45
 
                {
46
 
                        Test test = MakeTestCase( fixture.GetType(), methodName );
47
 
                        test.Fixture = fixture;
48
 
                        return test;
49
 
                }
50
 
 
51
 
                public static TestResult RunTestFixture( Type type )
52
 
                {
53
 
            return MakeFixture(type).Run(NullListener.NULL, TestFilter.Empty);
54
 
                }
55
 
 
56
 
                public static TestResult RunTestFixture( object fixture )
57
 
                {
58
 
            return MakeFixture(fixture).Run(NullListener.NULL, TestFilter.Empty);
59
 
                }
60
 
 
61
 
                public static TestResult RunTestCase( Type type, string methodName )
62
 
                {
63
 
            return MakeTestCase(type, methodName).Run(NullListener.NULL, TestFilter.Empty);
64
 
                }
65
 
 
66
 
                private TestBuilder() { }
67
 
        }
68
 
}
 
1
// ****************************************************************
 
2
// Copyright 2007, Charlie Poole
 
3
// This is free software licensed under the NUnit license. You may
 
4
// obtain a copy of the license at http://nunit.org
 
5
// ****************************************************************
 
6
 
 
7
using System;
 
8
using System.Reflection;
 
9
using NUnit.Framework;
 
10
using NUnit.Core;
 
11
using NUnit.Core.Builders;
 
12
using NUnit.Core.Extensibility;
 
13
 
 
14
namespace NUnit.TestUtilities
 
15
{
 
16
        /// <summary>
 
17
        /// Utility Class used to build NUnit tests for use as test data
 
18
        /// </summary>
 
19
        public class TestBuilder
 
20
        {
 
21
                private static ISuiteBuilder suiteBuilder = (ISuiteBuilder)CoreExtensions.Host.GetExtensionPoint("SuiteBuilders");
 
22
        private static ITestCaseBuilder testBuilder = (ITestCaseBuilder)CoreExtensions.Host.GetExtensionPoint("TestCaseBuilders");
 
23
 
 
24
                public static TestSuite MakeFixture( Type type )
 
25
                {
 
26
                        return (TestSuite)suiteBuilder.BuildFrom( type );
 
27
                }
 
28
 
 
29
                public static TestSuite MakeFixture( object fixture )
 
30
                {
 
31
                        TestSuite suite = (TestSuite)suiteBuilder.BuildFrom( fixture.GetType() );
 
32
                        suite.Fixture = fixture;
 
33
                        return suite;
 
34
                }
 
35
 
 
36
                public static Test MakeTestCase( Type type, string methodName )
 
37
                {
 
38
            MethodInfo method = Reflect.GetNamedMethod(type, methodName);
 
39
            if (method == null)
 
40
                Assert.Fail("Method not found: " + methodName);
 
41
            return testBuilder.BuildFrom(method);
 
42
        }
 
43
 
 
44
                public static Test MakeTestCase( object fixture, string methodName )
 
45
                {
 
46
                        Test test = MakeTestCase( fixture.GetType(), methodName );
 
47
                        test.Fixture = fixture;
 
48
                        return test;
 
49
                }
 
50
 
 
51
                public static TestResult RunTestFixture( Type type )
 
52
                {
 
53
            return MakeFixture(type).Run(NullListener.NULL, TestFilter.Empty);
 
54
                }
 
55
 
 
56
                public static TestResult RunTestFixture( object fixture )
 
57
                {
 
58
            return MakeFixture(fixture).Run(NullListener.NULL, TestFilter.Empty);
 
59
                }
 
60
 
 
61
                public static TestResult RunTestCase( Type type, string methodName )
 
62
                {
 
63
            return MakeTestCase(type, methodName).Run(NullListener.NULL, TestFilter.Empty);
 
64
                }
 
65
 
 
66
                private TestBuilder() { }
 
67
        }
 
68
}