public string GenerateStockName(StockEnum stocktype) { // Stock Name gets generated from the number of occurrences of that Stock Type int count = AllStocks.Where(c => c.StockType == stocktype).Count(); return((stocktype == StockEnum.Equity ? "Equity" : "Bond") + (count + 1).ToString()); }
public void TransactionCostGreaterThanTolerance_Equity_ReturnRedBrush() { IMultiValueConverter converter = new StockNameHighlightConverter(); string strMarketValue = "10"; string strTransactionCost = "250000"; StockEnum strStocktype = StockEnum.Equity; object[] values = new object[3]; values[0] = strMarketValue; values[1] = strTransactionCost; values[2] = strStocktype; Double transactionCost = Double.TryParse(values[1].ToString(), out transactionCost) ? transactionCost : 0; object returnValue = converter.Convert(values, null, null, null); Assert.AreEqual(returnValue, Brushes.Red); }
public void TransactionCostLessThanTolerance_Bond_ReturnRedBrush() { IMultiValueConverter converter = new StockNameHighlightConverter(); string strMarketValue = "10"; string strTransactionCost = "50000"; StockEnum strStocktype = StockEnum.Bond; object[] values = new object[3]; values[0] = strMarketValue; values[1] = strTransactionCost; values[2] = strStocktype; Double transactionCost = Double.TryParse(values[1].ToString(), out transactionCost) ? transactionCost : 0; object returnValue = converter.Convert(values, null, null, null); Assert.IsNull(returnValue); }
public void MarketValueLessThan0_ReturnRedBrush() { IMultiValueConverter converter = new StockNameHighlightConverter(); string strMarketValue = "-10"; string strTransactionCost = "10"; StockEnum strStocktype = StockEnum.Equity; object[] values = new object[3]; values[0] = strMarketValue; values[1] = strTransactionCost; values[2] = strStocktype; Double marketValue = Double.TryParse(values[0].ToString(), out marketValue) ? marketValue : 0; object returnValue = converter.Convert(values, null, null, null); Assert.AreEqual(marketValue, -10); Assert.AreEqual(returnValue, Brushes.Red); }
// This Converter is used to highligh Stock Name as Red for any Stocks whose Market Value < 0 // or Transaction Cost > Tolerance where Tolerance = 100,000 when Stock Type is "Bond" or // Tolerance = 200,000 when Stock Type is "Equity"; public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { if (values != null) { double marketValue, transactionCost, tolerance; marketValue = Double.TryParse(values[0].ToString(), out marketValue) ? marketValue : 0; transactionCost = Double.TryParse(values[1].ToString(), out transactionCost) ? transactionCost : 0; StockEnum type = (StockEnum)values[2]; if (type == StockEnum.Bond) { tolerance = 100000; } else { tolerance = 200000; } if (marketValue < 0 || transactionCost > tolerance) { return(Brushes.Red); } } return(null); }