PageRenderTime 45ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/V2.2/trunk/Quickstarts/Modularity/Modularity.Tests.AcceptanceTest/Modularity.Tests.AcceptanceTest/RemoteModuleLoading/RemoteModuleLoadingSilverlightFixture.cs

#
C# | 159 lines | 107 code | 23 blank | 29 comment | 3 complexity | 702c2b3893c9fa79711040701cd6b09c 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 System.Threading;
  23. using System.IO;
  24. using System.Diagnostics;
  25. using System.Windows;
  26. using System.Windows.Forms;
  27. using System.Windows.Automation;
  28. using System.Windows.Automation.Peers;
  29. using System.Windows.Automation.Text;
  30. using System.Windows.Automation.Provider;
  31. using AcceptanceTestLibrary.Common;
  32. using Modularity.Tests.AcceptanceTest.TestEntities.Page;
  33. using AcceptanceTestLibrary.ApplicationObserver;
  34. using AcceptanceTestLibrary.Common.Silverlight;
  35. using Modularity.Tests.AcceptanceTest.TestEntities.Assertion;
  36. using Modularity.Tests.AcceptanceTest.TestEntities.Action;
  37. using System.Configuration;
  38. using AcceptanceTestLibrary.ApplicationHelper;
  39. using System.Collections.Specialized;
  40. using System.Text.RegularExpressions;
  41. using AcceptanceTestLibrary.TestEntityBase;
  42. namespace Modularity.Tests.AcceptanceTest.RemoteModuleLoading.Silverlight
  43. {
  44. /// <summary>
  45. /// Summary description for SilverlightAcceptanceTest
  46. /// </summary>
  47. #if DEBUG
  48. [DeploymentItem(@"..\RemoteModularityQuickstart\RemoteModuleLoading.Silverlight\Bin\Debug\")]
  49. [DeploymentItem(@".\Modularity.Tests.AcceptanceTest\bin\Debug\")]
  50. #else
  51. [DeploymentItem(@"..\RemoteModularityQuickstart\RemoteModuleLoading.Silverlight\Bin\Release\")]
  52. [DeploymentItem(@".\Modularity.Tests.AcceptanceTest\bin\Release\")]
  53. #endif
  54. [TestClass]
  55. public class RemoteModuleLoadingSilverlightFixture : FixtureBase<SilverlightAppLauncher>
  56. {
  57. #region Additional test attributes
  58. // Use TestInitialize to run code before running each test
  59. [TestInitialize()]
  60. public void MyTestInitialize()
  61. {
  62. //Launch Cassini server
  63. const int BACKTRACKLENGTH = 5;
  64. string pp = GetAbsolutePath(BACKTRACKLENGTH);
  65. //Parameter list as follows.
  66. //1. Port number of host application 2. Absolute path of the Silverlight Host.
  67. base.StartWebServer(GetPortNumber(GetSilverlightApplication()), GetAbsolutePath(BACKTRACKLENGTH) + GetSilverlightApplicationHostPath());
  68. Shell<SilverlightAppLauncher>.Window = base.LaunchApplication(GetSilverlightApplication(), GetBrowserTitle())[0];
  69. }
  70. // Use TestCleanup to run code after each test has run
  71. [TestCleanup()]
  72. public void MyTestCleanup()
  73. {
  74. PageBase<SilverlightAppLauncher>.DisposeWindow();
  75. SilverlightAppLauncher.UnloadBrowser(GetBrowserTitle());
  76. base.StopWebServer();
  77. }
  78. #endregion
  79. #region Test Methods
  80. [TestMethod]
  81. public void RemoteModuleSilverlightApplicationLoadTest()
  82. {
  83. Assert.IsNotNull(Shell<SilverlightAppLauncher>.Window, "Remote Module Loading is not launched.");
  84. }
  85. [TestMethod]
  86. public void RemoteModuleSilverlightModuleLoadTest()
  87. {
  88. ShellAssertion<SilverlightAppLauncher>.AssertRemoteModuleLoading();
  89. }
  90. [TestMethod]
  91. public void RemoteModuleSilverlightLoadModuleXOnDemand()
  92. {
  93. ShellAction<SilverlightAppLauncher>.LoadModuleXOnDemand();
  94. ShellAssertion<SilverlightAppLauncher>.AssertOnDemandRemoteModuleXLoading();
  95. }
  96. #endregion
  97. #region Private Methods
  98. private static string GetSilverlightApplication()
  99. {
  100. return ConfigHandler.GetValue("RemoteModuleSilverlightAppLocation");
  101. }
  102. private static string GetSilverlightApplicationHostPath()
  103. {
  104. return ConfigHandler.GetValue("RemoteModuleSilverlightAppHostRelativeLocation");
  105. }
  106. private static string GetBrowserTitle()
  107. {
  108. return new ResXConfigHandler(ConfigHandler.GetValue("ControlIdentifiersFile")).GetValue("SilverlightAppTitleRemoteModule");
  109. }
  110. private static string GetAbsolutePath(int backTrackLength)
  111. {
  112. string currentDirectory = Directory.GetCurrentDirectory();
  113. if (!String.IsNullOrEmpty(currentDirectory) && Directory.Exists(currentDirectory))
  114. {
  115. for (int iIndex = 0; iIndex < backTrackLength; iIndex++)
  116. {
  117. currentDirectory = Directory.GetParent(currentDirectory).ToString();
  118. }
  119. }
  120. return currentDirectory;
  121. }
  122. /// <summary>
  123. /// Extract the Port number from a URL of the format http://ServerName:PortNumber/SitePath
  124. /// </summary>
  125. /// <param name="url">URL of the above format</param>
  126. /// <returns>port number sub-string</returns>
  127. private static string GetPortNumber(string url)
  128. {
  129. string urlPattern = @"^(?<proto>\w+)://[^/]+?(?<port>:\d+)?/";
  130. Regex urlExpression = new Regex(urlPattern, RegexOptions.Compiled);
  131. Match urlMatch = urlExpression.Match(url);
  132. return urlMatch.Groups["port"].Value;
  133. }
  134. #endregion
  135. }
  136. }