/// <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 TestInvalidDegreeLatitude() { double[] degreeLatitudes = { -91.0d, 91.0d, 190.0d, -190.0d, 270.0, -270.0d, 360.0d, 360.0d, 200.0d, -300.0d }; foreach (var degreeLatitude in degreeLatitudes) { Assert.IsFalse(GeographicalLocation.IsDegreeLatitudeValid(degreeLatitude), String.Format("Degree latitude {0} declared valid, even though it is invalid!", degreeLatitude)); } }
public void TestValidDegreeLatitude() { double[] degreeLatitudes = { -90.0d, 00.0d, 0.0d, -19.0d, -45.0d, 45.0d, 23.0d, 47.0d, -20.43d, 60.0d, -60.0d, 34.23d, -86.0d }; foreach (var degreeLatitude in degreeLatitudes) { Assert.IsTrue(GeographicalLocation.IsDegreeLatitudeValid(degreeLatitude), String.Format("Degree latitude {0} declared invalid, even though it is valid!", degreeLatitude)); } }