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