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