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));
        }
Esempio n. 2
0
        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.");
        }
Esempio n. 3
0
        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);
        }
        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 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);
        }
        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);
        }
Esempio n. 7
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.True(ex.GetType() == typeof(InvalidOperationException), "got the exception we threw");
            Assert.True(ex.StackTrace.Contains("DoWhenCall"), "Lost the original stack trace");

            AssertResetCalledLastOnCurrentAndDownstream();
        }
        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);
        }
Esempio n. 9
0
        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();
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        public void EmptyPoint()
        {
            GeographyPoint p = GeographyFactory.Point();

            Assert.True(p.IsEmpty);
            double coord;
            NotSupportedException ex = SpatialTestUtils.RunCatching <NotSupportedException>(() => coord = p.Latitude);

            Assert.NotNull(ex);
            Assert.Equal(Strings.Point_AccessCoordinateWhenEmpty, ex.Message);

            ex = SpatialTestUtils.RunCatching <NotSupportedException>(() => coord = p.Longitude);
            Assert.NotNull(ex);
            Assert.Equal(Strings.Point_AccessCoordinateWhenEmpty, ex.Message);

            Assert.False(p.Z.HasValue);
            Assert.False(p.M.HasValue);
        }
Esempio n. 12
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.NotNull(ex);
                }
                else
                {
                    t.Value(v);
                    v = setup();
                }
            }
        }
Esempio n. 13
0
        public void ValidateLongitude_Geography()
        {
            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.NotNull(ex);
            Assert.Equal(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.NotNull(ex);
            Assert.Equal(Strings.Validator_InvalidLongitudeCoordinate(15070), ex.Message);
        }