public INativeTest ForTest(FixtureContext fixtureContext, TestContext testContext)
 {
     Contexts[testContext.Name.FullName] = testContext;
     var result = new GenericNativeTest(testContext.Name);
     RecordTestAt(fixtureContext.FixtureFactory, testContext.Position, result);
     return result;
 }
Example #2
0
        public INativeTest CreateTest(INativeTest parentTest, TestPosition position, string description)
        {
            var testContext = new TestContext()
            {
                Name = NameReservations.GetReservedTestName(description, parentTest.Name),
                Position = position,
                FixtureContext = this
            };

            return NativeTestFactory.ForTest(this, testContext);
        }
        public static TestResultShim RunTest(TestContext testContext, List<string> traceMessages)
        {
            var startTime = DateTime.UtcNow;
            var testResult = new TestResultShim();

            Exception existingError = testContext.FixtureContext.GlobalSetupManager.PrepareForTestPosition(testContext.Position);

            if (existingError != null)
            {
                TestResultUtil.Error(testResult, testContext.Name.MultilineName, existingError, null,
                                     TestResultShim.Site.SetUp);
            }
            else
            {
                traceMessages.AddRange(testContext.FixtureContext.GlobalSetupManager.GetTraceMessages());
                try
                {
                    List<string> traceMessages1 = traceMessages;
                    traceMessages1 = traceMessages1 ?? new List<string>();

                    var executionContext = new NJasmineTestRunContext(testContext.Position, testContext.FixtureContext.GlobalSetupManager, traceMessages1);
                    var runner = new NJasmineTestRunner(executionContext);

                    SpecificationFixture fixture = testContext.FixtureContext.FixtureFactory();

                    fixture.CurrentPosition = TestPosition.At(0);
                    fixture.Visitor = runner;
                    try
                    {
                        fixture.Run();
                    }
                    finally
                    {
                        executionContext.RunAllPerTestTeardowns();
                    }
                    testResult.Success();
                }
                catch (Exception e)
                {
                    TestResultUtil.Error(testResult, testContext.Name.MultilineName, e, traceMessages);
                }
            }

            testResult.SetExecutionTime(DateTime.UtcNow - startTime);
            return testResult;
        }
        public static INativeTest BuildSuiteForTextContext(FixtureContext fixtureContext, TestContext testContext1, Action invoke, bool isRootSuite, string explicitReason = null)
        {
            var result = fixtureContext.NativeTestFactory.ForSuite(fixtureContext, testContext1);

            if (explicitReason != null)
                result.MarkTestIgnored(explicitReason);

            var builder = new DiscoveryVisitor(result, fixtureContext, testContext1.FixtureContext.GlobalSetupManager);

            var exception = fixtureContext.RunActionWithVisitor(testContext1.Position.GetFirstChildPosition(), invoke, builder);

            if (exception == null)
            {
                builder.VisitAccumulatedTests(result.AddChild);
            }
            else
            {
                var failedTestPositon = isRootSuite
                                            ? testContext1.Position.GetFirestUnexpectedChildPosition()
                                            : testContext1.Position;

                var testContext = new TestContext()
                {
                    Name = fixtureContext.NameReservations.GetReservedNameLike(result.Name),
                    Position = failedTestPositon,
                    FixtureContext = testContext1.FixtureContext
                };

                var failingSuiteAsTest = fixtureContext.NativeTestFactory.ForTest(fixtureContext, testContext);
                failingSuiteAsTest.MarkTestFailed(exception);

                if (isRootSuite)
                {
                    result.AddChild(failingSuiteAsTest);
                }
                else
                {
                    return failingSuiteAsTest;
                }
            }

            return result;
        }
 public INativeTest ForTest(FixtureContext fixtureContext, TestContext testContext)
 {
     Results[testContext.Position] = testContext.Name.Shortname;
     return(new NoopTest(testContext.Name));
 }
        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);
        }
 public INativeTest ForTest(FixtureContext fixtureContext, TestContext testContext)
 {
     Results[testContext.Position] = testContext.Name.Shortname;
     return new NoopTest(testContext.Name);
 }
 public INativeTest ForTest(FixtureContext fixtureContext, TestContext testContext)
 {
     return new ValidatingNativeTestWrapper(_factory.ForTest(fixtureContext, testContext));
 }
 public INativeTest ForSuite(FixtureContext fixtureContext, TestContext testContext)
 {
     var result = new GenericNativeTest(testContext.Name);
     RecordTestAt(fixtureContext.FixtureFactory, testContext.Position, result);
     return result;
 }