/// <summary>
        ///     The test window.
        /// </summary>
        public void TestWindow()
        {
            var mocks         = new MockRepository();
            var mockHttpReq   = mocks.Stub <IHttpSonarConnector>();
            var mockVsHelpers = mocks.Stub <IVsEnvironmentHelper>();
            var config        = new ConnectionConfiguration("serveraddr", "login", "password");

            // set expectations
            using (mocks.Record())
            {
                SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/issues/search?components=resource"))
                .Return(File.ReadAllText("TestData/issuessearchbycomponent.txt"));
                SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/users/search")).Return(File.ReadAllText("TestData/userList.txt"));
            }

            ISonarRestService service = new SonarRestService(mockHttpReq);

            service.GetIssuesInResource(config, "resource");
            var associatedProject = new Resource {
                Key = "core:Common"
            };

            this.model = new ExtensionDataModel(service, mockVsHelpers, associatedProject, null);
            var t = new Thread(this.Threadprc);

            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
        }
        public void TesRestOfProperties()
        {
            var issue = new Issue();
            var connector = new SonarRestService(new JsonSonarConnector());
            var projectAsso = new Resource { Key = "proj" };
            var model = new ExtensionDataModel(this.service, this.vshelper, null, null)
            {
                AssociatedProjectKey = "proj",
                CommentData = "comment",
                SelectedIssue = issue,
                SonarInfo = "ver",
                SelectedUser = new User { Login = "******" },
                DiagnosticMessage = "MessageData",
                DisableEditorTags = false,
                RestService = connector,
                AssociatedProject = projectAsso,
            };

            Assert.AreEqual("Selected Project: proj", model.AssociatedProjectKey);
            Assert.AreEqual(issue, model.SelectedIssue);
            Assert.AreEqual("comment", model.CommentData);
            Assert.AreEqual("login", model.SelectedUser.Login);
            Assert.AreEqual("ver", model.SonarInfo);
            Assert.AreEqual("MessageData", model.DiagnosticMessage);
            Assert.IsFalse(model.DisableEditorTags);
            Assert.AreEqual(connector, model.RestService);
            Assert.AreEqual(projectAsso, model.AssociatedProject);
        }
        public void TesRestOfProperties()
        {
            var issue       = new Issue();
            var connector   = new SonarRestService(new JsonSonarConnector());
            var projectAsso = new Resource {
                Key = "proj"
            };
            var model = new ExtensionDataModel(this.service, this.vshelper, null, null)
            {
                AssociatedProjectKey = "proj",
                CommentData          = "comment",
                SelectedIssue        = issue,
                SonarInfo            = "ver",
                SelectedUser         = new User {
                    Login = "******"
                },
                DiagnosticMessage = "MessageData",
                DisableEditorTags = false,
                RestService       = connector,
                AssociatedProject = projectAsso,
            };

            Assert.AreEqual("Selected Project: proj", model.AssociatedProjectKey);
            Assert.AreEqual(issue, model.SelectedIssue);
            Assert.AreEqual("comment", model.CommentData);
            Assert.AreEqual("login", model.SelectedUser.Login);
            Assert.AreEqual("ver", model.SonarInfo);
            Assert.AreEqual("MessageData", model.DiagnosticMessage);
            Assert.IsFalse(model.DisableEditorTags);
            Assert.AreEqual(connector, model.RestService);
            Assert.AreEqual(projectAsso, model.AssociatedProject);
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SonarQubeViewModel" /> class. Plugins are initialized in InitModelFromPackageInitialization below
        /// </summary>
        /// <param name="vsverionIn">The vs version.</param>
        public SonarQubeViewModel(string vsverionIn)
        {
            this.vsversion = vsverionIn;
            this.ToolsProvidedByPlugins = new ObservableCollection <MenuItem>();
            this.AvailableBranches      = new List <Resource>();

            this.notificationManager       = new NotifyCationManager(this, vsverionIn);
            this.configurationHelper       = new ConfigurationHelper(vsverionIn);
            this.sonarKeyTranslator        = new SQKeyTranslator();
            this.sonarRestConnector        = new SonarRestService(new JsonSonarConnector());
            this.VSonarQubeOptionsViewData = new VSonarQubeOptionsViewModel(this.sonarRestConnector, this.configurationHelper, this.notificationManager);
            this.VSonarQubeOptionsViewData.ResetUserData();

            this.CanConnectEnabled = true;
            this.ConnectionTooltip = "Not Connected";
            this.BackGroundColor   = Colors.White;
            this.ForeGroundColor   = Colors.Black;
            this.IsExtensionBusy   = false;

            this.InitCommands();
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="SonarQubeViewModel" /> class.
        /// </summary>
        /// <param name="vsverionIn">The vsverion in.</param>
        /// <param name="helper">The helper.</param>
        public SonarQubeViewModel(string vsverionIn, IConfigurationHelper helper)
        {
            this.vsversion = vsverionIn;
            this.ToolsProvidedByPlugins = new ObservableCollection<MenuItem>();
            this.AvailableBranches = new List<Resource>();

            this.configurationHelper = helper;
            this.notificationManager = new NotifyCationManager(this, vsverionIn);
            this.sonarKeyTranslator = new SQKeyTranslator();
            this.sonarRestConnector = new SonarRestService(new JsonSonarConnector());
            this.VSonarQubeOptionsViewData = new VSonarQubeOptionsViewModel(this.sonarRestConnector, this.configurationHelper, this.notificationManager);
            this.VSonarQubeOptionsViewData.ResetUserData();

            this.CanConnectEnabled = true;
            this.ConnectionTooltip = "Not Connected";
            this.BackGroundColor = Colors.White;
            this.ForeGroundColor = Colors.Black;
            this.ErrorIsFound = true;
            this.IsExtensionBusy = false;

            this.InitCommands();
        }
        /// <summary>
        /// The button test connection click.
        /// </summary>
        /// <param name="sender">
        /// The sender.
        /// </param>
        /// <param name="e">
        /// The e.
        /// </param>
        private void ButtonTestConnectionClick(object sender, EventArgs e)
        {
            try
            {
                var userConf = new ConnectionConfiguration(this.textBoxSonarHost.Text, this.textBoxUserName.Text, this.textBoxPassword.Text);
                ISonarRestService restService = new SonarRestService(new JsonSonarConnector());
                var versionDouble = restService.GetServerInfo(userConf);

                if (versionDouble < 3.3)
                {
                    MessageBox.Show("Authentication Ok");
                    return;
                }

                MessageBox.Show(restService.AuthenticateUser(userConf)
                                                         ? "Authentication Ok"
                                                         : "Authentication Failed, Check Host/Password/User");
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot Authenticate" + ex.StackTrace + " Messsage: " + ex.Message);
            }
        }
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="parameter">
        /// The parameter.
        /// </param>
        public void Execute(object parameter)
        {
            var restService = new SonarRestService(new JsonSonarConnector());

            var project = new ProjectAssociationDataModel(restService, this.model.UserConfiguration);
            var data = new ProjectAssociationWindow(project);
            data.ShowDialog();
            if (project.AssociatedProject != null)
            {
                this.model.AssociatedProject = project.AssociatedProject;
            }
        }
        /// <summary>
        ///     The test window.
        /// </summary>
        public void TestWindow()
        {
            var mocks = new MockRepository();
            var mockHttpReq = mocks.Stub<IHttpSonarConnector>();
            var mockVsHelpers = mocks.Stub<IVsEnvironmentHelper>();
            var config = new ConnectionConfiguration("serveraddr", "login", "password");

            // set expectations
            using (mocks.Record())
            {
                SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/issues/search?components=resource"))
                    .Return(File.ReadAllText("TestData/issuessearchbycomponent.txt"));
                SetupResult.For(mockHttpReq.HttpSonarGetRequest(config, "/api/users/search")).Return(File.ReadAllText("TestData/userList.txt"));
            }

            ISonarRestService service = new SonarRestService(mockHttpReq);
            var issues = service.GetIssuesInResource(config, "resource");
            var associatedProject = new Resource { Key = "core:Common" };

            this.model = new ExtensionDataModel(service, mockVsHelpers, associatedProject);
            var t = new Thread(this.Threadprc);
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
            t.Join();
        }