public void SonarQubeServiceWrapper_TryGetProjects() { var p1 = new ProjectInformation { Name = "Project 1", Key = "1" }; var p2 = new ProjectInformation { Name = "Project 2", Key = "2" }; using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup case 1: first time connect testSubject.AllowAnonymous = true; testSubject.RegisterConnectionHandler(new RequestHandler { ResponseText = Serialize(new[] { p1 }) }); var connectionInfo1 = new ConnectionInformation(new Uri("http://server")); // Act ProjectInformation[] projects = null; Assert.IsTrue(testSubject.TryGetProjects(connectionInfo1, CancellationToken.None, out projects), "Expected to get the projects"); // Verify AssertEqualProjects(new[] { p1 }, projects); this.outputWindowPane.AssertOutputStrings(0); // Setup case 2: second time connect var connectionInfo2 = new ConnectionInformation(new Uri("http://server")); // Act testSubject.RegisterConnectionHandler(new RequestHandler { ResponseText = Serialize(new[] { p1, p2 }) }); Assert.IsTrue(testSubject.TryGetProjects(connectionInfo2, CancellationToken.None, out projects), "Expected to get the projects"); // Verify AssertEqualProjects(new[] { p1, p2 }, projects); this.outputWindowPane.AssertOutputStrings(0); } }
private static ConnectionInformation ConfigureValidConnection(TestableSonarQubeServiceWrapper testSubject, IEnumerable <ProjectInformation> projects) { var connectionInfo = new ConnectionInformation(new Uri("http://test-server")); testSubject.AllowAnonymous = true; testSubject.RegisterConnectionHandler(new RequestHandler { ResponseText = Serialize(projects) }); return(connectionInfo); }
public void SonarQubeServiceWrapper_TryGetProjects_UnhandledExceptions() { using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup testSubject.AllowAnonymous = true; testSubject.RegisterConnectionHandler(new RequestHandler(ctx => { throw new InvalidOperationException(); })); var connectionInfo = new ConnectionInformation(new Uri("http://server")); // Act ProjectInformation[] projects = null; Assert.IsFalse(testSubject.TryGetProjects(connectionInfo, CancellationToken.None, out projects), "Exception been thrown"); // Verify this.outputWindowPane.AssertOutputStrings(1); Assert.IsNull(projects, "Not expecting projects"); } }
public void SonarQubeServiceWrapper_TryGetProjects_InvalidStatusCode() { using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup testSubject.AllowAnonymous = true; testSubject.RegisterConnectionHandler(new RequestHandler { ResponseStatusCode = HttpStatusCode.InternalServerError }); var connectionInfo = new ConnectionInformation(new Uri("http://server")); // Act ProjectInformation[] projects = null; Assert.IsFalse(testSubject.TryGetProjects(connectionInfo, CancellationToken.None, out projects), "Should fail"); // Verify Assert.IsNull(projects); this.outputWindowPane.AssertOutputStrings(1); } }
public void SonarQubeServiceWrapper_TryGetProjects_Authentication_Basic_Valid() { using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup testSubject.BasicAuthUsers.Add("admin", "admin"); testSubject.RegisterConnectionHandler(new RequestHandler { ResponseText = Serialize(new ProjectInformation[0]) }); var connectionInfo = new ConnectionInformation(new Uri("http://server"), "admin", "admin".ConvertToSecureString()); // Act ProjectInformation[] projects = null; Assert.IsTrue(testSubject.TryGetProjects(connectionInfo, CancellationToken.None, out projects), "Should be get an empty array of projects"); // Verify this.outputWindowPane.AssertOutputStrings(0); Assert.IsNotNull(projects, "Expected projects"); Assert.AreEqual(0, projects.Length, "Expected an empty array"); } }