コード例 #1
0
        public void can_load_tests()
        {
            Type type = typeof(has_test_in_loop);

            var nativeTestFactory = new TrackingTestFactory();

            using (var globalSetupOwner = new GlobalSetupOwner())
            {
                SpecificationBuilder.BuildTestFixture(type, nativeTestFactory, globalSetupOwner);

                expect(() => nativeTestFactory.Results[TestPosition.At(0)] == "a1");
                expect(() => nativeTestFactory.Results[TestPosition.At(1)] == "a2");
                expect(() => nativeTestFactory.Results[TestPosition.At(2)] == "a3");
                expect(() => nativeTestFactory.Results[TestPosition.At(3)] == "nested");
                expect(() => nativeTestFactory.Results[TestPosition.At(3, 0)] == "b1");
                expect(() => nativeTestFactory.Results[TestPosition.At(3, 1)] == "b2");
                expect(() => nativeTestFactory.Results[TestPosition.At(3, 2)] == "b3");
            }
        }
コード例 #2
0
        public static void BuildTestFixture(Type type, INativeTestFactory nativeTestFactory, GlobalSetupOwner globalSetupOwner)
        {
            if (nativeTestFactory is ValidatingNativeTestFactory)
                throw new InvalidOperationException("Do not pass a ValidatingNativeTestFactory here.");

            nativeTestFactory = new ValidatingNativeTestFactory(nativeTestFactory);

            var constructor = type.GetConstructor(new Type[0]);

            Func<SpecificationFixture> fixtureFactory = delegate()
            {
                var fixture = constructor.Invoke(new object[0]) as SpecificationFixture;
                return fixture;
            };

            var setupManager  = globalSetupOwner.GetSetupManager(type, fixtureFactory);

            FixtureContext fixtureContext = new FixtureContext(nativeTestFactory, fixtureFactory, new NameReservations(), setupManager);

            var testContext = new TestContext()
            {
                Position = TestPosition.At(),
                FixtureContext = fixtureContext,
                Name = new TestName
                {
                    FullName = type.Namespace + "." + type.Name,
                    Shortname = type.Name,
                    MultilineName = type.Namespace + "." + type.Name
                }
            };

            var explicitReason = ExplicitAttributeReader.GetFor(type);

            var result = BuildSuiteForTextContext(fixtureContext, testContext, fixtureContext.GetSpecificationRootAction(), true, explicitReason);

            nativeTestFactory.SetRoot(result);
        }