Ejemplo n.º 1
0
        public TestBuilder RunSuiteAction(FixtureDiscoveryContext buildContext, GlobalSetupManager globalSetup, Action action,
            bool isOuterScopeOfSpecification, TestBuilder resultBuilder)
        {
            var builder = new NJasmineTestSuiteBuilder(_nativeTestFactory, resultBuilder, buildContext, globalSetup);

            var exception = buildContext.RunActionWithVisitor(_position.GetFirstChildPosition(), action, builder);

            if (exception == null)
            {
                builder.VisitAccumulatedTests(v => resultBuilder.AddChildTest(v));
            }
            else
            {
                var failingSuiteAsTest = new TestBuilder(_nativeTestFactory.ForFailingSuite(_position, exception));

                failingSuiteAsTest.FullName = resultBuilder.FullName;
                failingSuiteAsTest.Shortname = resultBuilder.Shortname;
                failingSuiteAsTest.MultilineName = resultBuilder.MultilineName;

                buildContext.NameGenator.ReserveName(failingSuiteAsTest);

                if (isOuterScopeOfSpecification)
                {
                    resultBuilder.AddChildTest(failingSuiteAsTest);
                }
                else
                {
                    return failingSuiteAsTest;
                }
            }
            return resultBuilder;
        }
        public NJasmineTestMethod CreateTest(GlobalSetupManager globalSetupManager, NJasmineTestSuite parentTest, TestPosition position, string description)
        {
            var test = new NJasmineTestMethod(_fixtureFactory, position, globalSetupManager);

            NameGenator.NameTest(description, parentTest, test);
            return test;
        }
Ejemplo n.º 3
0
 public NJasmineTestSuite(TestPosition position, GlobalSetupManager setupManager)
     : base("thistestname", "willbeoverwritten")
 {
     Position = position;
     _setupManager = setupManager;
     maintainTestOrder = true;
 }
        public TestBuilder CreateTest(GlobalSetupManager globalSetupManager, TestBuilder parentTest, TestPosition position, string description)
        {
            var test = new TestBuilder(_nativeTestFactory.ForTest(_fixtureFactory, position, globalSetupManager));

            NameGenator.NameTest(description, parentTest, test);
            return test;
        }
Ejemplo n.º 5
0
        public Test BuildNJasmineTestSuite(FixtureDiscoveryContext buildContext, GlobalSetupManager globalSetup, Action action, bool isOuterScopeOfSpecification)
        {
            var builder = new NJasmineTestSuiteBuilder(this, buildContext, globalSetup);

            var exception = buildContext.RunActionWithVisitor(Position.GetFirstChildPosition(), action, builder);

            if (exception == null)
            {
                builder.VisitAccumulatedTests(Add);
            }
            else
            {
                var nJasmineInvalidTestSuite = new NJasmineInvalidTestSuite(exception, Position);

                nJasmineInvalidTestSuite.TestName.FullName = TestName.FullName;
                nJasmineInvalidTestSuite.TestName.Name = TestName.Name;

                nJasmineInvalidTestSuite.SetMultilineName(this.GetMultilineName());

                if (isOuterScopeOfSpecification)
                {
                    Add(nJasmineInvalidTestSuite);
                }
                else
                {
                    return nJasmineInvalidTestSuite;
                }
            }

            return this;
        }
Ejemplo n.º 6
0
        public Test BuildFrom(Type type)
        {
            var constructor = type.GetConstructor(new Type[0]);

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

            NativeTestFactory nativeTestFactory = new NativeTestFactory();

            FixtureDiscoveryContext buildContext = new FixtureDiscoveryContext(nativeTestFactory, fixtureFactory, new NameGenerator(), fixtureFactory());

            var globalSetup = new GlobalSetupManager();

            globalSetup.Initialize(fixtureFactory);

            NJasmineTestSuite rootSuite = new NJasmineTestSuite(nativeTestFactory, new TestPosition(), globalSetup);

            TestBuilder root = rootSuite.BuildNJasmineTestSuite(type.Namespace, type.Name, buildContext, globalSetup, buildContext.GetSpecificationRootAction(), true);

            var result = (root.GetUnderlyingTest() as NativeTest).GetNative(root);

            NUnitFramework.ApplyCommonAttributes(type.GetCustomAttributes(false).Cast<Attribute>().ToArray(), result);

            return result;
        }
Ejemplo n.º 7
0
        public TestBuilder BuildNJasmineTestSuite(string parentName, string name, FixtureDiscoveryContext buildContext, GlobalSetupManager globalSetup, Action action, bool isOuterScopeOfSpecification)
        {
            var position = _position;

            var resultBuilder = new TestBuilder(_nativeTestFactory.ForSuite(position, () => _globalSetup.Cleanup(position)));
            resultBuilder.FullName = parentName + "." + name;
            resultBuilder.Shortname = name;
            resultBuilder.MultilineName = resultBuilder.FullName;

            return RunSuiteAction(buildContext, globalSetup, action, isOuterScopeOfSpecification, resultBuilder);
        }
Ejemplo n.º 8
0
        public GlobalSetupManager GetSetupManager(Type type, Func<SpecificationFixture> fixtureFactory)
        {
            GlobalSetupManager result;
            if (_setupManagers.TryGetValue(type, out result))
                return result;

            result = new GlobalSetupManager(fixtureFactory);
            _setupManagers[type] = result;

            return result;
        }
Ejemplo n.º 9
0
        public Test BuildNJasmineTestSuite(AllSuitesBuildContext buildContext, GlobalSetupManager globalSetup, Action action, bool isOuterScopeOfSpecification)
        {
            var builder = new NJasmineTestSuiteBuilder(this, buildContext, globalSetup);

            Exception exception = null;

            var originalVisitor = buildContext._fixtureInstanceForDiscovery.Visitor;

            buildContext._fixtureInstanceForDiscovery.CurrentPosition = Position;
            buildContext._fixtureInstanceForDiscovery.CurrentPosition = buildContext._fixtureInstanceForDiscovery.CurrentPosition.GetFirstChildPosition();
            buildContext._fixtureInstanceForDiscovery.Visitor = builder;

            try
            {
                try
                {
                    action();
                }
                catch (Exception e)
                {
                    exception = e;
                }

                if (exception == null)
                {
                    builder.VisitAccumulatedTests(Add);
                }
                else
                {
                    var nJasmineInvalidTestSuite = new NJasmineInvalidTestSuite(exception, Position);

                    nJasmineInvalidTestSuite.TestName.FullName = TestName.FullName;
                    nJasmineInvalidTestSuite.TestName.Name = TestName.Name;

                    nJasmineInvalidTestSuite.SetMultilineName(this.GetMultilineName());

                    if (isOuterScopeOfSpecification)
                    {
                        Add(nJasmineInvalidTestSuite);
                    }
                    else
                    {
                        return nJasmineInvalidTestSuite;
                    }
                }
            }
            finally
            {
                buildContext._fixtureInstanceForDiscovery.Visitor = originalVisitor;
            }

            return this;
        }
Ejemplo n.º 10
0
        public static Test CreateRootNJasmineSuite(Func<SpecificationFixture> fixtureFactory, Type type)
        {
            AllSuitesBuildContext buildContext = new AllSuitesBuildContext(fixtureFactory, new NameGenerator(), fixtureFactory());

            var globalSetup = new GlobalSetupManager();

            globalSetup.Initialize(fixtureFactory);

            NJasmineTestSuite rootSuite = new NJasmineTestSuite(new TestPosition(), globalSetup);
            rootSuite.TestName.FullName = type.Namespace + "." + type.Name;
            rootSuite.TestName.Name = type.Name;

            return rootSuite.BuildNJasmineTestSuite(buildContext, globalSetup, buildContext._fixtureInstanceForDiscovery.Run, true);
        }
Ejemplo n.º 11
0
 public INativeTestBuilder ForTest(Func<SpecificationFixture> fixtureFactory, TestPosition position, GlobalSetupManager globalSetupManager)
 {
     var result = new NativeTest(new NJasmineTestMethod(fixtureFactory, position, globalSetupManager));
     return result;
 }
Ejemplo n.º 12
0
 public NJasmineTestSuite(INativeTestFactory nativeTestFactory, TestPosition position, GlobalSetupManager globalSetup)
 {
     _nativeTestFactory = nativeTestFactory;
     _position = position;
     _globalSetup = globalSetup;
 }