public void SolutionBindingSerializer_WriteSolutionBinding_AddConfigFileToSolutionItemsFolder()
        {
            // Arrange
            SolutionBindingSerializer testSubject = this.CreateTestSubject();
            var         serverUri       = new Uri("http://xxx.www.zzz/yyy:9000");
            var         creds           = new BasicAuthCredentials("user", "pwd".ToSecureString());
            var         projectKey      = "MyProject Key";
            var         toWrite         = new BoundSonarQubeProject(serverUri, projectKey, "projectName", creds);
            ProjectMock solutionProject = (ProjectMock)this.projectSystemHelper.SolutionItemsProject;

            // Act
            string output = testSubject.WriteSolutionBinding(toWrite);

            // Assert that not actually done anything until the pending files were written
            this.store.data.Should().NotContainKey(serverUri);
            solutionProject.Files.ContainsKey(output).Should().BeFalse("Not expected to be added to solution items folder just yet");

            // Act (write pending)
            this.sourceControlledFileSystem.WritePendingNoErrorsExpected();

            // Assert
            this.store.data.Should().ContainKey(serverUri);
            solutionProject.Files.ContainsKey(output).Should().BeTrue("File {0} was not added to project", output);

            // Act (write again)
            string output2 = testSubject.WriteSolutionBinding(toWrite);

            this.sourceControlledFileSystem.WritePendingNoErrorsExpected();

            // Assert
            output2.Should().Be(output, "Should be the same file");
            this.store.data.Should().ContainKey(serverUri);
            solutionProject.Files.ContainsKey(output).Should().BeTrue("File {0} should remain in the project", output);
        }
コード例 #2
0
        private void RegisterLocalServices()
        {
            this.localServices.Add(typeof(ISolutionRuleSetsInformationProvider), new Lazy <ILocalService>(() => new SolutionRuleSetsInformationProvider(this, Logger)));
            this.localServices.Add(typeof(IRuleSetSerializer), new Lazy <ILocalService>(() => new RuleSetSerializer(this)));
            this.localServices.Add(typeof(ICredentialStoreService), new Lazy <ILocalService>(() => new CredentialStore(new SecretStore(SolutionBindingSerializer.StoreNamespace))));
            this.localServices.Add(typeof(IConfigurationProvider), new Lazy <ILocalService>(() =>
            {
                var solution            = this.GetService <SVsSolution, IVsSolution>();
                var store               = this.GetService <ICredentialStoreService>();
                var legacySerializer    = new SolutionBindingSerializer(this);
                var sccFileSystem       = this.GetService <ISourceControlledFileSystem>();
                var newConfigSerializer = new ConfigurationSerializer(solution, sccFileSystem, store, Logger);
                return(new ConfigurationProvider(legacySerializer, newConfigSerializer));
            }));
            this.localServices.Add(typeof(IProjectSystemHelper), new Lazy <ILocalService>(() => new ProjectSystemHelper(this)));
            this.localServices.Add(typeof(IRuleSetInspector), new Lazy <ILocalService>(() => new RuleSetInspector(this, Logger)));
            this.localServices.Add(typeof(IRuleSetConflictsController), new Lazy <ILocalService>(() => new RuleSetConflictsController(this, new ConflictsManager(this, Logger))));
            this.localServices.Add(typeof(IProjectSystemFilter), new Lazy <ILocalService>(() => new ProjectSystemFilter(this)));
            this.localServices.Add(typeof(IErrorListInfoBarController), new Lazy <ILocalService>(() => new ErrorListInfoBarController(this, new SolutionBindingInformationProvider(this))));

            // Use Lazy<object> to avoid creating instances needlessly, since the interfaces are serviced by the same instance
            var sccFs = new Lazy <ILocalService>(() => new SourceControlledFileSystem(this, Logger));

            this.localServices.Add(typeof(ISourceControlledFileSystem), sccFs);
            this.localServices.Add(typeof(IFileSystem), sccFs);

            Debug.Assert(SupportedLocalServices.Length == this.localServices.Count, "Unexpected number of local services");
            Debug.Assert(SupportedLocalServices.All(t => this.localServices.ContainsKey(t)), "Not all the LocalServices are registered");
        }
        public void SolutionBindingSerializer_WriteSolutionBinding_ReadSolutionBinding()
        {
            // Arrange
            SolutionBindingSerializer testSubject = this.CreateTestSubject();
            var serverUri  = new Uri("http://xxx.www.zzz/yyy:9000");
            var creds      = new BasicAuthCredentials("user", "pwd".ToSecureString());
            var projectKey = "MyProject Key";
            var written    = new BoundSonarQubeProject(serverUri, projectKey, "projectName", creds);

            // Act (write)
            string output = testSubject.WriteSolutionBinding(written);

            this.sourceControlledFileSystem.WritePendingNoErrorsExpected();
            output.Should().NotBeNull("Expected a real file");
            this.TestContext.AddResultFile(output);
            File.Exists(output).Should().BeTrue("Expected a real file");

            // Assert
            this.store.data.Should().ContainKey(serverUri);

            // Act (read)
            BoundSonarQubeProject read = testSubject.ReadSolutionBinding();

            // Assert
            var newCreds = read.Credentials as BasicAuthCredentials;

            newCreds.Should().NotBe(creds, "Different credential instance were expected");
            newCreds.UserName.Should().Be(creds.UserName);
            newCreds.Password.ToUnsecureString().Should().Be(creds.Password.ToUnsecureString());
            read.ServerUri.Should().Be(written.ServerUri);
            this.outputPane.AssertOutputStrings(0);
        }
        public void SolutionBindingSerializer_WriteSolutionBinding_ReadSolutionBinding()
        {
            // Setup
            SolutionBindingSerializer testSubject = this.CreateTestSubject();
            var serverUri  = new Uri("http://xxx.www.zzz/yyy:9000");
            var creds      = new BasicAuthCredentials("user", "pwd".ConvertToSecureString());
            var projectKey = "MyProject Key";
            var written    = new BoundSonarQubeProject(serverUri, projectKey, creds);

            // Act (write)
            string output = testSubject.WriteSolutionBinding(written);

            this.sourceControlledFileSystem.WritePendingNoErrorsExpected();
            Assert.IsNotNull(output, "Expected a real file");
            this.TestContext.AddResultFile(output);
            Assert.IsTrue(File.Exists(output), "Expected a real file");

            // Verify
            this.store.AssertHasCredentials(serverUri);

            // Act (read)
            BoundSonarQubeProject read = testSubject.ReadSolutionBinding();

            // Verify
            var newCreds = read.Credentials as BasicAuthCredentials;

            Assert.AreNotEqual(creds, newCreds, "Different credential instance were expected");
            Assert.AreEqual(creds.UserName, newCreds.UserName);
            Assert.AreEqual(creds.Password.ConvertToUnsecureString(), newCreds.Password.ConvertToUnsecureString());
            Assert.AreEqual(written.ServerUri, read.ServerUri);
            this.outputPane.AssertOutputStrings(0);
        }
        public void SolutionBindingSerializer_WriteSolutionBinding_ArgChecks()
        {
            // Arrange
            SolutionBindingSerializer testSubject = this.CreateTestSubject();

            // Act + Assert
            Exceptions.Expect <ArgumentNullException>(() => testSubject.WriteSolutionBinding(null));
        }
        public void SolutionBindingSerializer_WriteSolutionBinding_ReadSolutionBinding_OnRealStore()
        {
            // Arrange
            var testSubject = new SolutionBindingSerializer(this.serviceProvider);
            var serverUri   = new Uri("http://xxx.www.zzz/yyy:9000");
            var projectKey  = "MyProject Key";

            this.store.DeleteCredentials(serverUri);

            // Case 1: has credentials
            var creds   = new BasicAuthCredentials("user", "pwd".ToSecureString());
            var written = new BoundSonarQubeProject(serverUri, projectKey, "projectName", creds);

            // Act (write + read)
            BoundSonarQubeProject read = null;

            try
            {
                testSubject.WriteSolutionBinding(written);
                this.sourceControlledFileSystem.WritePendingNoErrorsExpected();
                read = testSubject.ReadSolutionBinding();
            }
            finally
            {
                this.store.DeleteCredentials(serverUri);
            }

            // Assert
            var newCreds = read.Credentials as BasicAuthCredentials;

            newCreds.Should().NotBe(creds, "Different credential instance were expected");
            newCreds.UserName.Should().Be(creds.UserName);
            newCreds?.Password.ToUnsecureString().Should().Be(creds.Password.ToUnsecureString());
            read.ServerUri.Should().Be(written.ServerUri);
            this.outputPane.AssertOutputStrings(0);

            // Case 2: has not credentials (anonymous)
            creds   = null;
            written = new BoundSonarQubeProject(serverUri, projectKey, "projectName", creds);

            // Act (write + read)
            read = null;
            try
            {
                testSubject.WriteSolutionBinding(written);
                read = testSubject.ReadSolutionBinding();
            }
            finally
            {
                this.store.DeleteCredentials(serverUri);
            }

            // Assert
            read.Credentials.Should().BeNull();
            read.ServerUri.Should().Be(written.ServerUri);
            this.outputPane.AssertOutputStrings(0);
        }
コード例 #7
0
        private void RegisterLocalServices()
        {
            this.localServices.Add(typeof(ISolutionRuleSetsInformationProvider), new Lazy <ILocalService>(() => new SolutionRuleSetsInformationProvider(this, Logger)));
            this.localServices.Add(typeof(IRuleSetSerializer), new Lazy <ILocalService>(() => new RuleSetSerializer()));
            this.localServices.Add(typeof(ICredentialStoreService), new Lazy <ILocalService>(() => new CredentialStore(new SecretStore("SonarLint.VisualStudio.Integration"))));
            this.localServices.Add(typeof(IConfigurationProvider), new Lazy <ILocalService>(() =>
            {
                var solution = this.GetService <SVsSolution, IVsSolution>();
                var connectedModeConfigPathProvider = new ConnectedModeSolutionBindingPathProvider(solution);
                var legacyConfigPathProvider        = new LegacySolutionBindingPathProvider(this);
                var legacyPostSaveOperation         = new LegacySolutionBindingPostSaveOperation(this);

                var store             = this.GetService <ICredentialStoreService>();
                var credentialsLoader = new SolutionBindingCredentialsLoader(store);
                var bindingFileLoader = new SolutionBindingFileLoader(Logger);

                var sccFileSystem = this.GetService <ISourceControlledFileSystem>();

                var bindingSerializer = new SolutionBindingSerializer(sccFileSystem, bindingFileLoader, credentialsLoader);

                return(new ConfigurationProvider(legacyConfigPathProvider, connectedModeConfigPathProvider, bindingSerializer, legacyPostSaveOperation));
            }));

            var projectNameTestProjectIndicator = new Lazy <ILocalService>(() => new ProjectNameTestProjectIndicator(Logger));

            this.localServices.Add(typeof(ITestProjectRegexSetter), projectNameTestProjectIndicator);

            this.localServices.Add(typeof(IProjectSystemHelper), new Lazy <ILocalService>(() => new ProjectSystemHelper(this)));
            this.localServices.Add(typeof(IRuleSetInspector), new Lazy <ILocalService>(() => new RuleSetInspector(this, Logger)));
            this.localServices.Add(typeof(IRuleSetConflictsController), new Lazy <ILocalService>(() => new RuleSetConflictsController(this, new ConflictsManager(this, Logger))));
            this.localServices.Add(typeof(IProjectSystemFilter), new Lazy <ILocalService>(() =>
            {
                var testProjectIndicators = new List <ITestProjectIndicator>
                {
                    new BuildPropertyTestProjectIndicator(this),
                    new ProjectKindTestProjectIndicator(this),
                    new ProjectCapabilityTestProjectIndicator(this),
                    new ServiceGuidTestProjectIndicator(Logger),
                    projectNameTestProjectIndicator.Value as ITestProjectIndicator,
                };

                var testProjectIndicator = new TestProjectIndicator(testProjectIndicators);

                return(new ProjectSystemFilter(this, testProjectIndicator));
            }));
            this.localServices.Add(typeof(IErrorListInfoBarController), new Lazy <ILocalService>(() => new ErrorListInfoBarController(this, new UnboundProjectFinder(this))));

            // Use Lazy<object> to avoid creating instances needlessly, since the interfaces are serviced by the same instance
            var sccFs = new Lazy <ILocalService>(() => new SourceControlledFileSystem(this, Logger));

            this.localServices.Add(typeof(ISourceControlledFileSystem), sccFs);

            Debug.Assert(SupportedLocalServices.Length == this.localServices.Count, "Unexpected number of local services");
            Debug.Assert(SupportedLocalServices.All(t => this.localServices.ContainsKey(t)), "Not all the LocalServices are registered");
        }
        public void SolutionBindingSerializer_ReadSolutionBinding_NoFile()
        {
            // Arrange
            SolutionBindingSerializer testSubject = this.CreateTestSubject();

            // Act (read)
            BoundSonarQubeProject read = testSubject.ReadSolutionBinding();

            // Assert
            read.Should().BeNull("Not expecting any binding information when there is no file");
            this.outputPane.AssertOutputStrings(0);
        }
        public void SolutionBindingSerializer_ReadSolutionBinding_NoFile()
        {
            // Setup
            SolutionBindingSerializer testSubject = this.CreateTestSubject();

            // Act (read)
            BoundSonarQubeProject read = testSubject.ReadSolutionBinding();

            // Verify
            Assert.IsNull(read, "Not expecting any binding information when there is no file");
            this.outputPane.AssertOutputStrings(0);
        }
コード例 #10
0
        public void SolutionBindingSerializer_ReadSolutionBinding_OnClosedSolution()
        {
            // Arrange
            SolutionBindingSerializer testSubject = this.CreateTestSubject();

            this.dte.Solution = new SolutionMock(dte, "" /*When the solution is closed the file is empty*/);

            // Act (read)
            BoundSonarQubeProject read = testSubject.ReadSolutionBinding();

            // Assert
            read.Should().BeNull();
        }
コード例 #11
0
        public void SolutionBindingSerializer_WriteSolutionBinding_ReadSolutionBinding_WithProfiles()
        {
            // Arrange
            SolutionBindingSerializer testSubject = this.CreateTestSubject();
            var serverUri  = new Uri("http://xxx.www.zzz/yyy:9000");
            var creds      = new BasicAuthCredentials("user", "pwd".ToSecureString());
            var projectKey = "MyProject Key";
            var written    = new BoundSonarQubeProject(serverUri, projectKey, "projectName", creds)
            {
                Profiles = new Dictionary <Language, ApplicableQualityProfile>()
                {
                    { Language.VBNET, new ApplicableQualityProfile {
                          ProfileKey = "VB"
                      } },
                    { Language.CSharp, new ApplicableQualityProfile {
                          ProfileKey = "CS", ProfileTimestamp = DateTime.Now
                      } }
                }
            };

            // Act (write)
            string output = testSubject.WriteSolutionBinding(written);

            this.sourceControlledFileSystem.WritePendingNoErrorsExpected();
            output.Should().NotBeNull("Expected a real file");
            this.TestContext.AddResultFile(output);
            File.Exists(output).Should().BeTrue("Expected a real file");

            // Assert
            this.store.data.Should().ContainKey(serverUri);

            // Act (read)
            BoundSonarQubeProject read = testSubject.ReadSolutionBinding();

            // Assert
            var newCreds = read.Credentials as BasicAuthCredentials;

            newCreds.Should().NotBe(creds, "Different credential instance were expected");
            newCreds.UserName.Should().Be(creds.UserName);
            newCreds.Password.ToUnsecureString().Should().Be(creds.Password.ToUnsecureString());
            read.ServerUri.Should().Be(written.ServerUri);
            (read.Profiles?.Count ?? 0).Should().Be(2);
            read.Profiles[Language.VBNET].ProfileKey.Should().Be(written.Profiles[Language.VBNET].ProfileKey);
            read.Profiles[Language.VBNET].ProfileTimestamp.Should().Be(written.Profiles[Language.VBNET].ProfileTimestamp);
            read.Profiles[Language.CSharp].ProfileKey.Should().Be(written.Profiles[Language.CSharp].ProfileKey);
            read.Profiles[Language.CSharp].ProfileTimestamp.Should().Be(written.Profiles[Language.CSharp].ProfileTimestamp);
            this.outputPane.AssertOutputStrings(0);
        }
コード例 #12
0
        public void SolutionBindingSerializer_ReadSolutionBinding_IOError()
        {
            // Arrange
            SolutionBindingSerializer testSubject = this.CreateTestSubject();
            var    serverUri  = new Uri("http://xxx.www.zzz/yyy:9000");
            var    creds      = new BasicAuthCredentials("user", "pwd".ToSecureString());
            var    projectKey = "MyProject Key";
            var    written    = new BoundSonarQubeProject(serverUri, projectKey, "projectName", creds);
            string output     = testSubject.WriteSolutionBinding(written);

            this.sourceControlledFileSystem.WritePendingNoErrorsExpected();
            using (new FileStream(output, FileMode.Open, FileAccess.Read, FileShare.None))
            {
                // Act (read)
                BoundSonarQubeProject read = testSubject.ReadSolutionBinding();

                // Assert
                read.Should().BeNull("Not expecting any binding information in case of error");
                this.outputPane.AssertOutputStrings(1);
            }
        }
コード例 #13
0
        public void SolutionBindingSerializer_ReadSolutionBinding_InvalidData()
        {
            // Arrange
            SolutionBindingSerializer testSubject = this.CreateTestSubject();
            var    serverUri  = new Uri("http://xxx.www.zzz/yyy:9000");
            var    creds      = new BasicAuthCredentials("user", "pwd".ToSecureString());
            var    projectKey = "MyProject Key";
            var    written    = new BoundSonarQubeProject(serverUri, projectKey, creds);
            string output     = testSubject.WriteSolutionBinding(written);

            this.sourceControlledFileSystem.WritePendingNoErrorsExpected();
            output.Should().NotBeNull("Expected a real file");
            File.WriteAllText(output, "bla bla bla: bla");

            // Act (read)
            BoundSonarQubeProject read = testSubject.ReadSolutionBinding();

            // Assert
            read.Should().BeNull("Not expecting any binding information in case of error");
            this.outputPane.AssertOutputStrings(1);
        }
コード例 #14
0
        public void TestInitialize()
        {
            sourceControlledFileSystem = new Mock <ISourceControlledFileSystem>();
            credentialsLoader          = new Mock <ISolutionBindingCredentialsLoader>();
            solutionBindingFileLoader  = new Mock <ISolutionBindingFileLoader>();
            onSaveCallback             = new Mock <Predicate <string> >();

            testSubject = new SolutionBindingSerializer(sourceControlledFileSystem.Object,
                                                        solutionBindingFileLoader.Object,
                                                        credentialsLoader.Object);

            mockCredentials = new BasicAuthCredentials("user", "pwd".ToSecureString());

            boundSonarQubeProject = new BoundSonarQubeProject(
                new Uri("http://xxx.www.zzz/yyy:9000"),
                "MyProject Key",
                "projectName",
                mockCredentials);

            sourceControlledFileSystem
            .Setup(x => x.QueueFileWrite(MockFilePath, It.IsAny <Func <bool> >()))
            .Callback((string filePath, Func <bool> method) => method());
        }
        public void SolutionBindingSerializer_WriteSolutionBinding_IOError()
        {
            // Setup
            SolutionBindingSerializer testSubject = this.CreateTestSubject();
            var    serverUri  = new Uri("http://xxx.www.zzz/yyy:9000");
            var    creds      = new BasicAuthCredentials("user", "pwd".ConvertToSecureString());
            var    projectKey = "MyProject Key";
            var    written    = new BoundSonarQubeProject(serverUri, projectKey, creds);
            string output     = testSubject.WriteSolutionBinding(written);

            this.sourceControlledFileSystem.WritePendingNoErrorsExpected();

            using (new FileStream(output, FileMode.Open, FileAccess.Read, FileShare.None))
            {
                // Act (write again)
                string output2 = testSubject.WriteSolutionBinding(written);
                this.sourceControlledFileSystem.WritePendingErrorsExpected();

                // Verify
                Assert.AreEqual(output, output2, "Same output is expected");
                this.outputPane.AssertOutputStrings(1);
            }
        }