Esempio n. 1
0
        public void CanApplyToCurrentContext()
        {
            // act
            var buildServer = new LocalBuildServer(GetLogger());

            // arrange
            var result = buildServer.CanApplyToCurrentContext();

            // assert
            Assert.False(result);
        }
Esempio n. 2
0
        public void Name()
        {
            // act
            var buildServer = new LocalBuildServer(GetLogger());

            // arrange
            var name = buildServer.Name;

            // assert
            Assert.Equal("Local console", name);
        }
Esempio n. 3
0
        public ParseReportCommand(Logger logger,
                                  IFileSystem fileSystem,
                                  [ImportMany]IEnumerable<IBuildServer> buildServers,
                                  LocalBuildServer localBuildServer,
                                  [ImportMany]IEnumerable<IReportParser> parsers)
            : base(logger)
        {
            _fileSystem = fileSystem;
            _buildServers = buildServers;
            _localBuildServer = localBuildServer;
            _parsers = parsers;

            IsCommand("parsereport", "Parse the report and show warnings in console or inject them to the build server");
            HasOption("includesource", "Include the source in messages", s => _includeSourceInMessage = true);

            // TODO
            // force display warnings to console additionally to the build server
            // warning as error
        }
Esempio n. 4
0
        public void WriteIntegration()
        {
            // act
            var buildServer = new LocalBuildServer(GetLogger());

            var issues = GetIssues();

            // arrange
            foreach (var issue in issues)
            {
                buildServer.WriteMessage(issue);
            }

            // assert
            var outputLines = _loggerOutput.ToString();
            Assert.Contains("Suggestion Name1 'FilePath1' - Line 42: Message1", outputLines);
            Assert.Contains("Warning Name2 'FilePath2' - Line 465: Message2", outputLines);
            Assert.Contains("Error Name3 'FilePath3' - Line 82: Message3", outputLines);
        }
        public void Execute_ExistingButEmptyReport_ShouldLogErrorOnLoad_DefaultBuildServerIsLocal()
        {
            // arrange
            var logger = GetLogger();
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { "report.xml", MockFileData.NullObject } });
            var localBuildServer = new LocalBuildServer(logger);
            var mockBuildServer = GetMockBuildServer();
            var buildServers = new List<IBuildServer> { localBuildServer, mockBuildServer };
            var buildServerCommand = new BuildServerCommand(logger, fileSystem, buildServers, localBuildServer, Enumerable.Empty<IReportParser>());
            var remainingArgs = buildServerCommand.GetActualOptions().Parse(new[] { "report.xml" });

            // act
            var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

            // assert
            Assert.Equal(2, exitCode);
            var logs = _loggerOutput.ToString();
            Assert.Contains("\t- Local console", logs);
            Assert.Contains("An exception happened when loading the report 'System.Xml.XmlException: Root element is missing.", logs);
        }
        public void Execute_MultipleReports_ShouldWriteMessageFromIssues()
        {
            // arrange
            var logger = GetLogger();
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData>
            {
                { "report.xml", new MockFileData("<root></root>") },
                { "report2.xml", new MockFileData("<root></root>") }
            });
            var localBuildServer = new LocalBuildServer(logger);
            var mockBuildServer = GetMockBuildServer(true);
            var buildServers = new List<IBuildServer> { localBuildServer, mockBuildServer };
            var parsers = new List<IReportParser> { GetMockReportParser(true, true, true) };
            var buildServerCommand = new BuildServerCommand(logger, fileSystem, buildServers, localBuildServer, parsers);
            var remainingArgs = buildServerCommand.GetActualOptions().Parse(new[] { "report.xml", "report2.xml", "--debug" });

            // act
            var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

            // assert
            Assert.Equal(4, exitCode);
            var logs = _loggerOutput.ToString();
            Assert.Contains("3 issues was found", logs);
            Assert.Contains("Message1", logs);
            Assert.Contains("Message2", logs);
            Assert.Contains("Message3", logs);
            Assert.Contains("Message4", logs);
            Assert.Contains("Message5", logs);
            Assert.Contains("Message6", logs);
        }
        public void Execute_IncludeSource_BuildServerShouldIncludeSource()
        {
            // arrange
            var logger = GetLogger();
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { "report.xml", new MockFileData("<root></root>") } });
            var localBuildServer = new LocalBuildServer(logger);
            var mockBuildServer = GetMockBuildServer(true);
            var buildServers = new List<IBuildServer> { localBuildServer, mockBuildServer };
            var parsers = new List<IReportParser> { GetMockReportParser(true, false) };
            var buildServerCommand = new BuildServerCommand(logger, fileSystem, buildServers, localBuildServer, parsers);
            var remainingArgs = buildServerCommand.GetActualOptions().Parse(new[] { "report.xml", "--includesource" });

            // act
            var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

            // assert
            Assert.Equal(0, exitCode);
            var logs = _loggerOutput.ToString();
            Assert.Contains("Message1 - Source1", logs);
            Assert.Contains("Message2 - Source2", logs);
            Assert.Contains("Message3 - Source3", logs);
        }
        public void Execute_ParserCantParse_ShouldLogError()
        {
            // arrange
            var logger = GetLogger();
            var fileSystem = new MockFileSystem(new Dictionary<string, MockFileData> { { "report.xml", new MockFileData("<root></root>") } });
            var localBuildServer = new LocalBuildServer(logger);
            var mockBuildServer = GetMockBuildServer(true);
            var buildServers = new List<IBuildServer> { localBuildServer, mockBuildServer };
            var parsers = new List<IReportParser> { GetMockReportParser() };
            var buildServerCommand = new BuildServerCommand(logger, fileSystem, buildServers, localBuildServer, parsers);
            var remainingArgs = buildServerCommand.GetActualOptions().Parse(new[] { "report.xml" });

            // act
            var exitCode = buildServerCommand.Run(remainingArgs.ToArray());

            // assert
            Assert.Equal(3, exitCode);
            var logs = _loggerOutput.ToString();
            Assert.Contains("The adequate parser for this report was not found. You are welcome to address us an issue.", logs);
        }