Exemple #1
0
        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);
        }
Exemple #2
0
        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));
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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"));
        }
Exemple #5
0
        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"));
        }
Exemple #6
0
        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"));
        }
Exemple #7
0
        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);
        }
Exemple #8
0
        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);
            }
        }
Exemple #9
0
        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"));
        }
Exemple #10
0
        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");
            }
        }
Exemple #11
0
        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"));
        }
Exemple #12
0
        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"));
        }
Exemple #13
0
        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);
     }
 }
Exemple #16
0
        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 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"));
        }
Exemple #19
0
        public void InvalidPointTest()
        {
            var pipeline = SpatialImplementation.CurrentImplementation.CreateBuilder();

            pipeline.GeographyPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeography);
            pipeline.GeographyPipeline.BeginGeography(SpatialType.Point);
            SpatialTestUtils.VerifyExceptionThrown <ArgumentException>(() => pipeline.GeographyPipeline.BeginFigure(new GeographyPosition(double.NaN, 122, null, null)), Strings.InvalidPointCoordinate(double.NaN, "latitude"));
            pipeline.GeographyPipeline.Reset();

            pipeline.GeographyPipeline.BeginGeography(SpatialType.Point);
            SpatialTestUtils.VerifyExceptionThrown <ArgumentException>(() => pipeline.GeographyPipeline.BeginFigure(new GeographyPosition(47, double.NegativeInfinity, null, null)), Strings.InvalidPointCoordinate(double.NegativeInfinity, "longitude"));
            pipeline.GeographyPipeline.Reset();

            pipeline.GeometryPipeline.SetCoordinateSystem(CoordinateSystem.DefaultGeometry);
            pipeline.GeometryPipeline.BeginGeometry(SpatialType.Point);
            SpatialTestUtils.VerifyExceptionThrown <ArgumentException>(() => pipeline.GeometryPipeline.BeginFigure(new GeometryPosition(double.PositiveInfinity, 122, null, null)), Strings.InvalidPointCoordinate(double.PositiveInfinity, "x"));
            pipeline.GeometryPipeline.Reset();

            pipeline.GeometryPipeline.BeginGeometry(SpatialType.Point);
            SpatialTestUtils.VerifyExceptionThrown <ArgumentException>(() => pipeline.GeometryPipeline.BeginFigure(new GeometryPosition(123, double.NaN, null, null)), Strings.InvalidPointCoordinate(double.NaN, "y"));
            pipeline.GeometryPipeline.Reset();
        }
Exemple #20
0
        public void ErrorOnNullDestinationInCtor()
        {
            Action act = () => new TrivialReader(null);

            SpatialTestUtils.VerifyExceptionThrown <ArgumentNullException>(act, "Value cannot be null.\r\nParameter name: destination");
        }