public void TestCaseFilter_ErrorParsingFilterString()
        {
            var filterHelper = new TestCaseFilterHelper(dummyKnownTraits);
            var dummyTestCaseList = GetDummyTestCases();
            var context = Substitute.For<IV12RunContext>();
            context.GetTestCaseFilter(null, null).ReturnsForAnyArgs(x => { throw new TestPlatformFormatException(); });

            var results = filterHelper.GetFilteredTestList(dummyTestCaseList, context, GetLoggerHelper(), "dummyTestAssembly");

            // Make sure we don't run anything due to the filtering string parse error
            Assert.Empty(results);
        }
        public void TestCaseFilter_NoFilterString()
        {
            var filterHelper = new TestCaseFilterHelper(dummyKnownTraits);
            var dummyTestCaseList = GetDummyTestCases();
            var context = Substitute.For<IV12RunContext>();
            context.GetTestCaseFilter(null, null).ReturnsForAnyArgs((ITestCaseFilterExpression)null);

            var results = filterHelper.GetFilteredTestList(dummyTestCaseList, context, GetLoggerHelper(), "dummyTestAssembly");

            // Make sure we run the whole set since there is not filtering string specified
            Assert.Equal(dummyTestCaseList.Count(), results.Count());
        }
        public void TestCaseFilter_ErrorParsingFilterString()
        {
            var filterHelper      = new TestCaseFilterHelper(dummyKnownTraits);
            var dummyTestCaseList = GetDummyTestCases();
            var context           = Substitute.For <IV12RunContext>();

            context.GetTestCaseFilter(null, null).ReturnsForAnyArgs(x => { throw new TestPlatformFormatException(); });

            var results = filterHelper.GetFilteredTestList(dummyTestCaseList, context, GetLoggerHelper(), "dummyTestAssembly");

            // Make sure we don't run anything due to the filtering string parse error
            Assert.Empty(results);
        }
        public void TestCaseFilter_NoFilterString()
        {
            var filterHelper      = new TestCaseFilterHelper(dummyKnownTraits);
            var dummyTestCaseList = GetDummyTestCases();
            var context           = Substitute.For <IV12RunContext>();

            context.GetTestCaseFilter(null, null).ReturnsForAnyArgs((ITestCaseFilterExpression)null);

            var results = filterHelper.GetFilteredTestList(dummyTestCaseList, context, GetLoggerHelper(), "dummyTestAssembly");

            // Make sure we run the whole set since there is not filtering string specified
            Assert.Equal(dummyTestCaseList.Count(), results.Count());
        }
        public void TestCaseFilter_SingleMatch()
        {
            var filterHelper = new TestCaseFilterHelper(dummyKnownTraits);
            var dummyTestCaseList = GetDummyTestCases();
            var dummyTestCaseDisplayNamefilterString = "Test4";
            var context = Substitute.For<IV12RunContext>();
            var filterExpression = Substitute.For<ITestCaseFilterExpression>();
            // The matching should return a single testcase
            filterExpression.MatchTestCase(Arg.Any<TestCase>(), Arg.Any<Func<string, object>>()).Returns(x => ((TestCase)x[0]).FullyQualifiedName.Equals(dummyTestCaseDisplayNamefilterString));
            context.GetTestCaseFilter(null, null).ReturnsForAnyArgs(filterExpression);

            var results = filterHelper.GetFilteredTestList(dummyTestCaseList, context, GetLoggerHelper(), "dummyTestAssembly");

            var result = Assert.Single(results);
            Assert.Equal("Test4", result.FullyQualifiedName);
        }
예제 #6
0
        List <AssemblyRunInfo> GetTests(IEnumerable <string> sources, LoggerHelper logger, IRunContext runContext)
        {
            // For store apps, the files are copied to the AppX dir, we need to load it from there
#if PLATFORM_DOTNET
            sources = sources.Select(s => Path.Combine(Windows.ApplicationModel.Package.Current.InstalledLocation.Path, Path.GetFileName(s)));
#endif

            var result          = new List <AssemblyRunInfo>();
            var knownTraitNames = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            DiscoverTests(
                sources,
                logger,
                (source, discoverer, discoveryOptions) => new VsExecutionDiscoveryVisitor(),
                (source, discoverer, discoveryOptions, visitor) =>
            {
                var vsFilteredTestCases = visitor.TestCases.Select(testCase => VsDiscoveryVisitor.CreateVsTestCase(source, discoverer, testCase, false, logger: logger, knownTraitNames: knownTraitNames)).ToList();

                // Apply any filtering
                var filterHelper    = new TestCaseFilterHelper(knownTraitNames);
                vsFilteredTestCases = filterHelper.GetFilteredTestList(vsFilteredTestCases, runContext, logger, source).ToList();

                // Re-create testcases with unique names if there is more than 1
                var testCases = visitor.TestCases.Where(tc => vsFilteredTestCases.Any(vsTc => vsTc.DisplayName == tc.DisplayName)).GroupBy(tc => $"{tc.TestMethod.TestClass.Class.Name}.{tc.TestMethod.Method.Name}")
                                .SelectMany(group => group.Select(testCase =>
                                                                  VsDiscoveryVisitor.CreateVsTestCase(
                                                                      source,
                                                                      discoverer,
                                                                      testCase,
                                                                      forceUniqueNames: group.Count() > 1,
                                                                      logger: logger,
                                                                      knownTraitNames: knownTraitNames))
                                            .Where(vsTestCase => vsTestCase != null)).ToList();             // pre-enumerate these as it populates the known trait names collection

                var runInfo = new AssemblyRunInfo
                {
                    AssemblyFileName = source,
                    Configuration    = LoadConfiguration(source),
                    TestCases        = testCases
                };
                result.Add(runInfo);
            }
                );

            return(result);
        }
        public void TestCaseFilter_SingleMatch()
        {
            var filterHelper      = new TestCaseFilterHelper(dummyKnownTraits);
            var dummyTestCaseList = GetDummyTestCases();
            var dummyTestCaseDisplayNamefilterString = "Test4";
            var context          = Substitute.For <IV12RunContext>();
            var filterExpression = Substitute.For <ITestCaseFilterExpression>();

            // The matching should return a single testcase
            filterExpression.MatchTestCase(Arg.Any <TestCase>(), Arg.Any <Func <string, object> >()).Returns(x => ((TestCase)x[0]).FullyQualifiedName.Equals(dummyTestCaseDisplayNamefilterString));
            context.GetTestCaseFilter(null, null).ReturnsForAnyArgs(filterExpression);

            var results = filterHelper.GetFilteredTestList(dummyTestCaseList, context, GetLoggerHelper(), "dummyTestAssembly");

            var result = Assert.Single(results);

            Assert.Equal("Test4", result.FullyQualifiedName);
        }
        public void TestCaseFilter_ErrorParsingFilterString()
        {
            var messageLogger     = Substitute.For <IMessageLogger>();
            var filterHelper      = new TestCaseFilterHelper(dummyKnownTraits);
            var dummyTestCaseList = GetDummyTestCases();
            var context           = Substitute.For <IRunContext>();

            context.GetTestCaseFilter(null, null).ReturnsForAnyArgs(x => { throw new TestPlatformFormatException("Hello from the exception"); });

            var results = filterHelper.GetFilteredTestList(dummyTestCaseList, context, GetLoggerHelper(messageLogger), "dummyTestAssembly");

            // Make sure we don't run anything due to the filtering string parse error
            Assert.Empty(results);
            var args = messageLogger.ReceivedCalls().Single().GetArguments();

            Assert.Collection(args,
                              arg => Assert.Equal(TestMessageLevel.Error, arg),
                              arg => Assert.EndsWith("dummyTestAssembly: Exception filtering tests: Hello from the exception", (string)arg)
                              );
        }