Пример #1
0
        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;
 }
Пример #3
0
 public UsersController(IMapsStorageService mapsStorageService, IAzureMapsApiService azureMapsApiService, AzureMapsOptions azureMapsOptions)
 {
     _mapsStorageService  = mapsStorageService;
     _azureMapsApiService = azureMapsApiService;
     _azureMapsOptions    = azureMapsOptions;
 }
Пример #4
0
 public MapsStorageService(IAzureMapsApiService azureMapsApiService, AzureMapsOptions azureMapsOptions)
 {
     _azureMapsOptions    = azureMapsOptions;
     _azureMapsApiService = azureMapsApiService;
     FakeUsers            = GetFakeUsers(_azureMapsOptions.FakeUserDefaultLatitude, _azureMapsOptions.FakeUserDefaultLongitude);
 }
Пример #5
0
 public ConfigController(AzureMapsOptions azureMapsOptions)
 {
     _azureMapsOptions = azureMapsOptions;
 }
Пример #6
0
 public AzureMapsRoutingService(IHttpClient httpClient, IOptions <AzureMapsOptions> options, ILogger <AzureMapsRoutingService> logger)
 {
     _httpClient = httpClient;
     _logger     = logger;
     _options    = options.Value;
 }