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

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

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

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

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

            await Assert.ThrowsAsync <GCException>(() => service.GetCoordinate("Good address"));
        }
示例#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 BingService("SOME_KEY", MockHttp.ToHttpClient());

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

            var vals = Generic.ParseCoordinatesFromBingJson(goodResponse);

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