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

/V2.2/trunk/RI/Desktop/StockTraderRI.Infrastructure.Tests/TreeHelperFixture.cs

#
C# | 53 lines | 31 code | 6 blank | 16 comment | 2 complexity | 886a243033b7b8031254b62f74afbdf2 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.Windows.Controls;
18using Microsoft.VisualStudio.TestTools.UnitTesting;
19
20namespace StockTraderRI.Infrastructure.Tests
21{
22    [TestClass]
23    public class TreeHelperFixture
24    {
25        [TestMethod]
26        public void ShouldFindDirectAncestor()
27        {
28            ContentControl parent = new ContentControl();
29            TextBlock child = new TextBlock();
30            parent.Content = child;
31
32            var foundParent = TreeHelper.FindAncestor(child, d => d == parent);
33
34            Assert.IsNotNull(foundParent);
35            Assert.AreSame(parent, foundParent);
36        }
37
38        [TestMethod]
39        public void ShouldFindIndirectAncestor()
40        {
41            ContentControl grandParent = new ContentControl();
42            ContentControl parent = new ContentControl();
43            TextBlock child = new TextBlock();
44            grandParent.Content = parent;
45            parent.Content = child;
46
47            var foundGrandParent = TreeHelper.FindAncestor(child, d => d == grandParent);
48
49            Assert.IsNotNull(foundGrandParent);
50            Assert.AreSame(grandParent, foundGrandParent);
51        }
52    }
53}