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