PageRenderTime 18ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/V4/PrismLibrary/Desktop/Prism.Tests/Mocks/MockCommand.cs

#
C# | 51 lines | 30 code | 5 blank | 16 comment | 2 complexity | f40daa8eca4384cfad0ade932ffbb326 MD5 | raw file
 1//===================================================================================
 2// Microsoft patterns & practices
 3// Composite Application Guidance for Windows Presentation Foundation and Silverlight
 4//===================================================================================
 5// Copyright (c) Microsoft Corporation.  All rights reserved.
 6// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
 7// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
 8// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 9// FITNESS FOR A PARTICULAR PURPOSE.
10//===================================================================================
11// The example companies, organizations, products, domain names,
12// e-mail addresses, logos, people, places, and events depicted
13// herein are fictitious.  No association with any real company,
14// organization, product, domain name, email address, logo, person,
15// places, or events is intended or should be inferred.
16//===================================================================================
17using System;
18using System.Windows.Input;
19
20namespace Microsoft.Practices.Prism.Tests.Mocks
21{
22    internal class MockCommand : ICommand
23    {
24        public bool ExecuteCalled { get; set; }
25        public bool CanExecuteReturnValue = true;
26        public object ExecuteParameter;
27        public object CanExecuteParameter;
28        public int CanExecuteTimesCalled;
29
30        public event EventHandler CanExecuteChanged;
31
32        public void Execute(object parameter)
33        {
34            ExecuteCalled = true;
35            ExecuteParameter = parameter;
36        }
37
38        public bool CanExecute(object parameter)
39        {
40            CanExecuteTimesCalled++;
41            CanExecuteParameter = parameter;
42            return CanExecuteReturnValue;
43        }
44
45        public void RaiseCanExecuteChanged()
46        {
47            if (this.CanExecuteChanged != null)
48                this.CanExecuteChanged(this, EventArgs.Empty);
49        }
50    }
51}