|
using System.Windows;
using System.Windows.Input;
using CodeProject.Windows.Markup;
namespace CodeProject.VisualStudio.QualityTools.UnitTestFramework
{
public class CommandTester
{
private RoutedCommand command;
private FrameworkElement element = new FrameworkElement();
public CommandTester(object viewModel, RoutedCommand command)
{
this.command = command;
ViewModel.SetInstance(element, viewModel);
}
public CommandTester(object viewModel, string commands, RoutedCommand command)
{
this.command = command;
ViewModel.SetInstance(element, viewModel);
ViewModel.SetCommands(element, commands);
}
public CommandTester(RoutedCommand command, ExecutedRoutedEventHandler executedHandler)
: this(command, executedHandler, null)
{
}
public CommandTester(RoutedCommand command, ExecutedRoutedEventHandler executedHandler,
CanExecuteRoutedEventHandler canExecuteHandler)
{
this.command = command;
element.CommandBindings.Add(new CommandBinding(this.command, executedHandler, canExecuteHandler));
}
public bool CanExecute()
{
return CanExecute(null);
}
public bool CanExecute(object commandParameter)
{
return command.CanExecute(commandParameter, element);
}
public void Execute()
{
Execute(null);
}
public void Execute(object commandParameter)
{
command.Execute(commandParameter, element);
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Windows developer with 10+ years experience working in the banking industry.