public void run_proper_items_are_full_calculated() { int itemsForAnalysis = 240; TimeframeSymbol timeframe = TimeframeSymbol.M5; AnalysisType analysisType = AnalysisType.Price; AssetTimeframe atf = UnitTestTools.testAssetTimeframe(); PriceAnalyzer analyzer = new PriceAnalyzer(atf); DateTime startDate = (new DateTime(2016, 4, 21, 12, 30, 0)).Proper(timeframe); DateTime lastAnalysisDate = (new DateTime(2016, 4, 23, 15, 0, 0)).Proper(timeframe); DateTime endDate = (new DateTime(2016, 4, 27, 15, 30, 0)).Proper(timeframe); DataItem[] items = UnitTestTools.getDataItemsArray(timeframe, startDate, endDate, UnitTestTools.createAnalysisTypeList(new AnalysisType[] { AnalysisType.Price })); Mock<IQuotationService> mockQuotationService = mockedQuotationService(atf, lastAnalysisDate, AnalysisType.Price); mockQuotationService.Setup(q => q.getLastCalculationDate(atf, analysisType)).Returns(lastAnalysisDate); Mock<IPriceProcessor> mockedProcessor = new Mock<IPriceProcessor>(); analyzer.injectProcessor(mockedProcessor.Object); analyzer.injectQuotationService(mockQuotationService.Object); DateTime expectedFirstRightOnlyItem = lastAnalysisDate.addTimeUnits(timeframe, -itemsForAnalysis); DateTime expectedLastRightOnlyItem = lastAnalysisDate; analyzer.Analyze(items); //Test 1. DateTime d = startDate; while (d.CompareTo(endDate) < 0) { d = d.getNext(timeframe); DataItem dataItem = items.SingleOrDefault(i => i.Date.Equals(d)); if (dataItem == null) { throw new ArgumentNullException(string.Format("Data item for [0] has not been found", d.ToString())); } if (d.CompareTo(expectedLastRightOnlyItem) > 0) { mockedProcessor.Verify(p => p.runFull(It.IsAny<IAnalyzer>(), dataItem, atf), Times.Exactly(1)); } else { mockedProcessor.Verify(p => p.runFull(It.IsAny<IAnalyzer>(), dataItem, atf), Times.Exactly(0)); } } }
public void fetchData_for_firstRequiredDate_equal_to_null_proper_method_of_dataService_is_called() { AssetTimeframe atf = UnitTestTools.testAssetTimeframe(); Dictionary<AnalysisType, IAnalyzer> analyzers = new Dictionary<AnalysisType, IAnalyzer>(); DateTime firstRequired = new DateTime(2016, 8, 1); analyzers.Add(AnalysisType.Price, UnitTestTools.generateMockAnalyzer(atf, AnalysisType.Price, firstRequired).Object); analyzers.Add(AnalysisType.MACD, UnitTestTools.generateMockAnalyzer(atf, AnalysisType.MACD, null).Object); analyzers.Add(AnalysisType.ADX, UnitTestTools.generateMockAnalyzer(atf, AnalysisType.ADX, firstRequired).Object); Mock<IDataService> mockedDataService = new Mock<IDataService>(); QuotationService qService = new QuotationService(); qService.injectDataService(mockedDataService.Object); DataItem[] items = qService.fetchData(analyzers); mockedDataService.Verify(x => x.GetDataItems(atf, null, null, analyzers.Keys), Times.Exactly(1)); }