public SonarQubeSqaleRatingController( ILogger <SonarQubeSqaleRatingController> logger, SonarQubeApiClient apiClient) { this.logger = logger; this.apiClient = apiClient; }
public async void ReturnProjectMetricsGivenValidArgs() { // arrange const string projectKey = "asdf"; const string expected = "{'name' : 'Test McGee'}"; const string metric = "sqale_rating"; var settings = new SonarQubeSettings() { HostURL = "http://example.org" }; var mockHttp = new MockHttpMessageHandler(); mockHttp.When($"{settings.HostURL}/api/measures/component?component={projectKey}&metricKeys={metric}") .Respond("application/json", expected); HttpClient httpClient = new HttpClient(mockHttp); SonarQubeApiClient apiClient = new SonarQubeApiClient(settings, httpClient); // act var jsonObject = await apiClient.GetProjectMetrics(projectKey, metric); // assert var actual = JsonConvert.SerializeObject(jsonObject); Assert.Equal(FormatJson(expected), FormatJson(actual)); }
public async void ReturnSqaleBadgeGivenValidArgs(string sqaleRating, string expectedGrade) { // arrange // setup mock HTTP client const string projectKey = "asdf"; string expected = "{'component':{'id':'AVolRB9SkCgaqSRFQon1','key':'org.example:my-project:develop','name':'My Project','qualifier':'TRK','measures':[{'metric':'sqale_rating','value':'" + sqaleRating + "','periods':[{'index':1,'value':'0.0'}]}]}}"; const string metric = "sqale_rating"; var settings = new SonarQubeSettings() { HostURL = "http://example.org" }; var mockHttp = new MockHttpMessageHandler(); mockHttp.When($"{settings.HostURL}/api/measures/component?component={projectKey}&metricKeys={metric}") .Respond("application/json", expected); var httpClient = new HttpClient(mockHttp); // setup the SUT var apiClient = new SonarQubeApiClient(settings, httpClient); var logger = new LoggerFactory().CreateLogger <SonarQubeSqaleRatingController>(); var controller = new SonarQubeSqaleRatingController(logger, apiClient); // make sure the controller has a non-null Request property (used for logging) SetupControllerContext(controller); // set working directory so the test finds assets Directory.SetCurrentDirectory("../netcoreapp2.0/"); // act var response = await controller.Get(projectKey); // assert Assert.IsType <FileStreamResult>(response); var content = response as FileStreamResult; var actual = new StreamReader(content.FileStream, Encoding.UTF8).ReadToEnd(); Assert.Matches("<text ?.+>" + expectedGrade + "<\\/text>", actual); }