Beispiel #1
0
            public void ExampleStarted(DiscoveredExample example)
            {
                var test = exampleMapper.MapToTest(example);

                startedTestMap[example.FullName] = test;

                connection.TestStarted(test);
            }
Beispiel #2
0
        public Test MapToTest(DiscoveredExample example)
        {
            var test = new Test()
            {
                FullyQualifiedName = example.FullName,
                DisplayName        = BeautifyForDisplay(example.FullName),
                CodeFilePath       = example.SourceFilePath,
                LineNumber         = example.SourceLineNumber,
            };

            return(test);
        }
Beispiel #3
0
        public void it_should_lack_source_code_info()
        {
            var pendingExpected = new DiscoveredExample()
            {
                FullName         = fixtureData.Example.FullName(),
                SourceAssembly   = someAssemblyPath,
                SourceFilePath   = String.Empty,
                SourceLineNumber = 0,
                Tags             = fixtureData.Example.Tags.Select(tag => tag.Replace("_", " ")).ToArray(),
            };

            var actual = mapper.FromExample(fixtureData.Example);

            actual.ShouldBeEquivalentTo(pendingExpected);
        }
        public TestCase FromDiscoveredExample(DiscoveredExample discoveredExample)
        {
            var testCase = new TestCase(discoveredExample.FullName, Constants.ExecutorUri, discoveredExample.SourceAssembly)
            {
                DisplayName  = BeautifyForDisplay(discoveredExample.FullName),
                CodeFilePath = discoveredExample.SourceFilePath,
                LineNumber   = discoveredExample.SourceLineNumber,
            };

            var traits = discoveredExample.Tags
                         .Select(tag => tag.Replace('_', ' '))
                         .Select(tag => new Trait(tag, null));

            testCase.Traits.AddRange(traits);

            return(testCase);
        }
Beispiel #5
0
        public DiscoveredExample FromExample(ExampleBase example)
        {
            var methodInfo = GetFunctionBodyInfo(example);

            string specClassName     = methodInfo.DeclaringType.FullName;
            string exampleMethodName = methodInfo.Name;

            var navigationData = debugInfoProvider.GetNavigationData(specClassName, exampleMethodName);

            var discoveredExample = new DiscoveredExample()
            {
                FullName         = example.FullName(),
                SourceAssembly   = binaryPath,
                SourceFilePath   = navigationData.FileName,
                SourceLineNumber = navigationData.MinLineNumber,
                Tags             = example.Tags.Select(tag => tag.Replace("_", " ")).ToArray(),
            };

            return(discoveredExample);
        }
        public virtual void before_each()
        {
            autoSubstitute = new AutoSubstitute();

            mapper = autoSubstitute.Resolve <TestCaseMapper>();

            discoveredExample = new DiscoveredExample()
            {
                FullName         = "nspec. L1 context. L2 context. example name.",
                SourceFilePath   = @".\some\path\to\source\code.cs",
                SourceLineNumber = 123,
                SourceAssembly   = @".\some\path\to\library.dll",
                Tags             = new string[]
                {
                    "tag1", "tag2", "tag3_with_underscore", "tag4-with-dash",
                },
            };

            expectedTestCase = new TestCase(
                discoveredExample.FullName,
                Constants.ExecutorUri,
                discoveredExample.SourceAssembly)
            {
                DisplayName  = "L1 context › L2 context › example name.",
                CodeFilePath = discoveredExample.SourceFilePath,
                LineNumber   = discoveredExample.SourceLineNumber,
            };

            var expectedTraits = new string[]
            {
                "tag1", "tag2", "tag3 with underscore", "tag4-with-dash",
            }
            .Select(tag => new Trait(tag, null));

            expectedTestCase.Traits.AddRange(expectedTraits);
        }
Beispiel #7
0
        public DiscoveredExampleMapper_desc_base()
        {
            var parentContext = new Context("some parent context");

            var context = new Context("some child context");

            context.Parent = parentContext;

            fixtureData = BuildFixtureData();

            var example = fixtureData.Example;

            example.Context = context;
            example.Spec    = "some specification";

            expected = new DiscoveredExample()
            {
                FullName         = example.FullName(),
                SourceAssembly   = someAssemblyPath,
                SourceFilePath   = someSourceCodePath,
                SourceLineNumber = someLineNumber,
                Tags             = example.Tags.Select(tag => tag.Replace("_", " ")).ToArray(),
            };
        }
        public DiscoveredExample[] Discover(string binaryPath, ICrossDomainLogger logger)
        {
            logger.Debug(String.Format("Start discovering tests locally in binary '{0}'", binaryPath));

            DiscoveredExample[] discoveredExampleArray;

            try
            {
                var exampleFinder = new ExampleFinder();

                var examples = exampleFinder.Find(binaryPath);

                var debugInfoProvider = new DebugInfoProvider(binaryPath, logger);

                var discoveredExampleMapper = new DiscoveredExampleMapper(binaryPath, debugInfoProvider);

                var discoveredExamples = examples.Select(discoveredExampleMapper.FromExample);

                discoveredExampleArray = discoveredExamples.ToArray();
            }
            catch (Exception ex)
            {
                // report problem and return, without letting exception cross app domain boundary

                discoveredExampleArray = new DiscoveredExample[0];

                var exInfo  = new ExceptionLogInfo(ex);
                var message = String.Format("Exception thrown while discovering tests locally in binary '{0}'", binaryPath);

                logger.Error(exInfo, message);
            }

            logger.Debug(String.Format("Finish discovering {0} tests locally in binary '{1}'", discoveredExampleArray.Length, binaryPath));

            return(discoveredExampleArray);
        }
Beispiel #9
0
 void OnDiscovered(DiscoveredExample example)
 {
     actualDiscoveredExamples.Add(example);
 }