public void CanExecuteDuringAsyncExecute2() { var tcs = new TaskCompletionSource <object>(); var canExecute = false; var executeCalled = false; var command = new AsyncDelegateCommand(() => { executeCalled = true; return(tcs.Task); }, () => canExecute); Assert.IsFalse(command.CanExecute(null)); command.Execute(null); Assert.IsFalse(executeCalled); canExecute = true; Assert.IsTrue(command.CanExecute(null)); command.Execute(null); executeCalled = false; Assert.IsFalse(command.CanExecute(null)); command.Execute(null); Assert.IsFalse(executeCalled); tcs.SetResult(null); Assert.IsTrue(command.CanExecute(null)); command.Execute(null); Assert.IsTrue(executeCalled); }
public void CanExecuteDuringAsyncExecute() { AssertHelper.ExpectedException <ArgumentNullException>(() => new AsyncDelegateCommand((Func <Task>)null)); var tcs = new TaskCompletionSource <object>(); var executeCalled = false; var command = new AsyncDelegateCommand(() => { executeCalled = true; return(tcs.Task); }); Assert.IsTrue(command.CanExecute(null)); command.Execute(null); executeCalled = false; Assert.IsFalse(command.CanExecute(null)); command.Execute(null); Assert.IsFalse(executeCalled); tcs.SetResult(null); Assert.IsTrue(command.CanExecute(null)); command.Execute(null); Assert.IsTrue(executeCalled); }
public async Task CanExecute_returns_false_during_execution_and_true_after_completion() { var tcs = new TaskCompletionSource <bool>(); var command = new AsyncDelegateCommand <int>(x => tcs.Task); command.Execute(42); command.CanExecute(42).Should().BeFalse(); tcs.SetResult(true); await command.WaitForCompletionAsync(); command.CanExecute(42).Should().BeTrue(); }
public void RaiseCanExecuteChangedTest() { var executed = false; var canExecute = false; var command = new AsyncDelegateCommand(() => { executed = true; return(Task.FromResult((object)null)); }, () => canExecute); Assert.IsFalse(command.CanExecute(null)); canExecute = true; Assert.IsTrue(command.CanExecute(null)); AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged()); AssertHelper.CanExecuteChangedEvent(command, () => command.Execute(null), 2, ExpectedChangedCountMode.Exact); // Because during execution CanExecute returns false Assert.IsTrue(executed); }
public void Execute_CanExecuteFunction_NoOptions_ReturnsFalseAsCanExecute() { var funcMock = new Mock <Func <object, Task> >(); var asyncDelegate = new AsyncDelegateCommand <object>(funcMock.Object, canExecute: _ => false); Assert.IsFalse(asyncDelegate.CanExecute(null)); }
public void Execute_ExecuteOnce_ReturnsTrueBeforeExecution() { var funcMock = new Mock <Func <object, Task> >(); var asyncDelegate = new AsyncDelegateCommand <object>(funcMock.Object, executeOnce: true); Assert.IsTrue(asyncDelegate.CanExecute()); }
public void Execute_CanExecuteFunction_NoOptions_ReturnsTrueAsCanExecute() { var funcMock = new Mock <Func <Task> >(); var asyncDelegate = new AsyncDelegateCommand(funcMock.Object, canExecute: () => true); Assert.IsTrue(asyncDelegate.CanExecute()); }
public void Execute_ExecuteOnce_ReturnsFalseAfterExecution() { var funcMock = new Mock <Func <Task> >(); var asyncDelegate = new AsyncDelegateCommand(funcMock.Object, executeOnce: true); asyncDelegate.Execute(); Assert.IsFalse(asyncDelegate.CanExecute()); }
public void CanExecuteDuringAsyncExecuteWithParameter() { var tcs = new TaskCompletionSource <object>(); string commandParameter = null; var command = new AsyncDelegateCommand(p => { commandParameter = (string)p; return(tcs.Task); }); Assert.IsTrue(command.CanExecute(null)); command.Execute("test"); Assert.IsFalse(command.CanExecute(null)); tcs.SetResult(null); Assert.IsTrue(command.CanExecute(null)); Assert.AreEqual("test", commandParameter); }
public void AsyncDelegateCommand_CanExecute_Should_Invoke_Lambad() { bool invoked = false; var c = new AsyncDelegateCommand(_ => Task.CompletedTask, _ => { invoked = true; return(true); }); c.CanExecute(null).Should().BeTrue(); invoked.Should().BeTrue(); }
public void CanExecute_returns_true_if_not_specified() { var command = new AsyncDelegateCommand <int>(x => Task.CompletedTask); command.CanExecute(42).Should().BeTrue(); }
public void CanExecute_returns_value_from_specified_delegate(int parameter, bool canExecute) { var command = new AsyncDelegateCommand <int>(x => Task.CompletedTask, x => x % 2 == 0); command.CanExecute(parameter).Should().Be(canExecute); }
public void AsyncDelegateCommand_CanExecute_NotSpecified_Should_Returns_True() { var c = new AsyncDelegateCommand(_ => Task.CompletedTask); c.CanExecute(null).Should().BeTrue(); }
public void CanExecute_returns_value_from_specified_delegate(bool canExecute) { var command = new AsyncDelegateCommand(() => Task.CompletedTask, () => canExecute); command.CanExecute(null).Should().Be(canExecute); }