public async Task TwoWay_CommandGeneric_Does_Not_Call_Execute_When_Argument_Can_Not_Be_Converted() { var command = Substitute.For <ICommand <int> >(); var fakeTestViewModel = new FakeTestViewModel() { CommandGenericInt = command }; var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "CommandGenericInt"); DoSafe(() => Call(jsCommand, "Execute", _WebView.Factory.CreateString("taDa"))); await Task.Delay(100); command.DidNotReceive().Execute(Arg.Any <int>()); } }; await RunAsync(test); }
public async Task TwoWay_CommandGeneric_Does_Not_Call_Execute_When_Called_Without_Argument() { var command = Substitute.For <ICommand <string> >(); var fakeTestViewModel = new FakeTestViewModel() { CommandGeneric = command }; var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "CommandGeneric"); DoSafe(() => Call(jsCommand, "Execute")); await Task.Delay(100); command.DidNotReceive().Execute(Arg.Any <string>()); } }; await RunAsync(test); }
public async Task TwoWay_CommandGeneric_Can_Convert_Argument_When_Argument_Mismatch() { var command = Substitute.For <ICommand <string> >(); var fakeTestViewModel = new FakeTestViewModel() { CommandGeneric = command }; var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "CommandGeneric"); DoSafe(() => Call(jsCommand, "Execute", _WebView.Factory.CreateInt(10))); await Task.Delay(100); command.Received(1).Execute("10"); } }; await RunAsync(test); }
public async Task TwoWay_CommandWithoutParameter_Is_Updated_When_CanExecute_Changes() { var command = Substitute.For <ICommandWithoutParameter>(); command.CanExecute.Returns(true); var fakeTestViewModel = new FakeTestViewModel() { CommandWithoutParameters = command }; var test = new TestInContextAsync() { Path = TestContext.GenericBind, Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "CommandWithoutParameters"); var res = GetBoolAttribute(jsCommand, "CanExecuteValue"); res.Should().BeTrue(); command.CanExecute.Returns(false); DoSafeUI(() => command.CanExecuteChanged += Raise.EventWith(command, new EventArgs())); await Task.Delay(150); jsCommand = GetAttribute(js, "CommandWithoutParameters"); res = GetBoolAttribute(jsCommand, "CanExecuteValue"); res.Should().BeFalse(); } }; await RunAsync(test); }
public async Task TwoWay_Updates_Command_From_Null() { var command = Substitute.For <ICommand>(); command.CanExecute(Arg.Any <object>()).Returns(true); var fakeTestViewModel = new FakeTestViewModel(); var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "Command"); jsCommand.IsNull.Should().BeTrue(); DoSafeUI(() => fakeTestViewModel.Command = command); await Task.Delay(200); jsCommand = GetAttribute(js, "Command"); DoSafe(() => Call(jsCommand, "Execute", js)); await Task.Delay(200); command.Received().Execute(fakeTestViewModel); } }; await RunAsync(test); }
public async Task TwoWay_Calls_Command_From_Js() { var command = Substitute.For <ICommand>(); var fakeTestViewModel = new FakeTestViewModel() { Command = command }; var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "Command"); DoSafe(() => Call(jsCommand, "Execute")); await Task.Delay(100); command.Received().Execute(Arg.Any <object>()); } }; await RunAsync(test); }
public async Task TwoWay_Calls_Command_With_Null_Parameter() { var command = Substitute.For <ICommand>(); var test = new FakeTestViewModel() { Command = command }; var testR = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, test, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "Command"); Call(jsCommand, "Execute", _WebView.Factory.CreateNull()); await Task.Delay(150); command.Received().Execute(null); } }; await RunAsync(testR); }
public async Task TwoWay_Command_Generic_String_CanExecute_Refresh_Ok() { var command = Substitute.For <ICommand <string> >(); command.CanExecute(Arg.Any <string>()).Returns(true); var datacontexttest = new FakeTestViewModel() { CommandGeneric = command }; var test = new TestInContextAsync() { Path = TestContext.GenericBind, Bind = (win) => HtmlBinding.Bind(win, datacontexttest, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var mycommand = GetAttribute(js, "CommandGeneric"); var res = GetBoolAttribute(mycommand, "CanExecuteValue"); res.Should().BeTrue(); command.CanExecute(Arg.Any <string>()).Returns(false); command.CanExecuteChanged += Raise.EventWith(_ICommand, new EventArgs()); await Task.Delay(100); mycommand = GetAttribute(js, "CommandGeneric"); res = GetBoolAttribute(mycommand, "CanExecuteValue"); res.Should().BeFalse(); } }; await RunAsync(test); }
public async Task TwoWay_CommandGeneric_Can_Be_Called_With_Parameter(string parameter) { var command = Substitute.For <ICommand <string> >(); var fakeTestViewModel = new FakeTestViewModel() { CommandGeneric = command }; var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "CommandGeneric"); var jsParameter = (parameter != null) ? _WebView.Factory.CreateString(parameter) : _WebView.Factory.CreateNull(); await DoSafeAsync(() => Call(jsCommand, "Execute", jsParameter)); await DoSafeAsyncUI(() => command.Received(1).Execute(parameter)); } }; await RunAsync(test); }
public async Task TwoWay_Maps_CommandWithoutParameter_CanExecuteValue_With_CanExecute(bool canExecute) { var command = Substitute.For <ICommandWithoutParameter>(); command.CanExecute.Returns(canExecute); var datacontexttest = new FakeTestViewModel() { CommandWithoutParameters = command }; var test = new TestInContext() { Bind = (win) => HtmlBinding.Bind(win, datacontexttest, JavascriptBindingMode.TwoWay), Test = (mb) => { var js = mb.JsRootObject; var mycommand = GetAttribute(js, "CommandWithoutParameters"); var res = GetBoolAttribute(mycommand, "CanExecuteValue"); res.Should().Be(canExecute); } }; await RunAsync(test); }
public async Task TwoWay_Command_Generic_Updates_From_Null() { var command = Substitute.For <ICommand <string> >(); var fakeTestViewModel = new FakeTestViewModel(); var argument = "argument"; var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "Command"); jsCommand.IsNull.Should().BeTrue(); await DoSafeAsyncUI(() => fakeTestViewModel.CommandGeneric = command); jsCommand = await GetAttributeAsync(js, "CommandGeneric"); await DoSafeAsync(() => Call(jsCommand, "Execute", _WebView.Factory.CreateString(argument))); await DoSafeAsyncUI(() => command.Received().Execute(argument)); } }; await RunAsync(test); }
public async Task TwoWay_Maps_CommandGeneric() { var command = Substitute.For <ICommand <string> >(); var fakeTestViewModel = new FakeTestViewModel() { CommandGeneric = command }; var test = new TestInContext() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = (mb) => { var js = ((HtmlBinding)mb).JsBrideRootObject as JsGenericObject; var jsCommand = js.GetAttribute("CommandGeneric") as JsCommand <string>; jsCommand.Should().NotBeNull(); jsCommand.ToString().Should().Be("{}"); jsCommand.Type.Should().Be(JsCsGlueType.Command); jsCommand.CachableJsValue.Should().NotBeNull(); } }; await RunAsync(test); }
public async Task TwoWay_Maps_CommandGeneric_CanExecuteValue_With_CanExecute(bool canExecute) { var command = Substitute.For <ICommand <string> >(); command.CanExecute(Arg.Any <string>()).Returns(canExecute); var fakeTestViewModel = new FakeTestViewModel() { CommandGenericNotBound = command }; var test = new TestInContext() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = (mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "CommandGenericNotBound"); var res = GetBoolAttribute(jsCommand, "CanExecuteValue"); res.Should().BeTrue(); } }; await RunAsync(test); }
public async Task TwoWay_CommandWithoutParameter_Updates_From_Null() { var command = Substitute.For <ICommandWithoutParameter>(); var fakeTestViewModel = new FakeTestViewModel(); var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "Command"); jsCommand.IsNull.Should().BeTrue(); await DoSafeAsyncUI(() => fakeTestViewModel.CommandWithoutParameters = command); await WaitAnotherWebContextCycle(); jsCommand = await GetAttributeAsync(js, "CommandWithoutParameters"); await DoSafeAsync(() => Call(jsCommand, "Execute")); await DoSafeAsyncUI(() => command.Received().Execute()); } }; await RunAsync(test); }
public async Task TwoWay_Updates_Command_From_Null() { var completion = new TaskCompletionSource <object>(); var command = Substitute.For <ICommand>(); command.CanExecute(Arg.Any <object>()).Returns(true); command.When(cmd => cmd.Execute(Arg.Any <object>())).Do(x => completion.SetResult(x[0])); var fakeTestViewModel = new FakeTestViewModel(); var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "Command"); jsCommand.IsNull.Should().BeTrue(); await DoSafeAsyncUI(() => fakeTestViewModel.Command = command); await WaitAnotherWebContextCycle(); jsCommand = await GetAttributeAsync(js, "Command"); await DoSafeAsync(() => Call(jsCommand, "Execute", js)); var calledValue = await completion.Task; calledValue.Should().Be(fakeTestViewModel); } }; await RunAsync(test); }
public async Task TwoWay_CommandWithoutParameter_Uptates_From_Null() { var command = Substitute.For <ICommandWithoutParameter>(); var datacontexttest = new FakeTestViewModel(); var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, datacontexttest, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var mycommand = GetAttribute(js, "Command"); mycommand.IsNull.Should().BeTrue(); DoSafeUI(() => datacontexttest.CommandWithoutParameters = command); await Task.Delay(200); mycommand = GetAttribute(js, "CommandWithoutParameters"); DoSafe(() => Call(mycommand, "Execute")); await Task.Delay(200); command.Received().Execute(); } }; await RunAsync(test); }
public async Task TwoWay_Call_Command_From_Js_With_Parameter() { var command = Substitute.For <ICommand>(); var fakeTestViewModel = new FakeTestViewModel() { Command = command }; var test = new TestInContextAsync() { Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "Command"); await DoSafeAsync(() => Call(jsCommand, "Execute", js)); await DoSafeAsyncUI(() => command.Received().Execute(fakeTestViewModel)); } }; await RunAsync(test); }
public async Task TwoWay_Command_Generic_FakeTestViewModel_CanExecute_Refresh_Ok() { var command = Substitute.For <ICommand <FakeTestViewModel> >(); command.CanExecute(Arg.Any <FakeTestViewModel>()).Returns(true); var fakeTestViewModel = new FakeTestViewModel() { AutoCommand = command }; var test = new TestInContextAsync() { Path = TestContext.GenericBind, Bind = (win) => HtmlBinding.Bind(win, fakeTestViewModel, JavascriptBindingMode.TwoWay), Test = async(mb) => { var js = mb.JsRootObject; var jsCommand = GetAttribute(js, "AutoCommand"); var res = GetBoolAttribute(jsCommand, "CanExecuteValue"); res.Should().BeTrue(); DoSafeUI(() => { command.CanExecute(Arg.Any <FakeTestViewModel>()).Returns(false); command.CanExecuteChanged += Raise.EventWith(command, new EventArgs()); }); await Task.Delay(200); jsCommand = GetAttribute(js, "AutoCommand"); res = GetBoolAttribute(jsCommand, "CanExecuteValue"); res.Should().BeFalse(); } }; await RunAsync(test); }
public async Task TwoWay_Command_Generic_String_Maps_As_ObservableReadOnly() { var command = Substitute.For <ICommand <string> >(); command.CanExecute(Arg.Any <string>()).Returns(true); var datacontexttest = new FakeTestViewModel() { CommandGeneric = command }; var test = new TestInContext() { Path = TestContext.GenericBind, Bind = (win) => HtmlBinding.Bind(win, datacontexttest, JavascriptBindingMode.TwoWay), Test = (mb) => { var js = mb.JsRootObject; var mycommand = GetAttribute(js, "CommandGeneric"); CheckObjectObservability(mycommand, ObjectObservability.ReadOnlyObservable); } }; await RunAsync(test); }