public void GetTotalGainLoss_PriceDropped_ExpectCorrectNegativeAnswer() { // Arrange decimal originalSharePrice = 125.44M; decimal currentPrice = 99.33M; int numShares = 44; InvestmentProduct investmentProduct = new InvestmentProduct(1, "ABC", currentPrice, DateTime.Now); TradeTransaction purchaseTransaction = new TradeTransaction(_nLogger, 1, TransactionType.Buy, DateTime.Now.AddMonths(-4), numShares, originalSharePrice); UserInvestment userInvestment = new UserInvestment(_nLogger, investmentProduct, purchaseTransaction); // Act decimal loss = userInvestment.GetTotalGainLoss(); // Assert decimal expectedLoss = (currentPrice - originalSharePrice) * numShares; Assert.AreEqual(expectedLoss, loss); }
private void DisplayInvestmentDetails(UserInvestment selectedInvestment) { try { InvestmentProduct product = selectedInvestment.GetInvestmentProduct(); TradeTransaction transaction = selectedInvestment.GetPurchaseTransaction(); investmentName.InnerText = product.Name; numShares.InnerText = transaction.NumShares.ToString();; costBasisPerShare.InnerText = selectedInvestment.GetCostPerBasisShare().ToString("C3"); currentValue.InnerText = selectedInvestment.GetCurrentValue().ToString("C3"); currentPrice.InnerText = product.CurrentPrice.ToString("C3"); term.InnerText = selectedInvestment.GetTerm().ToString(); totalGainLoss.InnerText = selectedInvestment.GetTotalGainLoss().ToString("C3"); _nLogger.Info($"Displaying details for {product.Name}"); } catch (Exception ex) { errorLabel.InnerText = "Error displaying investment details. Please try again later"; _nLogger.Error(ex, "Exception displaying investment details"); } }