public void VerifyMissingBuildPropertiesWithCondition()
        {
            BuildFile   file   = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement config = new ruleElement();
            ruleElementBuildProperty buildProperty;

            // Add missing build properties.
            buildProperty           = new ruleElementBuildProperty();
            buildProperty.name      = "dummy";
            buildProperty.value     = "dummy";
            buildProperty.condition = "Debug";
            config.buildProperties.Add(buildProperty);
            config.name        = "BuildProperty";
            config.RuleChecker = new BuildPropertiesRule(config);

            ruleElementBuildProperty rule = new ruleElementBuildProperty();

            rule.name = "BuildProperty";
            IList <LogEntry> entries = config.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(config.buildProperties.Count, entries.Count);
            foreach (LogEntry entry in entries)
            {
                Assert.AreEqual <string>("BuildProperty", entry.Rule);
                Assert.AreEqual <string>("PropertyShouldExist", entry.Code);
            }
        }
예제 #2
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);
        }
        public void VerifyCompareEqualToIncorrectCaseSensitive()
        {
            BuildFile   file   = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement config = new ruleElement();

            ruleElementBuildProperty buildProperty = new ruleElementBuildProperty();

            buildProperty.name                = "Configuration";
            buildProperty.value               = "debug";
            buildProperty.compareOption       = CompareOption.EqualTo.ToString();
            buildProperty.stringCompareOption = StringComparison.Ordinal.ToString();
            config.buildProperties.Add(buildProperty);
            config.name        = "BuildProperty";
            config.RuleChecker = new BuildPropertiesRule(config);

            ruleElementBuildProperty rule = new ruleElementBuildProperty();

            rule.name = "BuildProperty";
            IList <LogEntry> entries = config.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(1, entries.Count);
            Assert.AreEqual <string>("BuildProperty", entries[0].Rule);
            Assert.AreEqual <string>("IncorrectValue", entries[0].Code);
        }
예제 #4
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);
        }
예제 #5
0
        public void TestMiscProperties()
        {
            ruleElement rule = new ruleElement();

            rule.name          = "MyName";
            rule.type          = "MyType";
            rule.excludedFiles = "MyExcludedFiles";
            Assert.AreEqual <string>("MyName", rule.name);
            Assert.AreEqual <string>("MyType", rule.type);
            Assert.AreEqual <string>("MyExcludedFiles", rule.excludedFiles);

            formatterElement formatter = new formatterElement();

            formatter.name = "MyName";
            formatter.type = "MyType";
            Assert.AreEqual <string>("MyName", formatter.name);
            Assert.AreEqual <string>("MyType", formatter.type);

            outputTypeElement outputType = new outputTypeElement();

            outputType.alias           = "MyAlias";
            outputType.projectTypeGuid = "MyProjectTypeGuid";
            Assert.AreEqual <string>("MyAlias", outputType.alias);
            Assert.AreEqual <string>("MyProjectTypeGuid", outputType.projectTypeGuid);
        }
        public void VerifyIncorrectBuildPropertiesForMultipleConditions()
        {
            BuildFile   file   = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement config = new ruleElement();
            ruleElementBuildProperty buildProperty;

            // Add incorrect build properties.
            buildProperty           = new ruleElementBuildProperty();
            buildProperty.name      = "Optimize";
            buildProperty.value     = "dummy";
            buildProperty.condition = ""; // No condition means it should be true for all configurations (two in this case).
            config.buildProperties.Add(buildProperty);

            buildProperty           = new ruleElementBuildProperty();
            buildProperty.name      = "Optimize";
            buildProperty.value     = "dummy";
            buildProperty.condition = null; // Also try with null.
            config.buildProperties.Add(buildProperty);
            config.name        = "BuildProperty";
            config.RuleChecker = new BuildPropertiesRule(config);

            ruleElementBuildProperty rule = new ruleElementBuildProperty();

            rule.name = "BuildProperty";
            IList <LogEntry> entries = config.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(config.buildProperties.Count * 2, entries.Count);
            foreach (LogEntry entry in entries)
            {
                Assert.AreEqual <string>("BuildProperty", entry.Rule);
                Assert.AreEqual <string>("IncorrectValue", entry.Code);
            }
        }
        public void VerifyCorrectBuildProperties()
        {
            BuildFile   file   = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement config = new ruleElement();
            ruleElementBuildProperty buildProperty;

            // Add correct build properties.
            buildProperty       = new ruleElementBuildProperty();
            buildProperty.name  = "Configuration";
            buildProperty.value = "Debug";
            config.buildProperties.Add(buildProperty);

            buildProperty       = new ruleElementBuildProperty();
            buildProperty.name  = "Platform";
            buildProperty.value = "AnyCPU";
            config.buildProperties.Add(buildProperty);

            buildProperty       = new ruleElementBuildProperty();
            buildProperty.name  = "ProductVersion";
            buildProperty.value = "8.0.50727";
            config.buildProperties.Add(buildProperty);

            buildProperty           = new ruleElementBuildProperty();
            buildProperty.name      = "DebugSymbols";
            buildProperty.value     = "true";
            buildProperty.condition = "debug";
            config.buildProperties.Add(buildProperty);

            buildProperty           = new ruleElementBuildProperty();
            buildProperty.name      = "DebugType";
            buildProperty.value     = "full";
            buildProperty.condition = "debug";
            config.buildProperties.Add(buildProperty);

            buildProperty           = new ruleElementBuildProperty();
            buildProperty.name      = "DebugType";
            buildProperty.value     = "pdbonly";
            buildProperty.condition = "release";
            config.buildProperties.Add(buildProperty);

            buildProperty           = new ruleElementBuildProperty();
            buildProperty.name      = "ErrorReport";
            buildProperty.value     = "prompt";
            buildProperty.condition = ""; // No condition means it should be true for all configurations (two in this case).
            config.buildProperties.Add(buildProperty);
            config.name        = "BuildProperty";
            config.RuleChecker = new BuildPropertiesRule(config);

            ruleElementBuildProperty rule = new ruleElementBuildProperty();

            rule.name = "BuildProperty";
            IList <LogEntry> entries = config.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(0, entries.Count);
        }
예제 #8
0
        public void VerifyUnsignedProjectThatShouldNotBeSigned()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement rule = new  ruleElement();

            rule.strongNaming.strongNameRequired = false;
            rule.name        = "StrongNaming";
            rule.RuleChecker = new StrongNamingRule(rule);
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(0, entries.Count);
        }
예제 #9
0
        public void ProjectInSolutionShouldBeFound()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement rule = new ruleElement();

            rule.solutions.searchPath = "BuildFiles";
            rule.RuleChecker          = new OrphanedProjectsRule(rule);
            rule.name = "OrphanedProjects";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(0, entries.Count);
        }
예제 #10
0
        public void VerifySignedProjectThatIsSignedWithCorrectKey()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\SignedConsoleApplication.csproj");
            ruleElement rule = new ruleElement();

            rule.strongNaming.keyPath            = @"C:\MyKey.snk";
            rule.strongNaming.strongNameRequired = true;
            rule.RuleChecker = new StrongNamingRule(rule);
            rule.name        = "StrongNaming";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(0, entries.Count);
        }
        public void CheckCorrectlyNamedProjects()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement rule = new ruleElement();

            rule.prefixes.assemblyNamePrefix = "Default";
            rule.prefixes.namespacePrefix    = "Default";
            rule.prefixes.assemblyNameShouldMatchRootNamespace = true;
            rule.RuleChecker = new NamingConventionsRule(rule);
            rule.name        = "NamingConventions";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(0, entries.Count);
        }
        public void VerifyCorrectAssemblyReferences()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\SignedConsoleApplication.csproj");
            ruleElement rule = new ruleElement();
            ruleElementAssemblyLocation asmLocation = new ruleElementAssemblyLocation();

            asmLocation.assemblyName = "EnvDTE";
            asmLocation.assemblyPath = @"X:\References\Microsoft.Practices.RecipeFramework\1.0.60429.0\EnvDTE.dll";
            rule.assemblyLocations.Add(asmLocation);
            rule.RuleChecker = new AssemblyReferenceRule(rule);
            rule.name        = "AssemblyReference";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(0, entries.Count);
        }
예제 #13
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."));
        }
예제 #14
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);
        }
예제 #15
0
        public void VerifyCompareDoesNotExistCorrect()
        {
            BuildFile   file   = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement config = new ruleElement();

            ruleElementBuildProperty buildProperty = new ruleElementBuildProperty();

            buildProperty.name          = "Dummy";
            buildProperty.compareOption = CompareOption.DoesNotExist.ToString();
            config.buildProperties.Add(buildProperty);
            config.RuleChecker = new BuildPropertiesRule(config);

            IList <LogEntry> entries = config.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(0, entries.Count);
        }
예제 #16
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");
        }
예제 #17
0
        public void ProjectNotInSolutionShouldBeError()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\SignedConsoleApplication.csproj");
            ruleElement rule = new ruleElement();

            rule.solutions.searchPath = "BuildFiles";
            rule.RuleChecker          = new OrphanedProjectsRule(rule);
            rule.name = "OrphanedProjects";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(1, entries.Count);
            LogEntry entry = entries[0];

            Assert.AreEqual <LogLevel>(LogLevel.Error, entry.Level);
            Assert.AreEqual <string>("OrphanedProjects", entry.Rule);
            Assert.AreEqual <string>("OrphanedProject", entry.Code);
        }
        public void VerifyMissingAssemblyLocation()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\SignedConsoleApplication.csproj");
            ruleElement rule = new ruleElement();
            ruleElementAssemblyLocation asmLocation = new ruleElementAssemblyLocation();

            rule.name        = "AssemblyReference";
            rule.RuleChecker = new AssemblyReferenceRule(rule);
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(1, entries.Count);
            LogEntry entry = entries[0];

            Assert.AreEqual <LogLevel>(LogLevel.Warning, entry.Level);
            Assert.AreEqual <string>("AssemblyReference", entry.Rule);
            Assert.AreEqual <string>("MissingAssemblyLocation", entry.Code);
        }
예제 #19
0
        public void VerifySignedProjectThatShouldNotBeSigned()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\SignedConsoleApplication.csproj");
            ruleElement rule = new ruleElement();

            rule.strongNaming.strongNameRequired = false;
            rule.RuleChecker = new StrongNamingRule(rule);
            rule.name        = "StrongNaming";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(1, entries.Count);
            LogEntry entry = entries[0];

            Assert.AreEqual <LogLevel>(LogLevel.Error, entry.Level);
            Assert.AreEqual <string>("StrongNaming", entry.Rule);
            Assert.AreEqual <string>("SigningShouldBeDisabled", entry.Code);
        }
예제 #20
0
        public void VerifySignedProjectThatIsSignedWithIncorrectKey()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\SignedConsoleApplication.csproj");
            ruleElement rule = new ruleElement();

            rule.strongNaming.keyPath            = "dummy";
            rule.strongNaming.strongNameRequired = true;
            rule.RuleChecker = new StrongNamingRule(rule);
            rule.name        = "StrongNaming";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(1, entries.Count);
            LogEntry entry = entries[0];

            Assert.AreEqual <LogLevel>(LogLevel.Error, entry.Level);
            Assert.AreEqual <string>("StrongNaming", entry.Rule);
            Assert.AreEqual <string>("SignedWithIncorrectKey", entry.Code);
        }
        public void CheckProjectWithNonMatchingAssemblyName()
        {
            BuildFile   file = new BuildFile(@"NamingBuildFiles\ConsoleApplicationMismatchingNames.csproj");
            ruleElement rule = new ruleElement();

            rule.prefixes.assemblyNamePrefix = "Mismatching";
            rule.prefixes.namespacePrefix    = "Default";
            rule.prefixes.assemblyNameShouldMatchRootNamespace = true;
            rule.RuleChecker = new NamingConventionsRule(rule);
            rule.name        = "NamingConventions";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(1, entries.Count);
            LogEntry entry = entries[0];

            Assert.AreEqual <LogLevel>(LogLevel.Error, entry.Level);
            Assert.AreEqual <string>("NamingConventions", entry.Rule);
            Assert.AreEqual <string>("AssemblyNameRootNamespaceMismatch", entry.Code);
        }
        public void VerifyCorrectAssemblyReferencesBecauseOfMissingAssemblyPath()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\SignedConsoleApplication.csproj");
            ruleElement rule = new ruleElement();
            ruleElementAssemblyLocation asmLocation = new ruleElementAssemblyLocation();

            asmLocation.assemblyName = "dummy";
            asmLocation.assemblyPath = "";
            rule.assemblyLocations.Add(asmLocation);
            asmLocation = new ruleElementAssemblyLocation();
            asmLocation.assemblyName = "EnvDTE";
            asmLocation.assemblyPath = "";
            rule.assemblyLocations.Add(asmLocation);
            rule.RuleChecker = new AssemblyReferenceRule(rule);
            rule.name        = "AssemblyReference";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(0, entries.Count);
        }
예제 #23
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");
        }
예제 #24
0
        public void VerifyCompareNotInCorrect()
        {
            BuildFile   file   = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement config = new ruleElement();

            ruleElementBuildProperty buildProperty = new ruleElementBuildProperty();

            buildProperty.name          = "Configuration";
            buildProperty.value         = "Something Release Custom Whatever";
            buildProperty.compareOption = CompareOption.NotIn.ToString();
            config.buildProperties.Add(buildProperty);
            config.RuleChecker = new BuildPropertiesRule(config);

            ruleElementBuildProperty rule = new ruleElementBuildProperty();

            rule.name = "BuildProperty";
            IList <LogEntry> entries = config.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(0, entries.Count);
        }
        public void VerifyIncorrectAssemblyReferences()
        {
            BuildFile   file = new BuildFile(@"BuildFiles\SignedConsoleApplication.csproj");
            ruleElement rule = new ruleElement();
            ruleElementAssemblyLocation asmLocation = new ruleElementAssemblyLocation();

            asmLocation.assemblyName = "EnvDTE";
            asmLocation.assemblyPath = "dummy";
            rule.assemblyLocations.Add(asmLocation);
            rule.RuleChecker = new AssemblyReferenceRule(rule);
            rule.name        = "AssemblyReference";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(1, entries.Count);
            LogEntry entry = entries[0];

            Assert.AreEqual <LogLevel>(LogLevel.Error, entry.Level);
            Assert.AreEqual <string>("AssemblyReference", entry.Rule);
            Assert.AreEqual <string>("IncorrectHintPath", entry.Code);
        }
예제 #26
0
        public void VerifyIncorrectBuildProperties()
        {
            BuildFile   file   = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement config = new ruleElement();
            ruleElementBuildProperty buildProperty;

            // Add incorrect build properties.
            buildProperty       = new ruleElementBuildProperty();
            buildProperty.name  = "Configuration";
            buildProperty.value = "dummy";
            config.buildProperties.Add(buildProperty);

            buildProperty       = new ruleElementBuildProperty();
            buildProperty.name  = "RootNamespace";
            buildProperty.value = "dummy";
            config.buildProperties.Add(buildProperty);

            buildProperty           = new ruleElementBuildProperty();
            buildProperty.name      = "DebugType";
            buildProperty.value     = "dummy";
            buildProperty.condition = "debug";
            config.buildProperties.Add(buildProperty);
            config.name        = "BuildProperty";
            config.RuleChecker = new BuildPropertiesRule(config);

            ruleElementBuildProperty rule = new ruleElementBuildProperty();

            rule.name = "BuildProperty";
            IList <LogEntry> entries = config.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(config.buildProperties.Count, entries.Count);
            foreach (LogEntry entry in entries)
            {
                Assert.AreEqual <string>("BuildProperty", entry.Rule);
                Assert.AreEqual <string>("IncorrectValue", entry.Code);
            }
        }
예제 #27
0
        public void VerifyExistsChecksAllConfigurations()
        {
            BuildFile   file   = new BuildFile(@"BuildFiles\DefaultConsoleApplicationNoReleaseErrorReport.csproj");
            ruleElement config = new ruleElement();
            ruleElementBuildProperty buildProperty;

            // Add correct build properties.
            buildProperty           = new ruleElementBuildProperty();
            buildProperty.name      = "ErrorReport";
            buildProperty.value     = "prompt";
            buildProperty.condition = ""; // No condition means it should be true for all configurations (two in this case).
            config.buildProperties.Add(buildProperty);
            config.name        = "BuildProperty";
            config.RuleChecker = new BuildPropertiesRule(config);

            ruleElementBuildProperty rule = new ruleElementBuildProperty();

            rule.name = "BuildProperty";
            IList <LogEntry> entries = config.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(1, entries.Count);
        }
예제 #28
0
        public void VerifyCompareExistsIncorrect()
        {
            BuildFile   file   = new BuildFile(@"BuildFiles\DefaultConsoleApplication.csproj");
            ruleElement config = new ruleElement();

            ruleElementBuildProperty buildProperty = new ruleElementBuildProperty();

            buildProperty.name          = "Dummy";
            buildProperty.compareOption = CompareOption.Exists.ToString();
            config.buildProperties.Add(buildProperty);
            config.name        = "BuildProperty";
            config.RuleChecker = new BuildPropertiesRule(config);

            ruleElementBuildProperty rule = new ruleElementBuildProperty();

            rule.name = "BuildProperty";
            IList <LogEntry> entries = config.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(1, entries.Count);
            Assert.AreEqual <string>("BuildProperty", entries[0].Rule);
            Assert.AreEqual <string>("PropertyShouldExist", entries[0].Code);
        }
예제 #29
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);
        }
        public void CheckProjectWithAllSettingsIncorrect()
        {
            BuildFile   file = new BuildFile(@"NamingBuildFiles\ConsoleApplicationMismatchingNames.csproj");
            ruleElement rule = new ruleElement();

            rule.prefixes.assemblyNamePrefix = "Dummy";
            rule.prefixes.namespacePrefix    = "Dummy";
            rule.prefixes.assemblyNameShouldMatchRootNamespace = true;
            rule.RuleChecker = new NamingConventionsRule(rule);
            rule.name        = "NamingConventions";
            IList <LogEntry> entries = rule.RuleChecker.Check(file);

            Assert.IsNotNull(entries);
            Assert.AreEqual <int>(3, entries.Count);
            Assert.AreEqual <LogLevel>(LogLevel.Error, entries[0].Level);
            Assert.AreEqual <string>("NamingConventions", entries[0].Rule);
            Assert.AreEqual <string>("IncorrectRootNamespace", entries[0].Code);
            Assert.AreEqual <LogLevel>(LogLevel.Error, entries[1].Level);
            Assert.AreEqual <string>("NamingConventions", entries[1].Rule);
            Assert.AreEqual <string>("IncorrectAssemblyName", entries[1].Code);
            Assert.AreEqual <LogLevel>(LogLevel.Error, entries[2].Level);
            Assert.AreEqual <string>("NamingConventions", entries[2].Rule);
            Assert.AreEqual <string>("AssemblyNameRootNamespaceMismatch", entries[2].Code);
        }