コード例 #1
0
        public void GetQueryStringParametersWhenTravelModeTransitAndDepartureTimeTest()
        {
            var request = new DirectionsRequest
            {
                Key           = "key",
                Origin        = new LocationEx(new Address("address")),
                Destination   = new LocationEx(new Address("address")),
                TravelMode    = TravelMode.Transit,
                DepartureTime = DateTime.UtcNow.AddHours(1)
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var mode         = queryStringParameters.FirstOrDefault(x => x.Key == "mode");
            var modeExpected = request.TravelMode.ToString().ToLower();

            Assert.IsNotNull(mode);
            Assert.AreEqual(modeExpected, mode.Value);

            var transitMode         = queryStringParameters.FirstOrDefault(x => x.Key == "transit_mode");
            var transitModeExpected = request.TransitMode.ToEnumString('|');

            Assert.IsNotNull(transitMode);
            Assert.AreEqual(transitModeExpected, transitMode.Value);

            var departureTime         = queryStringParameters.FirstOrDefault(x => x.Key == "departure_time");
            var departureTimeExpected = request.DepartureTime.GetValueOrDefault().DateTimeToUnixTimestamp().ToString(CultureInfo.InvariantCulture);

            Assert.IsNotNull(departureTime);
            Assert.AreEqual(departureTimeExpected, departureTime.Value);
        }
コード例 #2
0
        public void GetQueryStringParametersWhenTravelModeDrivingAndDepartureTimeAndTrafficModelAndWayPointsViaTest()
        {
            var request = new DirectionsRequest
            {
                Key           = "key",
                Origin        = new LocationEx(new Address("address")),
                Destination   = new LocationEx(new Address("address")),
                TravelMode    = TravelMode.Driving,
                DepartureTime = DateTime.UtcNow.AddHours(1),
                TrafficModel  = TrafficModel.Best_Guess,
                WayPoints     = new[]
                {
                    new WayPoint(new LocationEx(new Address("waypoint_address")), true)
                }
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var departureTime         = queryStringParameters.FirstOrDefault(x => x.Key == "departure_time");
            var departureTimeExpected = request.DepartureTime.GetValueOrDefault().DateTimeToUnixTimestamp().ToString(CultureInfo.InvariantCulture);

            Assert.IsNotNull(departureTime);
            Assert.AreEqual(departureTimeExpected, departureTime.Value);

            var trafficModel         = queryStringParameters.FirstOrDefault(x => x.Key == "traffic_model");
            var trafficModelExpected = request.TrafficModel.ToString().ToLower();

            Assert.IsNotNull(trafficModel);
            Assert.AreEqual(trafficModelExpected, trafficModel.Value);
        }
コード例 #3
0
        public void GetQueryStringParametersWhenTravelModeTransitTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                TravelMode  = TravelMode.Transit
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var mode         = queryStringParameters.FirstOrDefault(x => x.Key == "mode");
            var modeExpected = request.TravelMode.ToString().ToLower();

            Assert.IsNotNull(mode);
            Assert.AreEqual(modeExpected, mode.Value);

            var transitMode         = queryStringParameters.FirstOrDefault(x => x.Key == "transit_mode");
            var transitModeExpected = request.TransitMode.ToEnumString('|');

            Assert.IsNotNull(transitMode);
            Assert.AreEqual(transitModeExpected, transitMode.Value);

            var          departureTime           = queryStringParameters.FirstOrDefault(x => x.Key == "departure_time");
            const string DEPARTURE_TIME_EXPECTED = "now";

            Assert.IsNotNull(departureTime);
            Assert.AreEqual(DEPARTURE_TIME_EXPECTED, departureTime.Value);
        }
コード例 #4
0
        public void GetQueryStringParametersTest()
        {
            var request = new DirectionsRequest
            {
                Origin      = new Location("test"),
                Destination = new Location("test")
            };

            Assert.DoesNotThrow(() => request.GetQueryStringParameters());
        }
コード例 #5
0
        public void GetQueryStringParametersWhenKeyIsEmptyTest()
        {
            var request = new DirectionsRequest
            {
                Key = string.Empty
            };

            var exception = Assert.Throws <ArgumentException>(() => request.GetQueryStringParameters());

            Assert.AreEqual("'Key' is required", exception.Message);
        }
コード例 #6
0
        public void GetQueryStringParametersWhenDestinationIsNullTest()
        {
            var request = new DirectionsRequest
            {
                Key    = "key",
                Origin = new LocationEx(new Address("address"))
            };

            var exception = Assert.Throws <ArgumentException>(() => request.GetQueryStringParameters());

            Assert.AreEqual("'Destination' is required", exception.Message);
        }
コード例 #7
0
        public void GetQueryStringParametersTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address"))
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var key         = queryStringParameters.FirstOrDefault(x => x.Key == "key");
            var keyExpected = request.Key;

            Assert.IsNotNull(key);
            Assert.AreEqual(keyExpected, key.Value);

            var origin         = queryStringParameters.FirstOrDefault(x => x.Key == "origin");
            var originExpected = request.Origin.ToString();

            Assert.IsNotNull(origin);
            Assert.AreEqual(originExpected, origin.Value);

            var destination         = queryStringParameters.FirstOrDefault(x => x.Key == "destination");
            var destinationExpected = request.Destination.ToString();

            Assert.IsNotNull(origin);
            Assert.AreEqual(destinationExpected, destination.Value);

            var units         = queryStringParameters.FirstOrDefault(x => x.Key == "units");
            var unitsExpected = request.Units.ToString().ToLower();

            Assert.IsNotNull(units);
            Assert.AreEqual(unitsExpected, units.Value);

            var language         = queryStringParameters.FirstOrDefault(x => x.Key == "language");
            var languageExpected = request.Language.ToCode();

            Assert.IsNotNull(language);
            Assert.AreEqual(languageExpected, language.Value);

            var mode         = queryStringParameters.FirstOrDefault(x => x.Key == "mode");
            var modeExpected = request.TravelMode.ToString().ToLower();

            Assert.IsNotNull(mode);
            Assert.AreEqual(modeExpected, mode.Value);
        }
コード例 #8
0
        public void GetQueryStringParametersWhenDestinationsIsNullTest()
        {
            var request = new DirectionsRequest
            {
                Origin = new Location(0, 0)
            };

            var exception = Assert.Throws <ArgumentException>(() =>
            {
                var parameters = request.GetQueryStringParameters();
                Assert.IsNull(parameters);
            });

            Assert.IsNotNull(exception);
            Assert.AreEqual(exception.Message, "Destination is required");
        }
コード例 #9
0
        public void GetQueryStringParametersWhenUnitsTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                Units       = Units.Imperial
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var units         = queryStringParameters.FirstOrDefault(x => x.Key == "units");
            var unitsExpected = request.Units.ToString().ToLower();

            Assert.IsNotNull(units);
            Assert.AreEqual(unitsExpected, units.Value);
        }
コード例 #10
0
        public void GetQueryStringParametersWhenWhenTravelModeIsTransitAndDepartureTimeIsNullAndArrivalTimeIsNullTest()
        {
            var request = new DirectionsRequest
            {
                Origin        = new Location(0, 0),
                Destination   = new Location("test"),
                TravelMode    = TravelMode.Transit,
                DepartureTime = null,
                ArrivalTime   = null
            };

            var exception = Assert.Throws <ArgumentException>(() =>
            {
                var parameters = request.GetQueryStringParameters();
                Assert.IsNull(parameters);
            });

            Assert.IsNotNull(exception);
            Assert.AreEqual(exception.Message, "DepatureTime or ArrivalTime is required, when TravelMode is Transit");
        }
コード例 #11
0
        public void GetQueryStringParametersWhenRegionTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                Region      = "region"
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var region         = queryStringParameters.FirstOrDefault(x => x.Key == "region");
            var regionExpected = request.Region;

            Assert.IsNotNull(region);
            Assert.AreEqual(regionExpected, region.Value);
        }
コード例 #12
0
        public void GetQueryStringParametersWhenChannelTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                Channel     = "channel"
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var channel         = queryStringParameters.FirstOrDefault(x => x.Key == "channel");
            var channelExpected = request.Channel;

            Assert.IsNotNull(channel);
            Assert.AreEqual(channelExpected, channel.Value);
        }
コード例 #13
0
        public void GetQueryStringParametersWhenAvoidTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                Avoid       = AvoidWay.Highways | AvoidWay.Ferries
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var avoid         = queryStringParameters.FirstOrDefault(x => x.Key == "avoid");
            var avoidExpected = request.Avoid.ToEnumString('|');

            Assert.IsNotNull(avoid);
            Assert.AreEqual(avoidExpected, avoid.Value);
        }
コード例 #14
0
        public void GetQueryStringParametersWhenAlternativesTest()
        {
            var request = new DirectionsRequest
            {
                Key          = "key",
                Origin       = new LocationEx(new Address("address")),
                Destination  = new LocationEx(new Address("address")),
                Alternatives = true
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var alternatives         = queryStringParameters.FirstOrDefault(x => x.Key == "alternatives");
            var alternativesExpected = request.Alternatives.ToString().ToLower();

            Assert.IsNotNull(alternatives);
            Assert.AreEqual(alternativesExpected, alternatives.Value);
        }
コード例 #15
0
        public void GetQueryStringParametersWhenLanguageTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                Language    = Language.Afrikaans
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var language         = queryStringParameters.FirstOrDefault(x => x.Key == "language");
            var languageExpected = request.Language.ToCode();

            Assert.IsNotNull(language);
            Assert.AreEqual(languageExpected, language.Value);
        }
コード例 #16
0
        public void GetQueryStringParametersWhenTravelModeTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                TravelMode  = TravelMode.Bicycling
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var mode         = queryStringParameters.FirstOrDefault(x => x.Key == "mode");
            var modeExpected = request.TravelMode.ToString().ToLower();

            Assert.IsNotNull(mode);
            Assert.AreEqual(modeExpected, mode.Value);
        }
コード例 #17
0
        public void GetQueryStringParametersWhenTravelModeTransitAndTransitModeTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                TravelMode  = TravelMode.Transit,
                TransitMode = TransitMode.Subway | TransitMode.Rail
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var transitMode         = queryStringParameters.FirstOrDefault(x => x.Key == "transit_mode");
            var transitModeExpected = request.TransitMode.ToEnumString('|');

            Assert.IsNotNull(transitMode);
            Assert.AreEqual(transitModeExpected, transitMode.Value);
        }
コード例 #18
0
        public void GetQueryStringParametersWhenTravelModeTransitAndTransitRoutingPreferenceTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                TravelMode  = TravelMode.Transit,
                TransitMode = TransitMode.Subway | TransitMode.Rail,
                TransitRoutingPreference = TransitRoutingPreference.Fewer_Transfers
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var transitRoutingPreference         = queryStringParameters.FirstOrDefault(x => x.Key == "transit_routing_preference");
            var transitRoutingPreferenceExpected = request.TransitRoutingPreference.ToString().ToLower();

            Assert.IsNotNull(transitRoutingPreference);
            Assert.AreEqual(transitRoutingPreferenceExpected, transitRoutingPreference.Value);
        }
コード例 #19
0
        public void GetQueryStringParametersWhenWayPointsTest()
        {
            var request = new DirectionsRequest
            {
                Key         = "key",
                Origin      = new LocationEx(new Address("address")),
                Destination = new LocationEx(new Address("address")),
                WayPoints   = new[]
                {
                    new WayPoint(new LocationEx(new Address("waypoint_address")))
                }
            };

            var queryStringParameters = request.GetQueryStringParameters();

            Assert.IsNotNull(queryStringParameters);

            var wayPoints         = queryStringParameters.FirstOrDefault(x => x.Key == "waypoints");
            var wayPointsExpected = string.Join("|", request.WayPoints.Select(x => x.ToString()));

            Assert.IsNotNull(wayPoints);
            Assert.AreEqual(wayPointsExpected, wayPoints.Value);
        }