PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/V4/Quickstarts/Modularity/ModularityWithMef.Tests.AcceptanceTest/ModularityWithMef.Tests.AcceptanceTest/Desktop/ModularityWithMef.Desktop.test.cs

#
C# | 190 lines | 130 code | 25 blank | 35 comment | 0 complexity | 1bd1257a442f48c2a032c83be77d83cc 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;
  18. using System.Text;
  19. using System.Collections.Generic;
  20. using System.Linq;
  21. using Microsoft.VisualStudio.TestTools.UnitTesting;
  22. using AcceptanceTestLibrary.Common;
  23. using AcceptanceTestLibrary.Common.Desktop;
  24. using System.Reflection;
  25. using ModularityWithMef.Tests.AcceptanceTest.TestEntities.Page;
  26. using System.Threading;
  27. using AcceptanceTestLibrary.TestEntityBase;
  28. using AcceptanceTestLibrary.ApplicationHelper;
  29. using AcceptanceTestLibrary.UIAWrapper;
  30. using System.Windows.Automation;
  31. using System.Drawing;
  32. namespace ModularityWithMef.Tests.AcceptanceTest
  33. {
  34. #if DEBUG
  35. [DeploymentItem(@".\ModularityWithMef.Tests.AcceptanceTest\bin\Debug")]
  36. [DeploymentItem(@"..\Desktop\ModularityWithMef\ModularityWithMef.Desktop\bin\Debug", "WPF")]
  37. #else
  38. [DeploymentItem(@".\ModularityWithMef.Tests.AcceptanceTest\bin\Release")]
  39. [DeploymentItem(@"..\Desktop\ModularityWithMef\ModularityWithMef.Desktop\bin\Release", "WPF")]
  40. #endif
  41. [TestClass]
  42. public class MefDesktopTests : FixtureBase<WpfAppLauncher>
  43. {
  44. #region Additional test attributes
  45. [TestInitialize]
  46. public void TestInitialize()
  47. {
  48. string currentOutputPath = (new System.IO.DirectoryInfo(Assembly.GetExecutingAssembly().Location)).Parent.FullName;
  49. ModularityPage<WpfAppLauncher>.Window = base.LaunchApplication(currentOutputPath + GetDesktopApplication(), GetDesktopApplicationTitle())[0];
  50. ModularityPage<WpfAppLauncher>.Window.SetFocus();
  51. Thread.Sleep(5000);
  52. }
  53. // Use TestCleanup to run code after each test has run
  54. [TestCleanup()]
  55. public void MyTestCleanup()
  56. {
  57. UnloadApplication();
  58. }
  59. #endregion
  60. [TestMethod]
  61. //[Ignore]
  62. public void DesktopModularityLaunchTest()
  63. {
  64. Assert.IsNotNull(ModularityPage<WpfAppLauncher>.Window, "Modularity QuickStart - Desktop with MEF is not launched");
  65. }
  66. [TestMethod]
  67. //[Ignore]
  68. public void DesktopModulesLoadedOnStartup()
  69. {
  70. AutomationElement aeModuleA = ModularityPage<WpfAppLauncher>.ModuleA;
  71. Thread.Sleep(1000);
  72. AutomationElement aeClickToloadModuleA = aeModuleA.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  73. Assert.IsTrue(aeClickToloadModuleA.Current.IsOffscreen, "Module A is not initialized at startup");
  74. AutomationElement aeModuleD = ModularityPage<WpfAppLauncher>.ModuleD;
  75. AutomationElement aeClickToloadModuleD = aeModuleD.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  76. Assert.IsTrue(aeClickToloadModuleD.Current.IsOffscreen, "Module D is not initialized at startup");
  77. }
  78. [TestMethod]
  79. //[Ignore]
  80. public void DesktopLoadModuleBOnDemand()
  81. {
  82. //Check if Module B is already loaded
  83. AutomationElement aeModuleB = ModularityPage<WpfAppLauncher>.ModuleB;
  84. AutomationElement aeClickToloadModuleB = aeModuleB.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  85. Assert.IsFalse(aeClickToloadModuleB.Current.IsOffscreen, "Module B is initialized");
  86. //Get the clickable point and click on it.
  87. System.Windows.Point clickablePoint = aeModuleB.GetClickablePoint();
  88. System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);
  89. Thread.Sleep(1000);
  90. MouseEvents.Click();
  91. //Check if Module B is loaded
  92. AutomationElement aeClickToloadModB = aeModuleB.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  93. Assert.IsTrue(aeClickToloadModB.Current.IsOffscreen, "Module B is not initialized");
  94. }
  95. [TestMethod]
  96. //[Ignore]
  97. public void DesktopLoadModuleCOnDemand()
  98. {
  99. //Check if Module C is already loaded
  100. AutomationElement aeModuleC = ModularityPage<WpfAppLauncher>.ModuleC;
  101. AutomationElement aeClickToloadModuleC = aeModuleC.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  102. Assert.IsFalse(aeClickToloadModuleC.Current.IsOffscreen, "Module C is initialized");
  103. //Get the clickable point and click on it.
  104. System.Windows.Point clickablePoint = aeModuleC.GetClickablePoint();
  105. System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);
  106. Thread.Sleep(1000);
  107. MouseEvents.Click();
  108. //Check if Module C is loaded
  109. AutomationElement aeClickToloadModC = aeModuleC.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  110. Assert.IsTrue(aeClickToloadModC.Current.IsOffscreen, "Module C is not initialized");
  111. }
  112. [TestMethod]
  113. public void DesktopLoadModuleEOnDemand()
  114. {
  115. //Check if Module E is already loaded
  116. AutomationElement aeModuleE = ModularityPage<WpfAppLauncher>.ModuleE;
  117. AutomationElement aeClickToloadModuleE = aeModuleE.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  118. Assert.IsFalse(aeClickToloadModuleE.Current.IsOffscreen, "Module E is initialized");
  119. //Get the clickable point and click on it.
  120. System.Windows.Point clickablePoint = aeModuleE.GetClickablePoint();
  121. System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);
  122. Thread.Sleep(1000);
  123. MouseEvents.Click();
  124. Thread.Sleep(1000);
  125. //Check if Module E is loaded
  126. AutomationElement aeClickToloadModE = aeModuleE.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  127. Assert.IsTrue(aeClickToloadModE.Current.IsOffscreen, "Module E is not initialized");
  128. //Check if Module F is also loaded
  129. AutomationElement aeModuleF = ModularityPage<WpfAppLauncher>.ModuleF;
  130. AutomationElement aeClickToloadModuleF = aeModuleF.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  131. Assert.IsFalse(aeClickToloadModuleF.Current.IsOffscreen, "Module F is also initialized");
  132. }
  133. [TestMethod]
  134. public void DesktopLoadModuleFAndDependency()
  135. {
  136. //Check if Module F is already loaded
  137. AutomationElement aeModuleF = ModularityPage<WpfAppLauncher>.ModuleF;
  138. AutomationElement aeClickToloadModuleF = aeModuleF.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  139. Assert.IsFalse(aeClickToloadModuleF.Current.IsOffscreen, "Module F is initialized");
  140. //Get the clickable point and click on it.
  141. System.Windows.Point clickablePoint = aeModuleF.GetClickablePoint();
  142. System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)clickablePoint.X, (int)clickablePoint.Y);
  143. Thread.Sleep(1000);
  144. MouseEvents.Click();
  145. Thread.Sleep(1000);
  146. //Check if depency module (Module E) is loaded
  147. AutomationElement aeModuleE = ModularityPage<WpfAppLauncher>.ModuleE;
  148. AutomationElement aeClickToloadModE = aeModuleE.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  149. Assert.IsTrue(aeClickToloadModE.Current.IsOffscreen, "Module E is not initialized");
  150. //Check if Module F is loaded
  151. AutomationElement aeClickToloadModF = aeModuleF.FindElementByContent(new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("ClickToLoadTextBlock"));
  152. Assert.IsTrue(aeClickToloadModF.Current.IsOffscreen, "Module F is not initialized");
  153. }
  154. #region Private methods
  155. private static string GetDesktopApplication()
  156. {
  157. return ConfigHandler.GetValue("WpfAppLocation");
  158. }
  159. private static string GetDesktopApplicationTitle()
  160. {
  161. return new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("DesktopApplicationTitle");
  162. }
  163. #endregion
  164. }
  165. }