public void TwoSimpleExpressionParameter() { var param1 = new UIHintParameterValue("ipsum"); var param2 = new UIHintParameterValue("dolor"); var parameterValueParser = Mock.Of <IUIHintParameterValueParser>(); Mock.Get(parameterValueParser).Setup(p => p.Parse(It.IsAny <IParser>())).Returns <IParser>(p => { if (p.IsThenSkip("ipsum")) { return(param1); } if (p.IsThenSkip("dolor")) { return(param2); } throw new Exception($"Unknown input at {p}"); }); var result = new UIHintParser(parameterValueParser).Parse("lorem(ipsum, dolor)"); Assert.Equal("lorem", result.Id); Assert.Equal(2, result.Parameters.Count); }
public void WithParenthesis() { var result = new UIHintParser(Mock.Of <IUIHintParameterValueParser>()).Parse("lorem()"); Assert.Equal("lorem", result.Id); Assert.Empty(result.Parameters); }
public FieldDescriptor Create(PropertyInfo property) { var displayAttribute = PropertyAttributeInheritor.GetFor <DisplayAttribute>(property).FirstOrDefault(); var autoGenerate = displayAttribute?.GetAutoGenerateField() ?? true; var group = displayAttribute?.GetGroupName(); var label = displayAttribute?.GetName(); var type = property.PropertyType; var isSortable = false; if (type.IsGenericType && (type.GetGenericTypeDefinition() == typeof(IEnumerable <>) || type.GetGenericTypeDefinition() == typeof(List <>) || type.GetGenericTypeDefinition() == typeof(IList <>))) { type = type.GetGenericArguments().Single(); isSortable = true; } var uiHints = new List <UIHint>(); foreach (var uiHintAttribute in PropertyAttributeInheritor.GetFor <UIHintAttribute>(property)) { var uiHint = uiHintAttribute.UIHint; foreach (var replacer in ComposableProvider.GetAll <IUIHintReplacer>()) { uiHint = replacer.Replace(uiHint); } uiHints.Add(UIHintParser.Parse(uiHint)); } return(new FieldDescriptor(property.Name, type, uiHints.AsReadOnly(), label, isSortable, autoGenerate, group)); }
public void OneParameter() { var param = new UIHintParameterValue("ipsum"); var parameterValueParser = Mock.Of <IUIHintParameterValueParser>(); Mock.Get(parameterValueParser).Setup(p => p.Parse(It.IsAny <IParser>())).Returns <IParser>(p => { if (p.IsThenSkip("ipsum")) { return(param); } throw new Exception("Unknown input"); }); var result = new UIHintParser(parameterValueParser).Parse("lorem(ipsum)"); Assert.Equal("lorem", result.Id); Assert.Single(result.Parameters); Assert.Same(param, result.Parameters.Single()); }