CanExecute() public method

public CanExecute ( object parameter ) : bool
parameter object
return bool
Esempio n. 1
0
        public void RaiseCanExecuteChangedTest()
        {
            var executed = false;
            var canExecute = false;
            var command = new DelegateCommand(() => executed = true, () => canExecute);
            
            Assert.IsFalse(command.CanExecute(null));
            canExecute = true;
            Assert.IsTrue(command.CanExecute(null));

            AssertHelper.CanExecuteChangedEvent(command, () => command.RaiseCanExecuteChanged());
            
            Assert.IsFalse(executed);
        }
Esempio n. 2
0
        public void ExecuteTest3()
        {
            var executed = false;
            var canExecute = true;
            var command = new DelegateCommand(() => executed = true, () => canExecute);

            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);
            Assert.IsTrue(executed);

            executed = false;
            canExecute = false;
            Assert.IsFalse(command.CanExecute(null));
            command.Execute(null);
            Assert.IsFalse(executed);
        }
Esempio n. 3
0
        public void WhenCanExecuteParameterIsNull_ThenExecutes()
        {
            var command = new DelegateCommand(() => { }, () => true);

            var can = command.CanExecute(null);

            Assert.True(can);
        }
Esempio n. 4
0
 public void ExecuteNoPredicateWithNull()
 {
     bool called = false;
     DelegateCommand cmd = new DelegateCommand((o) => called = true);
     Assert.IsTrue(cmd.CanExecute(null), "Command should always be able to execute when no predicate is supplied.");
     cmd.Execute(null);
     Assert.IsTrue(called, "Command did not run supplied Action.");
 }
        public void CanExectue_WithoutCanExecute_True()
        {
            var subject = new DelegateCommand(() => { });

            var result = subject.CanExecute();

            Assert.IsTrue(result);
        }
        public void CanExecuteReturnsResultOfTheFunctionIfItWasGiven()
        {
            _sut = new DelegateCommand(d => executed = true, d => false);

            var result = _sut.CanExecute(null);

            Assert.IsFalse(result);
        }
        public void CanExecute()
        {
            bool b = false;
            int i = 0;

            Action<int> execute = (param => i = i + param);
            Func<int, bool> predicate = (param => b);
            var command = new DelegateCommand<int>(execute, predicate);

            Assert.IsFalse(((ICommand)command).CanExecute(i));
            Assert.IsFalse(command.CanExecute(i));
            b = true;
            Assert.IsTrue(((ICommand)command).CanExecute(i));
            Assert.IsTrue(command.CanExecute(i));
            b = false;
            Assert.IsFalse(((ICommand)command).CanExecute(i));
            Assert.IsFalse(command.CanExecute(i));
        }
Esempio n. 8
0
		public void CanExecute_NoCanExecuteDelegateDefined_ReturnsTrue ()
		{
			Action<object> execute = delegate { };
			var command = new DelegateCommand (execute);

			bool result = command.CanExecute (null);

			Assert.IsTrue (result);
		}
        public void CanExecuteDelegateWorks()
        {
            Predicate<object> predicate = (o) =>
                {
                    if (o is bool)
                        return (bool)o;
                    else
                        return false;
                };
            Action<object> action = o => { };

            bool canExecute = false;
            ICommand delegateCommand = new DelegateCommand(action, predicate);
            Assert.IsFalse(delegateCommand.CanExecute(canExecute));

            canExecute = true;
            Assert.IsTrue(delegateCommand.CanExecute(canExecute));
        }
        public void CanExecuteReturnsTrueWithouthCanExecuteDelegate()
        {
            var handlers = new DelegateHandlers();
            var command = new DelegateCommand<object>(handlers.Execute);

            bool retVal = command.CanExecute(null);

            Assert.AreEqual(true, retVal);
        }
Esempio n. 11
0
        public void ExecuteTest2()
        {
            var executed = false;
            object commandParameter = null;
            var command = new DelegateCommand(parameter =>
            {
                executed = true;
                commandParameter = parameter;
            });

            var obj = new object();
            Assert.IsTrue(command.CanExecute(null));
            Assert.IsTrue(command.CanExecute(obj));

            command.Execute(obj);
            Assert.IsTrue(executed);
            Assert.AreSame(obj, commandParameter);
        }
            public void ShouldReturnTrueIfConstructedWithNull()
            {
                bool methodCalled = false;
                DelegateCommand testCommand = new DelegateCommand((param) => methodCalled = true);

                testCommand.Execute(null);
                Assert.IsTrue(methodCalled);

                Assert.IsTrue(testCommand.CanExecute(null));
            }
        public void CanExecute_CanExecuteDelegateDefinedToReturnFalse_ReturnsFalse()
        {
            Action<object> execute = delegate { };
            Predicate<object> canExecute = delegate { return false; };
            var command = new DelegateCommand(execute, canExecute);

            bool result = command.CanExecute(null);

            Assert.IsFalse(result);
        }
Esempio n. 14
0
        public void CanExecute()
        {
            bool b = false;
            int i = 0;

            Action execute = (() => i++);
            Func<bool> predicate = (() => b);
            var command = new DelegateCommand(execute, predicate);

            object dummy = new object();
            Assert.IsFalse(((ICommand)command).CanExecute(dummy));
            Assert.IsFalse(command.CanExecute());
            b = true;
            Assert.IsTrue(((ICommand)command).CanExecute(dummy));
            Assert.IsTrue(command.CanExecute());
            b = false;
            Assert.IsFalse(((ICommand)command).CanExecute(dummy));
            Assert.IsFalse(command.CanExecute());
        }
Esempio n. 15
0
        public void CanExecuteCallsPassedInCanExecuteDelegate()
        {
            var handlers = new DelegateHandlers();
            var command = new DelegateCommand<object>(handlers.Execute, handlers.CanExecute);
            object parameter = new object();

            handlers.CanExecuteReturnValue = true;
            bool retVal = command.CanExecute(parameter);

            Assert.AreSame(parameter, handlers.CanExecuteParameter);
            Assert.AreEqual(handlers.CanExecuteReturnValue, retVal);
        }
Esempio n. 16
0
        public void ShouldPassParameterInstanceOnCanExecute()
        {
            bool     canExecuteCalled = false;
            MyClass  testClass        = new MyClass();
            ICommand command          = new DelegateCommand <MyClass>((p) => { }, delegate(MyClass parameter)
            {
                Assert.Same(testClass, parameter);
                canExecuteCalled = true;
                return(true);
            });

            command.CanExecute(testClass);
            Assert.True(canExecuteCalled);
        }
Esempio n. 17
0
        private void Stop()
        {
            if (_resumeCommand.CanExecute(null))
            {
                _resumeCommand.Execute(null);
            }

            _crawlerCancellationTokenSource.Cancel();
            _crawlerService.IsCrawl = false;
            _crawlCommand.RaiseCanExecuteChanged();
            _pauseCommand.RaiseCanExecuteChanged();
            _resumeCommand.RaiseCanExecuteChanged();
            _stopCommand.RaiseCanExecuteChanged();
        }
Esempio n. 18
0
        private void Stop()
        {
            if (resumeCommand.CanExecute(null))
            {
                resumeCommand.Execute(null);
            }

            crawlBlogsCancellation.Cancel();
            crawlerService.IsCrawl = false;
            crawlCommand.RaiseCanExecuteChanged();
            pauseCommand.RaiseCanExecuteChanged();
            resumeCommand.RaiseCanExecuteChanged();
            stopCommand.RaiseCanExecuteChanged();
        }
        private static void ElementOnLoaded(object sender, RoutedEventArgs e)
        {
            if (!(sender is FrameworkElement element))
            {
                return;
            }

            DelegateCommand command = GetOnLoaded(element);

            if (command != null && command.CanExecute())
            {
                command.Execute();
            }
        }
Esempio n. 20
0
        public void GenericDelegateCommandShouldObserveCanExecuteAndObserveOtherProperties()
        {
            bool canExecuteChangedRaised = false;

            ICommand command = new DelegateCommand <object>((o) => { }).ObservesCanExecute((o) => BoolProperty).ObservesProperty(() => IntProperty);

            command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

            Assert.False(canExecuteChangedRaised);
            Assert.False(command.CanExecute(null));

            IntProperty = 10;
            Assert.True(canExecuteChangedRaised);
            Assert.False(command.CanExecute(null));

            canExecuteChangedRaised = false;
            Assert.False(canExecuteChangedRaised);

            BoolProperty = true;

            Assert.True(canExecuteChangedRaised);
            Assert.True(command.CanExecute(null));
        }
Esempio n. 21
0
 public void CanExecutePassesParameterToPredicate()
 {
     object passedParameter = null;
     Predicate<object> predicate =
         o =>
             {
                 passedParameter = o;
                 return false;
             };
     var command = new DelegateCommand(null, predicate);
     var parameter = new object();
     command.CanExecute(parameter);
     Assert.AreSame(parameter, passedParameter);
 }
Esempio n. 22
0
        private void _clientBookingsView_currentChanged(object sender, EventArgs e)
        {
            bool nothingSelected   = _clientBookingsView.CurrentPosition == -1;
            bool somethingSelected = !nothingSelected;
            bool canExecute        = _selectBookingCommand.CanExecute(null);

            if (
                (somethingSelected && !canExecute) ||
                (nothingSelected && canExecute)
                )
            {
                _selectBookingCommand.ChangeCanExecute();
                _cancelBookingCommand.ChangeCanExecute();
            }
        }
Esempio n. 23
0
        public void DelegateCommand_CanExecute()
        {
            var callCount = 0;
            var x         = new DelegateCommand(() => callCount++, () => true);

            Assert.AreEqual(true, x.CanExecute());
            x.Execute();
            Assert.AreEqual(1, callCount);

            var y = (ICommand)x;

            Assert.AreEqual(true, y.CanExecute(""));
            y.Execute("");
            Assert.AreEqual(2, callCount);
        }
Esempio n. 24
0
        public void CanExecutePassesParameterToPredicate()
        {
            object             passedParameter = null;
            Predicate <object> predicate       =
                o =>
            {
                passedParameter = o;
                return(false);
            };
            var command   = new DelegateCommand(null, predicate);
            var parameter = new object();

            command.CanExecute(parameter);
            Assert.AreSame(parameter, passedParameter);
        }
Esempio n. 25
0
        public void DelegateCommand_CanExecute2()
        {
            var callCount = 0;
            var x         = new DelegateCommand <string>(p => callCount++);

            Assert.AreEqual(true, x.CanExecute(""));
            x.Execute("");
            Assert.AreEqual(1, callCount);

            var y = (ICommand)x;

            Assert.AreEqual(true, y.CanExecute(""));
            y.Execute("");
            Assert.AreEqual(2, callCount);
        }
Esempio n. 26
0
        public void Usage()
        {
            DelegateCommand command = new DelegateCommand(TestCommand);

            command.Execute(null);
            Assert.True(command.CanExecute(null));

            command = new DelegateCommand(TestCommand, TestCanExecute);
            Assert.True(command.CanExecute(null));
            command.Execute(null);

            command = new DelegateCommand(null);
            command.Execute(null);
            command.CanExecuteChanged += Command_CanExecuteChanged;
        }
 public void DelegateCommand_CanExecute_WhenConstructedWithAPredicate_PredicateIsCalled()
 {
     //------------Setup for test--------------------------
     var canExecuteWasCalled = false;
     var delegateCommand = new DelegateCommand(o => { }, o =>
         {
             canExecuteWasCalled = true;
             return true;
         });
     //------------Execute Test---------------------------
     var canExecute = delegateCommand.CanExecute(null);
     //------------Assert Results-------------------------
     Assert.IsTrue(canExecuteWasCalled);
     Assert.IsTrue(canExecute);
 }
            public void ShouldReturnResultFromCorrectCanExecuteDelegate()
            {
                bool methodCalled = false;
                bool canExecuteCalled = false;
                DelegateCommand testCommand = new DelegateCommand((param) => methodCalled = true, (param) =>
                {
                    canExecuteCalled = true;
                    return true;
                });

                testCommand.Execute(null);
                Assert.IsTrue(methodCalled);
                Assert.IsFalse(canExecuteCalled);
                Assert.IsTrue(testCommand.CanExecute(null));
                Assert.IsTrue(canExecuteCalled);
            }
Esempio n. 29
0
        public void DelegateCommand_CanExecute_WhenConstructedWithAPredicate_PredicateIsCalled()
        {
            //------------Setup for test--------------------------
            var canExecuteWasCalled = false;
            var delegateCommand     = new DelegateCommand(o => { }, o =>
            {
                canExecuteWasCalled = true;
                return(true);
            });
            //------------Execute Test---------------------------
            var canExecute = delegateCommand.CanExecute(null);

            //------------Assert Results-------------------------
            Assert.IsTrue(canExecuteWasCalled);
            Assert.IsTrue(canExecute);
        }
Esempio n. 30
0
        public void AttemptExecuteWithFalsePredicate()
        {
            bool called = false;
            DelegateCommand cmd = new DelegateCommand((o) => called = true, (o) => false);
            Assert.IsFalse(cmd.CanExecute(null), "Command should not be able to execute when predicate returns false.");

            try
            {
                cmd.Execute(null);
            }
            catch (InvalidOperationException)
            {
            }

            Assert.IsFalse(called, "Command should not have run supplied Action.");
        }
        public void CanExecute_DelegateCalled()
        {
            var called  = false;
            var subject = new DelegateCommand(
                () => { },
                () =>
            {
                called = true;
                return(true);
            });

            var result = subject.CanExecute();

            Assert.IsTrue(called);
            Assert.IsTrue(result);
        }
Esempio n. 32
0
        public void CanExecute_PassObject_ShouldPassObject()
        {
            // Prepare
            var parameter          = new object();
            var fakeClass          = new ClassFixture();
            var callBackActionMock = new Mock <Action <object> >();
            var command            = new DelegateCommand <object>(callBackActionMock.Object, (obj) =>
            {
                // Assert
                Assert.Equal(parameter, obj);
                return(true);
            });

            // Act
            var returnValue = command.CanExecute(parameter);
        }
        public void CanExecute_DelegateCalled()
        {
            var called = false;
            var subject = new DelegateCommand(
                () => { },
                () =>
                {
                    called = true;
                    return true;
                });

            var result = subject.CanExecute();

            Assert.IsTrue(called);
            Assert.IsTrue(result);
        }
Esempio n. 34
0
        public void TwoParameters_3()
        {
            string s;
            int    x;

            var dc = new DelegateCommand <string, int>((p, q) => { s = p; x = q; });

            s = ""; x = 0;
            dc.CanExecute("a", 33).Is(true);
            s.Is("");
            x.Is(0);

            s = ""; x = 0;
            dc.Execute("b", 44);
            s.Is("b");
            x.Is(44);
        }
Esempio n. 35
0
		public void CanExecute_CanExecuteDelegateDefined_ParameterPassedToCanExecuteDelegate ()
		{
			Action<object> execute = delegate { };

			object parameterPassed = null;
			Predicate<object> canExecute = param => {
				parameterPassed = param;
				return true;
			};
			var command = new DelegateCommand (execute, canExecute);

			object expectedParameter = new object ();
			bool result = command.CanExecute (expectedParameter);

			Assert.AreEqual (expectedParameter, parameterPassed);
			Assert.IsTrue (result);
		}
        public void CanExecute_CanExecuteDelegateDefined_ParameterPassedToCanExecuteDelegate()
        {
            Action <object> execute = delegate { };

            object             parameterPassed = null;
            Predicate <object> canExecute      = param => {
                parameterPassed = param;
                return(true);
            };
            var command = new DelegateCommand(execute, canExecute);

            object expectedParameter = new object();
            bool   result            = command.CanExecute(expectedParameter);

            Assert.AreEqual(expectedParameter, parameterPassed);
            Assert.IsTrue(result);
        }
        public void AttemptExecuteWithFalsePredicate()
        {
            bool            called = false;
            DelegateCommand cmd    = new DelegateCommand((o) => called = true, (o) => false);

            Assert.IsFalse(cmd.CanExecute(null), "Command should not be able to execute when predicate returns false.");

            try
            {
                cmd.Execute(null);
            }
            catch (InvalidOperationException)
            {
            }

            Assert.IsFalse(called, "Command should not have run supplied Action.");
        }
Esempio n. 38
0
        private static void ElementOnPreviewKeyDown(object sender, KeyEventArgs e)
        {
            if ((int)e.Key != (int)Key.Enter)
            {
                return;
            }
            if (!(sender is UIElement element))
            {
                return;
            }

            DelegateCommand command = GetOnEnterKeyDown(element);

            if (command != null && command.CanExecute())
            {
                command.Execute();
            }
        }
Esempio n. 39
0
        public void Execute()
        {
            int i = 0;
            var execute = new Action<int>(param => i = param);
            var command = new DelegateCommand<int>(execute);

            Assert.IsTrue(((ICommand)command).CanExecute(12));
            ((ICommand)command).Execute(12);
            Assert.AreEqual(12, i);
            Assert.IsTrue(((ICommand)command).CanExecute(15));
            ((ICommand)command).Execute(15);
            Assert.AreEqual(15, i);
            Assert.IsTrue(command.CanExecute(14));
            command.Execute(14);
            Assert.AreEqual(14, i);
            Assert.IsTrue(command.CanExecute(16));
            command.Execute(16);
            Assert.AreEqual(16, i);
        }
Esempio n. 40
0
        public void TestDelegateCommand()
        {
            bool   isCalled = false;
            string result   = "";

            var command = new DelegateCommand <string>((value) =>
            {
                isCalled = true;
                result   = value;
            });

            if (command.CanExecute("Ok"))
            {
                command.Execute("Ok");
            }

            Assert.IsTrue(isCalled);
            Assert.AreEqual("Ok", result);
        }
Esempio n. 41
0
        public MainWindowViewModel(WindowService windowService, MainWindowModel model) : base(windowService, model)
        {
            this.model = model;

            #region Event Initialize
            Loaded  = new DelegateCommand(MainWindow_Loaded);
            KeyDown = new DelegateCommand <KeyEventArgs>(MainWindow_KeyDown);

            NewFileBtClicked = new DelegateCommand(NewFileBt_Clicked);
            OpenBtClicked    = new DelegateCommand(OpenBt_Clicked);
            SaveAsBtClicked  = new DelegateCommand(SaveAsBt_Clicked);
            SaveBtClicked    = new DelegateCommand(SaveBt_Clicked);

            VersionsListSelectionChanged = new DelegateCommand(VersionsList_SelectionChanged);
            ConfigListSelectionChanged   = new DelegateCommand(ConfigList_SelectionChanged);
            ValueListSelectionChanged    = new DelegateCommand(ValueList_SelectionChanged);
            ValueTextTextChanged         = new DelegateCommand(ValueTextText_Changed);
            #endregion

            #region Propertiy Initialize
            ModifiedVisibility = model.ToReactivePropertyAsSynchronized(m => m.ModifiedVisibility);
            SaveBtEnabled      = model.ToReactivePropertyAsSynchronized(m => m.SaveBtEnabled);

            VersionList = model.ObserveProperty(m => m.VersionList).ToReactiveProperty();
            ConfigList  = model.ObserveProperty(m => m.ConfigList).ToReactiveProperty();
            ValueList   = model.ObserveProperty(m => m.ValueList).ToReactiveProperty();
            VersionListSelectedIndex = model.ToReactivePropertyAsSynchronized(m => m.VersionListSelectedIndex);
            ConfigListSelectedIndex  = model.ToReactivePropertyAsSynchronized(m => m.ConfigListSelectedIndex);
            ValueListSelectedIndex   = model.ToReactivePropertyAsSynchronized(m => m.ValueListSelectedIndex);

            NameLabel              = model.ToReactivePropertyAsSynchronized(m => m.NameLabel);
            DescriptionLabel       = model.ToReactivePropertyAsSynchronized(m => m.DescriptionLabel);
            ValueText              = model.ToReactivePropertyAsSynchronized(m => m.ValueText);
            ValueListVisibility    = model.ToReactivePropertyAsSynchronized(m => m.ValueListVisibility);
            ValueTextBoxVisibility = model.ToReactivePropertyAsSynchronized(m => m.ValueTextBoxVisibility);
            #endregion

            if (Loaded != null && Loaded.CanExecute(null))
            {
                Loaded?.Execute(null);
            }
        }
Esempio n. 42
0
        public void Execute()
        {
            int i = 0;
            Action execute = (() => i++);
            var command = new DelegateCommand(execute);

            object dummy = new object();
            Assert.IsTrue(((ICommand)command).CanExecute(dummy));
            ((ICommand)command).Execute(dummy);
            Assert.AreEqual(1, i);
            Assert.IsTrue(((ICommand)command).CanExecute(dummy));
            ((ICommand)command).Execute(dummy);
            Assert.AreEqual(2, i);
            Assert.IsTrue(command.CanExecute());
            command.Execute();
            Assert.AreEqual(3, i);
            Assert.IsTrue(command.CanExecute());
            command.Execute();
            Assert.AreEqual(4, i);
        }
Esempio n. 43
0
        private void _unlockSaveAndSumUpIfNeeded()
        {
            bool canSave  = _saveClientCommand.CanExecute(null);
            bool canSumUp = _sumUpCommand.CanExecute(null);
            bool isValid  = ((IDataErrorInfo)_clientEntity).Error == null;

            if ((canSave && !isValid) ||
                (!canSave && isValid)
                )
            {
                _saveClientCommand.ChangeCanExecute();
            }

            if ((canSumUp && !isValid) ||
                (!canSumUp && isValid)
                )
            {
                _sumUpCommand.ChangeCanExecute();
            }
        }
Esempio n. 44
0
        public void CanExecute_PassInstance_ShouldPassInstance()
        {
            // Prepare
            var executeCalled = false;
            var fakeClass     = new ClassFixture();
            var command       = new DelegateCommand <ClassFixture>((p) => { }, delegate(ClassFixture parameter)
            {
                // Assert
                Assert.Same(fakeClass, parameter);

                // Act
                executeCalled = true;
                return(true);
            });

            // Act
            command.CanExecute(fakeClass);

            // Assert
            Assert.True(executeCalled);
        }
Esempio n. 45
0
 public void Shutdown()
 {
     try
     {
         if (stopCommand.CanExecute(null))
         {
             stopCommand.Execute(null);
         }
         Task.WaitAll(runningTasks.ToArray());
     }
     catch (AggregateException)
     {
     }
     foreach (IBlog blog in managerService.BlogFiles)
     {
         if (blog.Dirty)
         {
             blog.Save();
         }
     }
 }
Esempio n. 46
0
 public void AddMenuItem(DelegateCommand command)
 {
     ToolStripMenuItem item = new ToolStripMenuItem(command.Label);
     item.Tag = command;
     item.Click += (s, e) =>
     {
         if (command.CanExecute()) command.Execute();
     };
     command.PropertyChanged += (s, e) =>
     {
         switch (e.PropertyName)
         {
             case "Label":
                 item.Text = command.Label;
                 break;
             default:
                 break;
         }
     };
     _contextMenu.Items.Add(item);
 }
Esempio n. 47
0
        private void Stop()
        {
            if (_resumeCommand.CanExecute(null))
            {
                _resumeCommand.Execute(null);
            }

            try
            {
                _crawlerCancellationTokenSource.Cancel();
            }
            catch
            {
                // sometimes it fails to cancel the crawlers, because they are already cancelled/disposed
            }
            _crawlerService.IsCrawl = false;
            _crawlCommand.RaiseCanExecuteChanged();
            _pauseCommand.RaiseCanExecuteChanged();
            _resumeCommand.RaiseCanExecuteChanged();
            _stopCommand.RaiseCanExecuteChanged();
        }
Esempio n. 48
0
        public void WithCondition_Is_Executed()
        {
            bool isCalled  = false;
            bool isChecked = false;

            var command = new DelegateCommand(() =>
            {
                isCalled = true;
            }, () =>
            {
                isChecked = true;
                return(true);
            });

            if (command.CanExecute(null))
            {
                command.Execute(null);
            }

            Assert.IsTrue(isChecked);
            Assert.IsTrue(isCalled);
        }
Esempio n. 49
0
 public void Shutdown()
 {
     try
     {
         if (stopCommand.CanExecute(null))
         {
             stopCommand.Execute(null);
         }
         Task.WaitAll(runningTasks.ToArray());
     }
     catch (System.AggregateException)
     {
     }
     foreach (Blog blog in selectionService.BlogFiles)
     {
         if (blog.Dirty)
         {
             blog.Dirty = false;
             SaveBlog(blog);
         }
     }
 }
Esempio n. 50
0
        public void Initialize()
        {
            GoLevelUpCommand    = new DelegateCommand(ExecuteGoLevelUp, () => SelectedFile != null && SelectedFile.IsParent);
            ListFolderCommand   = new DelegateCommand(ExecuteListFolder, () => SelectedFile != null && !SelectedFile.IsParent && SelectedFile.IsFolder);
            LoadFileListCommand = new DelegateCommand(ExecuteLoadFileList, () => GoLevelUpCommand.CanExecute() || ListFolderCommand.CanExecute());

            var commandLineArgs = Environment.GetCommandLineArgs();

            if ((commandLineArgs.Length != 2) || !Path.IsPathRooted(commandLineArgs[1]))
            {
                LogEvent("Incorrect number of arguments or passed argument doesn't represents file path");
                return;
            }

            FilePath = Path.GetPathRoot(commandLineArgs[1]);
            if (!FilePath.EndsWith(Path.DirectorySeparatorChar.ToString()))
            {
                FilePath += Path.DirectorySeparatorChar;
            }

            this.model.FileListLoaded += OnFileListLoaded;

            try
            {
                LogEvent("Requesting initial 'LoadFileList': " + FilePath);

                this.model.FilePath = FilePath;
                this.model.LoadFileList();

                IsIdle = false;

                LogEvent("Request for initial 'LoadFileList' queued: " + FilePath);
            }
            catch (Exception ex)
            {
                LogEvent("Exception requesting initial 'LoadFileList': " + ex.Message);
            }
        }
Esempio n. 51
0
        public void CanExecuteIsCalled()
        {
            int callCount = 0;

            object expectedParameter = new object();
            object gotParameter      = null;

            ICommand cmd = new DelegateCommand
            {
                CanExecute = delegate(object parameter)
                {
                    callCount++;
                    gotParameter = parameter;
                    return(false);
                }
            };

            var returnValue = cmd.CanExecute(expectedParameter);

            Assert.AreEqual(1, callCount);
            Assert.AreEqual(expectedParameter, gotParameter);
            Assert.IsFalse(returnValue);
        }
Esempio n. 52
0
        public void NonGenericDelegateCommandCanExecuteShouldInvokeCanExecuteFunc()
        {
            bool invoked = false;
            var command = new DelegateCommand(() => { }, () => { invoked = true; return true; });

            bool canExecute = command.CanExecute();

            Assert.IsTrue(invoked);
            Assert.IsTrue(canExecute);
        }
Esempio n. 53
0
        /// <summary>ユーザ入力関係の初期化</summary>
        private void InitInput()
        {
            #region コマンド初期化
            TogglePourCommand = new DelegateCommand(
                Properties.Resources.Command_Pour,
                () =>
                {
                    if (_model.IsPouring) _model.StopPour();
                    else _model.StartPour();
                },
                () => _model.IsAvailable && _configWin == null);

            StartPourCommand = new DelegateCommand(Properties.Resources.Command_Pour,
                () => _model.StartPour(), () => !_model.IsPouring && _configWin == null);
            StopPourCommand = new DelegateCommand(Properties.Resources.Command_Pour,
                () => _model.StopPour(), () => _model.IsPouring && _configWin == null);

            DrawWallCommand = new DelegateCommand(
                Properties.Resources.Command_DrawWall,
                () => _drawWall = true, () => _model.IsAvailable && _configWin == null);
            UnDrawWallCommand = new DelegateCommand(
                Properties.Resources.Command_DrawWall,
                () => _drawWall = false, () => _model.IsAvailable && _configWin == null);

            TogglePauseCommand = new DelegateCommand(
                _model.IsPaused ? Properties.Resources.Command_Resume : Properties.Resources.Command_Pause,
                () =>
                {
                    _model.TogglePause();
                    TogglePauseCommand.Label = _model.IsPaused ?
                        Properties.Resources.Command_Resume : Properties.Resources.Command_Pause;
                },
                () => _model.IsAvailable && _configWin == null);

            ConfigCommand = new DelegateCommand(Properties.Resources.Command_Config,
                () =>
                {
                    if(_configWin == null) _configWin = new View.ConfigWindow();
                    bool configPause = false;
                    if (!_model.IsPaused) // 設定中は停止する
                    {
                        configPause = true;
                        _model.Pause();
                    }
                    _configWin.ShowDialog();
                    if (configPause) // 停止した場合は再開する
                    {
                        configPause = false;
                        _model.Resume();
                    }
                    _configWin = null;
                },
                () => _model.IsAvailable && _configWin == null);

            ExitCommand = new DelegateCommand(Properties.Resources.Command_Exit,
                () => Close(), () => _configWin == null);
            #endregion

            #region グローバルキー
            GlobalHook.KeyDown += (s, e) =>
            {
                if (Config.Instance.Pour.Hit(e.Key, e.Modifiers))
                {
                    if (StartPourCommand.CanExecute()) StartPourCommand.Execute();
                }
                else if (Config.Instance.DrawWall.Hit(e.Key, e.Modifiers))
                {
                    if (DrawWallCommand.CanExecute()) DrawWallCommand.Execute();
                }
                else if (Config.Instance.Pause.Hit(e.Key, e.Modifiers))
                {
                    if (TogglePauseCommand.CanExecute()) TogglePauseCommand.Execute();
                }
                else if (Config.Instance.Exit.Hit(e.Key, e.Modifiers))
                {
                    if (ExitCommand.CanExecute()) ExitCommand.Execute();
                }

            };

            GlobalHook.KeyUp += (s, e) =>
            {
                if (Config.Instance.Pour.Hit(e.Key, e.Modifiers))
                {
                    if (StopPourCommand.CanExecute()) StopPourCommand.Execute();
                }
                else if (Config.Instance.DrawWall.Hit(e.Key, e.Modifiers))
                {
                    if (UnDrawWallCommand.CanExecute()) UnDrawWallCommand.Execute();
                }
            };
            #endregion

            // 通知アイコンのメニュー
            _notifyIconManager.AddMenuItem(TogglePauseCommand);
            _notifyIconManager.AddMenuItem(ConfigCommand);
            _notifyIconManager.AddMenuItem(ExitCommand);
        }
Esempio n. 54
0
        public void ShouldPassParameterInstanceOnCanExecute()
        {
            bool canExecuteCalled = false;
            MyClass testClass = new MyClass();
            ICommand command = new DelegateCommand<MyClass>((p) => { }, delegate(MyClass parameter)
            {
                Assert.AreSame(testClass, parameter);
                canExecuteCalled = true;
                return true;
            });

            command.CanExecute(testClass);
            Assert.IsTrue(canExecuteCalled);
        }
Esempio n. 55
0
        public void CanExecute_returns_true_if_not_specified()
        {
            var command = new DelegateCommand(() => { });

            command.CanExecute(null).Should().BeTrue();
        }
Esempio n. 56
0
        public void CanExecute_returns_value_from_specified_delegate(bool canExecute)
        {
            var command = new DelegateCommand(() => { }, () => canExecute);

            command.CanExecute(null).Should().Be(canExecute);
        }
Esempio n. 57
0
 public virtual bool CanExecute(T parameter)
 {
     return(_command.CanExecute(parameter));
 }
Esempio n. 58
0
 public void NonGenericDelegateCommandShouldDefaultCanExecuteToTrue()
 {
     var command = new DelegateCommand(() => { });
     Assert.IsTrue(command.CanExecute());
 }
Esempio n. 59
0
        public void NonGenericDelegateCommandShouldObserveCanExecute()
        {
            bool canExecuteChangedRaised = false;

            ICommand command = new DelegateCommand(() => { }).ObservesCanExecute((o) => BoolProperty);

            command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

            Assert.IsFalse(canExecuteChangedRaised);
            Assert.IsFalse(command.CanExecute(null));

            BoolProperty = true;

            Assert.IsTrue(canExecuteChangedRaised);
            Assert.IsTrue(command.CanExecute(null));
        }
Esempio n. 60
0
        public void GenericDelegateCommandShouldObserveCanExecuteAndObserveOtherProperties()
        {
            bool canExecuteChangedRaised = false;

            ICommand command = new DelegateCommand<object>((o) => { }).ObservesCanExecute((o) => BoolProperty).ObservesProperty(() => IntProperty);

            command.CanExecuteChanged += delegate { canExecuteChangedRaised = true; };

            Assert.IsFalse(canExecuteChangedRaised);
            Assert.IsFalse(command.CanExecute(null));

            IntProperty = 10;
            Assert.IsTrue(canExecuteChangedRaised);
            Assert.IsFalse(command.CanExecute(null));

            canExecuteChangedRaised = false;
            Assert.IsFalse(canExecuteChangedRaised);

            BoolProperty = true;

            Assert.IsTrue(canExecuteChangedRaised);
            Assert.IsTrue(command.CanExecute(null));
        }