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

/V1/trunk/Source/StockTraderRI/StockRI.Tests.AcceptanceTests/AutomatedTests/ModuleFixtures/PositionModuleFixture.cs

#
C# | 185 lines | 101 code | 22 blank | 62 comment | 9 complexity | eaee7b72e1dee2174eae99abf8d1f26d 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 Microsoft.VisualStudio.TestTools.UnitTesting;
  21. using Core.UIItems;
  22. using StockTraderRI.AcceptanceTests.TestInfrastructure.MockModels;
  23. using Core.UIItems.ListViewItems;
  24. using Core.UIItems.Finders;
  25. using StockTraderRI.AcceptanceTests.TestInfrastructure;
  26. using StockTraderRI.AcceptanceTests.Helpers;
  27. using System.Globalization;
  28. namespace StockTraderRI.AcceptanceTests.AutomatedTests
  29. {
  30. [TestClass]
  31. [DeploymentItem(@".\StockTraderRI\bin\Debug")]
  32. [DeploymentItem(@".\StockRI.Tests.AcceptanceTests\bin\Debug")]
  33. public class PositionModuleFixture : FixtureBase
  34. {
  35. [TestInitialize()]
  36. public void MyTestInitialize()
  37. {
  38. base.TestInitialize();
  39. }
  40. /// <summary>
  41. /// TestCleanup performs clean-up activities after each test method execution
  42. /// </summary>
  43. [TestCleanup()]
  44. public void MyTestCleanup()
  45. {
  46. base.TestCleanup();
  47. }
  48. /// <summary>
  49. /// The current account position view should have symbol details with 6 columns
  50. /// (Symbol, Shares, Last, Cost Basis, Market Value, Gain Loss %)
  51. ///
  52. /// Repro Steps:
  53. /// 1. Launch the Stock Trader application
  54. /// 2. Check for the following columns:
  55. /// (Symbol, Shares, Last, Cost Basis, Market Value, Gain Loss %)
  56. ///
  57. /// Expected Result:
  58. /// Account Position Table should have 6 columns and the column names should be as follows:
  59. /// Symbol, Shares, Last, Cost Basis, Market Value, Gain Loss %
  60. /// </summary>
  61. [TestMethod]
  62. public void AccountPositionTableColumns()
  63. {
  64. ListView list = Window.Get<ListView>(TestDataInfrastructure.GetControlId("PositionTableId"));
  65. ListViewHeader listHeader = list.Header;
  66. Assert.AreEqual(6, listHeader.Columns.Count);
  67. //The Columns in the Position Table are partly coming from two different XML files and
  68. //the rest are computed columns. the only place where the column names are defined is the
  69. //PositionView XAML file, hence the hard-coding.
  70. Assert.AreEqual(TestDataInfrastructure.GetTestInputData("PositionTableSymbol"), listHeader.Columns[0].Name);
  71. Assert.AreEqual(TestDataInfrastructure.GetTestInputData("PositionTableShares"), listHeader.Columns[1].Name);
  72. Assert.AreEqual(TestDataInfrastructure.GetTestInputData("PositionTableLast"), listHeader.Columns[2].Name);
  73. Assert.AreEqual(TestDataInfrastructure.GetTestInputData("PositionTableCost"), listHeader.Columns[3].Name);
  74. Assert.AreEqual(TestDataInfrastructure.GetTestInputData("PositionTableMarketValue"), listHeader.Columns[4].Name);
  75. Assert.AreEqual(TestDataInfrastructure.GetTestInputData("PositionTableGainLoss"), listHeader.Columns[5].Name);
  76. }
  77. /// <summary>
  78. /// The current account position view should display details of symbols from the AccountPosition.xml
  79. ///
  80. /// Repro Steps:
  81. /// 1. Launch the Stock Trader application
  82. /// 2. Check the number of symbols displayed in the account position table.
  83. ///
  84. /// Expected Result:
  85. /// As many rows as present in AccountPosition.xml is displayed.
  86. /// </summary>
  87. [TestMethod]
  88. public void AccountPositionTableRowCount()
  89. {
  90. ListView list = Window.Get<ListView>(TestDataInfrastructure.GetControlId("PositionTableId"));
  91. //read number of account positions from the AccountPosition.xml data file
  92. int positionRowCount = TestDataInfrastructure.GetCount<AccountPositionDataProvider, AccountPosition>();
  93. Assert.AreEqual(positionRowCount, list.Rows.Count);
  94. }
  95. /// <summary>
  96. /// The current account position view should display derived data of symbols
  97. /// (after processing data from AccountPosition.xml and Market.xml)
  98. ///
  99. /// Repro Steps:
  100. /// 1. Launch the Stock Trader application
  101. /// 2. Check the derived data (like Market Value and Gain Loss %) of symbols displayed in the account position table.
  102. ///
  103. /// Expected Result:
  104. /// Market Value = shares * lastPrice
  105. /// Gain Loss % = (lastPrice * Shares - CostBasis) * 100 / CostBasis
  106. /// </summary>
  107. [TestMethod]
  108. public void AccountPositionDerivedData()
  109. {
  110. ListView list = Window.Get<ListView>(TestDataInfrastructure.GetControlId("PositionTableId"));
  111. ListViewRow listRow = null;
  112. string symbol;
  113. int count = 0;
  114. int numberOfRetries = 3;
  115. string share;
  116. string lastPrice;
  117. string marketPrice;
  118. string gainLoss;
  119. string costBasis;
  120. bool isMarketPriceMatching = false;
  121. bool isGainLossMatching = false;
  122. //test driven by the number of rows displayed in the Account Position table in the UI
  123. for (int i = 0; i < list.Rows.Count; i++)
  124. {
  125. listRow = list.Rows[i];
  126. symbol = listRow.Cells[TestDataInfrastructure.GetTestInputData("PositionTableSymbol")].Text;
  127. while (count < numberOfRetries)
  128. {
  129. //input columns
  130. share = listRow.Cells[TestDataInfrastructure.GetTestInputData("PositionTableShares")].Text;
  131. lastPrice = listRow.Cells[TestDataInfrastructure.GetTestInputData("PositionTableLast")].Text;
  132. costBasis = listRow.Cells[TestDataInfrastructure.GetTestInputData("PositionTableCost")].Text;
  133. //computed columns
  134. marketPrice = listRow.Cells[TestDataInfrastructure.GetTestInputData("PositionTableMarketValue")].Text;
  135. gainLoss = listRow.Cells[TestDataInfrastructure.GetTestInputData("PositionTableGainLoss")].Text;
  136. if (!isMarketPriceMatching)
  137. {
  138. if (Convert.ToDouble(marketPrice, CultureInfo.CurrentCulture).ToString("0.00", CultureInfo.CurrentCulture)
  139. .Equals((Convert.ToDouble(share, CultureInfo.CurrentCulture) * Convert.ToDouble(lastPrice, CultureInfo.CurrentCulture)).ToString("0.00", CultureInfo.CurrentCulture)))
  140. {
  141. isMarketPriceMatching = true;
  142. }
  143. }
  144. if (!isGainLossMatching)
  145. {
  146. if (Convert.ToDouble(gainLoss, CultureInfo.CurrentCulture).ToString("0.00", CultureInfo.CurrentCulture)
  147. .Equals(Math.Round((Convert.ToDouble(lastPrice, CultureInfo.CurrentCulture) * Convert.ToDouble(share, CultureInfo.CurrentCulture) - Convert.ToDouble(costBasis, CultureInfo.CurrentCulture)) / Convert.ToDouble(costBasis, CultureInfo.CurrentCulture) * 100, 2).ToString("0.00", CultureInfo.CurrentCulture)))
  148. {
  149. isGainLossMatching = true;
  150. }
  151. }
  152. if (isMarketPriceMatching && isGainLossMatching)
  153. {
  154. break;
  155. }
  156. count++;
  157. }
  158. //if either the Market Price or the Gain-Loss value does not match, then the test case fails
  159. Assert.IsTrue(isMarketPriceMatching && isGainLossMatching, String.Format(CultureInfo.CurrentCulture, "Computed Value for {0} is not correct", symbol));
  160. }
  161. }
  162. }
  163. }