PageRenderTime 31ms CodeModel.GetById 21ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/V1/trunk/Source/QuickStarts/Commanding/Commanding.Tests.AcceptanceTests/AutomatedTests/ModuleFixtures/OrderModuleCommon.cs

#
C# | 89 lines | 60 code | 8 blank | 21 comment | 1 complexity | 18428d94d7f233930639a805d445a267 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 System.Windows.Automation;
24using Core;
25using Core.UIItems;
26using Core.UIItems.Finders;
27using Core.UIItems.WindowItems;
28using Commanding.AcceptanceTests.TestInfrastructure;
29using Commanding.AcceptanceTests;
30using Commanding.AcceptanceTests.Helpers;
31using Commanding.AcceptanceTests.ApplicationObserver;
32
33namespace Commanding.Tests.AcceptanceTests.AutomatedTests.ModuleFixtures
34{
35    [TestClass]
36    [DeploymentItem(@".\Commanding\bin\Debug")]
37    [DeploymentItem(@".\Commanding.Tests.AcceptanceTests\bin\Debug")]
38    public partial class OrderModuleFixture:FixtureBase
39    {
40        #region Additional test attributes
41        [TestInitialize()]
42        public void MyTestInitialize()
43        {
44            // Check whether any exception occured during previous application launches. 
45            // If so, fail the test case.
46            if (StateDiagnosis.IsFailed)
47            {
48                Assert.Fail(TestDataInfrastructure.GetTestInputData("ApplicationLoadFailure"));
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        #endregion
62
63        private void PopulateOrderDetailsWithData()
64        {
65            AutomationElement quantityTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("QuantityTextBox"));
66            SetTextBoxValue(quantityTextBox, TestDataInfrastructure.GetTestInputData("DefaultQuantity"));
67
68            AutomationElement priceTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("PriceTextBox"));
69            SetTextBoxValue(priceTextBox, TestDataInfrastructure.GetTestInputData("DefaultPrice"));                     
70
71            AutomationElement shippingTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("ShippingTextBox"));
72            SetTextBoxValue(shippingTextBox, TestDataInfrastructure.GetTestInputData("DefaultShipping"));
73          
74        }
75        private static void SetTextBoxValue(AutomationElement element, string value)
76        {
77            ValuePattern valuePattern = element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
78            valuePattern.SetValue(value);
79        }
80        private void PopulateOrderDetailsWithInvalidData()
81        {
82            AutomationElement quantityTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("QuantityTextBox"));
83            SetTextBoxValue(quantityTextBox, TestDataInfrastructure.GetTestInputData("InvalidQuantity"));
84
85            AutomationElement priceTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("PriceTextBox"));
86            SetTextBoxValue(priceTextBox, TestDataInfrastructure.GetTestInputData("InvalidPrice"));
87        }
88    }
89}