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"); }
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"); }