public GivenAGitCodeChurnProcessor()
        {
            args = new GitExtractCommandLineArgs();
            args.GitLogCommand = "git log blah";
            args.OutputType    = OutputType.SingleFile;
            args.OutputFile    = "outputfile";

            invokeLines = new List <string>();

            gitLogParserMock = new Mock <IGitLogParser>();

            outputProcessorMock = new Mock <IOutputProcessor>();
            outputProcessorMock.Setup(m => m.ProcessOutput(args.OutputType, args.OutputFile, It.IsAny <Dictionary <DateTime, Dictionary <string, DailyCodeChurn> > >())).Callback <OutputType, string, Dictionary <DateTime, Dictionary <string, DailyCodeChurn> > >(
                (outputType, outputFile, dict) =>
            {
                this.processedOutput = dict;
            });

            gitLogParserMock.Setup(m => m.Parse(invokeLines)).Returns(new List <GitCommit>());

            commandLineParserMock = new Mock <ICommandLineParser>();
            commandLineParserMock.Setup(m => m.ParseCommandLine("git log blah")).Returns(new Tuple <string, string>("git", "log blah"));

            processWrapperMock = new Mock <IProcessWrapper>();
            processWrapperMock.Setup(m => m.Invoke("git", "log blah")).Returns(new Tuple <int, List <string> >(0, invokeLines));

            bugDatabaseMock = new Mock <IBugDatabaseProcessor>();

            this.logger = new Mock <ILogger>();

            processor = new GitCodeChurnProcessor(this.commandLineParserMock.Object, this.processWrapperMock.Object, gitLogParserMock.Object, outputProcessorMock.Object, bugDatabaseMock.Object, logger.Object, args);
        }
        public void WhenCollectingBugDatabaseCacheAndNoOutputFileShouldThrowException()
        {
            args = new GitExtractCommandLineArgs()
            {
                BugDatabaseDLL = "some/path/to.dll"
            };

            Action action = () => new GitCodeChurnProcessor(this.commandLineParserMock.Object, this.processWrapperMock.Object,
                                                            this.gitLogParserMock.Object, this.outputProcessorMock.Object, this.bugDatabaseMock.Object, this.logger.Object, args);

            var exception = Assert.Throws <Exception>(action);

            Assert.Equal("Dll specified without known output file", exception.Message);
        }
        public void WhenCollectingBugDatabaseCacheAndDllIsEmptyShouldReturn()
        {
            args = new GitExtractCommandLineArgs()
            {
                BugDatabaseDLL = string.Empty
            };

            processor = new GitCodeChurnProcessor(this.commandLineParserMock.Object, this.processWrapperMock.Object,
                                                  this.gitLogParserMock.Object, this.outputProcessorMock.Object, this.bugDatabaseMock.Object, this.logger.Object, args);

            processor.QueryBugDatabase();

            this.bugDatabaseMock.Verify(b => b.ProcessBugDatabase(It.IsAny <string>(), It.IsAny <IEnumerable <string> >()), Times.Never);
        }
        public void WhenCollectingBugDatabaseCacheAndbugDatabaseNotSetShouldThrow()
        {
            this.args = new GitExtractCommandLineArgs()
            {
                BugDatabaseDLL        = "some/path/to.dll",
                BugDatabaseOutputFile = "some/path/to/output/files"
            };

            this.processor = new GitCodeChurnProcessor(this.commandLineParserMock.Object, this.processWrapperMock.Object,
                                                       this.gitLogParserMock.Object, this.outputProcessorMock.Object, null, this.logger.Object, args);

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

            Assert.Throws <NullReferenceException>(collect);
        }
        public void WhenExtractingAndHasBugRegexesShouldLogChangesetsWithBugs()
        {
            args = new GitExtractCommandLineArgs()
            {
                BugRegexes    = "bug+",
                GitLogCommand = "git log blah",
                OutputType    = OutputType.SingleFile,
                OutputFile    = "outputfile"
            };
            processor = new GitCodeChurnProcessor(this.commandLineParserMock.Object, this.processWrapperMock.Object,
                                                  this.gitLogParserMock.Object, this.outputProcessorMock.Object, this.bugDatabaseMock.Object, this.logger.Object, args);

            processor.Extract();

            this.logger.Verify(m => m.LogToConsole("Changesets with bugs: 0/0"));
        }
Пример #6
0
        private static int RunGitCodeChurnProcessor(GitExtractCommandLineArgs a)
        {
            var processWrapper       = new ProcessWrapper();
            var commandLineParser    = new CommandLineParser();
            var gitLogParser         = new GitLogParser();
            var logger               = new ConsoleLoggerWithTimestamp();
            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 GitCodeChurnProcessor(commandLineParser, processWrapper, gitLogParser, outputProcessor, bugDatabaseProcessor, logger, a);

            processor.QueryBugDatabase();
            return(processor.Extract());
        }
        public void WhenCrearingGitCodeChurnProcessorWithBugDatabaseDllAndNoOutputSpecifiedShouldThrowAnException()
        {
            var commandLineArgs = new GitExtractCommandLineArgs
            {
                BugDatabaseDLL = "some/path/to.dll"
            };

            Action action = () =>
            {
                new GitCodeChurnProcessor(this.commandLineParserMock.Object,
                                          this.processWrapperMock.Object,
                                          this.gitLogParserMock.Object, this.outputProcessorMock.Object, this.bugDatabaseMock.Object,
                                          this.logger.Object, commandLineArgs);
            };

            var exception = Assert.Throws <Exception>(action);

            Assert.Equal("Dll specified without known output file", exception.Message);
        }
        public void WhenCollectingBugDatabaseCacheShouldProcessOutput()
        {
            args = new GitExtractCommandLineArgs()
            {
                BugDatabaseDLL        = "some/path/to.dll",
                BugDatabaseOutputFile = "some/path/to/output/files"
            };

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

            processor = new GitCodeChurnProcessor(this.commandLineParserMock.Object, this.processWrapperMock.Object,
                                                  this.gitLogParserMock.Object, this.outputProcessorMock.Object, this.bugDatabaseMock.Object, this.logger.Object, args);

            processor.QueryBugDatabase();

            this.outputProcessorMock
            .Verify(o => o.ProcessOutput(args.BugDatabaseOutputType, args.BugDatabaseOutputFile, It.IsAny <Dictionary <DateTime, Dictionary <string, WorkItem> > >()),
                    Times.Once);
        }
Пример #9
0
        public GitCodeChurnProcessor(ICommandLineParser commandLineParser, IProcessWrapper processWrapper, IGitLogParser gitLogParser, IOutputProcessor outputProcessor, IBugDatabaseProcessor bugDatabaseProcessor, ILogger logger, GitExtractCommandLineArgs commandLineArgs) : this(commandLineParser, processWrapper, gitLogParser, outputProcessor, bugDatabaseProcessor, logger, commandLineArgs.OutputFile, commandLineArgs.OutputType, commandLineArgs.BugRegexes, commandLineArgs.BugDatabaseDLL, commandLineArgs.BugDatabaseOutputFile, commandLineArgs.BugDatabaseDllArgs, commandLineArgs.GitLogCommand)
        {
            if (string.IsNullOrWhiteSpace(bugDatabaseDLL) == false && string.IsNullOrWhiteSpace(bugDatabaseOutputFile))
            {
                throw new Exception("Dll specified without known output file");
            }

            this.bugDatabaseOutputFile = commandLineArgs.BugDatabaseOutputFile;
            this.bugDatabaseOutputType = commandLineArgs.BugDatabaseOutputType;
        }