public async Task TestDeserializationFailure() { //Arrange string fakeURL = "http://fakeURL"; var handlerMock = mockHandler(fakeOKResponseWithWrongJSON()); var httpClient = new HttpClient(handlerMock); ITrackerService trackerService = new TrackerService(httpClient, fakeURL); //Act Func <Task> action = async() => await trackerService.GetISSCurrentPosition(); //Assert action.Should() .Throw <Exception>() .WithMessage("Error calling ISS API"); }
public async Task TestEmptyResponse() { //Arrange string fakeURL = "http://fakeURL"; var handlerMock = mockHandler(fakeOKResponseWithEmptyContent()); var httpClient = new HttpClient(handlerMock); ITrackerService trackerService = new TrackerService(httpClient, fakeURL); //Act Func <Task> action = async() => await trackerService.GetISSCurrentPosition(); //Assert action.Should() .Throw <Exception>() .WithMessage("Error calling ISS API") .WithInnerException <Exception>() .WithMessage("Content response is Empty"); }
public async Task TestNotSuccessStatusCode() { //Arrange string fakeURL = "http://fakeURL"; var handlerMock = mockHandler(fakeKOResponse()); var httpClient = new HttpClient(handlerMock); ITrackerService trackerService = new TrackerService(httpClient, fakeURL); //Act Func <Task> action = async() => await trackerService.GetISSCurrentPosition(); //Assert action.Should() .Throw <Exception>() .WithMessage("Error calling ISS API") .WithInnerException <Exception>() .WithMessage("ISS API respond with a status error code of*"); }
public async Task TestGetISSCurrentPositionOkResult() { //Arrange string fakeURL = "http://fakeURL"; var handlerMock = mockHandler(fakeOKResponse()); var httpClient = new HttpClient(handlerMock); ITrackerService trackerService = new TrackerService(httpClient, fakeURL); //Act var apiResult = await trackerService.GetISSCurrentPosition(); //Assert apiResult.Should().BeOfType <IssApiResponse>().And.NotBeNull(); apiResult.timestamp.Should().Be(1600000000); apiResult.iss_position.Should().NotBeNull(); apiResult.iss_position.latitude.Should().Be("45.0"); apiResult.iss_position.longitude.Should().Be("13.0"); }