Ejemplo n.º 1
0
        public void GetGeocodingForAddress1()
        {
            // Arrange
            var request = new GeocodingRequest {
                Address = "1600 Amphitheatre Parkway Mountain View CA"
            };

            // Act
            var response = CreateService().GetResponse(request);

            // Assert
            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);
            Assert.AreEqual(1, response.Results.Length);

            var result = response.Results.Single();

            Assert.AreEqual("Google Bldg 42, 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", result.FormattedAddress);
            Assert.AreEqual(LocationType.Rooftop, result.Geometry.LocationType);

            var expectedLocation = new LatLng(37.42219410, -122.08459320);

            Assert.That(expectedLocation, Is.EqualTo(result.Geometry.Location).Using(LatLngComparer.Within(0.00001f)));

            Viewport expectedViewport = new Viewport(
                southWest: new LatLng(37.42084511970850, -122.0859421802915),
                northEast: new LatLng(37.42354308029149, -122.0832442197085)
                );

            Assert.That(expectedViewport.Southwest, Is.EqualTo(result.Geometry.Viewport.Southwest).Using(LatLngComparer.Within(0.00001f)));
            Assert.That(expectedViewport.Northeast, Is.EqualTo(result.Geometry.Viewport.Northeast).Using(LatLngComparer.Within(0.00001f)));
        }
        public void Ex_6_precision()
        {
            LatLng expected = new LatLng(30.343434, 40.412121);

            LatLng actual = new LatLng(30.34343400001, 40.41212100001);

            Assert.That(expected, Is.EqualTo(actual).Using(LatLngComparer.Within(0.000001f)));
        }
        public void Ex_1_precision()
        {
            LatLng expected = new LatLng(30.3, 40.4);

            LatLng actual = new LatLng(30.31, 40.41);

            Assert.That(expected, Is.EqualTo(actual).Using(LatLngComparer.Within(0.1f)));
        }
Ejemplo n.º 4
0
        public void GetResultForDirections_ex1()
        {
            // Arrange
            var request = new DirectionRequest
            {
                Origin      = "21 Henr St, Bristol, UK",            // Typo intended so that it produces a partial match
                Destination = "27 Victoria Drive, Lyneham"
            };

            // Act
            var response = CreateService().GetResponse(request);

            // Assert
            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status, "Status");
            Assert.AreEqual(1, response.Routes.Length, "ResultCount");

            var currentLeg = response.Routes[0].Legs[0];

            Assert.AreEqual("21 Henry St, Bristol BS3 4UD, UK", currentLeg.StartAddress);
            Assert.That(currentLeg.StartLocation, Is.EqualTo(new LatLng(51.442, -2.579)).Using(LatLngComparer.Within(0.001f)));

            Assert.AreEqual("27 Victoria Dr, Lyneham, Chippenham SN15 4RA, UK", currentLeg.EndAddress);
            Assert.That(currentLeg.EndLocation, Is.EqualTo(new LatLng(51.505, -1.958)).Using(LatLngComparer.Within(0.001f)));

            Assert.That(currentLeg.Distance.Value, Is.EqualTo(53939));
            Assert.That(currentLeg.Duration.Value, Is.EqualTo(2956));

            Assert.AreEqual(19, currentLeg.Steps.Count());

            Assert.AreEqual("M4", response.Routes[0].Summary);

            Assert.AreEqual(2, response.Waypoints.Length);
            Assert.AreEqual(ServiceResponseStatus.Ok, response.Waypoints[0].Status);
            Assert.AreEqual(AddressType.StreetAddress, response.Waypoints[0].Types[0]);
            Assert.AreEqual(true, response.Waypoints[0].PartialMatch);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Waypoints[1].Status);
            Assert.AreEqual(AddressType.StreetAddress, response.Waypoints[1].Types[0]);
            Assert.AreEqual(false, response.Waypoints[1].PartialMatch);
        }
        public void GetResultForDirections_ex1()
        {
            // expectations
            var expectedStatus      = ServiceResponseStatus.Ok;
            var expectedRoutesCount = 1;

            var expectedEndAddress  = "Montreal, QC, Canada";
            var expectedEndLocation = new LatLng(45.5017123, -73.5672184);

            var expectedStartAddress  = "Toronto, ON, Canada";
            var expectedStartLocation = new LatLng(43.6533103, -79.3827675);

            var expectedBounds = new Viewport(
                northEast: new LatLng(45.51048, -73.55332),
                southWest: new LatLng(43.65331, -79.38373)
                );

            var expectedDistance = new ValueText()
            {
                Text = "541 km", Value = "540965"
            };
            var expectedDuration = new ValueText()
            {
                Text = "5 hours 17 mins", Value = "18996"
            };

            var expectedSteps = 16;

            var expectedSummary = "ON-401 E";

            var expectedWaypointStatus       = ServiceResponseStatus.Ok;
            var expectedWaypointPartialMatch = true;
            var expectedWaypointAddressType1 = AddressType.Locality;
            var expectedWaypointAddressType2 = AddressType.Political;


            // test
            var request = new DirectionRequest();

            request.Origin      = "Toront";        // Typo intended
            request.Destination = "Montreal";
            request.Sensor      = false;

            var response = new DirectionService().GetResponse(request);

            // asserts
            Assert.AreEqual(expectedStatus, response.Status, "Status");
            Assert.AreEqual(expectedRoutesCount, response.Routes.Length, "ResultCount");

            var currentLeg = response.Routes[0].Legs[0];

            Assert.That(currentLeg.StartAddress, Is.EqualTo(expectedStartAddress), "Leg.StartAddress");
            Assert.That(currentLeg.StartLocation, Is.EqualTo(expectedStartLocation).Using(LatLngComparer.Within(0.000001f)), "Leg.StartLocation");

            Assert.That(currentLeg.EndAddress, Is.EqualTo(expectedEndAddress), "Leg.EndAddress");
            Assert.That(currentLeg.EndLocation, Is.EqualTo(expectedEndLocation).Using(LatLngComparer.Within(0.000001f)), "Leg.EndLocation");

            Assert.That(currentLeg.Distance, Is.EqualTo(expectedDistance).Using(new ValueTextComparer(StringComparer.InvariantCultureIgnoreCase)), "Leg.Distance");
            Assert.That(currentLeg.Duration, Is.EqualTo(expectedDuration).Using(new ValueTextComparer(StringComparer.InvariantCultureIgnoreCase)), "Leg.Duration");

            Assert.That(currentLeg.Steps.Count(), Is.EqualTo(expectedSteps), "Leg.Steps");

            Assert.That(response.Routes[0].Summary, Is.EqualTo(expectedSummary), "Route.Summary");

            Assert.AreEqual(expectedWaypointStatus, response.Waypoints[0].Status, "Waypoint.Status");
            Assert.AreEqual(expectedWaypointAddressType1, response.Waypoints[1].Types[0], "Waypoint.PlaceType1");
            Assert.AreEqual(expectedWaypointAddressType2, response.Waypoints[1].Types[1], "Waypoint.PlaceType2");
            Assert.AreEqual(expectedWaypointPartialMatch, response.Waypoints[0].PartialMatch, "Waypoint.PartialMatch");
        }
Ejemplo n.º 6
0
        public void GetGeocodingForAddress1()
        {
            // expectations
            var expectedStatus           = ServiceResponseStatus.Ok;
            var expectedResultCount      = 1;
            var expectedType             = AddressType.StreetAddress;
            var expectedFormattedAddress = "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA";
            var expectedComponentTypes   = new AddressType[] {
                AddressType.StreetNumber,
                AddressType.Route,
                AddressType.Locality,
                AddressType.AdministrativeAreaLevel1,
                AddressType.AdministrativeAreaLevel2,
                AddressType.AdministrativeAreaLevel3,
                AddressType.Country,
                AddressType.PostalCode,
                AddressType.Political
            };
            var      expectedLocation     = new LatLng(37.42219410, -122.08459320);
            var      expectedLocationType = LocationType.Rooftop;
            Viewport expectedViewport     = new Viewport(
                southWest: new LatLng(37.42084511970850, -122.0859421802915),
                northEast: new LatLng(37.42354308029149, -122.0832442197085)
                );

            // test
            var request = new GeocodingRequest();

            request.Address = "1600 Amphitheatre Parkway Mountain View CA";
            request.Sensor  = false;
            var response = new GeocodingService().GetResponse(request);

            // asserts
            Assert.AreEqual(expectedStatus, response.Status, "Status");
            Assert.AreEqual(expectedResultCount, response.Results.Length, "ResultCount");
            Assert.AreEqual(expectedType, response.Results.Single().Types.First(), "Type");
            Assert.AreEqual(expectedFormattedAddress, response.Results.Single().FormattedAddress, "FormattedAddress");
            //Assert.IsTrue(
            //    expectedComponentTypes.OrderBy(x => x).SequenceEqual(
            //        response.Results.Single().AddressComponents.SelectMany(y => y.Types).Distinct().OrderBy(z => z)), "Types");
            //Assert.AreEqual(expectedLatitude, response.Results.Single().Geometry.Location.Latitude, "Latitude");
            Assert.That(expectedLocation, Is.EqualTo(response.Results[0].Geometry.Location).Using(LatLngComparer.Within(0.000001f)), "Longitude");
            Assert.AreEqual(expectedLocationType, response.Results.Single().Geometry.LocationType, "LocationType");
            //Assert.AreEqual(expectedSouthwestLatitude, response.Results.Single().Geometry.Viewport.Southwest.Latitude, "Southwest.Latitude");
            //Assert.AreEqual(expectedSouthwestLongitude, response.Results.Single().Geometry.Viewport.Southwest.Longitude, "Southwest.Longitude");
            //Assert.AreEqual(expectedNortheastLatitude, response.Results.Single().Geometry.Viewport.Northeast.Latitude, "Northeast.Latitude");
            //Assert.AreEqual(expectedNortheastLongitude, response.Results.Single().Geometry.Viewport.Northeast.Longitude, "Northeast.Longitude");
        }
Ejemplo n.º 7
0
        public void GetResultForDirections_ex1()
        {
            // expectations
            var expectedStatus      = ServiceResponseStatus.Ok;
            var expectedRoutesCount = 1;

            var expectedEndAddress  = "Montreal, QC, Canada";
            var expectedEndLocation = new LatLng(45.508570, -73.553770);

            var expectedStartAddress  = "Toronto, ON, Canada";
            var expectedStartLocation = new LatLng(43.653310, -79.382770);

            var expectedBounds = new Viewport(
                northEast: new LatLng(45.51048, -73.55332),
                southWest: new LatLng(43.65331, -79.38373)
                );

            var expectedDistance = new ValueText()
            {
                Text = "542 km", Value = "542382"
            };
            var expectedDuration = new ValueText()
            {
                Text = "5 hours 27 mins", Value = "19608"
            };

            var expectedSteps = 13;

            var expectedSummary = "ON-401 E";

            // test
            var request = new DirectionRequest();

            request.Origin      = "Toronto";
            request.Destination = "Montreal";
            request.Sensor      = false;

            var response = new DirectionService().GetResponse(request);

            // asserts
            Assert.AreEqual(expectedStatus, response.Status, "Status");
            Assert.AreEqual(expectedRoutesCount, response.Routes.Length, "ResultCount");

            var currentLeg = response.Routes[0].Legs[0];

            Assert.That(expectedStartAddress, Is.EqualTo(currentLeg.StartAddress), "Leg.StartAddress");
            Assert.That(expectedStartLocation, Is.EqualTo(currentLeg.StartLocation).Using(LatLngComparer.Within(0.000001f)), "Leg.StartLocation");

            Assert.That(expectedEndAddress, Is.EqualTo(currentLeg.EndAddress), "Leg.EndAddress");
            Assert.That(expectedEndLocation, Is.EqualTo(currentLeg.EndLocation).Using(LatLngComparer.Within(0.000001f)), "Leg.EndLocation");

            Assert.That(expectedDistance, Is.EqualTo(currentLeg.Distance).Using(new ValueTextComparer(StringComparer.InvariantCultureIgnoreCase)));
            Assert.That(expectedDuration, Is.EqualTo(currentLeg.Duration).Using(new ValueTextComparer(StringComparer.InvariantCultureIgnoreCase)));

            Assert.That(expectedSteps, Is.EqualTo(currentLeg.Steps.Count()), "Leg.Steps");

            Assert.That(expectedSummary, Is.EqualTo(response.Routes[0].Summary), "Route.Summary");
        }