public void GetRecentTradesBySymbol_Valid_WithNoResults_Test() { // Setup with none valid. List <ITrade> listOfTrades = new List <ITrade>(); listOfTrades.Add(new Trade() { StockInformation = new Stock() { Symbol = "ABC" }, TimeStamp = DateTime.UtcNow.AddMinutes(-10) }); // INVALID TIME listOfTrades.Add(new Trade() { StockInformation = new Stock() { Symbol = "DEF" }, TimeStamp = DateTime.UtcNow.AddMinutes(-10) }); // INVALID NAME listOfTrades.Add(new Trade() { StockInformation = new Stock() { Symbol = "ABC" }, TimeStamp = DateTime.UtcNow.AddMinutes(-16) }); // INVALID TIME // Start InMemoryTradeRepository repo = new InMemoryTradeRepository(listOfTrades); IEnumerable <ITrade> result = repo.GetRecentTradesBySymbol("ABC", 5); Assert.AreEqual(0, result.Count()); }
public void NullConstructor_Test() { InMemoryTradeRepository repo = new InMemoryTradeRepository(null); IEnumerable <ITrade> result = repo.GetRecentTradesBySymbol("ABC", 15); Assert.IsNotNull(result); Assert.AreEqual(0, result.Count()); }
public void GetRecentTradesBySymbol_NullParameter_Test() { InMemoryTradeRepository repo = new InMemoryTradeRepository(null); // Doesn't matter what we pass in for this test. try { // Pass in null to simulate error. IEnumerable <ITrade> result = repo.GetRecentTradesBySymbol(null, 15); Assert.Fail("There should be an exception on this test"); } catch (ArgumentNullException ex) { Assert.AreEqual("stockSymbol", ex.ParamName); } }
public void Save_Test() { // Setup with none valid. List <ITrade> listOfTrades = new List <ITrade>(); listOfTrades.Add(new Trade() { StockInformation = new Stock() { Symbol = "ABC" }, TimeStamp = DateTime.UtcNow.AddMinutes(-10) }); // INVALID TIME listOfTrades.Add(new Trade() { StockInformation = new Stock() { Symbol = "DEF" }, TimeStamp = DateTime.UtcNow.AddMinutes(-10) }); // INVALID NAME listOfTrades.Add(new Trade() { StockInformation = new Stock() { Symbol = "ABC" }, TimeStamp = DateTime.UtcNow.AddMinutes(-16) }); // INVALID TIME // Start InMemoryTradeRepository repo = new InMemoryTradeRepository(listOfTrades); // Step one - check no results from initial data IEnumerable <ITrade> resultPreSave = repo.GetRecentTradesBySymbol("ABC", 5); Assert.AreEqual(0, resultPreSave.Count()); // Step two - save new trade then check again repo.Save(new Trade() { StockInformation = new Stock() { Symbol = "ABC" }, TimeStamp = DateTime.UtcNow }); // VALID IEnumerable <ITrade> resultPostSave = repo.GetRecentTradesBySymbol("ABC", 5); Assert.AreEqual(1, resultPostSave.Count()); }
public void RunThroughRequirements() { // Setup the sample data as per word document List <IStock> sampleData = DemoData; // Setup our stock repo with the sample data as standard and the trade with no data. IStockRepository stockRepo = new InMemoryStockRepository(sampleData); ITradeRepository tradeRepo = new InMemoryTradeRepository(null); ITradeService tradeService = new TradeService(tradeRepo); IStockManagementService stockManagementService = new StockManagementService(stockRepo, tradeService); // 1a i // Set the price, calculate the dividend yield and assert for COMMON stockManagementService.UpdateMarketPrice("POP", 100M); Decimal pop_dividendYield = stockManagementService.GetDividendYield("POP"); Assert.AreEqual(0.08M, pop_dividendYield); // Set the price, calculate the dividend yield and assert for PREFERRED stockManagementService.UpdateMarketPrice("GIN", 102M); Decimal gin_dividendYield = stockManagementService.GetDividendYield("GIN"); Assert.AreEqual(0.02M, gin_dividendYield); // 1a ii // Set the price, calculate the P/E ratio and assert stockManagementService.UpdateMarketPrice("ALE", 175M); Decimal ale_PERatio = stockManagementService.GetPERatio("ALE"); Assert.AreEqual(7.6M, ale_PERatio); // 1a iii // Record trades at multiple prices stockManagementService.BuyAtCurrentPrice("POP", 5); stockManagementService.BuyAtCurrentPrice("ALE", 6); stockManagementService.BuyAtCurrentPrice("GIN", 1); // Price Change stockManagementService.UpdateMarketPrice("POP", 101M); stockManagementService.UpdateMarketPrice("ALE", 101M); stockManagementService.UpdateMarketPrice("GIN", 87M); stockManagementService.UpdateMarketPrice("TEA", 104M); // More trades stockManagementService.BuyAtCurrentPrice("TEA", 1); stockManagementService.BuyAtCurrentPrice("POP", 5); stockManagementService.BuyAtCurrentPrice("ALE", 5); stockManagementService.BuyAtCurrentPrice("ALE", 2); stockManagementService.SellAtCurrentPrice("GIN", 1); // 1a iv // Assert a number of Volume Weighted Stock Prices now trades have been recorded. Decimal pop_vwsp = tradeService.GetVolumeWeightedStockPrice("POP", 15); // ((100*5)+(101*5))/10 = 100.5 Assert.AreEqual(100.5M, pop_vwsp); Decimal ale_vwsp = tradeService.GetVolumeWeightedStockPrice("ALE", 15); // ((175*6)+(101*5)+(101*2))/13 = 135.15 Assert.AreEqual(135.15M, ale_vwsp); Decimal gin_vwsp = tradeService.GetVolumeWeightedStockPrice("GIN", 15); // ((102*1)+(87*1))/2 = 94.5 Assert.AreEqual(94.5M, gin_vwsp); // 1b // Calculate the current price of the GBCE All Share Index Decimal indexPrice = stockManagementService.GetIndexPrice(); Assert.AreEqual(98.02M, indexPrice); }