PageRenderTime 23ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/V2.2/trunk/CAL/Desktop/Composite.Presentation.Tests/Commands/ClickFixture.cs

#
C# | 94 lines | 62 code | 16 blank | 16 comment | 0 complexity | c6b42dc36c1dfadcf8917adbb73d68c4 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 Microsoft.Practices.Composite.Presentation.Commands;
18using Microsoft.Practices.Composite.Presentation.Tests.Mocks;
19using Microsoft.VisualStudio.TestTools.UnitTesting;
20
21namespace Microsoft.Practices.Composite.Presentation.Tests.Commands
22{
23    [TestClass]
24    public class ClickFixture
25    {
26        [TestMethod]
27        public void ShouldHookUpClickCommandBehaviorWhenSettingProperty()
28        {
29            var clickableObject = new MockClickableObject();
30            var command = new MockCommand();
31
32            Click.SetCommand(clickableObject, command);
33            Assert.IsFalse(command.ExecuteCalled);
34
35            clickableObject.RaiseClick();
36
37            Assert.IsTrue(command.ExecuteCalled);
38            Assert.AreSame(command, Click.GetCommand(clickableObject));
39        }
40
41        [TestMethod]
42        public void ShouldUpdateCommandOnBehaviorWhenChangingProperty()
43        {
44            var clickableObject = new MockClickableObject();
45            var oldCommand = new MockCommand();
46            var newCommand = new MockCommand();
47
48            Click.SetCommand(clickableObject, oldCommand);
49            Click.SetCommand(clickableObject, newCommand);
50
51            clickableObject.RaiseClick();
52
53            Assert.IsTrue(newCommand.ExecuteCalled);
54            Assert.IsFalse(oldCommand.ExecuteCalled);
55        }
56
57        [TestMethod]
58        public void ShouldExecuteWithCommandParameter()
59        {
60            var clickableObject = new MockClickableObject();
61            var command = new MockCommand();
62            var parameter = new object();
63
64            Click.SetCommand(clickableObject, command);
65            Click.SetCommandParameter(clickableObject, parameter);
66            Assert.IsNull(command.ExecuteParameter);
67
68            clickableObject.RaiseClick();
69
70            Assert.IsTrue(command.ExecuteCalled);
71            Assert.IsNotNull(command.ExecuteParameter);
72            Assert.AreSame(parameter, command.ExecuteParameter);
73        }
74
75        [TestMethod]
76        public void ShouldCallCanExecuteOnParameterChange()
77        {
78            var clickableObject = new MockClickableObject();
79
80            var command = new MockCommand();
81            var parameter = new object();
82            Click.SetCommand(clickableObject, command);
83            Assert.IsNull(command.CanExecuteParameter);
84            Assert.IsTrue(clickableObject.IsEnabled);
85
86            command.CanExecuteReturnValue = false;
87            Click.SetCommandParameter(clickableObject, parameter);
88
89            Assert.IsNotNull(command.CanExecuteParameter);
90            Assert.AreSame(parameter, command.CanExecuteParameter);
91            Assert.IsFalse(clickableObject.IsEnabled);
92        }
93    }
94}