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