diff --git a/src/Framework/Testing/BindingTestHelper.cs b/src/Framework/Testing/BindingTestHelper.cs index bf67a3d1e4..6c3c4f275d 100644 --- a/src/Framework/Testing/BindingTestHelper.cs +++ b/src/Framework/Testing/BindingTestHelper.cs @@ -152,6 +152,25 @@ public StaticCommandBindingExpression StaticCommand(string expression, DataConte }); } + /// Creates a command binding by parsing the specified expression. + /// Hierarchy of data contexts. First element is _root, last element is _this. + /// If specified, an implicit conversion into this type will be applied in the expression. + public CommandBindingExpression Command(string expression, Type[] contexts, Type? expectedType = null) => + Command(expression, CreateDataContext(contexts), expectedType); + + /// Creates a command binding by parsing the specified expression. + /// If specified, an implicit conversion into this type will be applied in the expression. + public CommandBindingExpression Command(string expression, DataContextStack context, Type? expectedType = null) + { + expectedType ??= typeof(Command); + return new CommandBindingExpression(BindingService, new object[] { + context, + new OriginalStringBindingProperty(expression), + BindingParserOptions.Value.AddImports(context.NamespaceImports).AddImports(Configuration.Markup.ImportedNamespaces), + new ExpectedTypeBindingProperty(expectedType) + }); + } + /// Creates a value binding by parsing the specified expression. The expression will be implicitly converted to /// Hierarchy of data contexts. First element is _root, last element is _this. /// Convert the result to this type instead of converting it to . The type must be assignable to T. diff --git a/src/Tests/Runtime/DotvvmControlRenderedHtmlTests.cs b/src/Tests/Runtime/DotvvmControlRenderedHtmlTests.cs index 1803241eb4..f23705aec7 100644 --- a/src/Tests/Runtime/DotvvmControlRenderedHtmlTests.cs +++ b/src/Tests/Runtime/DotvvmControlRenderedHtmlTests.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.Globalization; using System.IO; +using System.Threading.Tasks; +using CheckTestOutput; using DotVVM.Framework.Binding; using DotVVM.Framework.Binding.Expressions; using DotVVM.Framework.Compilation.ControlTree; @@ -18,6 +20,8 @@ namespace DotVVM.Framework.Tests.Runtime [TestClass] public class DotvvmControlRenderedHtmlTests : DotvvmControlTestBase { + static readonly BindingTestHelper bindingHelper = new BindingTestHelper(); + readonly OutputChecker outputChecker = new OutputChecker("testoutputs"); [TestMethod] public void GridViewTextColumn_RenderedHtmlTest_ServerRendering() { @@ -211,6 +215,22 @@ public void Literal_DateTimeToBrowserLocalTime_RenderOnServer() }); } + [TestMethod] + public void Button_ClickArgumentsCommand() + { + var vm = new LiteralDateTimeViewModel(); + var command = bindingHelper.Command("null", [ typeof(LiteralDateTimeViewModel) ], typeof(Func)); + var button = new Button("text", command) { + ClickArguments = new object[] { + bindingHelper.ValueBinding("DateTime", [ typeof(LiteralDateTimeViewModel) ]), + 1 + } + }; + + var html = InvokeLifecycleAndRender(button, CreateContext(vm)); + outputChecker.CheckString(html, "Button_ClickArgumentsCommand", fileExtension: "html"); + } + public class OrderedDataBindTextBox : TextBox { diff --git a/src/Tests/Runtime/testoutputs/DotvvmControlRenderedHtmlTests.Button_ClickArgumentsCommand-Button_ClickArgumentsCommand.html b/src/Tests/Runtime/testoutputs/DotvvmControlRenderedHtmlTests.Button_ClickArgumentsCommand-Button_ClickArgumentsCommand.html new file mode 100644 index 0000000000..b9b51c393d --- /dev/null +++ b/src/Tests/Runtime/testoutputs/DotvvmControlRenderedHtmlTests.Button_ClickArgumentsCommand-Button_ClickArgumentsCommand.html @@ -0,0 +1 @@ +