public void CalculateDistance()
        {
            // Arrange
            GeoCoordinateVo  latitude1    = new GeoCoordinateVo(51.5f);
            GeoCoordinateVo  longitude1   = new GeoCoordinateVo(0);
            GeoCoordinatesVo coordinates1 = new GeoCoordinatesVo(latitude1, longitude1);

            GeoCoordinateVo  latitude2    = new GeoCoordinateVo(38.8f);
            GeoCoordinateVo  longitude2   = new GeoCoordinateVo(-77.1f);
            GeoCoordinatesVo coordinates2 = new GeoCoordinatesVo(latitude2, longitude2);

            LocationDistanceCalculator calculator = new LocationDistanceCalculator(coordinates1, coordinates2);

            // Act
            var result = Math.Round(calculator.CalculateDistanceInMeters(), 2);

            // Assert
            Assert.Equal(5918185.06, result);
        }
Exemplo n.º 2
0
        private UserDto FindTheClosestDonator(UserDto requestor, ICollection <UserDto> donators)
        {
            UserDto closestDonator   = null;
            double  shortestDistance = Single.NaN;
            double  distance         = Single.NaN;
            LocationDistanceCalculator calculator = null;

            foreach (var donator in donators)
            {
                calculator = new LocationDistanceCalculator(new GeoCoordinatesVo(requestor.geoCoordinatesDto), new GeoCoordinatesVo(donator.geoCoordinatesDto));

                distance = calculator.CalculateDistanceInMiles();

                if (distance < shortestDistance)
                {
                    shortestDistance = distance;
                    closestDonator   = donator;
                }
            }

            return(closestDonator);
        }