Filter() public méthode

public Filter ( IEnumerable testCases ) : IEnumerable
testCases IEnumerable
Résultat IEnumerable
Exemple #1
0
        public void Filter_ExpressionMatchesNothing_EmptyResult()
        {
            _mockFilterExpression.Setup(e => e.MatchTestCase(It.IsAny <TestCase>(), It.IsAny <Func <string, object> >())).Returns(false);
            IEnumerable <TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(tc => tc.ToVsTestCase());

            TestCaseFilter         filter            = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment.Logger);
            IEnumerable <TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(new List <TestCase>(), filteredTestCases);
        }
        public void Filter_ExpressionMatchesNothing_EmptyResult()
        {
            _mockFilterExpression.Setup(e => e.MatchTestCase(It.IsAny<TestCase>(), It.IsAny<Func<string, object>>())).Returns(false);
            IEnumerable<TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(DataConversionExtensions.ToVsTestCase);

            TestCaseFilter filter = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment);
            IEnumerable<TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(new List<TestCase>(), filteredTestCases);
        }
Exemple #3
0
        public void Filter_ExpressionAcceptsAnything_NoFiltering()
        {
            _mockFilterExpression.Setup(e => e.MatchTestCase(It.IsAny <TestCase>(), It.IsAny <Func <string, object> >())).Returns(true);
            IEnumerable <TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(DataConversionExtensions.ToVsTestCase);

            TestCaseFilter         filter            = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment.Logger);
            IEnumerable <TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(testCases, filteredTestCases);
        }
Exemple #4
0
        public void Filter_ExpressionMatchesDisplayName_CorrectFiltering()
        {
            List <TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(tc => tc.ToVsTestCase()).ToList();

            _mockFilterExpression.Setup(e => e.MatchTestCase(It.Is <TestCase>(tc => tc == testCases[0]), It.Is <Func <string, object> >(f => f("DisplayName").ToString() == "Foo.Bar"))).Returns(true);

            TestCaseFilter         filter            = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment.Logger);
            IEnumerable <TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(testCases[0].Yield(), filteredTestCases);
        }
Exemple #5
0
        public void Filter_NoFilterExpressionProvided_NoFiltering()
        {
            MockRunContext.Setup(rc => rc.GetTestCaseFilter(
                                     It.IsAny <IEnumerable <string> >(), It.IsAny <Func <string, TestProperty> >()))
            .Returns((ITestCaseFilterExpression)null);
            IEnumerable <TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(tc => tc.ToVsTestCase());

            TestCaseFilter         filter            = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment.Logger);
            IEnumerable <TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(testCases, filteredTestCases);
        }
        public void Filter_NoFilterExpressionProvided_NoFiltering()
        {
            MockRunContext.Setup(rc => rc.GetTestCaseFilter(
                    It.IsAny<IEnumerable<string>>(), It.IsAny<Func<string, TestProperty>>()))
                .Returns((ITestCaseFilterExpression)null);
            IEnumerable<TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(DataConversionExtensions.ToVsTestCase);

            TestCaseFilter filter = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment);
            IEnumerable<TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(testCases, filteredTestCases);
        }
Exemple #7
0
        public void Filter_Trait_CorrectFiltering()
        {
            List <TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(tc => tc.ToVsTestCase()).ToList();

            testCases[0].Traits.Add(new Trait("MyTrait", "value1"));
            SetupFilterToAcceptTraitForTestCase(testCases[0], "MyTrait", "value1");
            testCases[1].Traits.Add(new Trait("MyTrait", "value2"));
            SetupFilterToAcceptTraitForTestCase(testCases[1], "MyTrait", "value2");
            _traitNames.Add("MyTrait");

            TestCaseFilter         filter            = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment.Logger);
            IEnumerable <TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(testCases, filteredTestCases);
        }
        public void RunTests(IEnumerable<VsTestCase> vsTestCasesToRun, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                InitOrRefreshTestEnvironment(runContext.RunSettings, frameworkHandle);

                var vsTestCasesToRunAsArray = vsTestCasesToRun as VsTestCase[] ?? vsTestCasesToRun.ToArray();
                ISet<string> allTraitNames = GetAllTraitNames(vsTestCasesToRunAsArray.Select(DataConversionExtensions.ToTestCase));
                var filter = new TestCaseFilter(runContext, allTraitNames, _testEnvironment);
                vsTestCasesToRun = filter.Filter(vsTestCasesToRunAsArray);

                IEnumerable<TestCase> allTestCasesInExecutables =
                    GetAllTestCasesInExecutables(vsTestCasesToRun.Select(tc => tc.Source).Distinct());

                ICollection<TestCase> testCasesToRun = vsTestCasesToRun.Select(DataConversionExtensions.ToTestCase).ToArray();
                DoRunTests(allTestCasesInExecutables, testCasesToRun, runContext, frameworkHandle, stopwatch);
            }
            catch (Exception e)
            {
                _testEnvironment.LogError("Exception while running tests: " + e);
            }
        }
        public void RunTests(IEnumerable<string> executables, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            try
            {
                Stopwatch stopwatch = Stopwatch.StartNew();

                InitOrRefreshTestEnvironment(runContext.RunSettings, frameworkHandle);

                IList<TestCase> allTestCasesInExecutables = GetAllTestCasesInExecutables(executables).ToList();

                ISet<string> allTraitNames = GetAllTraitNames(allTestCasesInExecutables);
                var filter = new TestCaseFilter(runContext, allTraitNames, _testEnvironment);
                List<VsTestCase> vsTestCasesToRun =
                    filter.Filter(allTestCasesInExecutables.Select(DataConversionExtensions.ToVsTestCase)).ToList();
                ICollection<TestCase> testCasesToRun =
                    allTestCasesInExecutables.Where(tc => vsTestCasesToRun.Any(vtc => tc.FullyQualifiedName == vtc.FullyQualifiedName)).ToArray();

                DoRunTests(allTestCasesInExecutables, testCasesToRun, runContext, frameworkHandle, stopwatch);
            }
            catch (Exception e)
            {
                _testEnvironment.LogError("Exception while running tests: " + e);
            }
        }
        public void Filter_ExpressionMatchesDisplayName_CorrectFiltering()
        {
            List<TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(DataConversionExtensions.ToVsTestCase).ToList();
            _mockFilterExpression.Setup(e => e.MatchTestCase(It.Is<TestCase>(tc => tc == testCases[0]), It.Is<Func<string, object>>(f => f("DisplayName").ToString() == "Foo.Bar"))).Returns(true);

            TestCaseFilter filter = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment);
            IEnumerable<TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(testCases[0].Yield(), filteredTestCases);
        }
        public void Filter_Trait_CorrectFiltering()
        {
            List<TestCase> testCases = TestDataCreator.CreateDummyTestCases("Foo.Bar", "Foo.Baz").Select(DataConversionExtensions.ToVsTestCase).ToList();
            testCases[0].Traits.Add(new Trait("MyTrait", "value1"));
            SetupFilterToAcceptTraitForTestCase(testCases[0], "MyTrait", "value1");
            testCases[1].Traits.Add(new Trait("MyTrait", "value2"));
            SetupFilterToAcceptTraitForTestCase(testCases[1], "MyTrait", "value2");
            _traitNames.Add("MyTrait");

            TestCaseFilter filter = new TestCaseFilter(MockRunContext.Object, _traitNames, TestEnvironment);
            IEnumerable<TestCase> filteredTestCases = filter.Filter(testCases).ToList();

            AssertAreEqual(testCases, filteredTestCases);
        }