private static void ServiceChangeLog(IOwinContext context, QualityProfileChangeLog changeLog, bool simulateFault = false) { if (simulateFault) { SimulateServerFault(context); } else { context.Response.Write(Serialize(changeLog)); } }
public void SonarQubeServiceWrapper_TryGetQualityProfile_FullFunctionality() { using (var testSubject = new TestableSonarQubeServiceWrapper(this.serviceProvider)) { // Setup Language language = Language.CSharp; QualityProfile profile = CreateRandomQualityProfile(language); var project = new ProjectInformation { Key = "awesome1", Name = "My Awesome Project" }; var changeLog = new QualityProfileChangeLog { Page = 1, PageSize = 1, Total = 1, Events = new QualityProfileChangeLogEvent[] { new QualityProfileChangeLogEvent { Date = DateTime.Now } } }; ConnectionInformation conn = ConfigureValidConnection(testSubject, new[] { project }); // Setup test server RegisterQualityProfileChangeLogValidator(testSubject); RequestHandler getProfileHandler = testSubject.RegisterRequestHandler( SonarQubeServiceWrapper.CreateQualityProfileUrl(language, project), ctx => ServiceQualityProfiles(ctx, new[] { profile }) ); RequestHandler changeLogHandler = testSubject.RegisterRequestHandler( SonarQubeServiceWrapper.CreateQualityProfileChangeLogUrl(profile), ctx => ServiceChangeLog(ctx, changeLog) ); // Act QualityProfile actualProfile; Assert.IsTrue(testSubject.TryGetQualityProfile(conn, project, language, CancellationToken.None, out actualProfile), "TryGetExportProfile failed unexpectedly"); // Verify Assert.IsNotNull(actualProfile, "Expected a profile to be returned"); Assert.AreEqual(profile.Key, actualProfile.Key); Assert.AreEqual(profile.Name, actualProfile.Name); Assert.AreEqual(changeLog.Events[0].Date, actualProfile.QualityProfileTimestamp); getProfileHandler.AssertHandlerCalled(1); changeLogHandler.AssertHandlerCalled(1); this.outputWindowPane.AssertOutputStrings(0); } }
public bool TryGetQualityProfile(ConnectionInformation serverConnection, ProjectInformation project, Language language, CancellationToken token, out QualityProfile profile) { if (serverConnection == null) { throw new ArgumentNullException(nameof(serverConnection)); } if (project == null) { throw new ArgumentNullException(nameof(project)); } if (language == null) { throw new ArgumentNullException(nameof(language)); } if (!language.IsSupported) { throw new ArgumentOutOfRangeException(nameof(language)); } profile = this.SafeUseHttpClient <QualityProfile>(serverConnection, async client => { QualityProfile qp = await DownloadQualityProfile(client, project, language, token); if (qp == null) { return(null); } QualityProfileChangeLog changeLog = await DownloadQualityProfileChangeLog(client, qp, token); if (changeLog != null) { qp.QualityProfileTimestamp = changeLog.Events.SingleOrDefault()?.Date; } return(qp); }); return(profile != null); }