public void Simple() { var today = DateTime.Parse("1/1/2019"); var stockPrices = new List <(string stock, decimal price)> { ("ONE", 10), ("TWO", 10), ("THREE", 10) }; SetupStockPrices(stockPrices, today); var balancer = new Balancer(_stockClient.Object); var currentPortfolio = new Portfolio(new List <PortfolioStock> { new PortfolioStock(symbol: "ONE", shares: 1), new PortfolioStock(symbol: "TWO", shares: 1) }); var requestedPortfolio = new Portfolio(new List <PortfolioStock> { new PortfolioStock(symbol: "ONE", allocationPercentage: 50), new PortfolioStock(symbol: "THREE", allocationPercentage: 50) }); var(actions, updatedPortfolio) = balancer.Balance(currentPortfolio, requestedPortfolio, today); WriteOutput(actions, updatedPortfolio); Assert.Equal(3, actions.Count); AssertActionForStock(actions, "ONE", expectedPercentage: 50, shareDiff: 0); AssertActionForStock(actions, "TWO", expectedPercentage: 0, shareDiff: -1); AssertActionForStock(actions, "THREE", expectedPercentage: 50, shareDiff: 1); Assert.Equal(2, updatedPortfolio.Stocks.Count); AssertPortfolioStock(updatedPortfolio, "ONE", expectedPercentage: 50, expectedShares: 1); AssertPortfolioStock(updatedPortfolio, "THREE", expectedPercentage: 50, expectedShares: 1); }
public void More_complex() { var today = DateTime.Parse("1/1/2019"); var stockPrices = new List <(string stock, decimal price)> { ("AAPL", 195.85m), ("GOOG", 1169.59m), ("CYBR", 127.65m), ("ABB", 17.88m), ("GFN", 700.51m), ("ACAD", 28.64m) }; SetupStockPrices(stockPrices, today); var balancer = new Balancer(_stockClient.Object); var currentPortfolio = new Portfolio(new List <PortfolioStock> { new PortfolioStock(symbol: "AAPL", shares: 50), new PortfolioStock(symbol: "GOOG", shares: 200), new PortfolioStock(symbol: "CYBR", shares: 150), new PortfolioStock(symbol: "ABB", shares: 900) }); var requestedPortfolio = new Portfolio(new List <PortfolioStock> { new PortfolioStock(symbol: "AAPL", allocationPercentage: 22), new PortfolioStock(symbol: "GOOG", allocationPercentage: 38), new PortfolioStock(symbol: "GFN", allocationPercentage: 25), new PortfolioStock(symbol: "ACAD", allocationPercentage: 15) }); var(actions, updatedPortfolio) = balancer.Balance(currentPortfolio, requestedPortfolio, today); WriteOutput(actions, updatedPortfolio); Assert.Equal(6, actions.Count); AssertActionForStock(actions, "AAPL", expectedPercentage: 22, shareDiff: 263); AssertActionForStock(actions, "GOOG", expectedPercentage: 38, shareDiff: -109); AssertActionForStock(actions, "CYBR", expectedPercentage: 0, shareDiff: -150); AssertActionForStock(actions, "ABB", expectedPercentage: 0, shareDiff: -900); AssertActionForStock(actions, "GFN", expectedPercentage: 25, shareDiff: 9286); AssertActionForStock(actions, "ACAD", expectedPercentage: 15, shareDiff: 1461); Assert.Equal(4, updatedPortfolio.Stocks.Count); AssertPortfolioStock(updatedPortfolio, "AAPL", expectedPercentage: 22, expectedShares: 313); AssertPortfolioStock(updatedPortfolio, "GOOG", expectedPercentage: 38, expectedShares: 91); AssertPortfolioStock(updatedPortfolio, "GFN", expectedPercentage: 25, expectedShares: 9286); AssertPortfolioStock(updatedPortfolio, "ACAD", expectedPercentage: 15, expectedShares: 1461); }
//[Fact] public void For_real() { // remove Skip property and add api key below to run against live API var client = new StockApiClient("Api key goes here"); var balancer = new Balancer(client); var currentPortfolio = new Portfolio(new List <PortfolioStock> { new PortfolioStock(symbol: "AAPL", shares: 50), new PortfolioStock(symbol: "GOOG", shares: 200), new PortfolioStock(symbol: "CYBR", shares: 150), new PortfolioStock(symbol: "ABB", shares: 900) }); var requestedPortfolio = new Portfolio(new List <PortfolioStock> { new PortfolioStock(symbol: "AAPL", allocationPercentage: 22), new PortfolioStock(symbol: "GOOG", allocationPercentage: 38), new PortfolioStock(symbol: "GFN", allocationPercentage: 25), new PortfolioStock(symbol: "ACAD", allocationPercentage: 15) }); var today = DateTime.Now.Date; var(actions, updatedPortfolio) = balancer.Balance(currentPortfolio, requestedPortfolio, today); WriteOutput(actions, updatedPortfolio); }