PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/V1/trunk/Source/QuickStarts/UIComposition/UIComposition.Tests.AcceptanceTests/AutomatedTests/ModuleFixtures/EmployeeModuleFixture.cs

#
C# | 277 lines | 154 code | 44 blank | 79 comment | 1 complexity | 33ff59c49b46ee52f6a0b6cd81ada3a5 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 Microsoft.VisualStudio.TestTools.UnitTesting;
  22. using UIComposition.AcceptanceTests.Helpers;
  23. using UIComposition.AcceptanceTests.ApplicationObserver;
  24. using System.Threading;
  25. using Core.UIItems;
  26. using Core.UIItems.TabItems;
  27. using UIComposition.AcceptanceTests.TestInfrastructure;
  28. using Core.UIItems.Finders;
  29. namespace UIComposition.AcceptanceTests.AutomatedTests
  30. {
  31. [TestClass]
  32. [DeploymentItem(@".\UIComposition\bin\Debug")]
  33. [DeploymentItem(@".\UIComposition.Tests.AcceptanceTests\bin\Debug")]
  34. public class EmployeeModuleFixture : FixtureBase
  35. {
  36. [TestInitialize()]
  37. public void MyTestInitialize()
  38. {
  39. // Check whether any exception occured during previous application launches.
  40. // If so, fail the test case.
  41. if (StateDiagnosis.IsFailed)
  42. {
  43. Assert.Fail(TestDataInfrastructure.GetTestInputData("ApplicationLoadFailure"));
  44. }
  45. base.TestInitialize();
  46. }
  47. /// <summary>
  48. /// TestCleanup performs clean-up activities after each test method execution
  49. /// </summary>
  50. [TestCleanup()]
  51. public void MyTestCleanup()
  52. {
  53. base.TestCleanup();
  54. }
  55. /// <summary>
  56. /// Validate if the details view of the selected employee are displayed correctly.
  57. ///
  58. /// Repro Steps:
  59. /// 1. Launch the QS application
  60. /// 2. Click on the first employee row in the Employee List table
  61. /// 3. Check if the Details View Tab is displayed, and the number of tab items is 3.
  62. /// 4. Check if the tab items headers match with "General", "Location" and "Current Projects"
  63. ///
  64. /// Expected Result:
  65. /// Details View Tab is dispalyed with 3 tab items.
  66. /// The tab items headers match with "General", "Location" and "Current Projects"
  67. /// </summary>
  68. [TestMethod]
  69. [WorkItem(0)]
  70. public void ValidateEmployeeSelection()
  71. {
  72. //select first row (employee)
  73. ListView list = Window.Get<ListView>(TestDataInfrastructure.GetControlId("EmployeesList"));
  74. list.SelectEmployee(0);
  75. //validate details view
  76. Tab empDetailsTab = Window.Get<Tab>(TestDataInfrastructure.GetControlId("DetailsTabControl"));
  77. Assert.IsNotNull(empDetailsTab, TestDataInfrastructure.GetTestInputData("EmpDetailsTabNotFound"));
  78. //validate tab has three tab items, and their names are "General", "Location" and "Current Projects"
  79. Assert.AreEqual(3, empDetailsTab.Pages.Count, TestDataInfrastructure.GetTestInputData("EmpDetailsTabPagesCount"));
  80. Assert.IsTrue(
  81. (empDetailsTab.Pages[0].NameMatches(TestDataInfrastructure.GetTestInputData("EmpDetailsTabGeneral")) &&
  82. empDetailsTab.Pages[1].NameMatches(TestDataInfrastructure.GetTestInputData("EmpDetailsTabLocation")) &&
  83. empDetailsTab.Pages[2].NameMatches(TestDataInfrastructure.GetTestInputData("EmpDetailsTabCurrentProjects"))),
  84. TestDataInfrastructure.GetTestInputData("EmpDetailsTabPagesIncorrect"));
  85. //validate controls in each of the tabs
  86. ValidateGeneralTabControls();
  87. ValidateLocationTabControls();
  88. ValidateCurrentProjectsTabControls();
  89. }
  90. /// <summary>
  91. /// Validate General details in the General Tab for selected employee
  92. ///
  93. /// Repro Steps:
  94. /// 1. Launch the QS Application
  95. /// 2. Select the first employee row in the Employee List table
  96. /// 3. Check if the details of the selected employee are displayed in the General tab
  97. ///
  98. /// Expected results:
  99. /// Employee First Name, Last Name, Phone and Email are correctly displayed in the General Tab
  100. /// </summary>
  101. [TestMethod]
  102. public void ValidateEmployeeDetailsGeneralSection()
  103. {
  104. ListView list = Window.Get<ListView>(TestDataInfrastructure.GetControlId("EmployeesList"));
  105. list.SelectEmployee(TestDataInfrastructure.GetTestInputData("Emp_1_FirstName"));
  106. Employee emp = GetEmployeeId();
  107. ValidateEmployeeDetailsGeneralTabData(emp);
  108. }
  109. /// <summary>
  110. /// Validate Location details in the Location Tab for selected employee
  111. ///
  112. /// Repro Steps:
  113. /// 1. Launch the QS Application
  114. /// 2. Select the first employee row in the Employee List table
  115. /// 3. Check if the location details of the selected employee are displayed in the Location tab
  116. ///
  117. /// Expected results:
  118. /// Loaction Tab has a frame with required data
  119. /// </summary>
  120. [TestMethod]
  121. public void ValidateEmployeeDetailsLocationSection()
  122. {
  123. ListView list = Window.Get<ListView>(TestDataInfrastructure.GetControlId("EmployeesList"));
  124. list.SelectEmployee(TestDataInfrastructure.GetTestInputData("Emp_1_FirstName"));
  125. ValidateEmployeeDetailsLocationTabData();
  126. }
  127. /// <summary>
  128. /// Validate Current Projects details in the Current Projects Tab for selected employee
  129. ///
  130. /// Repro Steps:
  131. /// 1. Launch the QS Application
  132. /// 2. Select the first employee row in the Employee List table
  133. /// 3. Check if the Current Projects of the selected employee are displayed in the Current Projects tab
  134. ///
  135. /// Expected results:
  136. /// Current Project and Role of the selected Employee are correctly displayed in the Current Projects Tab
  137. /// </summary>
  138. [TestMethod]
  139. public void ValidateEmployeeDetailsCurrentProjectsSection()
  140. {
  141. ListView list = Window.Get<ListView>(TestDataInfrastructure.GetControlId("EmployeesList"));
  142. list.SelectEmployee(TestDataInfrastructure.GetTestInputData("Emp_1_FirstName"));
  143. ValidateEmployeeDetailsCurrentProjectsTabData();
  144. }
  145. #region Private Helper methods
  146. private void ValidateGeneralTabControls()
  147. {
  148. Tab empDetailsTab = Window.Get<Tab>(TestDataInfrastructure.GetControlId("DetailsTabControl"));
  149. empDetailsTab.Pages[0].Select();
  150. //check all Labels (TextBlocks)
  151. SearchCriteria searchCriteria = SearchCriteria.ByText(TestDataInfrastructure.GetTestInputData("FirstNameLabelText")).AndControlType(typeof(Label));
  152. Label firstNameLabel = Window.Get<Label>(searchCriteria);
  153. Assert.IsNotNull(firstNameLabel);
  154. searchCriteria = SearchCriteria.ByText(TestDataInfrastructure.GetTestInputData("LastNameLabelText")).AndControlType(typeof(Label));
  155. Label lastNameLabel = Window.Get<Label>(searchCriteria);
  156. Assert.IsNotNull(lastNameLabel);
  157. searchCriteria = SearchCriteria.ByText(TestDataInfrastructure.GetTestInputData("PhoneLabelText")).AndControlType(typeof(Label));
  158. Label phoneLabel = Window.Get<Label>(searchCriteria);
  159. Assert.IsNotNull(phoneLabel);
  160. searchCriteria = SearchCriteria.ByText(TestDataInfrastructure.GetTestInputData("EmailLabelText")).AndControlType(typeof(Label));
  161. Label emailLabel = Window.Get<Label>(searchCriteria);
  162. Assert.IsNotNull(emailLabel);
  163. //check all Textboxes
  164. TextBox firstName = Window.Get<TextBox>(TestDataInfrastructure.GetControlId("FirstNameTextBox"));
  165. Assert.IsNotNull(firstName);
  166. TextBox lastName = Window.Get<TextBox>(TestDataInfrastructure.GetControlId("LastNameTextBox"));
  167. Assert.IsNotNull(lastName);
  168. TextBox phone = Window.Get<TextBox>(TestDataInfrastructure.GetControlId("PhoneTextBox"));
  169. Assert.IsNotNull(phone);
  170. TextBox email = Window.Get<TextBox>(TestDataInfrastructure.GetControlId("EmailTextBox"));
  171. Assert.IsNotNull(email);
  172. }
  173. private void ValidateLocationTabControls()
  174. {
  175. //select the Location tab
  176. Tab empDetailsTab = Window.Get<Tab>(TestDataInfrastructure.GetControlId("DetailsTabControl"));
  177. empDetailsTab.Pages[1].Select();
  178. //TODO: validate display of frame
  179. }
  180. private void ValidateCurrentProjectsTabControls()
  181. {
  182. //select the "Current Projects" tab
  183. Tab empDetailsTab = Window.Get<Tab>(TestDataInfrastructure.GetControlId("DetailsTabControl"));
  184. empDetailsTab.Pages[2].Select();
  185. SearchCriteria searchCriteria = SearchCriteria.ByText(TestDataInfrastructure.GetTestInputData("PartOfFollowingProjectsLabel")).AndControlType(typeof(Label));
  186. Label projectsLabel = Window.Get<Label>(searchCriteria);
  187. Assert.IsNotNull(projectsLabel);
  188. ListView projectsList = Window.Get<ListView>(TestDataInfrastructure.GetControlId("CurrentProjectsList"));
  189. Assert.IsNotNull(projectsList);
  190. }
  191. private void ValidateEmployeeDetailsGeneralTabData(Employee emp)
  192. {
  193. Tab empDetailsTab = Window.Get<Tab>(TestDataInfrastructure.GetControlId("DetailsTabControl"));
  194. empDetailsTab.Pages[0].Select();
  195. TextBox firstName = Window.Get<TextBox>(TestDataInfrastructure.GetControlId("FirstNameTextBox"));
  196. Assert.AreEqual(firstName.Text, emp.FirstName);
  197. TextBox lastName = Window.Get<TextBox>(TestDataInfrastructure.GetControlId("LastNameTextBox"));
  198. Assert.AreEqual(lastName.Text, emp.LastName);
  199. TextBox phone = Window.Get<TextBox>(TestDataInfrastructure.GetControlId("PhoneTextBox"));
  200. Assert.AreEqual(phone.Text, emp.Phone);
  201. TextBox email = Window.Get<TextBox>(TestDataInfrastructure.GetControlId("EmailTextBox"));
  202. Assert.AreEqual(email.Text, emp.Email);
  203. }
  204. private void ValidateEmployeeDetailsLocationTabData()
  205. {
  206. Tab empDetailsTab = Window.Get<Tab>(TestDataInfrastructure.GetControlId("DetailsTabControl"));
  207. empDetailsTab.Pages[1].Select();
  208. //TODO: get handle of the frame in location taband validate
  209. }
  210. private void ValidateEmployeeDetailsCurrentProjectsTabData()
  211. {
  212. Tab empDetailsTab = Window.Get<Tab>(TestDataInfrastructure.GetControlId("DetailsTabControl"));
  213. empDetailsTab.Pages[2].Select();
  214. ListView projectsList = Window.Get<ListView>(TestDataInfrastructure.GetControlId("CurrentProjectsList"));
  215. //check if the list has two columns
  216. Assert.AreEqual(2, projectsList.Header.Columns.Count);
  217. //check if the list has two rows
  218. Assert.AreEqual(2, projectsList.Rows.Count);
  219. }
  220. private static Employee GetEmployeeId()
  221. {
  222. Employee emp = new Employee(1)
  223. {
  224. FirstName = TestDataInfrastructure.GetTestInputData("Emp_1_FirstName"),
  225. LastName = TestDataInfrastructure.GetTestInputData("Emp_1_LastName"),
  226. Phone = TestDataInfrastructure.GetTestInputData("Emp_1_Phone"),
  227. Email = TestDataInfrastructure.GetTestInputData("Emp_1_Email")
  228. };
  229. return emp;
  230. }
  231. #endregion
  232. }
  233. }