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

/V1/trunk/Source/QuickStarts/Modularity/Modularity.Tests.AcceptanceTests/AutomatedTests/FixtureBase.cs

#
C# | 103 lines | 65 code | 15 blank | 23 comment | 3 complexity | 950014c26c00b14dca2d99639e08a4cf MD5 | raw file
  1//===============================================================================
  2// Microsoft patterns & practices
  3// Composite Application Guidance for Windows Presentation Foundation
  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
 18using System;
 19using System.Collections.Generic;
 20using System.Linq;
 21using System.Text;
 22using Modularity.AcceptanceTests.ApplicationObserver;
 23using Core;
 24using Core.UIItems.WindowItems;
 25using Modularity.AcceptanceTests.TestInfrastructure;
 26using System.Collections.Specialized;
 27using Modularity.AcceptanceTests.Helpers;
 28using Core.Configuration;
 29using System.Globalization;
 30
 31namespace Modularity.AcceptanceTests
 32{
 33    public abstract class FixtureBase : IStateObserver
 34    {
 35        private Application app;
 36        private Window window;
 37        private TestDataInfrastructure testDataInfrastructure;       
 38
 39        public Window Window
 40        {
 41            get { return window; }
 42        }
 43
 44        public TestDataInfrastructure TestDataInfrastructure
 45        {
 46            get { return testDataInfrastructure; }
 47        }
 48
 49        public void TestInitialize()
 50        {
 51            SetupWhiteConfigParameters();
 52
 53            // Instantiate and initiate the diagnosis process. Diagnosis steps are included
 54            // to identify the successful launch of the application window without any unexpected
 55            // exceptions.
 56            StateDiagnosis.Instance.StartDiagnosis(this);
 57
 58            app = Application.Launch(GetApplicationToLaunch());
 59            window = app.GetWindow(GetApplicationWindowName(), Core.Factory.InitializeOption.NoCache);
 60            testDataInfrastructure = new TestDataInfrastructure();
 61
 62            //Stop the diagnosis.
 63            StateDiagnosis.Instance.StopDiagnosis(this);
 64        }
 65
 66        /// <summary>
 67        /// TestCleanup performs clean-up activities after each test method execution
 68        /// </summary>
 69        public void TestCleanup()
 70        {
 71            if (null != app)
 72            {
 73                app.Kill();
 74            }
 75        }
 76
 77        public abstract string GetApplicationToLaunch();
 78        public abstract string GetApplicationWindowName();
 79
 80        private static void SetupWhiteConfigParameters()
 81        {
 82            NameValueCollection collection = ConfigHandler.GetConfigSection("White/Core");
 83
 84            Type coreAppXmlConfigType = CoreAppXmlConfiguration.Instance.GetType();
 85            foreach (string property in collection.Keys)
 86            {
 87                if (coreAppXmlConfigType.GetProperty(property).PropertyType.Equals(typeof(Int32)))
 88                {
 89                    coreAppXmlConfigType.GetProperty(property).SetValue(CoreAppXmlConfiguration.Instance, Convert.ToInt32(collection[property],CultureInfo.InvariantCulture), null);
 90                }
 91            }
 92        }
 93
 94        #region IStateObserver Members
 95
 96        public void Notify()
 97        {
 98            TestCleanup();
 99        }
100
101        #endregion
102    }
103}