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")); }
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")); }
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); }