Exemple #1
0
        public void Ctor_ValidProperties_AreSetCorrectly()
        {
            var testSubject = new FilePathAndContent <int>("foo", 123);

            testSubject.Path.Should().Be("foo");
            testSubject.Content.Should().Be(123);
        }
        public void TestInitialize()
        {
            fileSystem = new MockFileSystem();

            this.dte             = new DTEMock();
            this.serviceProvider = new ConfigurableServiceProvider();
            this.solutionMock    = new SolutionMock(dte, Path.Combine(SolutionRoot, "xxx.sln"));
            this.projectMock     = this.solutionMock.AddOrGetProject(Path.Combine(SolutionRoot, @"Project\project.proj"));
            this.outputPane      = new ConfigurableVsOutputWindowPane();
            this.serviceProvider.RegisterService(typeof(SVsGeneralOutputWindowPane), this.outputPane);
            this.projectSystemHelper = new ConfigurableVsProjectSystemHelper(this.serviceProvider);
            this.sccFileSystem       = new ConfigurableSourceControlledFileSystem(fileSystem);
            this.ruleSetFS           = new ConfigurableRuleSetSerializer(fileSystem);
            this.serviceProvider.RegisterService(typeof(ISourceControlledFileSystem), this.sccFileSystem);
            this.serviceProvider.RegisterService(typeof(IRuleSetSerializer), this.ruleSetFS);
            this.serviceProvider.RegisterService(typeof(ISolutionRuleSetsInformationProvider),
                                                 new SolutionRuleSetsInformationProvider(this.serviceProvider, new Mock <ILogger>().Object, new MockFileSystem()));
            this.serviceProvider.RegisterService(typeof(IProjectSystemHelper), this.projectSystemHelper);

            var coreRuleSet    = new FilePathAndContent <CoreRuleSet>(@"c:\Solution\sln.ruleset", new CoreRuleSet());
            var vsRuleSet      = new VsRuleSet("VS ruleset");
            var additionalFile = new FilePathAndContent <SonarLintConfiguration>(@"c:\Solution\additionalFile.txt", new SonarLintConfiguration());

            cSharpVBBindingConfig = new CSharpVBBindingConfig(coreRuleSet, additionalFile);

            ruleSetFS.RegisterRuleSet(vsRuleSet, coreRuleSet.Path);

            additionalFileConflictChecker = new Mock <IAdditionalFileConflictChecker>();
            ruleSetReferenceChecker       = new Mock <IRuleSetReferenceChecker>();
        }
        public void Save_FilesSaved()
        {
            // We can't mock the RuleSet class so we're testing Save by actually
            // writing to disk.
            // Arrange
            var testDir = Path.Combine(TestContext.DeploymentDirectory, TestContext.TestName);

            Directory.CreateDirectory(testDir);

            var rulesetFullPath        = Path.Combine(testDir, "savedRuleSet.txt");
            var additionalFileFullPath = Path.Combine(testDir, "additionalFile.txt");

            var ruleSet        = new FilePathAndContent <RuleSet>(rulesetFullPath, new CoreRuleSet());
            var additionalFile = new FilePathAndContent <SonarLintConfiguration>(additionalFileFullPath, new SonarLintConfiguration());

            var testSubject = new CSharpVBBindingConfig(ruleSet, additionalFile);

            // Act
            testSubject.Save();

            // Assert
            File.Exists(rulesetFullPath).Should().BeTrue();
            File.Exists(additionalFileFullPath).Should().BeTrue();

            var savedAdditionalFile = File.ReadAllText(additionalFileFullPath);

            savedAdditionalFile.Should().Be(@"<?xml version=""1.0"" encoding=""utf-8""?>
<AnalysisInput xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"">
  <Settings />
  <Rules />
</AnalysisInput>");
        }
        private static CSharpVBBindingConfig CreateCSharpVbBindingConfig(string newSolutionRuleSetPath, CoreRuleSet coreRuleSet)
        {
            var ruleset        = new FilePathAndContent <CoreRuleSet>(newSolutionRuleSetPath, coreRuleSet);
            var additionalFile = new FilePathAndContent <SonarLintConfiguration>("dummy.txt", new SonarLintConfiguration());
            var csharpVbConfig = new CSharpVBBindingConfig(ruleset, additionalFile);

            return(csharpVbConfig);
        }
        private FilePathAndContent <SonarLintConfiguration> GetAdditionalFile(Language language, BindingConfiguration bindingConfiguration, IEnumerable <SonarQubeRule> activeRules, Dictionary <string, string> sonarProperties)
        {
            var additionalFilePath    = GetSolutionAdditionalFilePath(language, bindingConfiguration);
            var additionalFileContent = sonarLintConfigGenerator.Generate(activeRules, sonarProperties, language);

            var additionalFile = new FilePathAndContent <SonarLintConfiguration>(additionalFilePath, additionalFileContent);

            return(additionalFile);
        }
        public void GetSolutionLevelFilePaths_ReturnFilePaths()
        {
            var ruleSet        = new FilePathAndContent <RuleSet>("ruleset dummy", new CoreRuleSet());
            var additionalFile = new FilePathAndContent <SonarLintConfiguration>("additional file dummy", new SonarLintConfiguration());

            var testSubject = new CSharpVBBindingConfig(ruleSet, additionalFile);

            testSubject.SolutionLevelFilePaths.Count().Should().Be(2);
            testSubject.SolutionLevelFilePaths.First().Should().Be(ruleSet.Path);
            testSubject.SolutionLevelFilePaths.Last().Should().Be(additionalFile.Path);
        }
        public void Ctor_InvalidArgs()
        {
            var ruleSet        = new FilePathAndContent <RuleSet>("dummy", new CoreRuleSet());
            var additionalFile = new FilePathAndContent <SonarLintConfiguration>("dummy", new SonarLintConfiguration());

            Action act = () => new CSharpVBBindingConfig(null, additionalFile);

            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("ruleset");

            act = () => new CSharpVBBindingConfig(ruleSet, null);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("additionalFile");

            act = () => new CSharpVBBindingConfig(ruleSet, additionalFile, null);
            act.Should().ThrowExactly <ArgumentNullException>().And.ParamName.Should().Be("fileSystem");
        }
 internal CSharpVBBindingConfig(FilePathAndContent <RuleSet> ruleset, FilePathAndContent <SonarLintConfiguration> additionalFile, IFileSystem fileSystem)
 {
     RuleSet         = ruleset ?? throw new ArgumentNullException(nameof(ruleset));
     AdditionalFile  = additionalFile ?? throw new ArgumentNullException(nameof(additionalFile));
     this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
 }
 public CSharpVBBindingConfig(FilePathAndContent <RuleSet> ruleset, FilePathAndContent <SonarLintConfiguration> additionalFile)
     : this(ruleset, additionalFile, new FileSystem())
 {
 }