public InvestmentPerformance GetInvestmentDetail(int investmentId) { const string sql = @"SELECT sp.[Id], s.[Name], sp.Shares, sp.PurchaseCostPerShare, sp.Shares * s.Price As CurrentValue, s.Price As CurrentPrice, sp.PurchaseDate, (sp.Shares * s.Price) - (sp.Shares * sp.PurchaseCostPerShare) As NetGain FROM [Investment].[dbo].[StockPurchase] sp INNER JOIN [Investment].[dbo].[Stock] s on sp.StockId = s.Id WHERE sp.[Id] = @InvestmentId"; StockPurchase stockPurchase; using (var connection = new SqlConnection(_configuration["ConnectionStrings:DefaultConnection"])) { stockPurchase = connection.QuerySingleOrDefault <StockPurchase>(sql, new { InvestmentId = investmentId }); } InvestmentPerformance investmentPerformance = null; if (stockPurchase != null) { investmentPerformance = new InvestmentPerformance { Id = stockPurchase.Id, Name = stockPurchase.Name, Shares = stockPurchase.Shares, CostBasisPerShare = stockPurchase.PurchaseCostPerShare, CurrentValue = stockPurchase.CurrentValue, CurrentPrice = stockPurchase.CurrentPrice, Term = PerformanceCalculationHelper.GetTerm(stockPurchase.PurchaseDate), NetGain = PerformanceCalculationHelper.CalculateNetGain(stockPurchase.Shares, stockPurchase.CurrentPrice, stockPurchase.PurchaseCostPerShare), }; } return(investmentPerformance); }
public void NetGain_Should_Be_Positive_If_The_Customer_Earned_Money(int shares, decimal currentPrice, decimal purchaseCostPerShare) { Assert.IsTrue(PerformanceCalculationHelper.CalculateNetGain(shares, currentPrice, purchaseCostPerShare) > 0); }