Execute() public method

public Execute ( object parameter ) : void
parameter object
return void
Example #1
0
        public void WhenNoCanExecuteSpecified_ThenExecutesAlways()
        {
            var executed = 0;
            var command = new DelegateCommand<string>(s => executed++);

            command.Execute("foo");
            command.Execute("foo");

            Assert.Equal(2, executed);
        }
Example #2
0
        public void WhenNoCanExecuteSpecified_ThenExecutesAlways()
        {
            var executed = 0;
            var command = new DelegateCommand(() => executed++);

            command.Execute(new object());
            command.Execute(new object());

            Assert.Equal(2, executed);
        }
Example #3
0
        static void Main(string[] args)
        {
            Receiver receiver = new Receiver();
            Command command = new ConcreteCommand(receiver);
            var results = command.Execute().Results;
            Console.WriteLine(results);

            bool condition = false;
            DelegateCommand delegateCommand = new DelegateCommand(() => Console.WriteLine("Hello World!"), () => condition);
            delegateCommand.Execute();
            condition = true;
            delegateCommand.Execute();
        }
 public void Execute_should_run_action_with_progress_monitor()
 {
     var monitor = MockRepository.GenerateStub<IProgressMonitor>();
     var command = new DelegateCommand(pm => Assert.AreEqual(monitor, pm));
     
     command.Execute(monitor);
 }
        public ContactEditorViewModel(ICommandInvoker commandInvoker, IQueryInvoker queryInvoker)
        {
            this.queryInvoker = queryInvoker;
            Contacts = queryInvoker.Query<AllContactsQueryResult>().Contacts;

            SaveCommand = new DelegateCommand(() =>
                {
                    if (CurrentContact.Command is UpdateContactCommand)
                    {
                        commandInvoker.Execute<UpdateContactCommand, UpdateContactQueryResult>((UpdateContactCommand) CurrentContact.Command);
                    }
                    else
                    {
                        commandInvoker.Execute<CreateContactCommand, CreateContactQueryResult>(CurrentContact.Command);
                    }

                    Contacts = queryInvoker.Query<AllContactsQueryResult>().Contacts;
                });

            NewCommand = new DelegateCommand(() =>
                {
                    var modifyContactQueryResult = queryInvoker.Query<CreateContactQueryResult>();
                    CurrentContact = new CreateContactViewModel(modifyContactQueryResult, new ValidationService());
                });
            NewCommand.Execute(null);
        }
Example #6
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);
        }
 public MarvelSeriesPageViewModel(INavigationService navigationService, IPageDialogService dialogService, ApiComicsVine apiComicsVine) : base(navigationService, dialogService, apiComicsVine, MarvelUniverse, Disney, Offset)
 {
     LoadListCommand = new DelegateCommand(async() =>
     {
         await LoadSeries(Offset);
     });
     LoadListCommand.Execute();
 }
Example #8
0
        public async Task NonGenericDelegateCommandExecuteShouldInvokeExecuteAction()
        {
            bool executed = false;
            var  command  = new DelegateCommand(() => { executed = true; });
            await command.Execute();

            Assert.True(executed);
        }
        public void DelegateCommand_Execute_AsExpected()
        {
            bool invoked = false;
            var  c       = new DelegateCommand(_ => invoked = true);

            c.Execute(null);
            invoked.Should().BeTrue();
        }
        public void OnNavigatedTo(INavigationParameters parameters)
        {
            var param = (Comic)parameters[nameof(Comic)];

            Comic       = param;
            LoadCommand = new DelegateCommand(async() => await LoadComics(Comic.Id));
            LoadCommand.Execute();
        }
        public void ExecuteTest()
        {
            bool executed = false;
            DelegateCommand command = new DelegateCommand(() => executed = true);

            command.Execute(null);
            Assert.IsTrue(executed);
        }
Example #12
0
        public void ExecuteTest()
        {
            bool            executed = false;
            DelegateCommand command  = new DelegateCommand(() => executed = true);

            command.Execute(null);
            Assert.IsTrue(executed);
        }
Example #13
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.");
 }
Example #14
0
        public void WhenCanExecuteReturnsTrue_ThenExecutes()
        {
            var executed = false;
            var command  = new DelegateCommand <string>(s => executed = true, s => true);

            command.Execute("foo");

            Assert.True(executed);
        }
Example #15
0
        public void WhenCanExecuteReturnsFalse_ThenDoesNotExecute()
        {
            var executed = false;
            var command  = new DelegateCommand <string>(s => executed = true, s => false);

            command.Execute("foo");

            Assert.False(executed);
        }
Example #16
0
        public void WhenExecuteParameterIsNull_ThenExecutes()
        {
            var executed = false;
            var command  = new DelegateCommand(() => executed = true, () => true);

            command.Execute(null);

            Assert.True(executed);
        }
        public void Execute_should_run_action()
        {
            bool flag = false;
            var command = new DelegateCommand(pm => flag = true);

            command.Execute(MockRepository.GenerateStub<IProgressMonitor>());

            Assert.IsTrue(flag);
        }
Example #18
0
        public void ExecuteTest_CanExecute_True()
        {
            bool executed = false;
            bool canExecute = true;
            DelegateCommand command = new DelegateCommand(() => executed = true, () => canExecute);

            command.Execute();
            Assert.IsTrue(executed);
        }
        public MainPageViewModel(INavigationService navigationService)
            : base(navigationService)
        {
            Title = "Main Page";

            DelegateCommand cmd = new DelegateCommand(ExecuteIt);

            cmd.Execute();
        }
 public ListLeaguesViewModel(IApiServices api, INavigationService navigationService)
 {
     apiServices       = api;
     navigation        = navigationService;
     Tap               = new DelegateCommand <object>(SelectLeague);
     TitlePage         = "Leagues";
     GetLeaguesCommand = new DelegateCommand(async() => await GetLeagues());
     GetLeaguesCommand.Execute();
 }
 public CompareCharactersPageViewModel(INavigationService navigationService, IPageDialogService dialogService, ApiComicsVine apiComicsVine, ApiStatsCharacters apiStatsCharacters, string publisher) : base(navigationService, dialogService, apiComicsVine)
 {
     this.apiStatsCharacters = apiStatsCharacters;
     LoadListCommand         = new DelegateCommand(async() =>
     {
         await LoadCharacters(publisher);
     });
     LoadListCommand.Execute();
 }
Example #22
0
        public void NonGenericDelegateCommandExecuteShouldInvokeExecuteAction()
        {
            bool executed = false;
            var  command  = new DelegateCommand(() => { executed = true; });

            command.Execute();

            Assert.IsTrue(executed);
        }
        private void OnClicked(object sender, Controls.PopupResultEventArgs args)
        {
            RemovePopup();

            if (_command != null)
            {
                _command.Execute(args);
            }
        }
Example #24
0
        public void When_Correct()
        {
            var target = 0;
            var cmd    = new DelegateCommand <int>(i => target = i);

            Assert.IsTrue(target == 0);
            cmd.Execute(10);
            Assert.IsTrue(target == 10);
        }
Example #25
0
        public void ExecuteTest()
        {
            var executed = false;
            var command  = new DelegateCommand(() => executed = true);

            Assert.IsTrue(command.CanExecute(null));
            command.Execute(null);
            Assert.IsTrue(executed);
        }
Example #26
0
        public void TestParameterizedExecute()
        {
            var executeParameter = 0;
            var command          = new DelegateCommand <int>(i => executeParameter = i, i => (i % 2) == 0);

            Assert.That(executeParameter, Is.EqualTo(0));
            command.Execute(4);
            Assert.That(executeParameter, Is.EqualTo(4));
        }
        public void ExecuteNoPredicateWithArgument()
        {
            bool            called = false;
            DelegateCommand cmd    = new DelegateCommand((o) => called = true);

            Assert.IsTrue(cmd.CanExecute("x"), "Command should always be able to execute when no predicate is supplied.");
            cmd.Execute("x");
            Assert.IsTrue(called, "Command did not run supplied Action.");
        }
        public void ExecuteWithPredicate()
        {
            bool            called = false;
            DelegateCommand cmd    = new DelegateCommand((o) => called = true, (o) => true);

            Assert.IsTrue(cmd.CanExecute(null), "Command should be able to execute when predicate returns true.");
            cmd.Execute(null);
            Assert.IsTrue(called, "Command did not run supplied Action.");
        }
Example #29
0
        public void TestExecute()
        {
            var executed = false;
            var command  = new DelegateCommand(() => executed = true);

            Assert.That(executed, Is.False);
            command.Execute();
            Assert.That(executed, Is.True);
        }
Example #30
0
        public void ExecuteMethod_CanExecuteWithParameterInput()
        {
            var command = new DelegateCommand <string>(s => ExecuteMethod(s));

            _Parameter = "havn't raised";
            command.Execute("raised");

            Assert.AreEqual("raised", _Parameter);
        }
        public void Execute_WithoutCanExecute__DelegateCalled()
        {
            var called = false;
            var subject = new DelegateCommand(() => { called = true; });

            subject.Execute();

            Assert.IsTrue(called);
        }
        //Constructor//
        public MatchesViewModel(IApiServices api, IPageDialogService pageDialog, INavigationService navigationService) : base(pageDialog, navigationService)
        {
            apiServices = api;

            Title = "Games";

            GetLeaguesCommand = new DelegateCommand(async() => await GetLeagues());
            GetLeaguesCommand.Execute();
        }
Example #33
0
        public MainWindow()
        {
            OpenScreen = new DelegateCommand <ScreenInfo>(OpenScreenCommand_ExecuteMethod);

            InitializeComponent();
            var startScreenInfo = new ScreenInfo(new StartScreen(), new StartScreenViewModel(this));

            OpenScreen.Execute(startScreenInfo);
        }
Example #34
0
        public void WhenExecuteParameterIsNull_ThenExecutes()
        {
            var executed = false;
            var command = new DelegateCommand(() => executed = true, () => true);

            command.Execute(null);

            Assert.True(executed);
        }
Example #35
0
        public void WhenCanExecuteReturnsTrue_ThenExecutes()
        {
            var executed = false;
            var command = new DelegateCommand(() => executed = true, () => true);

            command.Execute(new object());

            Assert.True(executed);
        }
Example #36
0
        public void When_Parameter_Is_Null_And_Valid()
        {
            var target = new object();
            var cmd    = new DelegateCommand <object>(i => target = i);

            Assert.IsNotNull(target);
            cmd.Execute(null);
            Assert.IsNull(target);
        }
        public void Generic_DelegateCommand_Receives_Execute_Parameter()
        {
            int executeParameter = 0;
            var command          = new DelegateCommand <int>(x => executeParameter = x);

            command.Execute(55);

            Assert.That(executeParameter, Is.EqualTo(55));
        }
Example #38
0
        public void Execute_should_run_action()
        {
            bool flag    = false;
            var  command = new DelegateCommand(pm => flag = true);

            command.Execute(MockRepository.GenerateStub <IProgressMonitor>());

            Assert.IsTrue(flag);
        }
        public void ExecuteTest4()
        {
            bool executed = false;
            bool canExecute = false;
            DelegateCommand command = new DelegateCommand(() => executed = true, () => canExecute);

            AssertHelper.ExpectedException<InvalidOperationException>(() => command.Execute(null));
            Assert.IsFalse(executed);
        }
        public void Calling_Execute_Runs_Delegate()
        {
            bool commandWasRun = false;
            var  command       = new DelegateCommand(() => commandWasRun = true);

            command.Execute(null);

            Assert.That(commandWasRun);
        }
Example #41
0
        public void MissingExecuteDoesNothing()
        {
            ICommand cmd = new DelegateCommand
            {
                CanExecute = delegate { return(true); } // Just in case, for isolation.
            };

            cmd.Execute(null);
        }
Example #42
0
        public void ExecuteTest_CanExecute_True()
        {
            bool            executed   = false;
            bool            canExecute = true;
            DelegateCommand command    = new DelegateCommand(() => executed = true, () => canExecute);

            command.Execute();
            Assert.IsTrue(executed);
        }
        public DCCharactersPageViewModel(INavigationService navigationService, IPageDialogService dialogService, ApiComicsVine apiComicsVine, int offeset = 100) : base(navigationService, dialogService, apiComicsVine, DC_Comics, offeset)
        {
            LoadListCommand = new DelegateCommand(async () =>
            {
                await LoadCharacters(offeset);
            });
            LoadListCommand.Execute();

        }
Example #44
0
        public void WhenCanExecuteReturnsFalse_ThenDoesNotExecute()
        {
            var executed = false;
            var command = new DelegateCommand(() => executed = true, () => false);

            command.Execute(new object());

            Assert.False(executed);
        }
Example #45
0
        public void ExecuteCallsPassedInExecuteDelegate()
        {
            var    handlers  = new DelegateHandlers();
            var    command   = new DelegateCommand <object>(handlers.Execute);
            object parameter = new();

            command.Execute(parameter);
            Assert.Same(parameter, handlers.ExecuteParameter);
        }
        public void CanExecuteDelegateCommand()
        {
            bool goodExecute = false;
            Action<object> action = (o) => goodExecute = true;

            ICommand delegateCommand = new DelegateCommand(action);
            delegateCommand.Execute(null);

            Assert.IsTrue(goodExecute);
        }
            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 async Task ExecuteCallsPassedInExecuteDelegate()
        {
            var handlers = new DelegateHandlers();
            var command = new DelegateCommand<object>(handlers.Execute);
            object parameter = new object();

            await command.Execute(parameter);

            Assert.AreSame(parameter, handlers.ExecuteParameter);
        }
        public void ExecuteCallsPassedInExecuteDelegate()
        {
            var handlers = new DelegateHandlers();
            var command = new DelegateCommand<object>(handlers.Execute, null);
            object parameter = new object();

            command.Execute(parameter);

            Assert.AreSame(parameter, handlers.ExecuteParameter);
        }
        public void Execute_ObjectPassedAsParameter_ParameterPassedToExecuteDelegate()
        {
            object parameterPassed = null;
            Action<object> execute = param => parameterPassed = param;
            var command = new DelegateCommand(execute);

            object expectedParameter = new object();
            command.Execute(expectedParameter);

            Assert.AreEqual(expectedParameter, parameterPassed);
        }
        public void TestExecute()
        {
            int integer = 0;
            Action action = () => {
                integer = 10;
            };

            DelegateCommand command = new DelegateCommand(action);
            command.Execute(null);

            Assert.AreEqual(10, integer, "Die Action wurde vom DelegateCommand nicht ausgeführt.");
        }
Example #52
0
        public void ExecuteTest_CanExecute_True()
        {
            bool executed = false;
            DelegateCommand<object> command = new DelegateCommand<object>((o) =>
            {
                executed = true;
            }, (o) => true);

            object obj = new object();
            command.Execute(obj);
            Assert.IsTrue(executed);
        }
Example #53
0
 public void ExecuteInvokesAction()
 {
     var invoked = false;
     Action<object> action =
         o =>
             {
                 invoked = true;
             };
     var command = new DelegateCommand(action);
     command.Execute(null);
     Assert.IsTrue(invoked);
 }
Example #54
0
 public void ExecutePassesParameterToAction()
 {
     var parameter = new object();
     object passedParameter = null;
     Action<object> action =
         o =>
             {
                 passedParameter = o;
             };
     var command = new DelegateCommand(action);
     command.Execute(parameter);
     Assert.AreSame(parameter, passedParameter);
 }
        public void Execute_IsCalled_CallsActionFromConstructor()
        {
            // Setup
            //Action aTmp = nothing;
            Action aTmp = MockRepository.GenerateMock<Action>();
            DelegateCommand dcTestObj = new DelegateCommand(aTmp);

            // Test
            dcTestObj.Execute(null);

            // Verify
            aTmp.AssertWasCalled(t => t.Invoke());
        }
        public PurchaseTicketsViewModel() : base()
        {
            var synchronizer = ViewModelLocator.SynchronizerViewModel as SynchronizerViewModel;
            if (synchronizer != null)
            {
                SelectedAccount = synchronizer.Accounts[0];
            }

            FetchStakeDifficultyCommand = new DelegateCommand(FetchStakeDifficultyAsync);
            FetchStakeDifficultyCommand.Execute(null);

            _purchaseTickets = new DelegateCommand(PurchaseTicketsAction);
            _purchaseTickets.Executable = false;
        }
 public void DelegateCommand_Execute_PassingAnObject_ObjectPassedToAction()
 {
     //------------Setup for test--------------------------
     dynamic prop = null;
     var delegateCommand = new DelegateCommand(o =>
         {
             prop = o;
         });
     //------------Execute Test---------------------------
     delegateCommand.Execute(new { Name = "Tshepo", Surname = "Ntlhokoa" });
     //------------Assert Results-------------------------
     Assert.IsNotNull(prop);
     Assert.IsNotNull("Tshepo", prop.Name);
     Assert.IsNotNull("Ntlhokoa", prop.Surname);
 }
        public void ExecuteTest2()
        {
            bool executed = false;
            object commandParameter = null;
            DelegateCommand command = new DelegateCommand((object parameter) =>
            {
                executed = true;
                commandParameter = parameter;
            });

            object obj = new object();
            command.Execute(obj);
            Assert.IsTrue(executed);
            Assert.AreEqual(obj, commandParameter);
        }
Example #59
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 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);
            }