public void ReturnsDateOfMostRecentEntry() { //// SETUP // Test Data var stock = new Stock { Ticker = "FLWS", CompanyName = "1-800 FLOWERS.COM" }; var oldest = new HistoricPrice { Stock = stock, Date = DateTime.Parse("1/1/2000") }; var middle = new HistoricPrice { Stock = stock, Date = DateTime.Parse("1/2/2000") }; var newest = new HistoricPrice { Stock = stock, Date = DateTime.Parse("1/3/2000") }; var testData = new List<HistoricPrice> { oldest, newest, middle }; // Create a mock generic repository. var mockGenericRepository = new Mock<IReadOnlyRepository<HistoricPrice>>(); mockGenericRepository.Setup(mock => mock.FilterBy(It.IsAny<Expression<Func<HistoricPrice, bool>>>())).Returns(testData.AsQueryable()); // Setup target var target = new ReadOnlyPriceHistoryRepository(mockGenericRepository.Object); // EXECUTE var actual = target.GetMostRecentDateForTicker(stock.Ticker); // VERIFY Assert.AreEqual(newest.Date, actual); mockGenericRepository.Verify(mock => mock.FilterBy(It.IsAny<Expression<Func<HistoricPrice, bool>>>()), Times.Once()); }
public void ReturnsDefaultDateWhenNoRecordsExist() { //// SETUP // Test Data var stock = new Stock { Ticker = "FLWS", CompanyName = "1-800 FLOWERS.COM" }; // Create a mock generic repository. var mockGenericRepository = new Mock<IReadOnlyRepository<HistoricPrice>>(); mockGenericRepository.Setup(mock => mock.FilterBy(It.IsAny<Expression<Func<HistoricPrice, bool>>>())).Returns(stock.PriceHistory.AsQueryable()); // Setup target var target = new ReadOnlyPriceHistoryRepository(mockGenericRepository.Object); // EXECUTE var actual = target.GetMostRecentDateForTicker(stock.Ticker); // VERIFY Assert.AreEqual(DateTime.MinValue, actual); mockGenericRepository.Verify(mock => mock.FilterBy(It.IsAny<Expression<Func<HistoricPrice, bool>>>()), Times.Once()); }