示例#1
0
        Test GetAssemblyTest(IAssemblyInfo assembly, Test parentTest, Version frameworkVersion, bool populateRecursively)
        {
            NSpecAssemblyTest assemblyTest;

            if (!assemblyTests.TryGetValue(assembly, out assemblyTest))
            {
                assemblyTest = new NSpecAssemblyTest(assembly.Name, assembly, frameworkVersion);
                assemblyTest.Kind = TestKinds.Assembly;

                ModelUtils.PopulateMetadataFromAssembly(assembly, assemblyTest.Metadata);

                string frameworkName = String.Format("NSpec v{0}", frameworkVersion);
                assemblyTest.Metadata.SetValue(MetadataKeys.Framework, frameworkName);
                assemblyTest.Metadata.SetValue(MetadataKeys.File, assembly.Path);
                assemblyTest.Kind = TestKinds.Assembly;

                parentTest.AddChild(assemblyTest);
                assemblyTests.Add(assembly, assemblyTest);
            }

            if (populateRecursively)
            {
                var reflector = new NSpec.Domain.Reflector(assembly.Path);
                var finder = new SpecFinder(reflector);
                var builder = new ContextBuilder(finder, new DefaultConventions());

                ContextCollection contexts = builder.Contexts();
                contexts.Build();
                contexts.Do(c => assemblyTest.AddChild(this.CreateGallioTestFrom(c)));
            }

            return assemblyTest;
        }
    Test GetAssemblyTest(IAssemblyInfo assembly, Test parentTest, Version frameworkVersion, bool populateRecursively)
    {
      MachineAssemblyTest assemblyTest;
      if (!assemblyTests.TryGetValue(assembly, out assemblyTest))
      {
        assemblyTest = new MachineAssemblyTest(assembly.Name, assembly, frameworkVersion);
        assemblyTest.Kind = TestKinds.Assembly;

        ModelUtils.PopulateMetadataFromAssembly(assembly, assemblyTest.Metadata);

        string frameworkName = String.Format("Machine Specifications v{0}", frameworkVersion);
        assemblyTest.Metadata.SetValue(MetadataKeys.Framework, frameworkName);
        assemblyTest.Metadata.SetValue(MetadataKeys.File, assembly.Path);
        assemblyTest.Kind = TestKinds.Assembly;

        parentTest.AddChild(assemblyTest);
        assemblyTests.Add(assembly, assemblyTest);
      }

      if (populateRecursively)
      {
        AssemblyExplorer explorer = new AssemblyExplorer();
        Assembly resolvedAssembly = assembly.Resolve(false);

        assemblyTest.AssemblyContexts = explorer.FindAssemblyContextsIn( resolvedAssembly).ToList();
        assemblyTest.GlobalCleanup = explorer.FindAssemblyWideContextCleanupsIn(resolvedAssembly).ToList();
        assemblyTest.SpecificationSupplements = explorer.FindSpecificationSupplementsIn(resolvedAssembly).ToList();
        
        explorer.FindContextsIn(resolvedAssembly)
          .Select( context => GetContextTest( context))
          .Each( test => assemblyTest.AddChild( test));
      }

      return assemblyTest;
    }
示例#3
0
        public void UsesSuffixedLocalIdWhenConflictsOccur()
        {
            var parent = new Test("name", null);

            var test1 = new Test("test", null);
            parent.AddChild(test1);
            Assert.AreEqual("test", test1.LocalId, "Uses name because there is no conflict.");

            var test2 = new Test("test", null);
            parent.AddChild(test2);
            Assert.AreEqual("test2", test2.LocalId, "Uses suffixed name because there is a conflict in the name and no hint.");

            var test3 = new Test("name", null);
            test3.LocalIdHint = "test";
            parent.AddChild(test3);
            Assert.AreEqual("test3", test3.LocalId, "Uses suffixed name because there is a conflict in the hint.");
        }
示例#4
0
        public void UsesNameAsLocalIdIfNoHintAndNoConflicts()
        {
            var test = new Test("name", null);
            Assert.AreEqual("name", test.LocalId, "Uses name when no parent available.");

            var testWithParent = new Test("name", null);
            test.AddChild(testWithParent);
            Assert.AreEqual("name", testWithParent.LocalId, "Uses name when parent available but no conflicts.");
        }
示例#5
0
        public void UsesLocalIdHintAsLocalIdIfNoConflicts()
        {
            var test = new Test("name", null);
            test.LocalIdHint = "hint";
            Assert.AreEqual("hint", test.LocalId, "Uses local id hint when no parent available.");

            var testWithParent = new Test("name", null);
            test.AddChild(testWithParent);
            testWithParent.LocalIdHint = "hint";
            Assert.AreEqual("hint", testWithParent.LocalId, "Uses local id hint when parent available but no conflicts.");
        }
示例#6
0
        public void UsesSuffixedLocalIdWhenConflictsOccur()
        {
            var parent = new Test("name", null);

            var test1 = new Test("test", null);

            parent.AddChild(test1);
            Assert.AreEqual("test", test1.LocalId, "Uses name because there is no conflict.");

            var test2 = new Test("test", null);

            parent.AddChild(test2);
            Assert.AreEqual("test2", test2.LocalId, "Uses suffixed name because there is a conflict in the name and no hint.");

            var test3 = new Test("name", null);

            test3.LocalIdHint = "test";
            parent.AddChild(test3);
            Assert.AreEqual("test3", test3.LocalId, "Uses suffixed name because there is a conflict in the hint.");
        }
示例#7
0
        public void UsesNameAsLocalIdIfNoHintAndNoConflicts()
        {
            var test = new Test("name", null);

            Assert.AreEqual("name", test.LocalId, "Uses name when no parent available.");

            var testWithParent = new Test("name", null);

            test.AddChild(testWithParent);
            Assert.AreEqual("name", testWithParent.LocalId, "Uses name when parent available but no conflicts.");
        }
示例#8
0
        public void UsesLocalIdHintAsLocalIdIfNoConflicts()
        {
            var test = new Test("name", null);

            test.LocalIdHint = "hint";
            Assert.AreEqual("hint", test.LocalId, "Uses local id hint when no parent available.");

            var testWithParent = new Test("name", null);

            test.AddChild(testWithParent);
            testWithParent.LocalIdHint = "hint";
            Assert.AreEqual("hint", testWithParent.LocalId, "Uses local id hint when parent available but no conflicts.");
        }
        private NUnitAssemblyTest BuildAssemblyTest(Test parent)
        {
            IAssemblyInfo assemblyInfo = Reflector.Wrap(assembly);
            NUnit.Core.TestRunner runner = CreateTestRunner(assembly.Location);

            NUnitAssemblyTest assemblyTest = new NUnitAssemblyTest(assemblyInfo, runner);
            PopulateMetadata(assemblyTest);
            PopulateAssemblyTestMetadata(assemblyTest, assemblyInfo);

            foreach (NUnit.Core.ITest assemblyTestSuite in runner.Test.Tests)
                BuildTestChildren(assemblyInfo, assemblyTest, assemblyTestSuite);

            parent.AddChild(assemblyTest);
            return assemblyTest;
        }
示例#10
0
        private Test GetAssemblyTest(IAssemblyInfo assembly, Test parentTest, Version frameworkVersion, bool populateRecursively)
        {
            Test assemblyTest;
            if (!assemblyTests.TryGetValue(assembly, out assemblyTest))
            {
                assemblyTest = CreateAssemblyTest(assembly, frameworkVersion);

                string frameworkName = String.Format("MSTest v{0}", frameworkVersion);
                assemblyTest.Metadata.SetValue(MetadataKeys.Framework, frameworkName);
                assemblyTest.Metadata.SetValue(MetadataKeys.File, assembly.Path);
                assemblyTest.Kind = AssemblyKind;

                parentTest.AddChild(assemblyTest);
                assemblyTests.Add(assembly, assemblyTest);
            }

            if (populateRecursively)
            {
                foreach (ITypeInfo type in assembly.GetExportedTypes())
                    TryGetTypeTest(type, assemblyTest);
            }

            return assemblyTest;
        }
        private Test TryGetTypeTest(ITypeInfo type, Test assemblyTest)
        {
            Test typeTest;
            if (!typeTests.TryGetValue(type, out typeTest))
            {
                try
                {
                    foreach (var attribute in type.GetAttributes(null, false))
                    {
                        if (attribute is ConcordionTestAttribute)
                        {
                            typeTest = CreateTypeTest(new ConcordionTypeInfoAdapter(type));
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    TestModel.AddAnnotation(new Annotation(AnnotationType.Error, type, "An exception was thrown while exploring an concordion test type.", ex));
                }

                if (typeTest != null)
                {
                    assemblyTest.AddChild(typeTest);
                    typeTests.Add(type, typeTest);
                }
            }
            return typeTest;
        }
        private Test GetAssemblyTest(IAssemblyInfo assembly, Test parentTest, Version frameworkVersion, bool populateRecursively)
        {
            Test assemblyTest;
            if (!assemblyTests.TryGetValue(assembly, out assemblyTest))
            {
                assemblyTest = CreateAssemblyTest(assembly);

                String frameworkName = CONCORDION_ASSEMBLY_DISPLAY_NAME;
                assemblyTest.Metadata.SetValue(MetadataKeys.Framework, frameworkName);
                assemblyTest.Metadata.SetValue(MetadataKeys.File, assembly.Path);
                assemblyTest.Kind = AssemblyKind;

                parentTest.AddChild(assemblyTest);
                assemblyTests.Add(assembly, assemblyTest);
            }

            GetInputOutputDirectories(assembly);

            if (populateRecursively)
            {
                foreach (var type in assembly.GetExportedTypes())
                    TryGetTypeTest(type, assemblyTest);
            }

            return assemblyTest;
        }
        private MbUnit2AssemblyTest BuildAssemblyTest(Test parent, ICollection<KeyValuePair<Test, string>> unresolvedDependencies)
        {
            FixtureExplorer fixtureExplorer = InitializeFixtureExplorer(assembly);
            IAssemblyInfo assemblyInfo = Reflector.Wrap(assembly);

            MbUnit2AssemblyTest assemblyTest = new MbUnit2AssemblyTest(fixtureExplorer, assemblyInfo);
            PopulateAssemblyTestMetadata(assemblyTest, assemblyInfo);

            foreach (Fixture fixture in fixtureExplorer.FixtureGraph.Fixtures)
            {
                MbUnit2Test fixtureTest = CreateFixtureTest(fixture);

                foreach (RunPipeStarter starter in fixture.Starters)
                {
                    MbUnit2Test test = CreateTest(starter.Pipe);

                    fixtureTest.AddChild(test);
                }

                assemblyTest.AddChild(fixtureTest);
            }

            foreach (string assemblyName in fixtureExplorer.GetDependentAssemblies())
                unresolvedDependencies.Add(new KeyValuePair<Test, string>(assemblyTest, assemblyName));

            parent.AddChild(assemblyTest);
            return assemblyTest;
        }
示例#14
0
        private Test TryGetTypeTest(ITypeInfo type, Test assemblyTest)
        {
            Test typeTest;
            if (!typeTests.TryGetValue(type, out typeTest))
            {
                try
                {
                    if (IsFixture(type))
                    {
                        typeTest = CreateTypeTest(type);
                    }
                }
                catch (Exception ex)
                {
                    TestModel.AddAnnotation(new Annotation(AnnotationType.Error, type, "An exception was thrown while exploring an MSTest test type.", ex));
                }

                if (typeTest != null)
                {
                    assemblyTest.AddChild(typeTest);
                    typeTests.Add(type, typeTest);
                }
            }

            return typeTest;
        }
示例#15
0
        private Test TryGetTypeTest(ITypeInfo type, Test assemblyTest)
        {
            Test typeTest;
            if (!typeTests.TryGetValue(type, out typeTest))
            {
                try
                {
                    XunitTypeInfoAdapter xunitTypeInfo = new XunitTypeInfoAdapter(type);
                    ITestClassCommand command = TestClassCommandFactory.Make(xunitTypeInfo);
                    if (command != null)
                        typeTest = CreateTypeTest(xunitTypeInfo, command);
                }
                catch (Exception ex)
                {
                    TestModel.AddAnnotation(new Annotation(AnnotationType.Error, type, "An exception was thrown while exploring an xUnit.net test type.", ex));
                }

                if (typeTest != null)
                {
                    assemblyTest.AddChild(typeTest);
                    typeTests.Add(type, typeTest);
                }
            }

            return typeTest;
        }
        private static void BuildTest(IAssemblyInfo assembly, Test parentTest, NUnit.Core.ITest nunitTest)
        {
            string kind;
            ICodeElementInfo codeElement;

            switch (nunitTest.TestType)
            {
#if NUNIT248
                case @"Test Case":
#elif NUNIT253
                case @"NUnitTestMethod":
#elif NUNIT254TO10 || NUNITLATEST
                case @"TestMethod":
#else
#error "Unrecognized NUnit framework version."
#endif
                    kind = TestKinds.Test;
                    codeElement = ParseTestCaseName(assembly, nunitTest.TestName.FullName);
                    break;

#if NUNIT248
                case @"Test Fixture":
#elif NUNIT253
                case @"NUnitTestFixture":
#elif NUNIT254TO10 || NUNITLATEST
                case @"TestFixture":
#else
#error "Unrecognized NUnit framework version."
#endif                    
                    kind = TestKinds.Fixture;
                    codeElement = ParseTestFixtureName(assembly, nunitTest.TestName.FullName);
                    break;

#if NUNIT254TO10 || NUNITLATEST
                case @"ParameterizedTest":
                    kind = TestKinds.Suite;
                    codeElement = ParseTestCaseName(assembly, nunitTest.TestName.FullName);
                    break;

                case @"Namespace":
                    kind = TestKinds.Namespace;
                    codeElement = parentTest.CodeElement;
                    break;
#endif

                default:
                    kind = nunitTest.IsSuite ? TestKinds.Suite : TestKinds.Test;
                    codeElement = parentTest.CodeElement;
                    break;
            }

            // Build the test.
            NUnitTest test = new NUnitTest(nunitTest.TestName.Name, codeElement, nunitTest);
            test.Kind = kind;
            test.IsTestCase = !nunitTest.IsSuite;

            PopulateMetadata(test);

            parentTest.AddChild(test);
            BuildTestChildren(assembly, test, nunitTest);
        }
        private Test GetAssemblyTest(IAssemblyInfo assembly, Test parentTest, Version frameworkVersion)
        {
            Test assemblyTest;
            if (assemblyTests.TryGetValue(assembly, out assemblyTest))
                return assemblyTest;

            try
            {
                Assembly loadedAssembly = assembly.Resolve(false);

                if (Reflector.IsUnresolved(loadedAssembly))
                    assemblyTest = BuildAssemblyTest_Reflective(assembly);
                else
                    assemblyTest = BuildAssemblyTest_Native(assembly, loadedAssembly.Location);

                string frameworkName = String.Format(Resources.CSUnitTestExplorer_FrameworkNameWithVersionFormat, frameworkVersion);
                assemblyTest.Metadata.SetValue(MetadataKeys.Framework, frameworkName);
                assemblyTest.Metadata.SetValue(MetadataKeys.File, assembly.Path);
                assemblyTest.Kind = AssemblyKind;
            }
            catch (Exception ex)
            {
                TestModel.AddAnnotation(new Annotation(AnnotationType.Error, assembly,
                    "An exception was thrown while exploring a csUnit test assembly.", ex));
                return null;
            }

            if (assemblyTest != null)
            {
                parentTest.AddChild(assemblyTest);
                
                assemblyTests.Add(assembly, assemblyTest);
            }
            return assemblyTest;
        }