public void Empty_Address_Fails()
        {
            Assert.Throws <HttpRequestException>(() =>
            {
                // Arrange
                var request = new DirectionRequest {
                    Origin = ""
                };

                // Act
                var response = new DirectionService().GetResponse(request);
            });
        }
        public void PartialMatchTest()
        {
            // invalid address results in partial match
            var request = new DirectionRequest
            {
                Sensor = false,
                Origin = new Location("410 Beeeeeechwood Rd, NJ 07450"),
                Destination = new Location("204 Powell Ave, CA 94523")
            };
            var response = new DirectionService().GetResponse(request);

            Assert.True(response.GeocodedWaypoints.Any(wp => wp.PartialMatch));
        }
        public void Empty_address()
        {
            // expectations
            var expectedStatus = ServiceResponseStatus.ZeroResults;

            // test
            var request = new DirectionRequest();
            request.Sensor = false;
            request.Origin = "";
            var response = new DirectionService().GetResponse(request);

            // asserts
            Assert.AreEqual(expectedStatus, response.Status);
        }
        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 = new DirectionService().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, Is.EqualTo(new ValueText {
                Text = "53.9 km", Value = "53939"
            }).Using(new ValueTextComparer(StringComparer.InvariantCultureIgnoreCase)));
            Assert.That(currentLeg.Duration, Is.EqualTo(new ValueText {
                Text = "49 mins", Value = "2946"
            }).Using(new ValueTextComparer(StringComparer.InvariantCultureIgnoreCase)));

            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);
        }
        DirectionService CreateService()
        {
            var svc = new DirectionService(TestingApiKey);

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