public void OnConnectWithoutSolutionOpenShouldNotAssociate() { mockConfiguration.Setup(x => x.ReadSetting(It.IsAny <Context>(), It.IsAny <string>(), It.IsAny <string>())).Returns(new SonarQubeProperties { Value = "dummy" }); mockRest.Setup(x => x.GetProjectsList(It.IsAny <ISonarConfiguration>())).Returns(this.CreatProjects()); mockRest.Setup(x => x.AuthenticateUser(It.IsAny <ISonarConfiguration>())).Returns(true); AuthtenticationHelper.EstablishAConnection(mockRest.Object, "as", "asda", "asd"); var associationModel = new SonarQubeViewModel("test", mockConfiguration.Object, mockLogger.Object, mockTranslator.Object, mockRest.Object, locaAnalyser: mockAnalyser.Object, pluginManager: mockPluginManager.Object); associationModel.VsHelper = mockVsHelper.Object; associationModel.OnConnectToSonar(false); WaitForCompletionOrTimeout(associationModel); Assert.That(associationModel.AvailableProjects.Count, Is.EqualTo(2)); Assert.That(associationModel.AssociationModule.IsAssociated, Is.False); Assert.That(associationModel.SelectedProjectInView, Is.Null); Assert.That(associationModel.SelectedProjectName, Is.Null); Assert.That(associationModel.SelectedProjectKey, Is.Null); Assert.That(associationModel.SelectedProjectVersion, Is.Null); Assert.That(associationModel.IsConnected, Is.True); }
public void OnConnectWithSolutionOpenShouldAssociateToANormalProject() { mockConfiguration.Setup(x => x.ReadSetting(It.IsAny <Context>(), It.IsAny <string>(), It.IsAny <string>())).Returns(new SonarQubeProperties { Value = "tekla.utilities:project" }); mockRest.Setup(x => x.GetProjectsList(It.IsAny <ISonarConfiguration>())).Returns(this.CreatProjects()); mockRest.Setup(x => x.AuthenticateUser(It.IsAny <ISonarConfiguration>())).Returns(true); mockVsHelper.Setup(x => x.ActiveSolutionName()).Returns("solutionaname"); mockVsHelper.Setup(x => x.ActiveSolutionPath()).Returns("solutionapath"); AuthtenticationHelper.EstablishAConnection(mockRest.Object, "as", "asda", "asd"); var associationModel = new SonarQubeViewModel("test", mockConfiguration.Object, mockLogger.Object, mockTranslator.Object, mockRest.Object, mockSourceProvider.Object, mockPlugin.Object, mockAnalyser.Object); associationModel.VsHelper = mockVsHelper.Object; associationModel.IsSolutionOpen = true; associationModel.OnConnectToSonar(false); WaitForCompletionOrTimeout(associationModel); Assert.That(associationModel.AssociationModule.IsAssociated, Is.True); Assert.That(associationModel.ErrorIsFound, Is.False); Assert.That(associationModel.ShowRightFlyout, Is.False); Assert.That(associationModel.StatusMessage, Is.EqualTo("successfully associated with : project")); Assert.That(associationModel.IsConnected, Is.True); Assert.That(associationModel.AssociationModule.AssociatedProject.Name, Is.EqualTo("project")); Assert.That(associationModel.AssociationModule.AssociatedProject.Key, Is.EqualTo("tekla.utilities:project")); }
public void OnSolutionOpenButProjectNotFoundItShouldNotAssociate() { mockRest.Setup(x => x.GetProjectsList(It.IsAny <ISonarConfiguration>())).Returns(this.CreatProjects()); mockRest.Setup(x => x.AuthenticateUser(It.IsAny <ISonarConfiguration>())).Returns(true); mockVsHelper.Setup(x => x.ActiveSolutionName()).Returns("solutionaname"); mockVsHelper.Setup(x => x.ActiveSolutionPath()).Returns("solutionapath"); mockPlugin.Setup(x => x.SourceCodePlugins).Returns(new List <ISourceVersionPlugin>()); AuthtenticationHelper.EstablishAConnection(mockRest.Object, "as", "asda", "asd"); var associationModel = new SonarQubeViewModel("test", mockConfiguration.Object, mockLogger.Object, mockTranslator.Object, mockRest.Object, mockSourceProvider.Object, mockPlugin.Object, locaAnalyser: mockAnalyser.Object); associationModel.AssociationModule.AssociatedProject = new Resource(); associationModel.SelectedProjectKey = "jasd"; associationModel.SelectedProjectName = "jasd"; associationModel.SelectedProjectVersion = "jasd"; associationModel.VsHelper = mockVsHelper.Object; associationModel.IsSolutionOpen = true; associationModel.IsConnected = true; associationModel.OnSolutionOpen("abc", "dfc", "sds"); WaitForCompletionOrTimeout(associationModel); Assert.That(associationModel.AssociationModule.IsAssociated, Is.False); Assert.That(associationModel.IsConnected, Is.True); Assert.That(associationModel.ErrorIsFound, Is.True); Assert.That(associationModel.ShowRightFlyout, Is.True); Assert.That(associationModel.StatusMessage, Is.EqualTo("Was unable to associate with sonar project, use project association dialog to choose a project or to provision project")); Assert.That(associationModel.AssociationModule.AssociatedProject, Is.Null); Assert.That(associationModel.SelectedProjectName, Is.Null); Assert.That(associationModel.SelectedProjectKey, Is.Null); Assert.That(associationModel.SelectedProjectVersion, Is.Null); }
public void OnConnectWithSolutionOpenShouldAssociateToBranchWhenBranchIsAvailableInServer() { mockConfiguration.Setup(x => x.ReadSetting(It.IsAny <Context>(), It.IsAny <string>(), It.IsAny <string>())).Returns(new SonarQubeProperties { Value = "project_Main" }); mockRest.Setup(x => x.GetProjectsList(It.IsAny <ISonarConfiguration>())).Returns(this.CreatProjects()); mockRest.Setup(x => x.AuthenticateUser(It.IsAny <ISonarConfiguration>())).Returns(true); mockVsHelper.Setup(x => x.ActiveSolutionName()).Returns("solutionaname"); mockVsHelper.Setup(x => x.ActiveSolutionPath()).Returns("solutionapath"); mockSourceProvider.Setup(x => x.GetBranch()).Returns("feature_A"); AuthtenticationHelper.EstablishAConnection(mockRest.Object, "as", "asda", "asd"); var associationModel = new SonarQubeViewModel("test", mockConfiguration.Object, mockLogger.Object, mockTranslator.Object, mockRest.Object, mockSourceProvider.Object, mockPlugin.Object, mockAnalyser.Object); associationModel.VsHelper = mockVsHelper.Object; associationModel.IsSolutionOpen = true; associationModel.OnConnectToSonar(false); WaitForCompletionOrTimeout(associationModel); Assert.That(associationModel.AssociationModule.IsAssociated, Is.True); Assert.That(associationModel.AssociationModule.AssociatedProject.Name, Is.EqualTo("project feature_A")); Assert.That(associationModel.AssociationModule.AssociatedProject.Key, Is.EqualTo("tekla.utilities:project:feature_A")); Assert.That(associationModel.IsConnected, Is.True); }
/// <summary> /// Initializes a new instance of the MainViewModel class. /// </summary> public MainViewModel() { var address = PromptUserData.Prompt("Server Address", "Insert Server Address", "http://sonar"); if (address == null) { throw new Exception("Server Address must not be empty"); } using (var dialog = new Security.Windows.Forms.UserCredentialsDialog()) { if (dialog.ShowDialog() == DialogResult.OK) { if (dialog.SaveChecked) { dialog.ConfirmCredentials(true); } AuthtenticationHelper.EstablishAConnection(new SonarRestService(new JsonSonarConnector()), address, dialog.User, dialog.PasswordToString()); } else { throw new Exception("user name and pass should be set"); } } this.SonarQubeView = new SonarQubeViewModel("standalone", null); this.SonarQubeView.InitModelFromPackageInitialization(new VsEnvironmentHelper(), new VsStatusBarDummy(), new ServiceProviderDummy(), Environment.CurrentDirectory); }
/// <summary> /// The on test and save password. /// </summary> /// <param name="obj"> /// The obj. /// </param> private void OnTestAndSavePassword(object obj) { if (string.IsNullOrEmpty(this.ServerAddress)) { this.StatusMessage = "Failed: Address not set"; return; } var passwordBox = obj as PasswordBox; if (passwordBox != null) { try { string password = passwordBox.Password; AuthtenticationHelper.ResetConnection(); if (AuthtenticationHelper.EstablishAConnection(this.restService, this.ServerAddress.TrimEnd('/'), this.UserName, password)) { this.StatusMessage = "Authenticated"; this.SetCredentials(this.UserName, password); } else { this.StatusMessage = "Wrong Credentials"; } } catch (Exception ex) { UserExceptionMessageBox.ShowException("Cannot Authenticate", ex); } } }
/// <summary> /// The get credentials. /// </summary> private void GetCredentials() { var cm = new Credential { Target = "VSSonarQubeExtension", }; if (!cm.Exists()) { return; } cm.Load(); try { string address = this.configurationHelper.ReadSetting(Context.GlobalPropsId, OwnersId.ApplicationOwnerId, "ServerAddress").Value; string bootatstart = this.configurationHelper.ReadSetting(Context.GlobalPropsId, OwnersId.ApplicationOwnerId, GlobalIds.IsConnectAtStartOn).Value; if (address != null && bootatstart.Equals("true")) { if (AuthtenticationHelper.EstablishAConnection(this.restService, address, cm.Username, ConnectionConfiguration.ConvertToUnsecureString(cm.SecurePassword))) { this.UserName = cm.Username; this.ServerAddress = address; this.Password = ConnectionConfiguration.ConvertToUnsecureString(cm.SecurePassword); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// <summary> /// The get credentials. /// </summary> private void GetCredentials() { using (var cm = new Credential { Target = "VSSonarQubeExtension" }) { if (!cm.Exists()) { return; } cm.Load(); string address = "http://localhost:9000"; try { address = this.configurationHelper.ReadSetting(Context.GlobalPropsId, OwnersId.ApplicationOwnerId, "ServerAddress").Value; } catch (Exception ex) { this.notificationManager.ReportMessage(new Message { Id = "GeneralConfigurationViewModel", Data = "Failed To Connect To Server: " + ex.Message }); this.notificationManager.ReportException(ex); } string bootatstart = "false"; try { bootatstart = this.configurationHelper.ReadSetting(Context.GlobalPropsId, OwnersId.ApplicationOwnerId, GlobalIds.IsConnectAtStartOn).Value; } catch (Exception ex) { this.notificationManager.ReportMessage(new Message { Id = "GeneralConfigurationViewModel", Data = "Failed To Get Connect at Start: " + ex.Message }); } this.UserName = cm.Username; this.Password = ConnectionConfiguration.ConvertToUnsecureString(cm.SecurePassword); this.ServerAddress = address; if (address != null) { AuthtenticationHelper.EstablishAConnection(this.restService, address, cm.Username, ConnectionConfiguration.ConvertToUnsecureString(cm.SecurePassword)); } } }