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