PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/V2.2/trunk/CAL/Desktop/Composite.Presentation.Tests/Regions/RegionBehaviorCollectionFixture.cs

#
C# | 59 lines | 35 code | 8 blank | 16 comment | 0 complexity | 2ecc49960b1b1b93e4b451726acfb4ae 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.Regions;
18using Microsoft.Practices.Composite.Presentation.Tests.Mocks;
19using Microsoft.VisualStudio.TestTools.UnitTesting;
20
21namespace Microsoft.Practices.Composite.Presentation.Tests.Regions
22{
23    [TestClass]
24    public class RegionBehaviorCollectionFixture
25    {
26        [TestMethod]
27        public void CanAttachRegionBehaviors()
28        {
29            RegionBehaviorCollection behaviorCollection = new RegionBehaviorCollection(new MockRegion());
30
31            var mock1 = new MockRegionBehavior();
32            bool mock1Attached = false;
33            mock1.OnAttach = () => mock1Attached = true;
34            behaviorCollection.Add("Mock1", mock1);
35
36            var mock2 = new MockRegionBehavior();
37            bool mock2Attached = false;
38            mock2.OnAttach = () => mock2Attached = true;
39            behaviorCollection.Add("Mock2", mock2);
40
41            Assert.IsTrue(mock1Attached);
42            Assert.IsTrue(mock2Attached);
43        }
44
45        [TestMethod]
46        public void ShouldAddRegionWhenAddingBehavior()
47        {
48            var region = new MockRegion();
49            RegionBehaviorCollection behaviorCollection = new RegionBehaviorCollection(region);
50            var behavior = new MockRegionBehavior();
51
52            behaviorCollection.Add("Mock", behavior);
53
54            Assert.IsNotNull(behavior.Region);
55            Assert.AreSame(region, behavior.Region);
56        }
57
58    }
59}