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 void Execute_ObjParameter_NullParameterType_NoError() { var funcMock = new Mock <Func <object, Task> >(); var asyncDelegate = new AsyncDelegateCommand <object>(funcMock.Object); asyncDelegate.Execute(null); }
public void Execute_IntParameter_NullParameterType_ErrorSwallen() { var funcMock = new Mock <Func <int, Task> >(); var asyncDelegate = new AsyncDelegateCommand <int>(funcMock.Object); asyncDelegate.Execute(null); }
public void Execute_ExecuteOnce_ReturnsFalseAfterExecution() { var funcMock = new Mock <Func <object, Task> >(); var asyncDelegate = new AsyncDelegateCommand <object>(funcMock.Object, executeOnce: true); asyncDelegate.Execute(); Assert.IsFalse(asyncDelegate.CanExecute()); }
public async Task AsyncDelegateCommand_Execute_AsExpected() { bool invoked = false; var c = new AsyncDelegateCommand(_ => { invoked = true; return(Task.CompletedTask); }); c.Execute(null); await c.ExecutionTask; invoked.Should().BeTrue(); }
public void ShowProgress() { if (ProgressActionViewModel != null) { ProgressText = ProgressActionViewModel.Text; AsyncDelegateCommand asyncDelegateCommand = new AsyncDelegateCommand(ProgressActionViewModel.Action, () => true, OnComplete, OnError); asyncDelegateCommand.Execute(null); } }
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 Execute_Execute_WrongParameterType_InvalidOperationException() { var funcMock = new Mock <Func <int, Task> >(); var asyncDelegate = new AsyncDelegateCommand <int>(funcMock.Object, exceptionHandler: exception => { Assert.IsInstanceOfType(exception, typeof(InvalidOperationException)); return(true); }); asyncDelegate.Execute("test"); }
public void Execute_ExecutesFunction() { var funcMock = new Mock <Func <object, Task> >(); var asyncDelegate = new AsyncDelegateCommand <object>(funcMock.Object); asyncDelegate.Execute(null); // Waiting for async execution to end Thread.Sleep(100); Assert.AreEqual(1, funcMock.Invocations.Count); }
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 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 Execute_calls_specified_delegate_and_doesnt_wait_for_completion() { bool wasCalled = false; bool completed = false; var tcs = new TaskCompletionSource <bool>(); var command = new AsyncDelegateCommand <int>(async x => { wasCalled = true; await tcs.Task; completed = true; }); command.Execute(42); wasCalled.Should().BeTrue(); completed.Should().BeFalse(); // To prevent the test from hanging tcs.SetResult(true); }
//https://openweathermap.org/api/one-call-api public ActualWeatherViewModel() { RefreshCommand = new AsyncDelegateCommand(async() => await GetForeCastCommand()); RefreshCommand.Execute(null); }