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.");
        }
示例#2
0
        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));
        }
示例#4
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);
        }
 private void VerifyBuiltOnly(params Geography[] shapes)
 {
     SpatialTestUtils.AssertEqualContents(this.constructedInstances, shapes);
     foreach (var instance in constructedInstances)
     {
         Assert.AreSame(this.creator, instance.Creator);
     }
 }
示例#6
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);
        }
示例#7
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));
        }
        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);
        }
示例#9
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"));
        }
示例#10
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"));
        }
示例#11
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"));
        }
示例#12
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"));
        }
示例#13
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);
        }
示例#14
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);
            }
        }
        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);
        }
示例#16
0
        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();
        }
示例#17
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");
            }
        }
        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);
        }
示例#19
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"));
        }
示例#20
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"));
        }
示例#21
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);
        }
示例#22
0
 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));
     }
 }
示例#23
0
 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);
     }
 }
示例#24
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 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);
        }
示例#27
0
        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));
            }
        }
示例#28
0
        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"));
        }
示例#29
0
        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();
                }
            }
        }
示例#30
0
        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);
        }