public void GetQueryStringParametersWhenHeadingTest()
        {
            var request = new DistanceMatrixRequest
            {
                Origins = new[] { new Location(1, 2)
                                  {
                                      Heading = 90
                                  } },
                Destinations = new[] { new Location(1, 2)
                                       {
                                           Heading = 90
                                       } }
            };

            Assert.DoesNotThrow(() => request.GetQueryStringParameters());
        }
Exemple #2
0
        public void GetQueryStringParametersWhenOriginsIsNullTest()
        {
            var request = new DistanceMatrixRequest
            {
                Destinations = new[] { new Location("test") }
            };

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

            Assert.IsNotNull(exception);
            Assert.AreEqual(exception.Message, "Origins is required");
        }
        public void GetQueryStringParametersWhenTravelModeTransitAndArrivalTimeTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key     = "key",
                Origins = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Destinations = new[]
                {
                    new LocationEx(new Address("address"))
                },
                TravelMode  = TravelMode.Transit,
                ArrivalTime = 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");

            Assert.IsNotNull(departureTime);
            Assert.IsNull(departureTime.Value);

            var arrivalTime         = queryStringParameters.FirstOrDefault(x => x.Key == "arrival_time");
            var arrivalTimeExpected = request.ArrivalTime.GetValueOrDefault().DateTimeToUnixTimestamp().ToString(CultureInfo.InvariantCulture);

            Assert.IsNotNull(arrivalTime);
            Assert.AreEqual(arrivalTimeExpected, arrivalTime.Value);
        }
Exemple #4
0
        public void GetQueryStringParametersWhenWhenTravelModeIsTransitAndDepartureTimeIsNullAndArrivalTimeIsNullTest()
        {
            var request = new DistanceMatrixRequest
            {
                Origins       = new[] { new Location(1, 1) },
                Destinations  = new[] { 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");
        }
        public void GetQueryStringParametersWhenTravelModeTransitTest()
        {
            var request = new DistanceMatrixRequest
            {
                Key     = "key",
                Origins = new[]
                {
                    new LocationEx(new Address("address"))
                },
                Destinations = new[]
                {
                    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);
        }