public void ExpressionEvaluator_Complex_EvaluateInRootDataContext() { var view = new RedwoodView() { DataContext = new TestViewModel() { SubObject = new TestViewModel2() { Value = "hello" } }, Children = { new HtmlGenericControl("html") { Children = { new TextBox() { ID = "txb" } } } .WithBinding(RedwoodBindableControl.DataContextProperty, new ValueBindingExpression("SubObject")) } }; var textbox = view.FindControl("txb") as TextBox; var evaluator = new ExpressionEvaluator(); var result = evaluator.Evaluate(new ValueBindingExpression("Value"), RedwoodBindableControl.DataContextProperty, textbox); Assert.IsInstanceOfType(result, typeof(string)); Assert.AreEqual("hello", result); }
public void ExpressionEvaluator_UpdateSource_Simple() { var viewModel = new TestViewModel() { SubObject = new TestViewModel2() { Value = "hello" } }; var view = new RedwoodView() { DataContext = viewModel, Children = { new HtmlGenericControl("html") { Children = { new TextBox() { ID = "txb" } .WithBinding(TextBox.TextProperty, new ValueBindingExpression("Value")) } } .WithBinding(RedwoodBindableControl.DataContextProperty, new ValueBindingExpression("SubObject")) } }; var textbox = view.FindControl("txb") as TextBox; var binding = textbox.GetBinding(TextBox.TextProperty) as ValueBindingExpression; binding.UpdateSource("test", textbox, TextBox.TextProperty); Assert.AreEqual("test", viewModel.SubObject.Value); }
/// <summary> /// Resolves the command for the specified post data. /// </summary> public void ResolveCommand(RedwoodRequestContext context, RedwoodView view, string serializedPostData, out ActionInfo actionInfo) { // get properties var data = JObject.Parse(serializedPostData); var path = data["currentPath"].Values<string>().ToArray(); var command = data["command"].Value<string>(); var controlUniqueId = data["controlUniqueId"].Value<string>(); if (string.IsNullOrEmpty(command)) { // empty command actionInfo = null; } else { // find the command target if (!string.IsNullOrEmpty(controlUniqueId)) { var target = view.FindControl(controlUniqueId); if (target == null) { throw new Exception(string.Format("The control with ID '{0}' was not found!", controlUniqueId)); } actionInfo = commandResolver.GetFunction(target, view, context, path, command); } else { actionInfo = commandResolver.GetFunction(view, context, path, command); } } }