Exemple #1
0
        private static int RunDownloadCodeChurnFromCosmosDbToJsonFiles(DownloadFromCosmosDbCommandLineArgs a)
        {
            var logger                 = new ConsoleLoggerWithTimestamp();
            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 jsonOutputProcessor    = new JsonOutputProcessor(new DataConverter(), new FileStreamFactory(), logger);
            var environment            = new EnvironmentImpl();

            var endDate = a.EndDate ?? (a.EndDate = environment.GetCurrentDateTime());

            switch (a.DocumentType)
            {
            case DocumentType.BugDatabase:
            {
                var data = cosmosOutputProcessor.GetDocumentsInDateRange <WorkItem>(a.StartDate.Value, endDate.Value);
                jsonOutputProcessor.ProcessOutput(a.OutputType, a.OutputFile, data);
                break;
            }

            case DocumentType.CodeChurn:
            {
                var data = cosmosOutputProcessor.GetDocumentsInDateRange <DailyCodeChurn>(a.StartDate.Value, endDate.Value);
                jsonOutputProcessor.ProcessOutput(a.OutputType, a.OutputFile, data);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            return(0);
        }
Exemple #2
0
        public void WhenGetDocumentsInDateRangeReturnsNullShouldReturnEmptyDictionary()
        {
            var startDate = DateTime.Now;
            var endDate   = startDate.AddDays(1);

            var result = sut.GetDocumentsInDateRange <WorkItem>(startDate, endDate);

            dataDocumentRepositoryMock.Verify(x => x.GetDocumentsInDateRange <WorkItem>(ProjectName, DocumentType.BugDatabase, startDate, endDate), Times.Once);
            Assert.Empty(result);
        }
Exemple #3
0
        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);
        }