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

/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. using System;
  18. using System.Collections.Generic;
  19. using System.Linq;
  20. using System.Text;
  21. using Microsoft.VisualStudio.TestTools.UnitTesting;
  22. using System.Windows.Automation;
  23. using Core;
  24. using Core.UIItems;
  25. using Core.UIItems.Finders;
  26. using Core.UIItems.WindowItems;
  27. using Commanding.AcceptanceTests.TestInfrastructure;
  28. using Commanding.AcceptanceTests;
  29. using Commanding.AcceptanceTests.Helpers;
  30. using Commanding.AcceptanceTests.ApplicationObserver;
  31. namespace Commanding.Tests.AcceptanceTests.AutomatedTests.ModuleFixtures
  32. {
  33. [TestClass]
  34. [DeploymentItem(@".\Commanding\bin\Debug")]
  35. [DeploymentItem(@".\Commanding.Tests.AcceptanceTests\bin\Debug")]
  36. public partial class OrderModuleFixture:FixtureBase
  37. {
  38. #region Additional test attributes
  39. [TestInitialize()]
  40. public void MyTestInitialize()
  41. {
  42. // Check whether any exception occured during previous application launches.
  43. // If so, fail the test case.
  44. if (StateDiagnosis.IsFailed)
  45. {
  46. Assert.Fail(TestDataInfrastructure.GetTestInputData("ApplicationLoadFailure"));
  47. }
  48. base.TestInitialize();
  49. }
  50. /// <summary>
  51. /// TestCleanup performs clean-up activities after each test method execution
  52. /// </summary>
  53. [TestCleanup()]
  54. public void MyTestCleanup()
  55. {
  56. base.TestCleanup();
  57. }
  58. #endregion
  59. private void PopulateOrderDetailsWithData()
  60. {
  61. AutomationElement quantityTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("QuantityTextBox"));
  62. SetTextBoxValue(quantityTextBox, TestDataInfrastructure.GetTestInputData("DefaultQuantity"));
  63. AutomationElement priceTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("PriceTextBox"));
  64. SetTextBoxValue(priceTextBox, TestDataInfrastructure.GetTestInputData("DefaultPrice"));
  65. AutomationElement shippingTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("ShippingTextBox"));
  66. SetTextBoxValue(shippingTextBox, TestDataInfrastructure.GetTestInputData("DefaultShipping"));
  67. }
  68. private static void SetTextBoxValue(AutomationElement element, string value)
  69. {
  70. ValuePattern valuePattern = element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern;
  71. valuePattern.SetValue(value);
  72. }
  73. private void PopulateOrderDetailsWithInvalidData()
  74. {
  75. AutomationElement quantityTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("QuantityTextBox"));
  76. SetTextBoxValue(quantityTextBox, TestDataInfrastructure.GetTestInputData("InvalidQuantity"));
  77. AutomationElement priceTextBox = Window.AutomationElement.SearchInRawTreeByName(TestDataInfrastructure.GetControlId("PriceTextBox"));
  78. SetTextBoxValue(priceTextBox, TestDataInfrastructure.GetTestInputData("InvalidPrice"));
  79. }
  80. }
  81. }