public async Task Compact_Success_InitialLoad() { var mockDbContext = new Mock <AnalyzerDbContext>(); var mockStockQuoteDataSet = MockDataSet.Get(new List <StockQuote>()); mockDbContext.Setup(s => s.StockQuotes).Returns(mockStockQuoteDataSet.Object); var mockStockDataSet = MockDataSet.Get(new List <Stock>()); mockStockDataSet.Setup(s => s.Add(It.IsAny <Stock>())).Returns((Stock s) => s); mockDbContext.Setup(s => s.Stocks).Returns(mockStockDataSet.Object); var stockLoader = new StockLoaderTestFixture(); var processor = new StockProcessorTestFixture(mockDbContext, stockLoader) { IsMarketClosedValue = true }; var stockQuoteDataFixture = new StockQuoteDataFixture(); var ticker = "goog"; var numberofQuotes = 10; stockQuoteDataFixture.Create(numberofQuotes, ticker); stockLoader.Quotes = stockQuoteDataFixture.Entities.Where(s => s.Ticker == ticker).ToList(); var result = await processor.LoadCompactAsync(ticker); mockStockQuoteDataSet.Verify(s => s.Add(It.IsAny <StockQuote>()), Times.Exactly(stockLoader.Quotes.Count())); mockStockDataSet.Verify(s => s.Add(It.IsAny <Stock>()), Times.Once); mockDbContext.Verify(s => s.SaveChangesAsync(), Times.Once); Assert.IsTrue(result.Succeeded); }
public static StockRepositoryTestFixture Create() { var mockDbContext = new Mock <AnalyzerDbContext>(); var processor = new StockProcessorTestFixture(mockDbContext, new StockLoaderTestFixture()) { LoadCompactAsyncResult = AnalyzerResult.Sucess(), LoadFullAsyncResult = AnalyzerResult.Sucess() }; return(new StockRepositoryTestFixture(mockDbContext, processor)); }
public async Task StockRepository_GetStockWithChartVm_ByTake_Failed_FailedLoader() { var dataFixture = new StockDataFixture(); var processor = new StockProcessorTestFixture(); var repository = StockRepositoryFactory.Create(processor); repository.MockDbContext.Setup(s => s.StockQuotes).Returns(dataFixture.QuoteDataFixture.MockDataSet.Object); repository.MockDbContext.Setup(s => s.Stocks).Returns(dataFixture.MockDataSet.Object); processor.LoadCompactAsyncResult = AnalyzerResult.Fail("Failed to load."); var result = await repository.GetChartAsync("ticker", 30); Assert.IsNull(result); }
public async Task Process_Success_MarketNotClosed_MaxDayMinus2() { var mockDbContext = new Mock <AnalyzerDbContext>(); var stockDataFixture = new StockDataFixture(); var stock = stockDataFixture.Entities.First(); var ticker = stock.Id; stock.LastLoadDate = DateTime.Today.AddDays(-2); stock.MaxDate = stock.LastLoadDate; var mockStockDataSet = stockDataFixture.MockDataSet; mockStockDataSet.Setup(s => s.Add(It.IsAny <Stock>())).Returns((Stock s) => s); mockDbContext.Setup(s => s.Stocks).Returns(mockStockDataSet.Object); stockDataFixture.QuoteDataFixture.Entities.Remove(stockDataFixture.QuoteDataFixture.Entities.First(s => s.Ticker == ticker && s.Date == DateTime.Today)); stockDataFixture.QuoteDataFixture.Entities.Remove(stockDataFixture.QuoteDataFixture.Entities.First(s => s.Ticker == ticker && s.Date == DateTime.Today.AddDays(-1))); var mockStockQuoteDataSet = stockDataFixture.QuoteDataFixture.MockDataSet; mockDbContext.Setup(s => s.StockQuotes).Returns(mockStockQuoteDataSet.Object); var stockLoader = new StockLoaderTestFixture(); var processor = new StockProcessorTestFixture(mockDbContext, stockLoader) { IsMarketClosedValue = false }; stockLoader.Quotes = stockDataFixture.QuoteDataFixture.Entities.Where(s => s.Ticker == ticker).ToList(); stockLoader.Quotes.Add(new StockQuote() { Ticker = ticker, Date = DateTime.Today.AddDays(-1) }); stockLoader.Quotes.Add(new StockQuote() { Ticker = ticker, Date = DateTime.Today }); var result = await processor.LoadCompactAsync(ticker); mockStockQuoteDataSet.Verify(s => s.Add(It.IsAny <StockQuote>()), Times.Once); mockStockDataSet.Verify(s => s.Add(It.IsAny <Stock>()), Times.Never); mockDbContext.Verify(s => s.SaveChangesAsync(), Times.Once); Assert.IsTrue(result.Succeeded); Assert.AreEqual(stock.MaxDate, DateTime.Today.AddDays(-1)); }
public StockRepositoryTestFixture(Mock <AnalyzerDbContext> mockDbContext, StockProcessorTestFixture stockProcessor) : base(mockDbContext.Object, stockProcessor) { MockDbContext = mockDbContext; }
public static StockRepositoryTestFixture Create(StockProcessorTestFixture stockProcessor) { var mockDbContext = new Mock <AnalyzerDbContext>(); return(new StockRepositoryTestFixture(mockDbContext, stockProcessor)); }