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.NotNull(ex); Assert.Equal(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.NotNull(ex); Assert.Equal(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.NotNull(ex); Assert.Equal(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 Verify(CallSequenceLoggingPipeline expectedPipeline) { List <KeyValuePair <PipelineMethod, object> > expectedCalls = expectedPipeline.methodCalls; List <KeyValuePair <PipelineMethod, object> > actualCalls = this.methodCalls; SpatialTestUtils.AssertEqualContents(expectedCalls, actualCalls); }
public void TestUsageOfValidator() { Action action = () => GeographyFactory.Polygon().Ring(10, 10).Build(); var exception = SpatialTestUtils.RunCatching <FormatException>(action); Assert.True(exception != null, "didn't get an exception the validator is not in place."); }
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 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); }
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_Geometry() { GeometryPipeline v = new SpatialValidatorImplementation(); var ex = SpatialTestUtils.RunCatching <FormatException>(() => v.BeginGeometry(SpatialType.FullGlobe)); Assert.NotNull(ex); Assert.Equal(Strings.Validator_InvalidType(SpatialType.FullGlobe), ex.Message); }
private void VerifyBuiltOnly(params Geography[] shapes) { SpatialTestUtils.AssertEqualContents(this.constructedInstances, shapes); foreach (var instance in constructedInstances) { Assert.Same(this.creator, instance.Creator); } }
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 ErrorOnNullDestinationInCtor() { Action act = () => new TrivialReader(null); #if NETCOREAPP3_1 SpatialTestUtils.VerifyExceptionThrown <ArgumentNullException>(act, "Value cannot be null. (Parameter 'destination')"); #else SpatialTestUtils.VerifyExceptionThrown <ArgumentNullException>(act, "Value cannot be null.\r\nParameter name: destination"); #endif }
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 ReadUnexpectedToken() { Action <string> readGeography = (s) => this.d4Formatter.Read <Geography>(new StringReader(s), new SpatialToPositionPipeline()); Exception ex = SpatialTestUtils.RunCatching <ParseErrorException>(() => readGeography("POINT(10,20)")); Assert.NotNull(ex); Assert.Equal(Strings.WellKnownText_UnexpectedToken("Number", "", "Type:[7] Text:[,]"), ex.Message); }
public void ReadUnexpectedCharacter() { Action <string> readGeography = (s) => this.d4Formatter.Read <Geography>(new StringReader(s), new SpatialToPositionPipeline()); Exception ex = SpatialTestUtils.RunCatching <ParseErrorException>(() => readGeography("POINT:10 20")); Assert.NotNull(ex); Assert.Equal(Strings.WellKnownText_UnexpectedCharacter(":"), 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.NotNull(ex); Assert.Equal(Strings.WellKnownText_UnknownTaggedText(""), 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.True(ex.GetType() == typeof(InvalidOperationException), "got the exception we threw"); Assert.True(ex.StackTrace.Contains("DoWhenCall"), "Lost the original stack trace"); AssertResetCalledLastOnCurrentAndDownstream(); }
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 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 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 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.Equal(CoordinateSystem.Geography(1234), target.CoordinateSystem); }
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.NotNull(ex); Assert.Equal(Strings.WellKnownText_TooManyDimensions, ex.Message); }
private void ExceptionCallsResetForForwardCallsWithArgs(TracingPipe pipe) { pipe.CallAdded = (t, c) => this.DoWhenNotCall(resetCall, c, () => { throw new InvalidOperationException(); }); var coordinateSystem = CoordinateSystem.DefaultGeography; Exception ex = SpatialTestUtils.RunCatching(() => this.testSubject.GeographyPipeline.SetCoordinateSystem(coordinateSystem)); Assert.True(ex.GetType() == typeof(InvalidOperationException), "got the exception we threw"); #if !NETCOREAPP1_1 && !NETCOREAPP2_1 && !NETCOREAPP3_1 // .NET Core does not appear to generate this stack trace Assert.True(ex.StackTrace.Contains("DoWhenNotCall"), "Lost the original stack trace"); #endif AssertResetCalledLastOnCurrentAndDownstream(); }
public void ValidatePolygonRing_LessThanFour_Geography() { GeographyPipeline v = new SpatialValidatorImplementation(); v.SetCoordinateSystem(NonDefaultGeographicCoords); v.BeginGeography(SpatialType.Polygon); v.BeginFigure(new GeographyPosition(10, 20, 30, 40)); v.LineTo(new GeographyPosition(20, 30, 40, 50)); v.LineTo(new GeographyPosition(20, 30, 40, 50)); var ex = SpatialTestUtils.RunCatching <FormatException>(v.EndFigure); Assert.NotNull(ex); Assert.Equal(Strings.Validator_InvalidPolygonPoints, ex.Message); }