/// <summary> /// Method used to parse a single JSON object and return customer data. /// </summary> /// <param name="match">Regex match.</param> /// <returns>Customer data.</returns> /// <exception cref="IntercomTestException">Thrown if the JSON object is not properly formatted.</exception> private Customer ParseJsonObject(Match match) { if (ReferenceEquals(match, null)) { throw new IntercomTestException("JSON text is in invalid format!"); } var degreeLongitude = ReadDegreeLongitude(match); if (!GeographicalLocation.IsDegreeLongitudeValid(degreeLongitude)) { throw new IntercomTestException(String.Format("Invalid geographical longitude read: {0}!", degreeLongitude)); } var degreeLatitude = ReadDegreeLatitude(match); if (!GeographicalLocation.IsDegreeLatitudeValid(degreeLatitude)) { throw new IntercomTestException(String.Format("Invalid geographical latitude read: {0}!", degreeLatitude)); } var userId = ReadUserId(match); var customerName = ReadCustomerName(match); var location = GeographicalLocation.FromDegrees(degreeLongitude, degreeLatitude); return(new Customer(userId, customerName, location)); }
public void TestInvalidDegreeLongitude() { double[] degreeLongitudes = { -181.0d, 181.0d, 190.0d, -190.0d, 270.0, -270.0d, 360.0d, 360.0d, 200.0d, -300.0d }; foreach (var degreeLongitude in degreeLongitudes) { Assert.IsFalse(GeographicalLocation.IsDegreeLongitudeValid(degreeLongitude), String.Format("Degree longitude {0} declared valid, even though it is invalid!", degreeLongitude)); } }
public void TestValidDegreeLongitude() { double[] degreeLongitudes = { -180.0d, 180.0d, 0.0d, 90.0d, -19.0d, -45.0d, 45.0d, 23.0d, 47.0d, -123.4343d, 159.0d, -20.43d }; foreach (var degreeLongitude in degreeLongitudes) { Assert.IsTrue(GeographicalLocation.IsDegreeLongitudeValid(degreeLongitude), String.Format("Degree longitude {0} declared invalid, even though it is valid!", degreeLongitude)); } }