Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 3
0
        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*");
        }
Exemplo n.º 4
0
        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");
        }