/// <summary> /// Returns TestCaseFilterExpression validated for supportedProperties. /// If there is a parsing error in filter expression, TestPlatformFormatException() is thrown. /// </summary> /// <param name="supportedProperties"> The supported Properties. </param> /// <param name="propertyProvider"> The property Provider. </param> /// <returns> The <see cref="ITestCaseFilterExpression"/>. </returns> public ITestCaseFilterExpression GetTestCaseFilter(IEnumerable <string> supportedProperties, Func <string, TestProperty> propertyProvider) { TestCaseFilterExpression adapterSpecificTestCaseFilter = null; if (this.FilterExpressionWrapper != null) { if (!string.IsNullOrEmpty(this.FilterExpressionWrapper.ParseError)) { throw new TestPlatformFormatException(this.FilterExpressionWrapper.ParseError, this.FilterExpressionWrapper.FilterString); } adapterSpecificTestCaseFilter = new TestCaseFilterExpression(this.FilterExpressionWrapper); var invalidProperties = adapterSpecificTestCaseFilter.ValidForProperties(supportedProperties, propertyProvider); if (invalidProperties != null) { var invalidPropertiesString = string.Join(CrossPlatEngineResources.StringSeperator, invalidProperties); var validPropertiesSttring = supportedProperties == null ? string.Empty : string.Join(CrossPlatEngineResources.StringSeperator, supportedProperties.ToArray()); var errorMessage = string.Format(CultureInfo.CurrentCulture, CrossPlatEngineResources.UnsupportedPropertiesInTestCaseFilter, invalidPropertiesString, validPropertiesSttring); // For unsupported property don’t throw exception, just log the message. Later it is going to handle properly with TestCaseFilterExpression.MatchTestCase(). EqtTrace.Info(errorMessage); } } return(adapterSpecificTestCaseFilter); }
public void ValidForPropertiesShouldNotSetvalidForMatchVariableTofalseIfFilterIsInvalid() { var filterExpressionWrapper = new FilterExpressionWrapper("highlyunlikelyproperty=unused"); var testCaseFilterExpression = new TestCaseFilterExpression(filterExpressionWrapper); testCaseFilterExpression.ValidForProperties(new List <string>() { "TestCategory" }, (s) => { return(null); }); TestCase dummyTestCase = new TestCase(); bool result = testCaseFilterExpression.MatchTestCase(dummyTestCase, (s) => { return("unused"); }); Assert.IsTrue(result); }
private static void ValidateFilter(string filterString) { if (string.IsNullOrEmpty(filterString)) { filterExpression = null; return; } var filterWrapper = new FilterExpressionWrapper(filterString); if (filterWrapper.ParseError != null) { var fe = new FormatException(String.Format("Invalid Test Case Filter: {0}", filterString)); EqtTrace.Error("TestCaseFilter.ValidateFilter : Filtering failed with exception : " + fe.Message); throw fe; } filterExpression = new TestCaseFilterExpression(filterWrapper); }