public void QueriesTheRepoForTheTicker() { //// SETUP // Test Data var expected = new Stock { Ticker = "FLWS", CompanyName = "1-800 FLOWERS.COM" }; // Create a mock generic repository. var mockGenericRepository = new Mock<IReadOnlyRepository<Stock>>(); mockGenericRepository.Setup(mock => mock.FindBy(It.IsAny<Expression<Func<Stock, bool>>>())).Returns(expected); // Setup target var target = new ReadOnlyStockRepository(mockGenericRepository.Object); // EXECUTE var actual = target.GetByTicker(expected.Ticker); // VERIFY Assert.AreSame(expected, actual); mockGenericRepository.Verify(mock => mock.FindBy(It.IsAny<Expression<Func<Stock, bool>>>()), Times.Once()); }
public void ReturnsNullOnRepoException() { //// SETUP // Create a mock generic repository var mockGenericRepository = new Mock<IReadOnlyRepository<Stock>>(); mockGenericRepository.Setup( mock => mock.FindBy(It.IsAny<Expression<Func<Stock, bool>>>())).Throws(new Exception()); // Setup target var target = new ReadOnlyStockRepository(mockGenericRepository.Object); // EXECUTE var actual = target.GetByTicker(string.Empty); // VERIFY Assert.Null(actual); mockGenericRepository.Verify(mock => mock.FindBy(It.IsAny<Expression<Func<Stock, bool>>>()), Times.Once()); }