示例#1
0
        public void WhenProcessingWithMultipleFilesShouldProcessOutputForMultipleFiles()
        {
            commandLineArgs.OutputType = OutputType.MultipleFile;
            this.processor             = new PerforceCodeChurnProcessor(processWrapperMock.Object, changesParserMock.Object, describeParserMock.Object, commandLineParserMock.Object, bugDatabseMock.Object, loggerMock.Object, stopWatchMock.Object, outputProcessorMock.Object, commandLineArgs);

            var changesLines   = new List <string>();
            var describeLines1 = new List <string>();
            var describeLines2 = new List <string>();

            var changeset1 = new PerforceChangeset();
            var changeset2 = new PerforceChangeset();

            this.processWrapperMock.Setup(m => m.Invoke("changes", "commandline")).Returns(new Tuple <int, List <string> >(0, changesLines));
            this.processWrapperMock.Setup(m => m.Invoke("describe", "1")).Returns(new Tuple <int, List <string> >(0, describeLines1));
            this.processWrapperMock.Setup(m => m.Invoke("describe", "2")).Returns(new Tuple <int, List <string> >(0, describeLines2));
            this.changesParserMock.Setup(m => m.Parse(changesLines)).Returns(new List <int>()
            {
                1, 2
            });
            this.describeParserMock.Setup(m => m.Parse(describeLines1)).Returns(changeset1);
            this.describeParserMock.Setup(m => m.Parse(describeLines2)).Returns(changeset2);

            this.processor.Extract();

            this.outputProcessorMock.Verify(m => m.ProcessOutput(OutputType.MultipleFile, It.IsAny <string>(), It.IsAny <Dictionary <DateTime, Dictionary <string, DailyCodeChurn> > >()), Times.Once());
        }
示例#2
0
        public void WhenCreatingNewObjectWithBugDatabaseCacheAndbugDatabaseNotSetShouldThrow()
        {
            var args = new P4ExtractCommandLineArgs()
            {
                BugDatabaseDLL = "some/path/to.dll"
            };

            Action newObjectAction = () => this.processor = new PerforceCodeChurnProcessor(processWrapperMock.Object, changesParserMock.Object, describeParserMock.Object, commandLineParserMock.Object, bugDatabseMock.Object, loggerMock.Object, stopWatchMock.Object, outputProcessorMock.Object, args);

            Assert.Throws <Exception>(newObjectAction);
        }
示例#3
0
        public void WhenCollectingBugDatabaseCacheAndDllIsEmptyShouldReturn()
        {
            this.commandLineArgs = new P4ExtractCommandLineArgs()
            {
                BugDatabaseDLL = string.Empty
            };

            this.processor = new PerforceCodeChurnProcessor(processWrapperMock.Object, changesParserMock.Object, describeParserMock.Object, commandLineParserMock.Object, bugDatabseMock.Object, loggerMock.Object, stopWatchMock.Object, outputProcessorMock.Object, commandLineArgs);

            processor.QueryBugDatabase();

            this.bugDatabseMock.Verify(b => b.ProcessBugDatabase(It.IsAny <string>(), It.IsAny <IEnumerable <string> >()), Times.Never);
        }
示例#4
0
        public void WhenCollectingBugDatabaseCacheAndbugDatabaseNotSetShouldThrow()
        {
            this.commandLineArgs = new P4ExtractCommandLineArgs()
            {
                BugDatabaseDLL        = "some/path/to.dll",
                BugDatabaseOutputFile = "some/path/to/output/files"
            };

            this.processor = new PerforceCodeChurnProcessor(processWrapperMock.Object, changesParserMock.Object, describeParserMock.Object, commandLineParserMock.Object, null, loggerMock.Object, stopWatchMock.Object, outputProcessorMock.Object, commandLineArgs);

            Action collect = () => processor.QueryBugDatabase();

            Assert.Throws <NullReferenceException>(collect);
        }
示例#5
0
        public void WhenCollectingBugDatabaseCacheAndBugCacheNullShouldReturn()
        {
            this.commandLineArgs = new P4ExtractCommandLineArgs()
            {
                BugDatabaseDLL        = "some/path/to.dll",
                BugDatabaseOutputFile = "some/path/to/output/files"
            };

            this.bugDatabseMock
            .Setup(b => b.ProcessBugDatabase(It.IsAny <string>(), It.IsAny <IEnumerable <string> >()))
            .Returns((Dictionary <DateTime, Dictionary <string, WorkItem> >)null);

            this.processor = new PerforceCodeChurnProcessor(processWrapperMock.Object, changesParserMock.Object, describeParserMock.Object, commandLineParserMock.Object, bugDatabseMock.Object, loggerMock.Object, stopWatchMock.Object, outputProcessorMock.Object, commandLineArgs);

            processor.QueryBugDatabase();

            this.loggerMock.Verify(l => l.LogToConsole(It.IsAny <string>()), Times.Never);
        }
示例#6
0
        public void WhenCollectingBugDatabaseCacheShouldProcessOutput()
        {
            this.commandLineArgs = new P4ExtractCommandLineArgs()
            {
                BugDatabaseDLL        = "some/path/to.dll",
                BugDatabaseOutputFile = "some/path/to/output/files"
            };

            this.bugDatabseMock
            .Setup(b => b.ProcessBugDatabase(It.IsAny <string>(), It.IsAny <IEnumerable <string> >()))
            .Returns(new Dictionary <DateTime, Dictionary <string, WorkItem> >());

            this.processor = new PerforceCodeChurnProcessor(processWrapperMock.Object, changesParserMock.Object, describeParserMock.Object, commandLineParserMock.Object, bugDatabseMock.Object, loggerMock.Object, stopWatchMock.Object, outputProcessorMock.Object, commandLineArgs);

            processor.QueryBugDatabase();

            this.outputProcessorMock
            .Verify(o => o.ProcessOutput(this.commandLineArgs.BugDatabaseOutputType, this.commandLineArgs.BugDatabaseOutputFile, It.IsAny <Dictionary <DateTime, Dictionary <string, WorkItem> > >()),
                    Times.Once);
        }
示例#7
0
        private static int RunPerforceCodeChurnProcessor(P4ExtractCommandLineArgs a)
        {
            var processWrapper       = new ProcessWrapper();
            var changesParser        = new ChangesParser();
            var describeParser       = new DescribeParser();
            var commandLineParser    = new CommandLineParser();
            var logger               = new ConsoleLoggerWithTimestamp();
            var stopWatch            = new StopWatchWrapper();
            var outputProcessor      = new JsonOutputProcessor(new DataConverter(), new FileStreamFactory(), logger);
            var bugDatabaseFactory   = new BugDatabaseFactory();
            var bugDatabaseDllLoader = new BugDatabaseDllLoader(logger, bugDatabaseFactory);
            var webRequest           = new WebRequest(new HttpClientWrapperFactory(bugDatabaseFactory));
            var fileSystem           = new FileSystem();
            var jsonParser           = new JsonListParser <WorkItem>(new FileStreamFactory());
            var bugDatabaseProcessor = new BugDatabaseProcessor(bugDatabaseDllLoader, webRequest, fileSystem, jsonParser, logger, a.BugDatabaseOutputFile);
            var processor            = new PerforceCodeChurnProcessor(processWrapper, changesParser, describeParser, commandLineParser, bugDatabaseProcessor, logger, stopWatch, outputProcessor, a);

            processor.QueryBugDatabase();
            return(processor.Extract());
        }
示例#8
0
        public GivenAPerforceCodeChurnProcessor()
        {
            var invokeLines = new List <string>();

            this.processWrapperMock = new Mock <IProcessWrapper>();
            this.processWrapperMock.Setup(m => m.Invoke("changes", "commandline")).Returns(new Tuple <int, List <string> >(0, invokeLines));

            this.changesParserMock = new Mock <IChangesParser>();
            this.changesParserMock.Setup(m => m.Parse(invokeLines)).Returns(new List <int>());

            this.describeParserMock    = new Mock <IDescribeParser>();
            this.commandLineParserMock = new Mock <ICommandLineParser>();
            this.commandLineParserMock.Setup(m => m.ParseCommandLine("changes commandline")).Returns(new Tuple <string, string>("changes", "commandline"));
            this.commandLineParserMock.Setup(m => m.ParseCommandLine("describe 1")).Returns(new Tuple <string, string>("describe", "1"));
            this.commandLineParserMock.Setup(m => m.ParseCommandLine("describe 2")).Returns(new Tuple <string, string>("describe", "2"));
            this.commandLineParserMock.Setup(m => m.ParseCommandLine("describe 3")).Returns(new Tuple <string, string>("describe", "3"));
            this.loggerMock = new Mock <ILogger>();

            this.stopWatchMock = new Mock <IStopWatch>();

            this.outputProcessorMock = new Mock <IOutputProcessor>();
            this.outputProcessorMock.Setup(m => m.ProcessOutput(OutputType.SingleFile, It.IsAny <string>(), It.IsAny <Dictionary <DateTime, Dictionary <string, DailyCodeChurn> > >())).Callback <OutputType, string, Dictionary <DateTime, Dictionary <string, DailyCodeChurn> > >(
                (outputType, file, output) =>
            {
                this.output = output;
            }
                );

            this.bugDatabseMock = new Mock <IBugDatabaseProcessor>();

            this.commandLineArgs = new P4ExtractCommandLineArgs
            {
                OutputType            = OutputType.SingleFile,
                OutputFile            = "filename",
                P4ChangesCommandLine  = "changes commandline",
                P4DescribeCommandLine = "describe {0}"
            };
            this.processor = new PerforceCodeChurnProcessor(processWrapperMock.Object, changesParserMock.Object, describeParserMock.Object, commandLineParserMock.Object, bugDatabseMock.Object, loggerMock.Object, stopWatchMock.Object, outputProcessorMock.Object, commandLineArgs);
        }
示例#9
0
        private static int RunPerforceToCosmosDbCodeChurnProcessor(P4ExtractToCosmosDbCommandLineArgs a)
        {
            var processWrapper       = new ProcessWrapper();
            var changesParser        = new ChangesParser();
            var describeParser       = new DescribeParser();
            var commandLineParser    = new CommandLineParser();
            var logger               = new ConsoleLoggerWithTimestamp();
            var stopWatch            = new StopWatchWrapper();
            var bugDatabaseFactory   = new BugDatabaseFactory();
            var bugDatabaseDllLoader = new BugDatabaseDllLoader(logger, bugDatabaseFactory);
            var webRequest           = new WebRequest(new HttpClientWrapperFactory(bugDatabaseFactory));
            var fileSystem           = new FileSystem();

            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 bugDatabaseProcessor = new CosmosDbBugDatabaseProcessor(bugDatabaseDllLoader, fileSystem, webRequest, logger, dataDocumentRepository, a.CosmosProjectName);
            var processor            = new PerforceCodeChurnProcessor(processWrapper, changesParser, describeParser, commandLineParser, bugDatabaseProcessor, logger, stopWatch, cosmosOutputProcessor, a);

            processor.QueryBugDatabase();
            return(processor.Extract());
        }
示例#10
0
        public void WhenCreatingNewObjectWithP4ExtractToCosmosDbCommandLineArgsShouldNotThrow()
        {
            var exception = Record.Exception(() => this.processor = new PerforceCodeChurnProcessor(processWrapperMock.Object, changesParserMock.Object, describeParserMock.Object, commandLineParserMock.Object, bugDatabseMock.Object, loggerMock.Object, stopWatchMock.Object, outputProcessorMock.Object, new P4ExtractToCosmosDbCommandLineArgs()));

            Assert.Null(exception);
        }