Example #1
0
        public async Task BadResponse()
        {
            MockHttp.When(BaseUrl)
            .Respond(System.Net.HttpStatusCode.BadRequest);

            var service = new GoogleService("SOME_KEY", MockHttp.ToHttpClient());

            await Assert.ThrowsAsync <GCException>(() => service.GetCoordinate("Good address"));
        }
Example #2
0
        public async Task InvalidStatus(string jsonPath)
        {
            var invalidStatusResponse = await File.OpenText(jsonPath).ReadToEndAsync();

            MockHttp.When(BaseUrl)
            .Respond("application/json", invalidStatusResponse);

            var service = new GoogleService("SOME_KEY", MockHttp.ToHttpClient());

            await Assert.ThrowsAsync <GCException>(() => service.GetCoordinate("Good address"));
        }
Example #3
0
        public async Task HappyFlow(string jsonPath, AccuracyLevel expectedAccuracy)
        {
            var goodResponse = await File.OpenText(jsonPath).ReadToEndAsync();

            MockHttp.When(BaseUrl)
            .Respond("application/json", goodResponse);

            var service = new GoogleService("SOME_KEY", MockHttp.ToHttpClient());

            var coordinates = await service.GetCoordinate("Good address");

            var vals = Generic.ParseCoordinatesFromGoogleJson(goodResponse);

            Assert.Equal(vals.Item1, coordinates.Latitude);
            Assert.Equal(vals.Item2, coordinates.Longitude);
            Assert.Equal(expectedAccuracy, coordinates.Accuracy);
        }