public void TestUsageOfValidator() { Action action = () => GeographyFactory.Polygon().Ring(10, 10).Build(); var exception = SpatialTestUtils.RunCatching <FormatException>(action); Assert.IsNotNull(exception, "didn't get an exception the validator is not in place."); }
public void BuilderAccessBeforeEnd() { Geography g; this.builder.BeginGeography(SpatialType.Collection); // c1 var ex = SpatialTestUtils.RunCatching <InvalidOperationException>(() => g = this.builder.ConstructedGeography); Assert.IsNotNull(ex); Assert.AreEqual(ex.Message, Strings.SpatialBuilder_CannotCreateBeforeDrawn); this.builder.BeginGeography(SpatialType.Collection); // c2 this.builder.BeginGeography(SpatialType.Point); this.builder.BeginFigure(new GeographyPosition(10, 10, 10, 10)); this.builder.EndFigure(); this.builder.EndGeography(); ex = SpatialTestUtils.RunCatching <InvalidOperationException>(() => g = this.builder.ConstructedGeography); Assert.IsNotNull(ex); Assert.AreEqual(ex.Message, Strings.SpatialBuilder_CannotCreateBeforeDrawn); this.builder.EndGeography(); // c2 this.builder.BeginGeography(SpatialType.Point); this.builder.EndGeography(); ex = SpatialTestUtils.RunCatching <InvalidOperationException>(() => g = this.builder.ConstructedGeography); Assert.IsNotNull(ex); Assert.AreEqual(ex.Message, Strings.SpatialBuilder_CannotCreateBeforeDrawn); this.builder.EndGeography(); this.builder.ConstructedGeography.VerifyAsCollection( (c2) => c2.VerifyAsCollection((p) => p.VerifyAsPoint(new PositionData(10, 10, 10, 10))), (p) => p.VerifyAsPoint(null)); }
public void ValidateNoFullGlobe() { GeometryPipeline v = new SpatialValidatorImplementation(); var ex = SpatialTestUtils.RunCatching <FormatException>(() => v.BeginGeometry(SpatialType.FullGlobe)); Assert.IsNotNull(ex); Assert.AreEqual(Strings.Validator_InvalidType(SpatialType.FullGlobe), ex.Message); }
private void ExceptionCallsResetForForwardCallsWithoutArgs(TracingPipe pipe) { pipe.CallAdded = (t, c) => this.DoWhenCall(endFigure, c, () => { throw new InvalidOperationException(); }); var coordinateSystem = CoordinateSystem.DefaultGeography; Exception ex = SpatialTestUtils.RunCatching(() => this.testSubject.GeographyPipeline.EndFigure()); Assert.IsInstanceOfType(ex, typeof(InvalidOperationException), "got the exception we threw"); StringAssert.Contains(ex.StackTrace, "DoWhenCall", "Lost the original stack trace"); AssertResetCalledLastOnCurrentAndDownstream(); }
public void ReadUnexpectedToken() { Action <string> readGeography = (s) => this.d4Formatter.Read <Geography>(new StringReader(s), new SpatialToPositionPipeline()); Exception ex = SpatialTestUtils.RunCatching <ParseErrorException>(() => readGeography("POINT(10,20)")); Assert.IsNotNull(ex); Assert.AreEqual(Strings.WellKnownText_UnexpectedToken("Number", "", "Type:[7] Text:[,]"), ex.Message); }
public void ReadEmptyString() { Action <string> readGeography = (s) => this.d4Formatter.Read <Geography>(new StringReader(s), new SpatialToPositionPipeline()); Exception ex = SpatialTestUtils.RunCatching <ParseErrorException>(() => readGeography("")); Assert.IsNotNull(ex); Assert.AreEqual(Strings.WellKnownText_UnknownTaggedText(""), ex.Message); }
public void ValidatePolygonRing_LessThanFour() { GeometryPipeline v = new SpatialValidatorImplementation(); v.SetCoordinateSystem(NonDefaultGeometricCoords); v.BeginGeometry(SpatialType.Polygon); v.BeginFigure(new GeometryPosition(10, 20, 30, 40)); v.LineTo(new GeometryPosition(20, 30, 40, 50)); v.LineTo(new GeometryPosition(20, 30, 40, 50)); var ex = SpatialTestUtils.RunCatching <FormatException>(v.EndFigure); Assert.IsNotNull(ex); Assert.AreEqual(Strings.Validator_InvalidPolygonPoints, ex.Message); }
private void TestErrorOn3DValueIn2DOnlyMode(string wktValue) { Action <string> readGeography = (s) => this.d2Formatter.Read <Geography>(new StringReader(s), new SpatialToPositionPipeline()); // validate that it is valid in 4d mode this.d4Formatter.Read <Geography>(new StringReader(wktValue), new SpatialToPositionPipeline()); Exception ex = SpatialTestUtils.RunCatching <ParseErrorException>(() => readGeography(wktValue)); Assert.IsNotNull(ex); Assert.AreEqual(Strings.WellKnownText_TooManyDimensions, ex.Message); }
public void EmptyPoint() { GeographyPoint p = GeographyFactory.Point(); Assert.IsTrue(p.IsEmpty); double coord; NotSupportedException ex = SpatialTestUtils.RunCatching <NotSupportedException>(() => coord = p.Latitude); Assert.IsNotNull(ex); Assert.AreEqual(Strings.Point_AccessCoordinateWhenEmpty, ex.Message); ex = SpatialTestUtils.RunCatching <NotSupportedException>(() => coord = p.Longitude); Assert.IsNotNull(ex); Assert.AreEqual(Strings.Point_AccessCoordinateWhenEmpty, ex.Message); Assert.IsFalse(p.Z.HasValue); Assert.IsFalse(p.M.HasValue); }
private static void RunStateValidatorTest(Func <TypeWashedPipeline> setup, params String[] validTransitions) { var v = setup(); foreach (var t in Transitions) { if (!validTransitions.Contains(t.Key)) { var ex = SpatialTestUtils.RunCatching <FormatException>(() => t.Value(v)); Assert.IsNotNull(ex); } else { t.Value(v); v = setup(); } } }
public void ValidateLongitude() { GeographyPipeline v = new SpatialValidatorImplementation(); v.SetCoordinateSystem(NonDefaultGeographicCoords); v.BeginGeography(SpatialType.Point); var ex = SpatialTestUtils.RunCatching <FormatException>(() => v.BeginFigure(new GeographyPosition(0, -15070, 0, 0))); Assert.IsNotNull(ex); Assert.AreEqual(Strings.Validator_InvalidLongitudeCoordinate(-15070), ex.Message); v.Reset(); v.SetCoordinateSystem(NonDefaultGeographicCoords); v.BeginGeography(SpatialType.Point); ex = SpatialTestUtils.RunCatching <FormatException>(() => v.BeginFigure(new GeographyPosition(0, 15070, 0, 0))); Assert.IsNotNull(ex); Assert.AreEqual(Strings.Validator_InvalidLongitudeCoordinate(15070), ex.Message); }