PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/V1/trunk/Source/QuickStarts/EventAggregation/EventAggregation.Tests.AcceptanceTests/AutomatedTests/ModuleFixtures/ModuleBFixture.cs

#
C# | 150 lines | 79 code | 16 blank | 55 comment | 3 complexity | 3c2aa8e8a445e12a6daa0b9fa3296bda 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 System.Windows.Automation;
  22. using Core;
  23. using Core.UIItems;
  24. using Core.UIItems.WindowItems;
  25. using Core.UIItems.Finders;
  26. using Microsoft.VisualStudio.TestTools.UnitTesting;
  27. using EventAggregation.AcceptanceTests;
  28. using Core.UIItems.ListBoxItems;
  29. using EventAggregation.AcceptanceTests.TestInfrastructure;
  30. using EventAggregation.AcceptanceTests.Helpers;
  31. using System.Globalization;
  32. namespace EventAggregation.AcceptanceTests.AutomatedTests.ModuleFixtures
  33. {
  34. /// <summary>
  35. /// Summary description for UnitTest1
  36. /// </summary>
  37. [TestClass]
  38. [DeploymentItem(@".\bin\Debug")]
  39. [DeploymentItem(@".\EventAggregation.Tests.AcceptanceTests\bin\Debug")]
  40. public class ModuleBFixture : FixtureBase
  41. {
  42. [TestInitialize()]
  43. public void MyTestInitialize()
  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. /// Check if each of the customer in the customer combo box has an Article view.
  57. ///
  58. /// Repro Steps:
  59. /// 1. Launch the EventAgrregation QS
  60. /// 2. For every customer in the customer combo box, Check if a corresponding ArticleView is
  61. /// displayed on the right side of the screen.
  62. ///
  63. /// Expected Result:
  64. /// Every customer in the customer combo box should have a corresponding Article view displayed.
  65. /// </summary>
  66. [TestMethod]
  67. public void EachCustomerShouldHaveAnActivityView()
  68. {
  69. WPFComboBox customer;
  70. //Get the handle of the customer combo box
  71. customer = Window.Get<WPFComboBox>(TestDataInfrastructure.GetControlId("CustomerCombobox"));
  72. //For every customer in the customer combo box,check if a corresponding article view is displayed
  73. for (int count = 0; count < customer.Items.Count - 1; count++)
  74. {
  75. Assert.IsNotNull((Label)Window.Get(SearchCriteria.ByAutomationId(TestDataInfrastructure.GetControlId("ActivityLabel")).
  76. AndByText(TestDataInfrastructure.GetTestInputData("ActivityLabelText") + customer.Items[count].Text)
  77. .AndControlType(typeof(Label))));
  78. }
  79. }
  80. /// <summary>
  81. /// Check if the selected fund is added only to the selected customer.
  82. ///
  83. /// Repro Steps:
  84. /// 1. Launch the EventAggregation QS
  85. /// 2. Select the customer from customer dropdown.
  86. /// 3. Select the fund from fund dropdown.
  87. /// 4. Click on Add.
  88. /// 5. Repeat steps 2 to 4 by changing the customer and fund.
  89. /// 5. Check whether the added fund has been displayed correctly in the display area.
  90. ///
  91. /// Expected Result:
  92. /// Fund should get added to the selected customer.
  93. /// </summary>
  94. [TestMethod]
  95. public void SelectedFundIsAddedOnlyToTheSelectedCustomer()
  96. {
  97. string[] selectedCustomer = new string[2];
  98. string[] selectedFund = new string[2];
  99. const int CUSTOMERS_IN_DROPDOWN=2;
  100. for (int i = 0; i < CUSTOMERS_IN_DROPDOWN; i++)
  101. {
  102. //Get the handle of the Customer combo box and select customer.
  103. WPFComboBox customer = Window.Get<WPFComboBox>(TestDataInfrastructure.GetControlId("CustomerCombobox"));
  104. customer.Select(TestDataInfrastructure.GetTestInputData("Customer" + i.ToString(CultureInfo.InvariantCulture)).ToString());
  105. selectedCustomer[i] = customer.Items[i].Text;
  106. //Get the handle of the Fund combo box and select fund.
  107. WPFComboBox fund = Window.Get<WPFComboBox>(TestDataInfrastructure.GetControlId("FundCombobox"));
  108. fund.Select(TestDataInfrastructure.GetTestInputData("Fund" + i.ToString(CultureInfo.InvariantCulture)));
  109. selectedFund[i] = fund.Items[i].Text;
  110. //Get the handle of the Add button and click on it.
  111. Button addButton = Window.Get<Button>(TestDataInfrastructure.GetControlId("AddButton"));
  112. addButton.Click();
  113. }
  114. // Now validate whether the fund has been added correctly.
  115. List<AutomationElement> elements = Window.AutomationElement.FindSiblingsInTreeByName("ActivityView");
  116. int counter = 0;
  117. foreach (AutomationElement element in elements)
  118. {
  119. if (counter < CUSTOMERS_IN_DROPDOWN)
  120. {
  121. // Find the text box and the fund text associated.
  122. AutomationElement textBox = element.SearchInRawTreeByName("ActivityLabel");
  123. string textBoxValue = textBox.Current.Name;
  124. string expectedValue = TestDataInfrastructure.GetTestInputData("ActivityLabelText") + selectedCustomer[counter].ToString();
  125. Assert.AreEqual(expectedValue, textBoxValue);
  126. // Find the fund values
  127. AutomationElement fund = element.SearchInRawTreeByName(selectedFund[counter].ToString());
  128. Assert.AreEqual(fund.Current.Name, selectedFund[counter].ToString());
  129. counter++;
  130. }
  131. }
  132. }
  133. }
  134. }