private void ConfigureCondition() { filter.RemoveAllFilters(); dataGridViewFilterConditions.Rows.Clear(); object propertyValueA; object propertyValueB; string propertyName; foreach (FilterConditionUserControl condition in filterConditionsList.FilterConditions) { if (condition.Operation == nameof(Operations.EqualTo)) { propertyName = GetProperty(condition, out propertyValueA); filter.AndEqualTo(propertyName, propertyValueA); } if (condition.Operation == nameof(Operations.GreaterThan)) { propertyName = GetProperty(condition, out propertyValueA); filter.AndGreaterThan(propertyName, propertyValueA); } if (condition.Operation == nameof(Operations.GreaterTHanOrEqual)) { propertyName = GetProperty(condition, out propertyValueA); filter.AndGreaterThanOrEqual(propertyName, propertyValueA); } if (condition.Operation == nameof(Operations.LessThan)) { propertyName = GetProperty(condition, out propertyValueA); filter.AndLessThan(propertyName, propertyValueA); } if (condition.Operation == nameof(Operations.LessThanOrEqual)) { propertyName = GetProperty(condition, out propertyValueA); filter.AndLessThanOrEqual(propertyName, propertyValueA); } if (condition.Operation == nameof(Operations.Contains)) { propertyName = GetProperty(condition, out propertyValueA); filter.AndContains(propertyName, (string)propertyValueA); } if (condition.Operation == nameof(Operations.IsMatch)) { propertyName = GetProperty(condition, out propertyValueA); filter.AndIsMatch(propertyName, new Regex((string)propertyValueA)); } if (condition.Operation == nameof(Operations.IntoRange)) { propertyName = GetProperty(condition, out propertyValueA, out propertyValueB); filter.AndIntoRange(propertyName, propertyValueA, propertyValueB); } UpdateVisualization(condition); } }
public void TestStringAndContains(IEnumerable <StudentTestResult> testResults) { Filter <StudentTestResult> filters = new Filter <StudentTestResult>(); const string propertyName = "FirstName"; const string propertyValue = "iv"; IEnumerable <StudentTestResult> expected = testResults .Where(test => test.FirstName.Contains(propertyValue)).ToArray(); filters.AndContains(propertyName, propertyValue); IEnumerable <StudentTestResult> actual = filters.ApplyFilterSettings(testResults).ToArray(); Assert.AreEqual(expected, actual); }