コード例 #1
0
ファイル: TestBuilder.cs プロジェクト: stantoxt/nunitv2
        public static Test MakeTestCase(Type type, string methodName)
        {
            MethodInfo method = Reflect.GetNamedMethod(type, methodName);

            if (method == null)
            {
                Assert.Fail("Method not found: " + methodName);
            }
            return(testBuilder.BuildFrom(method));
        }
コード例 #2
0
        private void AddTestCasesToFixture(TestSuite fixture)
        {
            var methods = fixture.TypeInfo.GetMethods(
                BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            var tests = methods
                        .Where(method => _testBuilder.CanBuildFrom(method, fixture))
                        .Select(method => _testBuilder.BuildFrom(method, fixture));

            foreach (var test in tests)
            {
                fixture.Add(test);
            }
        }
コード例 #3
0
        public void CanAddTestCaseBuilder()
        {
            ITestCaseBuilder mockBuilder = Substitute.For <ITestCaseBuilder>();

            mockBuilder.CanBuildFrom(null).Returns(true);

            IExtensionPoint ep = host.GetExtensionPoint("TestCaseBuilders");

            ep.Install(mockBuilder);
            ITestCaseBuilder builders = (ITestCaseBuilder)ep;

            builders.BuildFrom(null);

            mockBuilder.Received().BuildFrom(null);
        }
コード例 #4
0
        public void CanAddTestCaseBuilder()
        {
            DynamicMock mock = new DynamicMock(typeof(ITestCaseBuilder));

            mock.ExpectAndReturn("CanBuildFrom", true, null);
            mock.Expect("BuildFrom");

            IExtensionPoint ep = host.GetExtensionPoint("TestCaseBuilders");

            ep.Install(mock.MockInstance);
            ITestCaseBuilder builders = (ITestCaseBuilder)ep;

            builders.BuildFrom(null);

            mock.Verify();
        }
コード例 #5
0
 /// <summary>
 /// Method to create a test case from a MethodInfo and add
 /// it to the fixture being built. It first checks to see if
 /// any global TestCaseBuilder addin wants to build the
 /// test case. If not, it uses the internal builder
 /// collection maintained by this fixture builder.
 ///
 /// The default implementation has no test case builders.
 /// Derived classes should add builders to the collection
 /// in their constructor.
 /// </summary>
 /// <param name="method">The MethodInfo for which a test is to be created</param>
 /// <param name="suite">The test suite being built.</param>
 /// <returns>A newly constructed Test</returns>
 private Test BuildTestCase(MethodInfo method, TestSuite suite)
 {
     return(testBuilder.CanBuildFrom(method, suite)
         ? testBuilder.BuildFrom(method, suite)
         : null);
 }
コード例 #6
0
 /// <summary>
 /// Method to create a test case from a MethodInfo and add
 /// it to the fixture being built. It first checks to see if
 /// any global TestCaseBuilder addin wants to build the
 /// test case. If not, it uses the internal builder
 /// collection maintained by this fixture builder.
 ///
 /// The default implementation has no test case builders.
 /// Derived classes should add builders to the collection
 /// in their constructor.
 /// </summary>
 /// <param name="method">The method for which a test is to be created</param>
 /// <param name="suite">The test suite being built.</param>
 /// <returns>A newly constructed Test</returns>
 private Test BuildTestCase(FixtureMethod method, TestSuite suite)
 {
     return(_testBuilder.CanBuildFrom(method, suite)
         ? _testBuilder.BuildFrom(method, suite)
         : null);
 }