public void Format_InvalidFilter_ThrowsExpectedException() { // verify an invalid integer value var template = BindingTemplate.FromString("Age gt {Age}"); var bindingData = new Dictionary <string, object> { { "Age", "25 or true" } }; var ex = Assert.Throws <InvalidOperationException>(() => TableFilterFormatter.Format(template, (IReadOnlyDictionary <string, object>)bindingData)); Assert.Equal($"An invalid parameter value was specified for filter parameter 'Age'.", ex.Message); // verify the same template reversed template = BindingTemplate.FromString("{Age} lt Age"); bindingData = new Dictionary <string, object> { { "Age", "25 or true" } }; ex = Assert.Throws <InvalidOperationException>(() => TableFilterFormatter.Format(template, (IReadOnlyDictionary <string, object>)bindingData)); Assert.Equal($"An invalid parameter value was specified for filter parameter 'Age'.", ex.Message); // verify datetime day operator value template = BindingTemplate.FromString("day({BirthDate}) eq 8"); bindingData = new Dictionary <string, object> { { "BirthDate", "BirthDate) neq 8 or day(BirthDate" } }; ex = Assert.Throws <InvalidOperationException>(() => TableFilterFormatter.Format(template, (IReadOnlyDictionary <string, object>)bindingData)); Assert.Equal($"An invalid parameter value was specified for filter parameter 'BirthDate'.", ex.Message); // verify ambiguous values are handled correctly template = BindingTemplate.FromString("Age eq '{Age}' or Age eq {Age}"); bindingData = new Dictionary <string, object> { { "Age", "25 or true" } }; ex = Assert.Throws <InvalidOperationException>(() => TableFilterFormatter.Format(template, (IReadOnlyDictionary <string, object>)bindingData)); Assert.Equal($"An invalid parameter value was specified for filter parameter 'Age'.", ex.Message); }
private static string GetFormattedValue(string templateString, Dictionary <string, object> bindingData) { var template = BindingTemplate.FromString(templateString); return(TableFilterFormatter.Format(template, (IReadOnlyDictionary <string, object>)bindingData)); }
public string TemplateBind(PropertyInfo propInfo, Attribute attribute, BindingTemplate template, IReadOnlyDictionary <string, object> bindingData) { return(TableFilterFormatter.Format(template, bindingData)); }