public void PropertiesWriter_InvalidOperations()
        {
            AnalysisConfig validConfig = new AnalysisConfig()
            {
                SonarProjectKey     = "key",
                SonarProjectName    = "name",
                SonarProjectVersion = "1.0",
                SonarOutputDir      = this.TestContext.DeploymentDirectory
            };

            // 1. Must supply an analysis config on construction
            AssertException.Expects <ArgumentNullException>(() => new PropertiesWriter(null));


            // 2. Can't call WriteSettingsForProject after Flush
            PropertiesWriter writer = new PropertiesWriter(validConfig);

            writer.Flush();
            AssertException.Expects <InvalidOperationException>(() => writer.Flush());

            // 3. Can't call Flush twice
            writer = new PropertiesWriter(validConfig);
            writer.Flush();
            using (new AssertIgnoreScope())
            {
                AssertException.Expects <InvalidOperationException>(() => writer.WriteSettingsForProject(new ProjectInfo(), new string[] { "file" }, "fxCopReport", "code coverage report"));
            }
        }
        public void BootSettings_InvalidArguments()
        {
            ILogger        validLogger = new TestLogger();
            IList <string> validArgs   = null;

            AssertException.Expects <ArgumentNullException>(() => new BootstrapperSettings(AnalysisPhase.PreProcessing, validArgs, LoggerVerbosity.Debug, null));
        }
        public void PreArgProc_MissingArguments()
        {
            // 0. Setup
            TestLogger logger;

            // 1. Null logger
            AssertException.Expects <ArgumentNullException>(() => ArgumentProcessor.TryProcessArgs(null, null));

            // 2. All required arguments missing
            logger = CheckProcessingFails(/* no command line args */);
            logger.AssertSingleErrorExists("/key:"); // we expect errors with info about the missing required parameters, which should include the primary alias
            logger.AssertSingleErrorExists("/name:");
            logger.AssertSingleErrorExists("/version:");
            logger.AssertErrorsLogged(3);

            // 3. Some required arguments missing
            logger = CheckProcessingFails("/k:key", "/v:version");

            logger.AssertErrorDoesNotExist("/key:");
            logger.AssertErrorDoesNotExist("/version:");

            logger.AssertSingleErrorExists("/name:");
            logger.AssertErrorsLogged(1);

            // 4. Argument is present but has no value
            logger = CheckProcessingFails("/key:k1", "/name:n1", "/version:");

            logger.AssertErrorDoesNotExist("/key:");
            logger.AssertErrorDoesNotExist("/name:");

            logger.AssertSingleErrorExists("/version:");
            logger.AssertErrorsLogged(1);
        }
        public void CmdLineArgProperties_InvalidArguments()
        {
            IAnalysisPropertyProvider provider;

            AssertException.Expects <ArgumentNullException>(() => CmdLineArgPropertyProvider.TryCreateProvider(null, new TestLogger(), out provider));
            AssertException.Expects <ArgumentNullException>(() => CmdLineArgPropertyProvider.TryCreateProvider(Enumerable.Empty <ArgumentInstance>(), null, out provider));
        }
        public void ProcArgs_GetSetting()
        {
            // 0. Setup
            ListPropertiesProvider cmdLineProps = new ListPropertiesProvider();

            cmdLineProps.AddProperty("cmd.key.1", "cmd value 1");
            cmdLineProps.AddProperty("shared.key.1", "shared cmd value");

            ListPropertiesProvider fileProps = new ListPropertiesProvider();

            fileProps.AddProperty("file.key.1", "file value 1");
            fileProps.AddProperty("shared.key.1", "shared file value");

            ProcessedArgs args = new ProcessedArgs("key", "name", "ver", true, cmdLineProps, fileProps);

            // 1. Throws on missing value
            AssertException.Expects <InvalidOperationException>(() => args.GetSetting("missing.property"));

            // 2. Returns existing values
            Assert.AreEqual("cmd value 1", args.GetSetting("cmd.key.1"));
            Assert.AreEqual("file value 1", args.GetSetting("file.key.1"));

            // 3. Precedence - command line properties should win
            Assert.AreEqual("shared cmd value", args.GetSetting("shared.key.1"));

            // 4. Preprocessor only settings
            Assert.AreEqual(true, args.InstallLoaderTargets);
        }
Пример #6
0
        public void Parser_DuplicateDescriptorIds()
        {
            var d1 = new ArgumentDescriptor("id1", new string[] { "a" }, true, "desc1", false);
            var d2 = new ArgumentDescriptor("id1", new string[] { "b" }, true, "desc2", false);

            AssertException.Expects <ArgumentException>(() => new CommandLineParser(
                                                            new ArgumentDescriptor[] { d1, d2 }, true));
        }
        public void Factory_InvalidCallSequence_Fails()
        {
            // Arrange
            var logger = new TestLogger();
            IPreprocessorObjectFactory testSubject = new PreprocessorObjectFactory(logger);

            // 2. Act and assert
            AssertException.Expects <InvalidOperationException>(() => testSubject.CreateRoslynAnalyzerProvider());
        }
Пример #8
0
        public void FilePropertiesProvider_InvalidArgs()
        {
            // 1. Missing arguments
            AssertException.Expects <ArgumentNullException>(() => new FilePropertiesProvider(null));
            AssertException.Expects <ArgumentNullException>(() => new FilePropertiesProvider(string.Empty));
            AssertException.Expects <ArgumentNullException>(() => new FilePropertiesProvider("\r\t"));

            // 2. Non-existent file
            AssertException.Expects <FileNotFoundException>(() => new FilePropertiesProvider(Guid.NewGuid().ToString()));
        }
        public void MergeRulesets_PrimaryRulesetDoesNotExist()
        {
            // Arrange
            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            MergeRuleSets    task        = CreateTask(dummyEngine, "missing.ruleset");

            // Act and Assert
            FileNotFoundException ex = AssertException.Expects <FileNotFoundException>(() => task.Execute());

            Assert.AreEqual("missing.ruleset", ex.FileName);
        }
        public void Serializer_ArgumentValidation()
        {
            // Load
            AssertException.Expects <ArgumentNullException>(() => Serializer.LoadModel <MyDataClass>(null));

            // Save
            AssertException.Expects <ArgumentNullException>(() => Serializer.SaveModel <MyDataClass>(null, "c:\\data.txt"));
            AssertException.Expects <ArgumentNullException>(() => Serializer.SaveModel <MyDataClass>(new MyDataClass(), null));

            // ToString
            AssertException.Expects <ArgumentNullException>(() => Serializer.ToString <MyDataClass>(null));
        }
Пример #11
0
        public void PreProc_InvalidArgs()
        {
            // Arrange
            MockSonarQubeServer mockServer = new MockSonarQubeServer();

            TeamBuildPreProcessor preprocessor = new TeamBuildPreProcessor(
                new MockObjectFactory(mockServer, new Mock <ITargetsInstaller>().Object, new MockRoslynAnalyzerProvider()),
                new TestLogger());

            // Act and assert
            AssertException.Expects <ArgumentNullException>(() => preprocessor.Execute(null));
        }
        public void RoslynRuleSet_GeneratorArgumentChecks()
        {
            IDictionary <string, string> dict = new Dictionary <string, string>();
            var generator = new RoslynRuleSetGenerator(dict);
            IEnumerable <ActiveRule> activeRules   = new List <ActiveRule>();
            IEnumerable <string>     inactiveRules = new List <string>();
            var language = "cs";

            AssertException.Expects <ArgumentNullException>(() => generator.Generate(activeRules, inactiveRules, null));
            AssertException.Expects <ArgumentNullException>(() => generator.Generate(activeRules, null, language));
            AssertException.Expects <ArgumentNullException>(() => generator.Generate(null, inactiveRules, language));
        }
        public void Factory_ThrowsOnInvalidInput()
        {
            // Arrange
            var logger    = new TestLogger();
            var validArgs = CreateValidArguments();
            IPreprocessorObjectFactory testSubject = new PreprocessorObjectFactory(logger);

            // 1. Ctor
            AssertException.Expects <ArgumentNullException>(() => new PreprocessorObjectFactory(null));

            // 1. CreateSonarQubeServer method
            AssertException.Expects <ArgumentNullException>(() => testSubject.CreateSonarQubeServer(null));
        }
        public void RulesetGet_ValidateArgs()
        {
            string testDir         = TestUtils.CreateTestSpecificFolder(this.TestContext);
            string rulesetFilePath = Path.Combine(testDir, "r1.txt");

            List <ActiveRule> activeRules = new List <ActiveRule>();

            RulesetGenerator generator = new RulesetGenerator();

            AssertException.Expects <ArgumentNullException>(() => generator.Generate("repo1", null, rulesetFilePath));
            AssertException.Expects <ArgumentNullException>(() => generator.Generate(null, activeRules, rulesetFilePath));
            AssertException.Expects <ArgumentNullException>(() => generator.Generate("repo1", activeRules, null));
        }
        public void PostArgProc_NoArgs()
        {
            // 0. Setup
            TestLogger logger = new TestLogger();
            IAnalysisPropertyProvider provider;

            // 1. Null input
            AssertException.Expects <ArgumentNullException>(() => ArgumentProcessor.TryProcessArgs(null, logger, out provider));

            // 2. Empty array input
            provider = CheckProcessingSucceeds(logger, new string[] { });
            provider.AssertExpectedPropertyCount(0);
        }
Пример #16
0
        public void MergeRulesets_PrimaryRulesetDoesNotExist()
        {
            // Arrange
            string projectDir            = this.TestContext.TestDeploymentDir;
            string targetRulesetFilePath = Path.Combine(projectDir, "merged.ruleset.txt");

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            MergeRuleSets    task        = CreateTask(dummyEngine, projectDir, "missing.ruleset", targetRulesetFilePath);

            // Act and Assert
            FileNotFoundException ex = AssertException.Expects <FileNotFoundException>(() => task.Execute());

            Assert.AreEqual("missing.ruleset", ex.FileName);
        }
        public void FileProvider_InvalidArguments()
        {
            // 0. Setup
            IAnalysisPropertyProvider provider;

            // 1. Null command line arguments
            AssertException.Expects <ArgumentNullException>(() => FilePropertyProvider.TryCreateProvider(null, string.Empty, new TestLogger(), out provider));

            // 2. Null directory
            AssertException.Expects <ArgumentNullException>(() => FilePropertyProvider.TryCreateProvider(Enumerable.Empty <ArgumentInstance>(), null, new TestLogger(), out provider));

            // 3. Null logger
            AssertException.Expects <ArgumentNullException>(() => FilePropertyProvider.TryCreateProvider(Enumerable.Empty <ArgumentInstance>(), string.Empty, null, out provider));
        }
Пример #18
0
        public void RoslynConfig_SetupAnalyzers_ArgumentChecks()
        {
            // Arrange
            TestLogger          logger     = new TestLogger();
            TeamBuildSettings   settings   = CreateSettings(this.TestContext.DeploymentDirectory);
            MockSonarQubeServer mockServer = CreateValidServer("valid.project", null, "valid.profile");

            RoslynAnalyzerProvider testSubject = CreateTestSubject(logger);

            // Act and assert (branch can be null)
            AssertException.Expects <ArgumentNullException>(() => testSubject.SetupAnalyzers(null, settings, "project", "branch"));
            AssertException.Expects <ArgumentNullException>(() => testSubject.SetupAnalyzers(mockServer, null, "project", "branch"));
            AssertException.Expects <ArgumentNullException>(() => testSubject.SetupAnalyzers(mockServer, settings, null, "branch"));
        }
Пример #19
0
        public void AggProperties_NullOrEmptyList()
        {
            // 1. Null -> error
            AssertException.Expects <ArgumentNullException>(() => new AggregatePropertiesProvider(null));

            // 2. Empty list of providers -> valid but returns nothing
            var provider = new AggregatePropertiesProvider(new IAnalysisPropertyProvider[] { });

            Assert.AreEqual(0, provider.GetAllProperties().Count());
            var success = provider.TryGetProperty("any key", out Property actualProperty);

            Assert.IsFalse(success, "Not expecting a property to be returned");
            Assert.IsNull(actualProperty, "Returned property should be null");
        }
        public void Factory_ThrowsOnInvalidInput()
        {
            // Arrange
            TestLogger    logger    = new TestLogger();
            ProcessedArgs validArgs = CreateValidArguments();
            IPreprocessorObjectFactory testSubject = new PreprocessorObjectFactory();

            // 1. CreateSonarQubeServer method
            AssertException.Expects <ArgumentNullException>(() => testSubject.CreateSonarQubeServer(null, logger));
            AssertException.Expects <ArgumentNullException>(() => testSubject.CreateSonarQubeServer(validArgs, null));

            // 2. CreateAnalyzerProvider method
            AssertException.Expects <ArgumentNullException>(() => testSubject.CreateAnalyzerProvider(null));
        }
        public void ProjectInfo_Serialization_InvalidFileName()
        {
            // 0. Setup
            ProjectInfo pi = new ProjectInfo();

            // 1a. Missing file name - save
            AssertException.Expects <ArgumentNullException>(() => pi.Save(null));
            AssertException.Expects <ArgumentNullException>(() => pi.Save(string.Empty));
            AssertException.Expects <ArgumentNullException>(() => pi.Save("\r\t "));

            // 1b. Missing file name - load
            AssertException.Expects <ArgumentNullException>(() => ProjectInfo.Load(null));
            AssertException.Expects <ArgumentNullException>(() => ProjectInfo.Load(string.Empty));
            AssertException.Expects <ArgumentNullException>(() => ProjectInfo.Load("\r\t "));
        }
        public void PreProc_InvalidArgs()
        {
            // Arrange
            TestLogger validLogger = new TestLogger();

            string[] validArgs = new string[] { "/k:key", "/n:name", "/v:1.0" };

            MockSonarQubeServer   mockServer           = new MockSonarQubeServer();
            MockTargetsInstaller  mockTargetsInstaller = new MockTargetsInstaller();
            TeamBuildPreProcessor preprocessor         = new TeamBuildPreProcessor(new MockSonarQubeServerFactory(mockServer), mockTargetsInstaller);

            // Act and assert
            AssertException.Expects <ArgumentNullException>(() => preprocessor.Execute(null, validLogger));
            AssertException.Expects <ArgumentNullException>(() => preprocessor.Execute(validArgs, null));
        }
        public void AnalysisConfig_Serialization_InvalidFileName()
        {
            // 0. Setup
            AnalysisConfig config = new AnalysisConfig();

            // 1a. Missing file name - save
            AssertException.Expects <ArgumentNullException>(() => config.Save(null));
            AssertException.Expects <ArgumentNullException>(() => config.Save(string.Empty));
            AssertException.Expects <ArgumentNullException>(() => config.Save("\r\t "));

            // 1b. Missing file name - load
            AssertException.Expects <ArgumentNullException>(() => ProjectInfo.Load(null));
            AssertException.Expects <ArgumentNullException>(() => ProjectInfo.Load(string.Empty));
            AssertException.Expects <ArgumentNullException>(() => ProjectInfo.Load("\r\t "));
        }
Пример #24
0
        public void PreProc_InvalidArgs()
        {
            // Arrange
            TestLogger validLogger = new TestLogger();

            string[] validArgs = new string[] { "/k:key", "/n:name", "/v:1.0" };

            MockPropertiesFetcher mockPropertiesFetcher = new MockPropertiesFetcher();
            MockRulesetGenerator  mockRulesetGenerator  = new MockRulesetGenerator();
            MockTargetsInstaller  mockTargetsInstaller  = new MockTargetsInstaller();
            TeamBuildPreProcessor preprocessor          = new TeamBuildPreProcessor(mockPropertiesFetcher, mockRulesetGenerator, mockTargetsInstaller);

            // Act and assert
            AssertException.Expects <ArgumentNullException>(() => preprocessor.Execute(null, validLogger));
            AssertException.Expects <ArgumentNullException>(() => preprocessor.Execute(validArgs, null));
        }
Пример #25
0
        public void MergeRulesets_MergedRulesetAlreadyExists()
        {
            // Arrange
            string projectDir            = this.TestContext.TestDeploymentDir;
            string primaryRuleset        = this.CreateValidRuleset("valid.ruleset.txt");
            string targetRulesetFilePath = Path.Combine(projectDir, "merged.ruleset.txt");

            File.WriteAllText(targetRulesetFilePath, "dummy existing ruleset");

            DummyBuildEngine dummyEngine = new DummyBuildEngine();
            MergeRuleSets    task        = CreateTask(dummyEngine, projectDir, primaryRuleset, targetRulesetFilePath);

            // Act and Assert
            InvalidOperationException ex = AssertException.Expects <InvalidOperationException>(() => task.Execute());

            Assert.IsTrue(ex.Message.Contains(targetRulesetFilePath));
        }
Пример #26
0
        public void FilePropertiesProvider_GetProperty_Throws()
        {
            // Arrange
            string contents = @"
a.b.c.=exists
";
            string fullName = CreatePropertiesFile("GetProperty_Throws.properties", contents);

            // Act
            FilePropertiesProvider provider = new FilePropertiesProvider(fullName);

            // Assert
            AssertExpectedValueReturned(provider, "a.b.c.", "exists");
            Exception ex = AssertException.Expects <ArgumentException>(() => provider.GetProperty("missing.property"));

            Assert.IsTrue(ex.Message.Contains(fullName), "Expecting the error message to contain the file name");
            Assert.IsTrue(ex.Message.Contains("missing.property"), "Expecting the error message to contain the name of the requested property");
        }
Пример #27
0
        public void Flush_WhenCalledTwice_ThrowsInvalidOperationException()
        {
            // Arrange
            var validConfig = new AnalysisConfig()
            {
                SonarProjectKey     = "key",
                SonarProjectName    = "name",
                SonarProjectVersion = "1.0",
                SonarOutputDir      = TestContext.DeploymentDirectory
            };

            var writer = new PropertiesWriter(validConfig, new TestLogger());

            writer.Flush();

            // Act & Assert
            AssertException.Expects <InvalidOperationException>(() => writer.Flush());
        }
Пример #28
0
        public void ProcArgs_GetSetting()
        {
            // 1. Throws on missing value
            AssertException.Expects <InvalidOperationException>(() => args.GetSetting("missing.property"));

            // 2. Returns existing values
            Assert.AreEqual("cmd value 1", args.GetSetting("cmd.key.1"));
            Assert.AreEqual("file value 1", args.GetSetting("file.key.1"));
            Assert.AreEqual("env value 1", args.GetSetting("env.key.1"));

            // 3. Precedence - command line properties should win
            Assert.AreEqual("shared cmd value", args.GetSetting("shared.key.1"));

            // 4. Precedence - file wins over env
            Assert.AreEqual("shared file value", args.GetSetting("shared.key.2"));

            // 5. Preprocessor only settings
            Assert.AreEqual(true, args.InstallLoaderTargets);
        }
Пример #29
0
        public void RoslynConfig_SetupAnalyzers_ArgumentChecks()
        {
            // Arrange
            var logger = new TestLogger();
            IList <ActiveRule> activeRules   = new List <ActiveRule>();
            IList <string>     inactiveRules = new List <string>();
            var pluginKey = RoslynAnalyzerProvider.CSharpPluginKey;
            IDictionary <string, string> serverSettings = new Dictionary <string, string>();
            var settings = CreateSettings(TestContext.DeploymentDirectory);

            var testSubject = CreateTestSubject(logger);

            // Act and assert
            AssertException.Expects <ArgumentNullException>(() => testSubject.SetupAnalyzer(null, serverSettings, activeRules, inactiveRules, pluginKey));
            AssertException.Expects <ArgumentNullException>(() => testSubject.SetupAnalyzer(settings, null, activeRules, inactiveRules, pluginKey));
            AssertException.Expects <ArgumentNullException>(() => testSubject.SetupAnalyzer(settings, serverSettings, null, inactiveRules, pluginKey));
            AssertException.Expects <ArgumentNullException>(() => testSubject.SetupAnalyzer(settings, serverSettings, activeRules, null, pluginKey));
            AssertException.Expects <ArgumentNullException>(() => testSubject.SetupAnalyzer(settings, serverSettings, activeRules, inactiveRules, null));
        }
Пример #30
0
        public void WriteSettingsForProject_WhenFlushed_ThrowsInvalidOperationException()
        {
            // Arrange
            var validConfig = new AnalysisConfig()
            {
                SonarProjectKey     = "key",
                SonarProjectName    = "name",
                SonarProjectVersion = "1.0",
                SonarOutputDir      = TestContext.DeploymentDirectory
            };

            var writer = new PropertiesWriter(validConfig, new TestLogger());

            writer.Flush();

            // Act & Assert
            using (new AssertIgnoreScope())
            {
                AssertException.Expects <InvalidOperationException>(
                    () => writer.WriteSettingsForProject(new ProjectData(new ProjectInfo())));
            }
        }