本文整理汇总了C#中Command.CanExecute方法的典型用法代码示例。如果您正苦于以下问题:C# Command.CanExecute方法的具体用法?C# Command.CanExecute怎么用?C# Command.CanExecute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Command
的用法示例。
在下文中一共展示了Command.CanExecute方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanExecuteShouldInvokeCallback
public void CanExecuteShouldInvokeCallback()
{
// arrange
var canExecute = new Mock<Func<object, bool>>();
canExecute.Setup( f => f( It.IsAny<object>() ) ).Returns( true );
var command = new Command<object>( DefaultAction.None, canExecute.Object );
// act
command.CanExecute();
// assert
canExecute.Verify( f => f( null ), Times.Once() );
}
示例2: CanExecute_ShouldReturnCorrectValue
public void CanExecute_ShouldReturnCorrectValue(
bool canExecute,
object arg,
ISchedulers schedulers,
Mock<ICanExecuteStrategy<object>> canExecuteStrat)
{
//arrange
canExecuteStrat.Setup(c => c.CanExecute(It.IsAny<object>())).Returns(canExecute);
var sut = new Command<object>(o => { }, schedulers, "name", canExecuteStrat.Object);
//act
var actual = sut.CanExecute(arg);
//assert
actual.Should().Be(canExecute);
}
示例3: CanExecute_ShouldBeCalledWithArg
public void CanExecute_ShouldBeCalledWithArg(
object arg,
ISchedulers schedulers,
Mock<ICanExecuteStrategy<object>> canExecuteStrat)
{
//arrange
object actual = null;
canExecuteStrat.Setup(c => c.CanExecute(It.IsAny<object>())).Returns(true);
var sut = new Command<object>(o => { }, schedulers, "name", canExecuteStrat.Object);
//act
sut.CanExecute(arg);
//assert
canExecuteStrat.Verify(c => c.CanExecute(arg));
}
示例4: RunTest
internal IEnumerable<SelectedItemCollection> RunTest( IEnumerable<SelectedItemCollection> selections )
{
PutInOrgView(false);
Command = CreateCommand();
((ICommand)Command).SetMainWindow(Program.MainWindow.CommandInterface);
bool noneExecuted = true;
foreach (SelectedItemCollection selection in selections)
{
((ICommand)Command).SetSelection(selection);
if (MW<bool>(() => Command.CanExecute()))
{
noneExecuted = false;
SelectNodes(selection);
yield return selection;
}
}
Assert.IsFalse(noneExecuted, "No tests were executed");
}
示例5: CanExecute
public void CanExecute ([Values (true, false)] bool expected)
{
bool canExecuteRan = false;
var cmd = new Command (() => { }, () => {
canExecuteRan = true;
return expected;
});
Assert.AreEqual(expected, cmd.CanExecute (null));
Assert.True (canExecuteRan);
}
示例6: GenericCanExecute
public void GenericCanExecute ([Values (true, false)] bool expected)
{
string result = null;
var cmd = new Command<string> (s => { }, s => {
result = s;
return expected;
});
Assert.AreEqual (expected, cmd.CanExecute ("Foo"));
Assert.AreEqual ("Foo", result);
}
示例7: Constructor
public void Constructor ()
{
var cmd = new Command (() => { });
Assert.True (cmd.CanExecute (null));
}
示例8: TestCanExecIfTrue
public void TestCanExecIfTrue()
{
Command<object> command = new Command<object>(Mock.Of<Action<object>>(), () => true);
Assert.IsTrue(command.CanExecute(null));
}