public void CanCallExecute() { var parameter = new object(); _testClass.Execute(parameter); Assert.Fail("Create or modify test"); }
public void CanExecuteChanged_RemoveHandler_HandlerIsNotCalled() { SynchronizationContext.SetSynchronizationContext(new TestSynchronizationContext()); var commandExecuted = false; _canExecuteChangedRaised = false; var command = new RelayCommand <string>(_ => { // ReSharper disable once AccessToModifiedClosure Assert.False(commandExecuted); commandExecuted = true; }); command.CanExecuteChanged += CommandOnCanExecuteChanged; command.Execute(null); Assert.True(commandExecuted); Assert.True(_canExecuteChangedRaised); _canExecuteChangedRaised = false; commandExecuted = false; command.CanExecuteChanged -= CommandOnCanExecuteChanged; command.Execute(null); Assert.True(commandExecuted); Assert.False(_canExecuteChangedRaised); }
public async Task ConnectionLost() { var applicationGlobalCommandsMock = ApplicationGlobalCommandsMock.Create().WithAskUserGlobalResult(false); _typesContainer.RegisterInstance <IApplicationGlobalCommands>(applicationGlobalCommandsMock); _configurationFragmentViewModel.DeviceContext.DeviceMemory.DeviceMemoryValues.Clear(); var connection = new MockConnection(); await _typesContainer.Resolve <IDevicesContainerService>() .ConnectDeviceAsync(_device, connection); MockConnection.IsConnectionLost = true; Assert.True(await TestsUtils.WaitUntil(() => _readCommand.CanExecute(null), 30000)); _readCommand.Execute(null); Assert.True(await TestsUtils.WaitUntil( () => !_deviceViewModel.ConnectionStateViewModel.IsDeviceConnected, 30000)); MockConnection.IsConnectionLost = false; Assert.True(await TestsUtils.WaitUntil(() => _readCommand.CanExecute(null), 30000)); _readCommand.Execute(null); Assert.True(await TestsUtils.WaitUntil( () => _deviceViewModel.ConnectionStateViewModel.IsDeviceConnected, 30000)); Assert.True(applicationGlobalCommandsMock.IsAskUserGlobalTriggered); }
internal static Delegate GetCommandHandler <T>( this EventInfo info, string eventName, Type elementType, RelayCommand <T> command, Binding <T, T> castedBinding) { Delegate result; if (string.IsNullOrEmpty(eventName) && elementType == typeof(CheckBox)) { EventHandler <CompoundButton.CheckedChangeEventArgs> handler = (s, args) => { var param = castedBinding == null ? default(T) : castedBinding.Value; command.Execute(param); }; result = handler; } else { EventHandler handler = (s, args) => { var param = castedBinding == null ? default(T) : castedBinding.Value; command.Execute(param); }; result = handler; } return(result); }
public void Test_RelayCommand_AlwaysEnabled() { int ticks = 0; var command = new RelayCommand(() => ticks++); Assert.IsTrue(command.CanExecute(null)); Assert.IsTrue(command.CanExecute(new object())); (object, EventArgs)args = default; command.CanExecuteChanged += (s, e) => args = (s, e); command.NotifyCanExecuteChanged(); Assert.AreSame(args.Item1, command); Assert.AreSame(args.Item2, EventArgs.Empty); command.Execute(null); Assert.AreEqual(ticks, 1); command.Execute(new object()); Assert.AreEqual(ticks, 2); }
public void TestExecute() { var executedCount = 0; string executedParameter = null; var command = new RelayCommand <string>(p => { executedCount++; executedParameter = p; }, p => p == "Test"); var canExecuteCount = 0; command.CanExecuteChanged += (sender, args) => { canExecuteCount++; }; command.Execute("Test"); Assert.AreEqual(1, executedCount); Assert.AreEqual("Test", executedParameter); Assert.AreEqual(1, canExecuteCount); Assert.IsTrue(command.CanExecute("Test")); Assert.IsFalse(command.CanExecute("Wrong parameter")); // Do not execute command.Execute("Wrong parameter"); Assert.AreEqual(1, executedCount); command.InvalidateCanExecute(); Assert.AreEqual(2, canExecuteCount); }
public void Test_RelayCommandOfT_AlwaysEnabled() { string text = string.Empty; var command = new RelayCommand <string>(s => text = s); Assert.IsTrue(command.CanExecute("Text")); Assert.IsTrue(command.CanExecute(null)); Assert.ThrowsException <InvalidCastException>(() => command.CanExecute(new object())); (object, EventArgs)args = default; command.CanExecuteChanged += (s, e) => args = (s, e); command.NotifyCanExecuteChanged(); Assert.AreSame(args.Item1, command); Assert.AreSame(args.Item2, EventArgs.Empty); command.Execute("Hello"); Assert.AreEqual(text, "Hello"); command.Execute(null); Assert.AreEqual(text, null); }
private void Answer1_Tapped(object sender, TappedRoutedEventArgs e) { if (_answerTapped != null) { _answerTapped.Execute(_item.Answers[0]); } }
public void ExecuteCanExecuteTest() { var counter = 0; var canExecute = true; try { Action <object> a = null; var c = new RelayCommand(a); Assert.Fail("Should have thrown ArgumentNullException.", c); } catch (Exception e) { Assert.IsInstanceOf <ArgumentNullException>(e); } var command = new RelayCommand(param => counter++); Assert.IsTrue(command.CanExecute(new object())); command.Execute(new object()); Assert.IsTrue(counter == 1); command = new RelayCommand(param => counter++, param => canExecute); Assert.IsTrue(command.CanExecute(new object())); command.Execute(new object()); Assert.IsTrue(counter == 2); canExecute = false; Assert.IsFalse(command.CanExecute(new object())); command.Execute(new object()); Assert.IsTrue(counter == 2); }
public void TestStubCommandCanExecuteWithParameters() { const String ExpectedString = "TestingParam"; _RelayCommand.Execute(ExpectedString); Assert.AreEqual(ExpectedString, _ActualString); }
public void Execute_Double_CounterEquals2() { int executionCounter = 0; RelayCommand relayCommand = new RelayCommand((o) => executionCounter++, o => true); relayCommand.Execute(new object()); relayCommand.Execute(new object()); Assert.AreEqual(2, executionCounter); }
public void TestActionGenericConstructor() { var n = 0; var command = new RelayCommand(execute: num => n = num as int? ?? -1); Assert.IsTrue(condition: command.CanExecute(parameter: null), message: "Should always be able to execute"); command.Execute(parameter: 1); Assert.AreEqual(expected: 1, actual: n, message: "Action did not run."); command.Execute(parameter: null); Assert.AreEqual(expected: -1, actual: n, message: "Action did not run."); }
public void Execute_IncreasesCount_GetsCalled() { int counter = 0; Action <object> execute = (o => { ++counter; }); var target = new RelayCommand(execute); counter.Should().Be(0); target.Execute(null); counter.Should().Be(1); target.Execute(true); counter.Should().Be(2); target.Execute(false); counter.Should().Be(3); }
public void RelayCommandTest() { _command.Execute(this); _genericCommand.Execute(PatameterValue); _canExecuteCommand = true; _command.RaiseCanExecuteChanged(); _command.Execute(this); _genericCommand.RaiseCanExecuteChanged(); _genericCommand.Execute(PatameterValue); Assert.Equal(12, _callTestMethodCount); }
private void Summary_Tapped(object sender, TappedRoutedEventArgs e) { if (_summaryTapped != null) { _summaryTapped.Execute(_item); } }
/// <summary> /// Sets a generic RelayCommand to an object and actuates the command when a specific event is raised. This method /// should be used when the event uses an EventHandler<TEventArgs>. /// </summary> /// <typeparam name="T">The type of the CommandParameter that will be passed to the RelayCommand.</typeparam> /// <typeparam name="TEventArgs">The type of the event's arguments.</typeparam> /// <param name="element">The element to which the command is added.</param> /// <param name="command">The command that must be added to the element.</param> /// <param name="eventName">The name of the event that will be subscribed to to actuate the command.</param> /// <param name="commandParameter">The command parameter that will be passed to the RelayCommand when it /// is executed. This is a fixed value. To pass an observable value, use one of the SetCommand /// overloads that uses a Binding as CommandParameter.</param> public static void SetCommand <T, TEventArgs>( this object element, string eventName, RelayCommand <T> command, T commandParameter) { var t = element.GetType(); var e = t.GetEventInfoForControl(eventName); EventHandler <TEventArgs> handler = (s, args) => command.Execute(commandParameter); e.AddEventHandler( element, handler); var enabledProperty = t.GetProperty("Enabled"); if (enabledProperty != null) { enabledProperty.SetValue(element, command.CanExecute(commandParameter)); command.CanExecuteChanged += (s, args) => enabledProperty.SetValue( element, command.CanExecute(commandParameter)); } }
public void CanExecutePreventsNotExecuteGenericWorks() { // prepare bool executed = false; bool execed = false; int param = 42, paramReceived = int.MinValue; var execute = new Action <int>((i) => { execed = true; }); var can = new Predicate <int>((i) => { executed = true; paramReceived = i; return(false); }); // execute var target = new RelayCommand <int>(execute, can, false); target.Execute(param); // verify Assert.IsTrue(execed, "Command executed execute"); }
private void Column_OnTapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs) { if (_itemTapped != null) { _itemTapped.Execute(_item); } }
public void RelayCommandCanExecuteTest() { int _ExecuteCount = 0; bool _CanExecute = true; int _CanExecuteChangedCount = 0; RelayCommand _testCommand = new RelayCommand(() => _ExecuteCount++, () => _CanExecute); _testCommand.CanExecuteChanged += (object sender, EventArgs e) => _CanExecuteChangedCount++; Assert.IsTrue(_testCommand.CanExecute(null)); _testCommand.Execute(null); _CanExecute = false; Assert.IsFalse(_testCommand.CanExecute(null)); _testCommand.Execute(null); Assert.AreEqual <int>(2, _ExecuteCount); Assert.AreEqual <int>(0, _CanExecuteChangedCount); }
public static void ExecuteRelayCommand(RelayCommand command) { if (command.CanExecute(null)) { command.Execute(null); } }
private void PortSelectionCommitted(object sender, System.EventArgs e) { if (SelectPortCommand.CanExecute(this)) { SelectPortCommand.Execute(this); } }
public void ExecuteDelegate_WhenExecuteMethodIsCalled() { // Arrange //var action = new Mock<Action<object>>(); //action.Setup(a => a.Invoke(It.IsAny<object>())).Callback((object a) => //{ // Assert.IsTrue(true); //}); //Action<object> action = ((a) => //{ // Assert.IsTrue(true); //}); // grozna shema var executed = false; Action <object> action = o => { executed = true; }; var relayCommand = new RelayCommand(action); // Act relayCommand.Execute(It.IsAny <object>()); // Assert Assert.IsTrue(executed); }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { MainFinishedBlock = new ObservableCollection <IChart>(); ////if (IsInDesignMode) ////{ //// // Code runs in Blend --> create design time data. ////} ////else ////{ //// // Code runs "for real" ////} //These commands are used in the main menu stuff. Its where we are going to stick most of our secondary functions StartChartBuilderCommand = new RelayCommand(() => Dialogs.ActivateChartBuilder()); //These commands and this command pipe is for code relating to loading and parseing charts LoadCommand = new RelayCommand(() => FoundCharts = PipeAssessor.PrePipe.LoadCommand()); RollCommand = new RelayCommand(() => MainFinishedBlock = new ObservableCollection <IChart>(PipeAssessor.PrePipe.RollOneCommand(SelectedCharts))); LocateCommand = new RelayCommand(() => { PipeAssessor.PrePipe.AddTablesToRepo(); LoadCommand.Execute(null); }); DeleteCommand = new RelayCommand(() => { PipeAssessor.PrePipe.DeleteTableCommand(SelectedCharts); LoadCommand.Execute(null); }); OpenContainingFoldersCommand = new RelayCommand(() => PipeAssessor.PrePipe.OpenFileLocation(SelectedCharts)); OpenFileCommand = new RelayCommand(() => PipeAssessor.PrePipe.OpenFile(SelectedCharts)); //end of pre commands //The Commmands are releated to AFTER we have data and its parsed SaveToFileCommand = new RelayCommand(() => PipeAssessor.PostPipe.SaveChartCommand((Chart)MainFinishedBlock.FirstOrDefault())); AddToFileCommand = new RelayCommand(() => PipeAssessor.PostPipe.AddToChartCommand((Chart)MainFinishedBlock.FirstOrDefault())); SaveSelectedToFileCommand = new RelayCommand(() => PipeAssessor.PostPipe.SaveSelectedChartCommand(GetSelected())); AddSelectedToFileCommand = new RelayCommand(() => PipeAssessor.PostPipe.AddSelectedToChartCommand(GetSelected())); //end of postcommand pipe //When main is populated we want to load up the tables LoadCommand.Execute(null); }
private void Check1_Unchecked(object sender, RoutedEventArgs e) { RelayCommand commChecckbo2 = viewModel.CommandCheckAllType; commChecckbo2.Execute(null); DataGrid1.Items.Refresh(); }
private void CheckBox_Unchecked(object sender, RoutedEventArgs e) { RelayCommand commChecckbo1 = viewModel.CommandCheckAllParameter; commChecckbo1.Execute(null); DataGrid1.Items.Refresh(); }
void Title_Tapped(object sender, TappedRoutedEventArgs e) { if (_titleTapped != null) { _titleTapped.Execute(_item.Question); } }
private void Author_Tapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs) { if (_authorTapped != null) { _authorTapped.Execute(_item.Author); } }
private void Answer_Tapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs) { if (_answerTapped != null) { _answerTapped.Execute(_item); } }
private void Question_Tapped(object sender, TappedRoutedEventArgs e) { if (_questionTapped != null) { _questionTapped.Execute(_item); } }
public HomeViewModel(ViewModelLocator locator) : base(locator) { GoToDetailCommand = new RelayCommand <string>(async p => await GoToDetailAsync(p), true); GoToSettingsCommand = new RelayCommand(GoToSettings); CheckForUpdatesCommmand = new RelayCommand(async() => await CheckForUpdatesAsync(), true); CheckForUpdatesCommmand.Execute(null); }
public void CorrectArgumentIsSent() { _intRelayCommand = new RelayCommand<int>(ExecuteFunction, CanExecuteFunction); _intRelayCommand.Execute(1); Assert.AreEqual(1, _intArgument); }
public void CorrectStringCanBeParsedToEnumType() { _enumRelayCommand = new RelayCommand<DummyEnum>(ExecuteFunction, CanExecuteFunction); _enumRelayCommand.Execute("AnotherValue"); Assert.AreEqual(DummyEnum.AnotherValue, _enumArgument); }
public void CommandIsExecuted() { _relayCommand = new RelayCommand(OnActionCalled); _relayCommand.Execute(null); Assert.AreEqual(true, _actionHasBeenCalled); }
public CarInfoCollection() { Cars = new ObservableCollection<CarInfoViewModel>(); UpdateEntryList = new RelayCommand("Refresh", (p) => { ReloadEntryList(); }); UpdateEntryList.Execute(null); }
public void ExecuteExecutesTheAction() { var run = false; var command = new RelayCommand(o => { run = true; }); command.Execute(null); run.Should().BeTrue(); }
public void RelayCommand_Construction_WithoutCanExecuteCanActuallyExecute() { var count = 0; var cmd = new RelayCommand(o => count = (int) o); if (cmd.CanExecute()) cmd.Execute(15); Assert.AreEqual(15, count); }
public void ExecuteDoesNotExecuteTheActionIfCanExecuteIsFalse() { var run = false; var command = new RelayCommand(o => { run = true; }, o => false); command.Execute(null); run.Should().BeFalse(); }
public void WrongTypeThrowsException() { _intRelayCommand = new RelayCommand<int>(ExecuteFunction, CanExecuteFunction); _intRelayCommand.Execute(0.0); }
public void IncorrectStringThrowsException() { _enumRelayCommand = new RelayCommand<DummyEnum>(ExecuteFunction, CanExecuteFunction); _enumRelayCommand.Execute("InvalidValue"); }
private void AddCommandToService(OleMenuCommandService service, Guid cmdSet, int cmdId, RelayCommand relayCommand) { var commandId = new CommandID(cmdSet, cmdId); var menuCommand = new OleMenuCommand((sender, args) => { relayCommand.Execute(null); }, commandId); menuCommand.BeforeQueryStatus += (sender, args) => { menuCommand.Enabled = relayCommand.CanExecute(null); }; service.AddCommand(menuCommand); }