PageRenderTime 52ms CodeModel.GetById 18ms RepoModel.GetById 0ms 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. //===================================================================================
  17. using System.Windows.Controls;
  18. using Microsoft.VisualStudio.TestTools.UnitTesting;
  19. namespace StockTraderRI.Infrastructure.Tests
  20. {
  21. [TestClass]
  22. public class TreeHelperFixture
  23. {
  24. [TestMethod]
  25. public void ShouldFindDirectAncestor()
  26. {
  27. ContentControl parent = new ContentControl();
  28. TextBlock child = new TextBlock();
  29. parent.Content = child;
  30. var foundParent = TreeHelper.FindAncestor(child, d => d == parent);
  31. Assert.IsNotNull(foundParent);
  32. Assert.AreSame(parent, foundParent);
  33. }
  34. [TestMethod]
  35. public void ShouldFindIndirectAncestor()
  36. {
  37. ContentControl grandParent = new ContentControl();
  38. ContentControl parent = new ContentControl();
  39. TextBlock child = new TextBlock();
  40. grandParent.Content = parent;
  41. parent.Content = child;
  42. var foundGrandParent = TreeHelper.FindAncestor(child, d => d == grandParent);
  43. Assert.IsNotNull(foundGrandParent);
  44. Assert.AreSame(grandParent, foundGrandParent);
  45. }
  46. }
  47. }