コード例 #1
0
        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));
        }
コード例 #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.");
        }
コード例 #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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #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();
        }
コード例 #8
0
        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);
        }
コード例 #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();
        }
コード例 #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);
        }
コード例 #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);
        }
コード例 #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();
                }
            }
        }
コード例 #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);
        }