예제 #1
0
        public async Task ExecuteTheCommandOnlyIfTheCommandCanBeExecuted_ReturnTrueIfTheCommandWasExecuted_OtherwiseFalse_IBoundedCommand()
        {
            int             executeCount = 0;
            bool            isEnabled    = true;
            IBoundedCommand command      = new BoundedRelayCommand(async() => { await Task.Yield(); executeCount++; }, () => isEnabled);

            Assert.True(command.CanExecute());
            Assert.True(await command.TryExecuteAsync());
            Assert.Equal(1, executeCount);

            isEnabled = false;
            Assert.False(command.CanExecute());
            Assert.False(await command.TryExecuteAsync());
            Assert.Equal(1, executeCount);
        }
예제 #2
0
        public async Task Return_TrueIfTheCommandHasBeenExecuted_FalseIfTheCommandHasNotBeenExecuted_IBoundedCommand()
        {
            int  executeCount             = 0;
            bool isEnabled                = true;
            IBoundedCommand <int> command = new BoundedRelayCommand <int>(async integer => { await Task.Yield(); executeCount += integer; }, _ => isEnabled);

            Assert.True(command.CanExecute(9));
            Assert.True(await command.TryExecuteAsync(9));
            Assert.Equal(9, executeCount);

            isEnabled = false;
            Assert.False(command.CanExecute(9));
            Assert.False(await command.TryExecuteAsync(9));
            Assert.Equal(9, executeCount);
        }