Esempio n. 1
0
        public void BuildCopShouldExcludeBuildGroupsFromExplicitConfig()
        {
            BuildCopConfiguration config     = new BuildCopConfiguration();
            buildGroupElement     buildGroup = new buildGroupElement();

            buildGroup.enabled = true;
            buildGroup.name    = "TestBuildGroup";
            buildFilePathElement path = new buildFilePathElement();

            path.rootPath      = @"BuildFiles";
            path.excludedFiles = "default";
            buildGroup.buildFiles.paths.Add(path);
            ruleElement mockRule = new ruleElement();

            mockRule.name = "Mock";
            mockRule.type = typeof(MockRule).AssemblyQualifiedName;
            buildGroup.rules.Add(mockRule);
            config.buildGroups.Add(buildGroup);

            BuildCopReport report = BuildCopEngine.Execute(config, new string[] { });

            Assert.IsNotNull(report);
            IList <BuildGroupReport> groupReports = report.BuildGroupReports;

            Assert.IsNotNull(groupReports);
            Assert.AreEqual <int>(0, groupReports.Count);
        }
Esempio n. 2
0
        public void VerifyMultipleFilesWithGlobalExclude()
        {
            BuildCopConfiguration config     = new BuildCopConfiguration();
            buildGroupElement     buildGroup = new buildGroupElement();

            buildGroup.name    = "TestBuildGroup";
            buildGroup.enabled = true;
            buildGroup.buildFiles.excludedFiles = "signed";
            buildFilePathElement path = new buildFilePathElement();

            path.rootPath      = @"BuildFiles";
            path.excludedFiles = "default";
            buildGroup.buildFiles.paths.Add(path);
            ruleElement mockRule = new ruleElement();

            mockRule.name = "Mock";
            mockRule.type = typeof(MockRule).AssemblyQualifiedName;
            buildGroup.rules.Add(mockRule);
            config.buildGroups.Add(buildGroup);

            BuildCopReport report = BuildCopEngine.Execute(config);

            Assert.IsNotNull(report);
            IList <BuildGroupReport> groupReports = report.BuildGroupReports;

            Assert.IsNotNull(groupReports);
            Assert.AreEqual <int>(1, groupReports.Count);
            BuildGroupReport groupReport = groupReports[0];

            Assert.IsNotNull(groupReport);
            Assert.AreEqual <string>("TestBuildGroup", groupReport.BuildGroupName);
            Assert.IsNotNull(groupReport.BuildFileReports);
            Assert.AreEqual <int>(0, groupReport.BuildFileReports.Count);
        }
Esempio n. 3
0
        public void BuildCopShouldExcludeBuildGroupsFromAppConfig()
        {
            BuildCopReport report = BuildCopEngine.Execute(new string[] { });

            Assert.IsNotNull(report);
            IList <BuildGroupReport> groupReports = report.BuildGroupReports;

            Assert.IsNotNull(groupReports);
            Assert.AreEqual <int>(0, groupReports.Count);
        }
Esempio n. 4
0
        public void BuildCopShouldReportRuleExceptions()
        {
            BuildCopConfiguration config     = new BuildCopConfiguration();
            buildGroupElement     buildGroup = new buildGroupElement();

            buildGroup.name    = "TestBuildGroup";
            buildGroup.enabled = true;
            buildFilePathElement path = new buildFilePathElement();

            path.rootPath      = @"BuildFiles";
            path.searchPattern = "DefaultConsoleApplication.csproj";
            buildGroup.buildFiles.paths.Add(path);
            ruleElement mockRule = new ruleElement();

            mockRule.name        = "Mock";
            mockRule.type        = typeof(ExceptionMockRule).AssemblyQualifiedName;
            mockRule.RuleChecker = new ExceptionMockRule(mockRule);
            buildGroup.rules.Add(mockRule);
            config.buildGroups.Add(buildGroup);

            BuildCopReport report = BuildCopEngine.Execute(config);

            Assert.IsNotNull(report);

            IList <BuildGroupReport> groupReports = report.BuildGroupReports;

            Assert.IsNotNull(groupReports);
            Assert.AreEqual <int>(1, groupReports.Count);
            BuildGroupReport groupReport = groupReports[0];

            Assert.IsNotNull(groupReport);
            Assert.AreEqual <string>("TestBuildGroup", groupReport.BuildGroupName);
            Assert.IsNotNull(groupReport.BuildFileReports);
            Assert.AreEqual <int>(1, groupReport.BuildFileReports.Count);
            BuildFileReport fileReport = groupReport.BuildFileReports[0];

            Assert.IsNotNull(fileReport);
            Assert.AreEqual <string>(@"BuildFiles\DefaultConsoleApplication.csproj", fileReport.FileName);
            Assert.IsNotNull(fileReport.LogEntries);
            Assert.AreEqual <int>(1, fileReport.LogEntries.Count);
            LogEntry entry = fileReport.LogEntries[0];

            Assert.AreEqual <LogLevel>(LogLevel.Exception, entry.Level);
            Assert.AreEqual <string>("An exception occurred while analysing the build file.", entry.Message);
            Assert.IsNotNull(entry.Detail);
            Assert.IsTrue(entry.Detail.Contains("ExceptionMock was configured to throw exceptions."));
        }
Esempio n. 5
0
        public void FormattersShouldNotThrowOnFormatting()
        {
            BuildCopConfiguration config     = new BuildCopConfiguration();
            buildGroupElement     buildGroup = new buildGroupElement();

            buildGroup.name = "TestBuildGroup";
            buildFilePathElement path = new buildFilePathElement();

            path.rootPath      = @"BuildFiles";
            path.searchPattern = "DefaultConsoleApplication.csproj";
            buildGroup.buildFiles.paths.Add(path);
            ruleElement mockRule = new ruleElement();

            mockRule.name = "Mock";
            mockRule.type = typeof(MockRule).AssemblyQualifiedName;
            buildGroup.rules.Add(mockRule);
            config.buildGroups.Add(buildGroup);
            BuildCopReport report = BuildCopEngine.Execute(config);

            Assert.IsNotNull(report);

            // Execute the known formatters.
            BaseFormatter formatter;

            formatter = new ConsoleFormatter(null);
            formatter.WriteReport(report, LogLevel.Information);
            formatterElement htmlFileConfiguration = new formatterElement();

            htmlFileConfiguration.output.fileName   = "TestFormatterOutput.html";
            htmlFileConfiguration.output.launch     = false;
            htmlFileConfiguration.output.stylesheet = string.Empty;
            formatter = new HtmlFormatter(htmlFileConfiguration);
            formatter.WriteReport(report, LogLevel.Information);
            formatterElement xmlFileConfiguration = new formatterElement();

            xmlFileConfiguration.output.fileName   = "TestFormatterOutput.xml";
            xmlFileConfiguration.output.launch     = false;
            xmlFileConfiguration.output.stylesheet = string.Empty;
            formatter = new XmlFormatter(xmlFileConfiguration);
            formatter.WriteReport(report, LogLevel.Information);
            formatterElement csvFileConfiguration = new formatterElement();

            csvFileConfiguration.output.fileName = "TestFormatterOutput.csv";
            csvFileConfiguration.output.launch   = false;
            formatter = new CsvFormatter(csvFileConfiguration);
            formatter.WriteReport(report, LogLevel.Information);
        }
Esempio n. 6
0
        public void BuildCopShouldExecuteFormatters()
        {
            BuildCopConfiguration config     = new BuildCopConfiguration();
            buildGroupElement     buildGroup = new buildGroupElement();

            buildGroup.name    = "TestBuildGroup";
            buildGroup.enabled = true;
            buildFilePathElement path = new buildFilePathElement();

            path.rootPath      = @"BuildFiles";
            path.searchPattern = "DefaultConsoleApplication.csproj";
            buildGroup.buildFiles.paths.Add(path);
            ruleElement mockRule = new ruleElement();

            mockRule.name        = "Mock";
            mockRule.type        = typeof(MockRule).AssemblyQualifiedName;
            mockRule.RuleChecker = new MockRule(mockRule);
            buildGroup.rules.Add(mockRule);
            config.buildGroups.Add(buildGroup);
            formatterElement formatter = new formatterElement();

            formatter.type            = typeof(MockFormatter).AssemblyQualifiedName;
            formatter.minimumLogLevel = LogLevel.Information;
            formatter.Formatter       = new MockFormatter(formatter);
            config.formatters.Add(formatter);

            MockFormatter.LastReport = null;
            BuildCopEngine.Execute(config);
            BuildCopReport lastReport = MockFormatter.LastReport;

            Assert.IsNotNull(lastReport);
            Assert.AreEqual <string>(typeof(BuildCopEngine).Assembly.GetName().Version.ToString(), lastReport.EngineVersion);
            Assert.IsTrue(DateTime.Now - lastReport.GeneratedTime < TimeSpan.FromMinutes(1));
            IList <BuildGroupReport> groupReports = lastReport.BuildGroupReports;

            Assert.IsNotNull(groupReports);
            Assert.AreEqual <int>(1, groupReports.Count);
            BuildGroupReport groupReport = groupReports[0];

            Assert.IsNotNull(groupReport);
            Assert.AreEqual <string>("TestBuildGroup", groupReport.BuildGroupName);
            Assert.IsNotNull(groupReport.BuildFileReports);
            Assert.AreEqual <int>(1, groupReport.BuildFileReports.Count);
            CheckMockFileReport(groupReport.BuildFileReports[0], @"BuildFiles\DefaultConsoleApplication.csproj");
        }
Esempio n. 7
0
 /// <summary>
 /// Main is the entry point of the application.
 /// </summary>
 /// <param name="args">contains the program arguments</param>
 static void Main(string[] args)
 {
     try
     {
         if (args == null || args.Length == 0)
         {
             BuildCopEngine.Execute();
         }
         else
         {
             BuildCopEngine.Execute(args);
         }
     }
     catch (Exception exc)
     {
         System.Console.WriteLine(string.Format("{2}{0}: {1}{2}{3}", exc.GetType().Name, exc.Message, Environment.NewLine, exc.StackTrace));
     }
 }
Esempio n. 8
0
        public void BuildCopShouldExecuteSharedRules()
        {
            BuildCopConfiguration config     = new BuildCopConfiguration();
            buildGroupElement     buildGroup = new buildGroupElement();

            buildGroup.name    = "TestBuildGroup";
            buildGroup.enabled = true;
            buildFilePathElement path = new buildFilePathElement();

            path.rootPath      = @"BuildFiles";
            path.searchPattern = "DefaultConsoleApplication.csproj";
            buildGroup.buildFiles.paths.Add(path);
            ruleElement mockRule = new ruleElement();

            mockRule.name        = "Mock";
            mockRule.RuleChecker = new MockRule(mockRule);
            buildGroup.rules.Add(mockRule);
            ruleElement sharedMockRule = new ruleElement();

            sharedMockRule.name        = "Mock";
            sharedMockRule.type        = typeof(MockRule).AssemblyQualifiedName;
            sharedMockRule.RuleChecker = new MockRule(sharedMockRule);
            config.sharedRules.Add(sharedMockRule);
            config.buildGroups.Add(buildGroup);

            BuildCopReport report = BuildCopEngine.Execute(config);

            Assert.IsNotNull(report);

            IList <BuildGroupReport> groupReports = report.BuildGroupReports;

            Assert.IsNotNull(groupReports);
            Assert.AreEqual <int>(1, groupReports.Count);
            BuildGroupReport groupReport = groupReports[0];

            Assert.IsNotNull(groupReport);
            Assert.AreEqual <string>("TestBuildGroup", groupReport.BuildGroupName);
            Assert.IsNotNull(groupReport.BuildFileReports);
            Assert.AreEqual <int>(1, groupReport.BuildFileReports.Count);
            CheckMockFileReport(groupReport.BuildFileReports[0], @"BuildFiles\DefaultConsoleApplication.csproj");
        }
Esempio n. 9
0
        public void BuildCopShouldExcludeBuildGroupsWithoutRules()
        {
            BuildCopConfiguration config     = new BuildCopConfiguration();
            buildGroupElement     buildGroup = new buildGroupElement();

            buildGroup.name    = "TestBuildGroup";
            buildGroup.enabled = true;
            buildFilePathElement path = new buildFilePathElement();

            path.rootPath      = @"BuildFiles";
            path.excludedFiles = "default";
            buildGroup.buildFiles.paths.Add(path);
            config.buildGroups.Add(buildGroup);

            BuildCopReport report = BuildCopEngine.Execute(config);

            Assert.IsNotNull(report);
            IList <BuildGroupReport> groupReports = report.BuildGroupReports;

            Assert.IsNotNull(groupReports);
            Assert.AreEqual <int>(0, groupReports.Count);
        }
Esempio n. 10
0
        public void BuildCopShouldExcludeRulesOnOutputTypeWithProjectTypeGuids()
        {
            BuildCopConfiguration config     = new BuildCopConfiguration();
            buildGroupElement     buildGroup = new buildGroupElement();

            buildGroup.name    = "TestBuildGroup";
            buildGroup.enabled = true;
            buildFilePathElement path = new buildFilePathElement();

            path.rootPath      = @"BuildFiles";
            path.searchPattern = "SignedConsoleApplication.csproj";
            buildGroup.buildFiles.paths.Add(path);
            ruleElement mockRule = new ruleElement();

            mockRule.name = "Mock";
            mockRule.type = typeof(MockRule).AssemblyQualifiedName;
            mockRule.excludedOutputTypes = "Dummy;Web";
            buildGroup.rules.Add(mockRule);
            config.buildGroups.Add(buildGroup);

            BuildCopReport report = BuildCopEngine.Execute(config);

            Assert.IsNotNull(report);

            IList <BuildGroupReport> groupReports = report.BuildGroupReports;

            Assert.IsNotNull(groupReports);
            Assert.AreEqual <int>(1, groupReports.Count);
            BuildGroupReport groupReport = groupReports[0];

            Assert.IsNotNull(groupReport);
            Assert.AreEqual <string>("TestBuildGroup", groupReport.BuildGroupName);
            Assert.IsNotNull(groupReport.BuildFileReports);
            Assert.AreEqual <int>(1, groupReport.BuildFileReports.Count);
            Assert.AreEqual <int>(0, groupReport.BuildFileReports[0].LogEntries.Count);
        }
Esempio n. 11
0
        public override bool Execute()
        {
            BuildCopReport theReport;

            if (buildGroups == null || buildGroups.Length == 0)
            {
                theReport = BuildCopEngine.Execute();
            }
            else
            {
                theReport = BuildCopEngine.Execute(buildGroups.Select(m => m.ItemSpec).ToArray <string>());
            }

            int errorCount = theReport.BuildGroupReports.Sum(m => m.BuildFileReports.Sum(n => n.FindLogEntries(LogLevel.Error).Count));

            List <TaskItem> exceptionList   = new List <TaskItem>();
            List <TaskItem> errorList       = new List <TaskItem>();
            List <TaskItem> warningList     = new List <TaskItem>();
            List <TaskItem> informationList = new List <TaskItem>();

            if (errorCount > 0)
            {
                /// TODO - How do you do this in Linq?
                foreach (BuildGroupReport aBuildGroupReport in theReport.BuildGroupReports)
                {
                    foreach (BuildFileReport aBuildFileReport in aBuildGroupReport.BuildFileReports)
                    {
                        foreach (LogEntry aLogEntry in aBuildFileReport.FindLogEntries(LogLevel.Information))
                        {
                            string message = aLogEntry.Level + " " + aBuildFileReport.FileName + " " + aLogEntry.Detail;
                            Log.LogMessage(MessageImportance.High, message);

                            switch (aLogEntry.Level)
                            {
                            case LogLevel.Exception:
                                exceptionList.Add(new TaskItem(message));
                                Log.LogError(message);
                                break;

                            case LogLevel.Error:
                                errorList.Add(new TaskItem(message));
                                Log.LogError(message);
                                break;

                            case LogLevel.Warning:
                                warningList.Add(new TaskItem(message));
                                Log.LogWarning(message);
                                break;

                            default:
                                informationList.Add(new TaskItem(message));
                                Log.LogMessage(message);
                                break;
                            }
                        }
                    }
                }
            }

            Exceptions  = exceptionList.ToArray();
            Errors      = errorList.ToArray();
            Warnings    = warningList.ToArray();
            Information = informationList.ToArray();



            if (errorCount > 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 12
0
 public void ExecuteShouldTakeAppConfig()
 {
     BuildCopReport report = BuildCopEngine.Execute();
 }