public void EvalEvaluatesDictionaryThenModel() { var obj = new { Foo = "NotBar" }; ViewDataDictionary vdd = new ViewDataDictionary(obj); vdd.Add("Foo", "Bar"); Assert.AreEqual("Bar", vdd.Eval("Foo")); }
public void EvalReturnsSimplePropertyValue() { var obj = new { Foo = "Bar" }; ViewDataDictionary vdd = new ViewDataDictionary(obj); Assert.Equal("Bar", vdd.Eval("Foo")); }
public void EvalWithModelAndDictionaryPropertyEvaluatesDictionaryValue() { var obj = new { Foo = new Dictionary<string, object> { { "Bar", "Baz" } } }; ViewDataDictionary vdd = new ViewDataDictionary(obj); Assert.Equal("Baz", vdd.Eval("Foo.Bar")); }
public void EvalWithCompoundExpressionReturnsPropertyOfAddedObject() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData.Add("Foo", new { Bar = "Baz" }); // Act var result = viewData.Eval("Foo.Bar"); // Assert Assert.Equal("Baz", result); }
public void EvalWithCompoundExpressionReturnsIndexedValue() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData.Add("Foo.Bar", "Baz"); // Act var result = viewData.Eval("Foo.Bar"); // Assert Assert.Equal("Baz", result); }
public void EvalFormatWithFormatReturnsFormattedViewData() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary(); vdd["foo"] = "value"; // Act string formattedValue = vdd.Eval("foo", "for{0}mat"); // Assert Assert.AreEqual <string>("forvaluemat", formattedValue); }
public void EvalReturnsValueJustAdded() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData.Add("Foo", "Blah"); // Act var result = viewData.Eval("Foo"); // Assert Assert.Equal("Blah", result); }
public void Eval_ReturnsModel_IfExpressionIsNullOrEmpty(string expression) { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); var model = new object(); viewData.Model = model; // Act var result = viewData.Eval(expression); // Assert Assert.Same(model, result); }
public void EvalThrowsIfExpressionIsNull() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary(); // Act & Assert Assert.ThrowsArgumentNullOrEmpty( delegate { vdd.Eval(null); }, "expression" ); }
public void EvalChoosesValueInDictionaryOverOtherValue() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()) { { "Foo", new { Bar = "Not Baz" } }, { "Foo.Bar", "Baz" } }; // Act var result = viewData.Eval("Foo.Bar"); // Assert Assert.Equal("Baz", result); }
public void EvalWithCompoundExpressionAndDictionarySubExpressionChoosesDictionaryValue() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData.Add("Foo", new Dictionary <string, object> { { "Bar", "Baz" } }); // Act var result = viewData.Eval("Foo.Bar"); // Assert Assert.Equal("Baz", result); }
public void EvalWithDictionaryAndNoMatchReturnsNull() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData.Add("Foo", new Dictionary <string, object> { { "NotBar", "Baz" } }); // Act var result = viewData.Eval("Foo.Bar"); // Assert Assert.Null(result); }
public void EvalChoosesCompoundValueInDictionaryOverOtherValuesWithCompoundProperty() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()) { { "Foo", new Person() }, { "Foo.Bar", new { Baz = "Quux" } } }; // Act var result = viewData.Eval("Foo.Bar.Baz"); // Assert Assert.Equal("Quux", result); }
public void EvalWithNestedDictionariesEvalCorrectly() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData.Add("Foo", new Dictionary <string, object> { { "Bar", new Hashtable { { "Baz", "Quux" } } } }); // Act var result = viewData.Eval("Foo.Bar.Baz"); // Assert Assert.Equal("Quux", result); }
public void EvalWithNestedDictionariesEvalCorrectly() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add( "Foo", new Dictionary <string, object> { { "Bar", new Hashtable { { "Baz", "Quux" } } } } ); Assert.Equal("Quux", vdd.Eval("Foo.Bar.Baz")); }
public void EvalSubPropertyNamedValueInModel() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary(); vdd["Title"] = "Home Page"; vdd["Message"] = "Welcome to ASP.NET MVC!"; vdd.Model = new TheQueryStringParam { Name = "The Name", Value = "The Value", Model = "The Model", }; // Act object o = vdd.Eval("Value"); // Assert Assert.AreEqual("The Value", o); }
public void EvalFormatWithNullValueReturnsEmptyString() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); // Act var formattedValue = viewData.Eval("foo", "for{0}mat"); // Assert Assert.Empty(formattedValue); }
public void EvalFormatWithFormatReturnsFormattedViewData() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary(); vdd["foo"] = "value"; // Act string formattedValue = vdd.Eval("foo", "for{0}mat"); // Assert Assert.AreEqual<string>("forvaluemat", formattedValue); }
public void EvalWithNestedDictionariesEvalCorrectly() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo", new Dictionary<string, object> { { "Bar", new Hashtable { { "Baz", "Quux" } } } }); Assert.AreEqual("Quux", vdd.Eval("Foo.Bar.Baz")); }
public void EvalWithCompoundExpressionAndDictionarySubExpressionChoosesDictionaryValue() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo", new Dictionary<string, object> { { "Bar", "Baz" } }); Assert.AreEqual("Baz", vdd.Eval("Foo.Bar")); }
public void EvalChoosesCompoundValueInDictionaryOverOtherValuesWithCompoundProperty() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo", new Person()); vdd.Add("Foo.Bar", new { Baz = "Quux" }); Assert.AreEqual("Quux", vdd.Eval("Foo.Bar.Baz")); }
public void EvalWithCompoundIndexAndCompoundExpressionReturnsValue() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo.Bar", new { Baz = new { Blah = "Quux" } }); Assert.AreEqual("Quux", vdd.Eval("Foo.Bar.Baz.Blah")); }
public void EvalWithCompoundExpressionReturnsPropertyOfAddedObject() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo", new { Bar = "Baz" }); Assert.AreEqual("Baz", vdd.Eval("Foo.Bar")); }
public static string GetComponentName(this ViewDataDictionary <dynamic> data) { return(data.Eval(ComponentNameKey) as string); }
public void EvalFormatWithEmptyFormatReturnsViewData() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary(); vdd["foo"] = "value"; // Act string formattedValue = vdd.Eval("foo", ""); // Assert Assert.Equal("value", formattedValue); }
public void EvalThrowsIfExpressionIsNull() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary(); // Act & Assert Assert.ThrowsArgumentNullOrEmpty( delegate { vdd.Eval(null); }, "expression"); }
public void EvalChoosesCompoundValueInDictionaryOverOtherValues() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo", new { Bar = new { Baz = "Not Quux" } }); vdd.Add("Foo.Bar", new { Baz = "Quux" }); Assert.Equal("Quux", vdd.Eval("Foo.Bar.Baz")); }
/// <summary> /// Get the value of a named property path on the view data as a string. /// </summary> public static string EvalString(this ViewDataDictionary viewData, string propertyPath) { return(Convert.ToString(viewData.Eval(propertyPath), CultureInfo.CurrentCulture)); }
/// <summary> /// Get the value of a named property path on the view data as a boolean. /// </summary> public static bool EvalBoolean(this ViewDataDictionary viewData, string propertyPath) { return(Convert.ToBoolean(viewData.Eval(propertyPath), CultureInfo.InvariantCulture)); }
public void EvalFormatWithFormatReturnsFormattedViewData() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData["foo"] = "value"; // Act var formattedValue = viewData.Eval("foo", "for{0}mat"); // Assert Assert.Equal("forvaluemat", formattedValue); }
public void Eval_ReturnsModel_IfExpressionIsNullOrEmpty(string expression) { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); var model = new object(); viewData = new ViewDataDictionary(viewData, model); // Act var result = viewData.Eval(expression); // Assert Assert.Same(model, result); }
public void EvalWithCompoundExpressionReturnsIndexedValue() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo.Bar", "Baz"); Assert.AreEqual("Baz", vdd.Eval("Foo.Bar")); }
private static bool EvalBoolean(ViewDataDictionary viewData, string key) { return(Convert.ToBoolean(viewData.Eval(key), CultureInfo.InvariantCulture)); }
public void EvalWithCompoundIndexExpressionReturnsEval() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo.Bar", new { Baz = "Quux" }); Assert.AreEqual("Quux", vdd.Eval("Foo.Bar.Baz")); }
static void SelectInternal( HtmlHelper htmlHelper, XcstWriter output, ModelMetadata?metadata, string?optionLabel, string name, IEnumerable <SelectListItem>?selectList, bool allowMultiple, HtmlAttribs?htmlAttributes) { ViewDataDictionary viewData = htmlHelper.ViewData; string fullName = viewData.TemplateInfo.GetFullHtmlFieldName(name); if (String.IsNullOrEmpty(fullName)) { throw new ArgumentNullException(nameof(name)); } bool usedViewData = false; // If we got a null selectList, try to use ViewData to get the list of items. if (selectList is null) { selectList = GetSelectData(htmlHelper, name); usedViewData = true; } object?defaultValue = (allowMultiple) ? htmlHelper.GetModelStateValue(fullName, typeof(string[])) : htmlHelper.GetModelStateValue(fullName, typeof(string)); // If we haven't already used ViewData to get the entire list of items then we need to // use the ViewData-supplied value before using the parameter-supplied value. if (defaultValue is null) { if (metadata is null) { if (!usedViewData && !String.IsNullOrEmpty(name)) { defaultValue = viewData.Eval(name); } } else { defaultValue = metadata.Model; } } if (defaultValue != null) { selectList = GetSelectListWithDefaultValue(selectList, defaultValue, allowMultiple); } output.WriteStartElement("select"); HtmlAttributeHelper.WriteId(fullName, output); output.WriteAttributeString("name", fullName); HtmlAttributeHelper.WriteBoolean("multiple", allowMultiple, output); // If there are any errors for a named field, we add the css attribute. string?cssClass = (viewData.ModelState.TryGetValue(fullName, out ModelState modelState) && modelState.Errors.Count > 0) ? HtmlHelper.ValidationInputCssClassName : null; var validationAttribs = htmlHelper.GetUnobtrusiveValidationAttributes( name, metadata #if !ASPNETMVC , excludeMinMaxLength: !allowMultiple #endif ); HtmlAttributeHelper.WriteClass(cssClass, htmlAttributes, output); HtmlAttributeHelper.WriteAttributes(validationAttribs, output); // name cannnot be overridden, and class was already written HtmlAttributeHelper.WriteAttributes(htmlAttributes, output, excludeFn: n => n == "name" || n == "class"); WriteOptions(optionLabel, selectList, output); output.WriteEndElement(); // </select> }
public void EvalChoosesValueInDictionaryOverOtherValue() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo", new { Bar = "Not Baz" }); vdd.Add("Foo.Bar", "Baz"); Assert.AreEqual("Baz", vdd.Eval("Foo.Bar")); }
public void EvalWithDictionaryAndNoMatchReturnsNull() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData.Add("Foo", new Dictionary<string, object> { { "NotBar", "Baz" } }); // Act var result = viewData.Eval("Foo.Bar"); // Assert Assert.Null(result); }
public void EvalThrowsIfExpressionIsNull() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary(); // Act & Assert ExceptionHelper.ExpectArgumentExceptionNullOrEmpty( delegate { vdd.Eval(null); }, "expression"); }
public void EvalReturnsNullIfExpressionDoesNotMatch() { var obj = new { Foo = new { Biz = "Baz" } }; ViewDataDictionary vdd = new ViewDataDictionary(obj); Assert.AreEqual(null, vdd.Eval("Foo.Bar")); }
public void EvalWithDictionaryAndNoMatchReturnsNull() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo", new Dictionary<string, object> { { "NotBar", "Baz" } }); object result = vdd.Eval("Foo.Bar"); Assert.IsNull(result); }
public void EvalFormatWithNullValueReturnsEmptyString() { // Arrange ViewDataDictionary vdd = new ViewDataDictionary(); // Act string formattedValue = vdd.Eval("foo", "for{0}mat"); // Assert Assert.AreEqual<string>(String.Empty, formattedValue); }
public void EvalWithCompoundExpressionAndDictionarySubExpressionChoosesDictionaryValue() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData.Add("Foo", new Dictionary<string, object> { { "Bar", "Baz" } }); // Act var result = viewData.Eval("Foo.Bar"); // Assert Assert.Equal("Baz", result); }
public void EvalWithNestedDictionariesEvalCorrectly() { // Arrange var viewData = new ViewDataDictionary(new EmptyModelMetadataProvider()); viewData.Add("Foo", new Dictionary<string, object> { { "Bar", new Hashtable { { "Baz", "Quux" } } } }); // Act var result = viewData.Eval("Foo.Bar.Baz"); // Assert Assert.Equal("Quux", result); }
public void EvalReturnsValueOfCompoundExpressionByFollowingObjectPath() { var obj = new { Foo = new { Bar = "Baz" } }; ViewDataDictionary vdd = new ViewDataDictionary(obj); Assert.AreEqual("Baz", vdd.Eval("Foo.Bar")); }
private bool GetValue(string name, out object result) { result = DynamicReflectionObject.Wrap(_dictionary.Eval(name)) ?? String.Empty; return(true); }
public void EvalReturnsValueJustAdded() { ViewDataDictionary vdd = new ViewDataDictionary(); vdd.Add("Foo", "Blah"); Assert.AreEqual("Blah", vdd.Eval("Foo")); }