public async Task DashboardClient_Get_With_Right_URL_with_module_name() { // Arrange var loggerMock = new Mock <ILogger <DashboardClient> >(MockBehavior.Loose); var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); var reporters = new[] { Reporter.Dashboard }; var options = new StrykerOptions { DashboardUrl = "http://www.example.com", DashboardApiKey = "Access_Token", ProjectName = "github.com/JohnDoe/project", ProjectVersion = "test/version", ModuleName = "moduleName", Reporters = reporters }; var readonlyInputComponent = new Mock <IReadOnlyProjectComponent>(MockBehavior.Loose).Object; var jsonReport = JsonReport.Build(options, readonlyInputComponent); var json = jsonReport.ToJson(); handlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.OK, Content = new StringContent(json, Encoding.UTF8, "application/json") }) .Verifiable(); var httpClient = new HttpClient(handlerMock.Object); var target = new DashboardClient(options, httpClient, loggerMock.Object); // Act var result = await target.PullReport("version"); // Assert var expectedUri = new Uri("http://www.example.com/api/reports/github.com/JohnDoe/project/version?module=moduleName"); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.RequestUri == expectedUri ), ItExpr.IsAny <CancellationToken>() ); result.ShouldNotBeNull(); result.ToJson().ShouldBe(json); }
public async Task DashboardClient_Get_Returns_Null_When_Statuscode_Not_200() { // Arrange var loggerMock = new Mock <ILogger <DashboardClient> >(MockBehavior.Loose); var handlerMock = new Mock <HttpMessageHandler>(MockBehavior.Strict); var reporters = new string[] { "dashboard" }; var options = new StrykerOptions( dashboardUrl: "http://www.example.com", dashboardApiKey: "Acces_Token", projectName: "github.com/JohnDoe/project", projectVersion: "test/version", reporters: reporters ); handlerMock .Protected() .Setup <Task <HttpResponseMessage> >( "SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage() { StatusCode = System.Net.HttpStatusCode.BadRequest, }) .Verifiable(); var httpClient = new HttpClient(handlerMock.Object); var target = new DashboardClient(options, httpClient, loggerMock.Object); // Act var result = await target.PullReport("version"); // Assert var expectedUri = new Uri("http://www.example.com/api/reports/github.com/JohnDoe/project/version"); handlerMock.Protected().Verify( "SendAsync", Times.Exactly(1), ItExpr.Is <HttpRequestMessage>(req => req.Method == HttpMethod.Get && req.RequestUri == expectedUri ), ItExpr.IsAny <CancellationToken>() ); result.ShouldBeNull(); }