Ejemplo n.º 1
0
        /// <summary>
        /// Filters the test cases.
        /// </summary>
        /// <param name="initialCollection">The initial collection.</param>
        /// <returns>filtered collection</returns>
        public List <TestCase> FilterTestCases(List <TestCase> initialCollection)
        {
            List <TestCase> resultCollection = new List <TestCase>();

            bool   shouldSetIdFilter         = this.IsIdTextSet && !string.IsNullOrEmpty(this.IdFilter);
            string idFilter                  = this.IdFilter;
            bool   shouldSetTextFilter       = this.IsTitleTextSet && !string.IsNullOrEmpty(this.TitleFilter);
            string titleFilter               = this.TitleFilter.ToLower();
            bool   shouldSetSuiteFilter      = this.IsSuiteTextSet && !string.IsNullOrEmpty(this.SuiteFilter);
            string suiteFilter               = this.SuiteFilter.ToLower();
            bool   shouldSetPriorityFilter   = this.IsPriorityTextSet && !string.IsNullOrEmpty(this.PriorityFilter);
            string priorityFilter            = this.PriorityFilter.ToLower();
            bool   shouldSetAssignedToFilter = this.IsAssignedToTextSet && !string.IsNullOrEmpty(this.AssignedToFilter);
            string assignedToFilter          = this.AssignedToFilter.ToLower();

            List <TestCase>         resultCollection1 = new List <TestCase>();
            List <TestCase>         resultCollection2 = new List <TestCase>();
            List <TestCase>         resultCollection3 = new List <TestCase>();
            List <TestCase>         resultCollection4 = new List <TestCase>();
            List <TestCase>         resultCollection5 = new List <TestCase>();
            List <TestCase>         resultCollection6 = new List <TestCase>();
            List <TestCase>         resultCollection7 = new List <TestCase>();
            ConditionalSearchEngine searchEngine      = new ConditionalSearchEngine();
            bool shouldBeAdded = false;

            if (shouldSetIdFilter)
            {
                if (searchEngine.IsExpressionConditionSearchable(IdFilter))
                {
                    foreach (var item in initialCollection)
                    {
                        shouldBeAdded = searchEngine.ShouldBeAdded(IdFilter, item.Id.ToString());
                        if (shouldBeAdded)
                        {
                            resultCollection1.Add(item);
                        }
                        shouldBeAdded = false;
                    }
                }
            }
            if (shouldSetTextFilter)
            {
                if (searchEngine.IsExpressionConditionSearchable(this.TitleFilter))
                {
                    foreach (var item in initialCollection)
                    {
                        shouldBeAdded = searchEngine.ShouldBeAdded(this.TitleFilter, item.Title);
                        if (shouldBeAdded)
                        {
                            resultCollection2.Add(item);
                        }
                        shouldBeAdded = false;
                    }
                }
            }
            //TODO: Optimize the methods add it to begining
            if (shouldSetIdFilter || shouldSetTextFilter)
            {
                resultCollection = resultCollection1.Intersect(resultCollection2).ToList();
            }
            else
            {
                return(initialCollection);
            }


            //var filteredList = initialCollection.Where(t =>
            //                                                            (t.ITestCase != null) &&
            //                                                            (shouldSetIdFilter ? (t.ITestCase.Id.ToString().Contains(idFilter)) : true) &&
            //                                                            (shouldSetTextFilter ? (t.ITestCase.Title.ToLower().Contains(titleFilter)) : true) &&
            //                                                            (this.FilterTestCasesBySuite(shouldSetSuiteFilter, suiteFilter, t)) &&
            //                                                            (shouldSetPriorityFilter ? t.Priority.ToString().ToLower().Contains(priorityFilter) : true) &&
            //                                                            (t.TeamFoundationIdentityName != null && shouldSetAssignedToFilter ? t.TeamFoundationIdentityName.DisplayName.ToLower().Contains(assignedToFilter) : true) &&
            //                                                            (!this.HideAutomated.Equals(t.ITestCase.IsAutomated) || !this.HideAutomated) &&
            //                                                            (this.CurrentExecutionStatusOption.Equals(TestCaseExecutionType.All) || t.LastExecutionOutcome.Equals(this.CurrentExecutionStatusOption))).ToList();
            //this.ObservableTestCases.Clear();
            //filteredList.ForEach(x => this.ObservableTestCases.Add(x));
            //this.TestCasesCount = filteredList.Count.ToString();

            return(resultCollection);
        }
        /// <summary>
        /// Filters the test cases.
        /// </summary>
        /// <param name="initialCollection">The initial collection.</param>
        /// <returns>filtered collection</returns>
        public List<TestCase> FilterTestCases(List<TestCase> initialCollection)
        {
            List<TestCase> resultCollection = new List<TestCase>();
           
            bool shouldSetIdFilter = this.IsIdTextSet && !string.IsNullOrEmpty(this.IdFilter);
            string idFilter = this.IdFilter;
            bool shouldSetTextFilter = this.IsTitleTextSet && !string.IsNullOrEmpty(this.TitleFilter);
            string titleFilter = this.TitleFilter.ToLower();
            bool shouldSetSuiteFilter = this.IsSuiteTextSet && !string.IsNullOrEmpty(this.SuiteFilter);
            string suiteFilter = this.SuiteFilter.ToLower();
            bool shouldSetPriorityFilter = this.IsPriorityTextSet && !string.IsNullOrEmpty(this.PriorityFilter);
            string priorityFilter = this.PriorityFilter.ToLower();
            bool shouldSetAssignedToFilter = this.IsAssignedToTextSet && !string.IsNullOrEmpty(this.AssignedToFilter);
            string assignedToFilter = this.AssignedToFilter.ToLower();

            List<TestCase> resultCollection1 = new List<TestCase>();
            List<TestCase> resultCollection2 = new List<TestCase>();
            List<TestCase> resultCollection3 = new List<TestCase>();
            List<TestCase> resultCollection4 = new List<TestCase>();
            List<TestCase> resultCollection5 = new List<TestCase>();
            List<TestCase> resultCollection6 = new List<TestCase>();
            List<TestCase> resultCollection7 = new List<TestCase>();
            ConditionalSearchEngine searchEngine = new ConditionalSearchEngine();
            bool shouldBeAdded = false;
            if (shouldSetIdFilter)
            {                
                if (searchEngine.IsExpressionConditionSearchable(IdFilter))
                {
                    foreach (var item in initialCollection)
                    {
                        shouldBeAdded = searchEngine.ShouldBeAdded(IdFilter, item.Id.ToString());
                        if (shouldBeAdded)
                        {
                            resultCollection1.Add(item);
                        }
                        shouldBeAdded = false;
                    }
                }
            }
            if (shouldSetTextFilter)
            {
                if (searchEngine.IsExpressionConditionSearchable(this.TitleFilter))
                {
                    foreach (var item in initialCollection)
                    {                       
                        shouldBeAdded = searchEngine.ShouldBeAdded(this.TitleFilter, item.Title);
                        if (shouldBeAdded)
                        {
                            resultCollection2.Add(item);
                        }
                        shouldBeAdded = false;
                    }
                }
            }
            //TODO: Optimize the methods add it to begining
            if (shouldSetIdFilter || shouldSetTextFilter)
            {
                resultCollection = resultCollection1.Intersect(resultCollection2).ToList();
            }
            else
            {
                return initialCollection;
            }
                
                
            //var filteredList = initialCollection.Where(t =>
            //                                                            (t.ITestCase != null) &&
            //                                                            (shouldSetIdFilter ? (t.ITestCase.Id.ToString().Contains(idFilter)) : true) &&
            //                                                            (shouldSetTextFilter ? (t.ITestCase.Title.ToLower().Contains(titleFilter)) : true) &&
            //                                                            (this.FilterTestCasesBySuite(shouldSetSuiteFilter, suiteFilter, t)) &&
            //                                                            (shouldSetPriorityFilter ? t.Priority.ToString().ToLower().Contains(priorityFilter) : true) &&
            //                                                            (t.TeamFoundationIdentityName != null && shouldSetAssignedToFilter ? t.TeamFoundationIdentityName.DisplayName.ToLower().Contains(assignedToFilter) : true) &&
            //                                                            (!this.HideAutomated.Equals(t.ITestCase.IsAutomated) || !this.HideAutomated) &&
            //                                                            (this.CurrentExecutionStatusOption.Equals(TestCaseExecutionType.All) || t.LastExecutionOutcome.Equals(this.CurrentExecutionStatusOption))).ToList();
            //this.ObservableTestCases.Clear();
            //filteredList.ForEach(x => this.ObservableTestCases.Add(x));
            //this.TestCasesCount = filteredList.Count.ToString();

            return resultCollection;
        }