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."); }
private static void GeometryGmlWriterTest(Action <GeometryPipeline> pipelineCalls, params string[] expectedXPaths) { var ms = new MemoryStream(); var w = XmlWriter.Create(ms, new XmlWriterSettings { Indent = false }); DrawBoth gw = new GmlWriter(w); gw.GeometryPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeometry); pipelineCalls(gw.GeometryPipeline); w.Flush(); w.Close(); // use XElement to validate basic XML integrity ms.Seek(0, SeekOrigin.Begin); XmlNameTable nt = new NameTable(); nt.Add(GmlConstants.GmlPrefix); // XPath or string contains var xnm = new XmlNamespaceManager(nt); xnm.AddNamespace(GmlConstants.GmlPrefix, GmlConstants.GmlNamespace); var xDoc = new XmlDocument(nt); xDoc.Load(ms); var nav = xDoc.CreateNavigator(); SpatialTestUtils.VerifyXPaths(nav, xnm, "/node()[@gml:srsName = '" + GmlConstants.SrsPrefix + CoordinateSystem.DefaultGeometry.EpsgId + "']"); SpatialTestUtils.VerifyXPaths(nav, xnm, expectedXPaths); }
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 ReadGmlPosListSingleNumber() { var reader = XElement.Parse("<gml:LineString xmlns:gml='http://www.opengis.net/gml'><gml:posList>10</gml:posList></gml:LineString>").CreateReader(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_PosListNeedsEvenCount); }
private void VerifyBuiltOnly(params Geography[] shapes) { SpatialTestUtils.AssertEqualContents(this.constructedInstances, shapes); foreach (var instance in constructedInstances) { Assert.AreSame(this.creator, instance.Creator); } }
public void TestChainTo() { var pipeline = SpatialImplementation.CurrentImplementation.CreateBuilder(); var pipeline2 = SpatialImplementation.CurrentImplementation.CreateBuilder(); var e = new NotImplementedException(); SpatialTestUtils.VerifyExceptionThrown <NotImplementedException>(() => pipeline.ChainTo(pipeline2), e.Message); }
public void ReadGmlInvalidSrsName() { var reader = XElement.Parse(@"<gml:Polygon xmlns:gml='http://www.opengis.net/gml' srsName='test'></gml:Polygon>").CreateReader(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_InvalidSrsName(GmlConstants.SrsPrefix)); }
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); }
public void ReadGmlUnexpectedSrsName() { // changing the srsName inside a tag is invalid var reader = XElement.Parse(@"<gml:Point xmlns:gml='http://www.opengis.net/gml'><pos srsName='foo' /></gml:Point>").CreateReader(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_InvalidAttribute("srsName", "pos")); }
public void ReadGmlInvalidAttribute() { // invalid attributes on inner elements var reader = XElement.Parse(@"<gml:Point xmlns:gml='http://www.opengis.net/gml'><pos srsDimension='3' /></gml:Point>").CreateReader(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_InvalidAttribute("srsDimension", "pos")); }
public void ReadGmlInvalidTopLevelAttribute() { // invalid attributes on top level elements var reader = XElement.Parse(@"<gml:Polygon xmlns:gml='http://www.opengis.net/gml' foo='bar'></gml:Polygon>").CreateReader(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_InvalidAttribute("foo", "gml:Polygon")); }
public void ReadGmlUnexpectedSrsName_Whitespace() { // Whitespace between tags should not affect how attributes are handled var reader = XElement.Parse(@"<gml:Point xmlns:gml='http://www.opengis.net/gml'> <pos srsName='foo' /></gml:Point>").CreateReader(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_InvalidAttribute("srsName", "pos")); }
public void ReadXmlNotOnElement() { var reader = XmlReader.Create(new StringReader("<gml:Point xmlns:gml='http://www.opengis.net/gml'><gml:pos>1.0 1.0</gml:pos></gml:Point>")); reader.ReadStartElement(); reader.ReadStartElement(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_ExpectReaderAtElement); }
public void SpatialOperationsThrowNotImplemented() { var operations = new BaseSpatialOperations(); var message = new NotImplementedException().Message; foreach (var method in typeof(SpatialOperations).GetMethods(BindingFlags.Instance | BindingFlags.Public).Where(m => m.DeclaringType != typeof(object))) { SpatialTestUtils.VerifyExceptionThrown <NotImplementedException>(() => this.InvokeOperation(operations, method), message); } }
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); }
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 ErrorOnNullInputToReadMethods() { var reader = new TrivialReader(new CallSequenceLoggingPipeline()); Action[] acts = { () => reader.ReadGeography(null), () => reader.ReadGeometry(null) }; foreach (var act in acts) { SpatialTestUtils.VerifyExceptionThrown <ArgumentNullException>(act, "Value cannot be null.\r\nParameter name: input"); } }
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 ReadInvalidShape() { var reader = XElement.Parse(@"<gml:Surface xmlns:gml='http://www.opengis.net/gml'> <gml:posList> 3 7 4 5 </gml:posList> </gml:Surface>").CreateReader(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_InvalidSpatialType("Surface")); }
public void ReadUnexpectedElement() { var reader = XElement.Parse(@"<gml:LineString xmlns:gml='http://www.opengis.net/gml'> <gml:posList> 3 7 4 5 <MyWeirdElement/> </gml:posList> </gml:LineString>").CreateReader(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_UnexpectedElement("MyWeirdElement")); }
public void ReadGmlEmptyLinearRing() { var reader = XElement.Parse(@"<gml:Polygon xmlns:gml='http://www.opengis.net/gml'> <gml:exterior> <gml:LinearRing></gml:LinearRing> </gml:exterior> </gml:Polygon>").CreateReader(); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>( () => new GmlReader(new SpatialToPositionPipeline()).ReadGeography(reader), Strings.GmlReader_EmptyRingsNotAllowed); }
public void InvalidPointTest() { foreach (var v in validators) { var validator = v(); validator.SetCoordinateSystem(NonDefaultEpsgId); validator.BeginGeo(SpatialType.Point); SpatialTestUtils.VerifyExceptionThrown <FormatException>( () => validator.BeginFigure(10, 20, double.NaN, 40), Strings.Validator_InvalidPointCoordinate(10, 20, double.NaN, 40)); } }
public void CoordinateSystemReset() { foreach (var v in validators) { var validator = v(); validator.SetCoordinateSystem(NonDefaultEpsgId); validator.BeginGeo(SpatialType.MultiPoint); SpatialTestUtils.VerifyExceptionThrown <FormatException>( () => validator.SetCoordinateSystem(CoordinateSystem.DefaultGeography.EpsgId), Strings.Validator_SridMismatch); } }
public void ResetReader() { var invalidReader = XElement.Parse("<gml:Point xmlns:gml='http://www.opengis.net/gml' gml:srsName=\"http://www.opengis.net/def/crs/EPSG/0/5555\"><gml:pos>1</gml:pos></gml:Point>").CreateReader(); var validReader = XElement.Parse("<gml:Point xmlns:gml='http://www.opengis.net/gml' gml:srsName=\"http://www.opengis.net/def/crs/EPSG/0/1234\"><gml:pos>2 2</gml:pos></gml:Point>").CreateReader(); var target = new SpatialToPositionPipeline(); var gmlReader = new GmlReader(target); SpatialTestUtils.VerifyExceptionThrown <ParseErrorException>(() => gmlReader.ReadGeography(invalidReader), Strings.GmlReader_PosNeedTwoNumbers); gmlReader.Reset(); gmlReader.ReadGeography(validReader); Assert.AreEqual(CoordinateSystem.Geography(1234), target.CoordinateSystem); }
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 MaxGeometryDepth() { foreach (var v in validators) { var validator = v(); validator.SetCoordinateSystem(NonDefaultEpsgId); for (int i = 0; i < 28; i++) { validator.BeginGeo(SpatialType.Collection); } SpatialTestUtils.VerifyExceptionThrown <FormatException>( () => validator.BeginGeo(SpatialType.Point), Strings.Validator_NestingOverflow(28)); } }
public void UnexpectedGeometry() { var validator1 = new SpatialValidatorImplementation(); validator1.GeographyPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeography); validator1.GeographyPipeline.BeginGeography(SpatialType.Point); SpatialTestUtils.VerifyExceptionThrown <FormatException>( () => validator1.GeometryPipeline.BeginGeometry(SpatialType.Point), Strings.Validator_UnexpectedCall("SetCoordinateSystem", "BeginPoint")); var validator2 = new SpatialValidatorImplementation(); validator2.GeographyPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeography); validator2.GeographyPipeline.BeginGeography(SpatialType.Point); validator2.GeographyPipeline.BeginFigure(new GeographyPosition(45, 180, null, null)); validator2.GeographyPipeline.EndFigure(); SpatialTestUtils.VerifyExceptionThrown <FormatException>( () => validator2.GeometryPipeline.EndGeometry(), Strings.Validator_UnexpectedCall("SetCoordinateSystem", "End")); var validator3 = new SpatialValidatorImplementation(); validator3.GeometryPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeometry); validator3.GeometryPipeline.BeginGeometry(SpatialType.Point); SpatialTestUtils.VerifyExceptionThrown <FormatException>( () => validator3.GeographyPipeline.BeginGeography(SpatialType.Point), Strings.Validator_UnexpectedCall("SetCoordinateSystem", "BeginPoint")); var validator4 = new SpatialValidatorImplementation(); validator4.GeometryPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeometry); validator4.GeometryPipeline.BeginGeometry(SpatialType.Point); validator4.GeometryPipeline.BeginFigure(new GeometryPosition(45, 180, null, null)); validator4.GeometryPipeline.EndFigure(); SpatialTestUtils.VerifyExceptionThrown <FormatException>( () => validator4.GeographyPipeline.EndGeography(), Strings.Validator_UnexpectedCall("SetCoordinateSystem", "End")); var validator5 = new SpatialValidatorImplementation(); validator5.GeographyPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeography); validator5.GeographyPipeline.BeginGeography(SpatialType.Point); SpatialTestUtils.VerifyExceptionThrown <FormatException>( () => validator5.GeometryPipeline.BeginFigure(new GeometryPosition(333, 3333333, 333, 333)), Strings.Validator_UnexpectedCall("SetCoordinateSystem", "BeginFigure")); }
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 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); }