コード例 #1
0
        public async Task ExecuteTheCommandOnlyIfTheCommandCanBeExecuted_ReturnTrueIfTheCommandWasExecuted_OtherwiseFalse_IBoundedCommandSlim()
        {
            int  executeCount           = 0;
            bool isEnabled              = true;
            IBoundedCommandSlim command = new BoundedRelayCommandSlim(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_IBoundedCommandSlim()
        {
            int  executeCount = 0;
            bool isEnabled    = true;
            IBoundedCommandSlim <int> command = new BoundedRelayCommandSlim <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);
        }