public void WhenGetAllDocumentsByProjectNameAndDocumentTypeShouldReturnExpectedNumberOfDocuments() { var dateTime = new DateTime(2018, 08, 30); var data = new List <CosmosDataDocument <DailyCodeChurn> > { new CosmosDataDocument <DailyCodeChurn> { DateTime = dateTime.ToString(DailyCodeChurn.DATE_FORMAT), Data = new List <DailyCodeChurn> { new DailyCodeChurn { FileName = "some-file-name", Timestamp = dateTime.ToString(DailyCodeChurn.DATE_FORMAT) } } } }; dataDocumentRepositoryMock.Setup(x => x.GetAllDocumentsByProjectAndDocumentType <DailyCodeChurn>(ProjectName, DocumentType.CodeChurn)) .Returns(data); var result = sut.GetAllDocumentsByProjectNameAndDocumentType <DailyCodeChurn>(); Assert.Single(result); }
private static int RunSonarGenericMetricsFromCosmosDb(SonarGenericMetricsCosmosDbCommandLineArgs a) { var logger = new ConsoleLoggerWithTimestamp(); var jsonParser = new JsonListParser <DailyCodeChurn>(new FileStreamFactory()); var jsonExporter = new JsonExporter(new FileStreamFactory()); var cosmosConnection = new CosmosConnection(new DatabaseFactory(a, JsonSerializerSettingsFactory.CreateDefaultSerializerSettingsForCosmosDB()), a.DatabaseId, Properties.Settings.Default.CosmosBulkBatchSize); var dataDocumentRepository = new DataDocumentRepository(cosmosConnection, a.CodeChurnCosmosContainer); var cosmosOutputProcessor = new CosmosDbOutputProcessor(logger, dataDocumentRepository, new DataConverter(), a.CosmosProjectName, Properties.Settings.Default.CosmosBulkBatchSize); var environment = new EnvironmentImpl(); var converters = new MeasureConverterListBuilder(environment).Build(a); Dictionary <DateTime, Dictionary <string, DailyCodeChurn> > data; if (a.StartDate == null && a.EndDate == null) { data = cosmosOutputProcessor.GetAllDocumentsByProjectNameAndDocumentType <DailyCodeChurn>(); } else { if (a.StartDate == null) { throw new ArgumentNullException(nameof(a.StartDate)); } if (a.EndDate == null) { a.EndDate = environment.GetCurrentDateTime(); } data = cosmosOutputProcessor.GetDocumentsInDateRange <DailyCodeChurn>(a.StartDate.Value, a.EndDate.Value); } var processor = new SonarGenericMetricsProcessor(jsonParser, converters, jsonExporter, new ConsoleLoggerWithTimestamp(), new DataConverter()); processor.Process(a, data); return(0); }