public void TestCalculatePortfolioQuantity() { { // -- case 1: mutiple buy trade records List <TradeHistory> histories = new List <TradeHistory>() { new TradeHistory { Ticker = "MSFT", TradeAction = TradeAction.Buy, Price = 85.95m, Quantity = 100 }, new TradeHistory { Ticker = "MSFT", TradeAction = TradeAction.Buy, Price = 87.82m, Quantity = 150 } }; var result = portfolioService.CalculatePortfolioQuantity(histories); Assert.AreEqual(250, result); } Init(); { // -- case 2: mutiple buy and sell trade records List <TradeHistory> histories = new List <TradeHistory>() { new TradeHistory { Ticker = "MSFT", TradeAction = TradeAction.Buy, Price = 85.95m, Quantity = 100 }, new TradeHistory { Ticker = "MSFT", TradeAction = TradeAction.Buy, Price = 87.82m, Quantity = 150 }, new TradeHistory { Ticker = "MSFT", TradeAction = TradeAction.Sell, Price = 100.00m, Quantity = 100 } }; var result = portfolioService.CalculatePortfolioQuantity(histories); Assert.AreEqual(150, result); } Init(); { // -- case 3: mutiple buy and sell trade records for mutiple tickers List <TradeHistory> histories = new List <TradeHistory>() { new TradeHistory { Ticker = "MSFT", TradeAction = TradeAction.Buy, Price = 85.95m, Quantity = 100 }, new TradeHistory { Ticker = "MSFT", TradeAction = TradeAction.Buy, Price = 87.82m, Quantity = 150 }, new TradeHistory { Ticker = "GOOG", TradeAction = TradeAction.Buy, Price = 1065.00m, Quantity = 50 }, }; var result = portfolioService.CalculatePortfolioQuantity(histories); Assert.AreEqual(300, result, "Should return total quantity for all records"); } }