public async Task GetDistance() { //Arrange var cancellation = new CancellationToken(); var httpClient = new Moq.Mock <IHttpClient>(Moq.MockBehavior.Strict); string response = new StreamReader( Assembly.GetExecutingAssembly().GetManifestResourceStream(this.GetType().Namespace + ".routingResponse.xml") ).ReadToEnd(); Uri calledUri = null; httpClient .Setup(c => c.GetStringAsync(It.IsAny <Uri>(), cancellation, It.IsAny <HttpStatusCode[]>())) .Callback <Uri, CancellationToken, HttpStatusCode[]>((uri, _, codes) => calledUri = uri) .ReturnsAsync((HttpStatusCode.OK, response)) ; var options = new AzureMapsOptions() { ApiKey = "some-key" }; var routingService = new AzureMapsRoutingService(httpClient.Object, Options.Create(options), TestData.GetLogger <AzureMapsRoutingService>()); var departure = new Coordinates() { Latitude = 1.2, Longitude = 3.4, }; var arrival = new Coordinates() { Latitude = 5.6, Longitude = 7.8, }; //Act var distance = await routingService.CalculateDistanceAsync(departure, arrival, cancellation); //Assert distance.Should().Be(1.146); calledUri.AbsolutePath.Should().Be("/route/directions/xml"); var query = HttpUtility.ParseQueryString(calledUri.Query); query["subscription-key"].Should().Be(options.ApiKey); query["query"].Should().Be("1.2,3.4:5.6,7.8"); }
public AzureMapsApiService(AzureMapsOptions azureMapsOptions) { _azureMapsOptions = azureMapsOptions; }
public UsersController(IMapsStorageService mapsStorageService, IAzureMapsApiService azureMapsApiService, AzureMapsOptions azureMapsOptions) { _mapsStorageService = mapsStorageService; _azureMapsApiService = azureMapsApiService; _azureMapsOptions = azureMapsOptions; }
public MapsStorageService(IAzureMapsApiService azureMapsApiService, AzureMapsOptions azureMapsOptions) { _azureMapsOptions = azureMapsOptions; _azureMapsApiService = azureMapsApiService; FakeUsers = GetFakeUsers(_azureMapsOptions.FakeUserDefaultLatitude, _azureMapsOptions.FakeUserDefaultLongitude); }
public ConfigController(AzureMapsOptions azureMapsOptions) { _azureMapsOptions = azureMapsOptions; }
public AzureMapsRoutingService(IHttpClient httpClient, IOptions <AzureMapsOptions> options, ILogger <AzureMapsRoutingService> logger) { _httpClient = httpClient; _logger = logger; _options = options.Value; }