public void if_quotationService_returns_empty_array_of_data_items_analyzers_are_not_run() { //Create mocked IQuotationService var mockQuotationService = UnitTestTools.mockedQuotationService(); DataItem[] items = UnitTestTools.getDataItemsArray(0); mockQuotationService.Setup(q => q.fetchData(It.IsAny<Dictionary<AnalysisType, IAnalyzer>>())).Returns(items); AssetTimeframe atf = UnitTestTools.testAssetTimeframe(); Dictionary<AnalysisType, IAnalyzer> analyzers = new Dictionary<AnalysisType, IAnalyzer>(); DateTime laterDate = new DateTime(2016, 8, 1); DateTime earlierDate = new DateTime(2016, 7, 5); //Create mocked analyzers. var mockedPriceAnalyzer = UnitTestTools.generateMockAnalyzer(atf, AnalysisType.Price, laterDate); var mockedMacdAnalyzer = UnitTestTools.generateMockAnalyzer(atf, AnalysisType.MACD, laterDate); var mockedAdxAnalyzer = UnitTestTools.generateMockAnalyzer(atf, AnalysisType.ADX, laterDate); analyzers.Add(AnalysisType.Price, mockedPriceAnalyzer.Object); analyzers.Add(AnalysisType.MACD, mockedMacdAnalyzer.Object); analyzers.Add(AnalysisType.ADX, mockedAdxAnalyzer.Object); var service = new ProcessService(atf); service.loadAnalyzers(analyzers); service.injectQuotationService(mockQuotationService.Object); service.Run(true); mockedPriceAnalyzer.Verify(x => x.Analyze(It.IsAny<DataItem[]>()), Times.Exactly(0)); mockedMacdAnalyzer.Verify(x => x.Analyze(It.IsAny<DataItem[]>()), Times.Exactly(0)); mockedAdxAnalyzer.Verify(x => x.Analyze(It.IsAny<DataItem[]>()), Times.Exactly(0)); }
public void quotationProcessor_is_called_once_for_loading_data() { Asset asset = new Asset(1, "USD"); Timeframe timeframe = Timeframe.GetTimeframe(TimeframeSymbol.M15); ProcessService service = new ProcessService(asset, timeframe); var mockQuotationService = UnitTestTools.mockedQuotationService(); AnalysisType[] types = new AnalysisType[] { AnalysisType.Price }; service.injectQuotationService(mockQuotationService.Object); service.Setup(types); service.Run(true); mockQuotationService.Verify(x => x.fetchData(It.IsAny<Dictionary<AnalysisType, IAnalyzer>>()), Times.Exactly(1)); }
public void if_quotationService_returns_non_empty_array_of_data_items_analyzers_are_run() { //Create mocked IQuotationService AssetTimeframe atf = UnitTestTools.testAssetTimeframe(); DateTime startDate = new DateTime(2016, 8, 1); DateTime endDate = new DateTime(2016, 8, 14); AnalysisType[] types = new AnalysisType[] { AnalysisType.Price, AnalysisType.MACD, AnalysisType.ADX }; DataItem[] items = UnitTestTools.getDataItemsArray(atf.timeframe.Symbol, startDate, endDate, UnitTestTools.createAnalysisTypeList(types)); var mockQuotationService = UnitTestTools.mockedQuotationService(); mockQuotationService.Setup(q => q.fetchData(It.IsAny<Dictionary<AnalysisType, IAnalyzer>>())).Returns(items); Dictionary<AnalysisType, IAnalyzer> analyzers = new Dictionary<AnalysisType, IAnalyzer>(); //Create mocked analyzers. var mockedPriceAnalyzer = UnitTestTools.generateMockAnalyzer(atf, AnalysisType.Price, null); var mockedMacdAnalyzer = UnitTestTools.generateMockAnalyzer(atf, AnalysisType.MACD, null); var mockedAdxAnalyzer = UnitTestTools.generateMockAnalyzer(atf, AnalysisType.ADX, null); analyzers.Add(AnalysisType.Price, mockedPriceAnalyzer.Object); analyzers.Add(AnalysisType.MACD, mockedMacdAnalyzer.Object); analyzers.Add(AnalysisType.ADX, mockedAdxAnalyzer.Object); var service = new ProcessService(atf); service.loadAnalyzers(analyzers); service.injectQuotationService(mockQuotationService.Object); service.Run(true); mockedPriceAnalyzer.Verify(x => x.Analyze(items), Times.Exactly(1)); mockedMacdAnalyzer.Verify(x => x.Analyze(items), Times.Exactly(1)); mockedAdxAnalyzer.Verify(x => x.Analyze(items), Times.Exactly(1)); }