예제 #1
0
        private ShapeRecord[] GenerateManyRecords(ShapeType typeOfShape, ShapeRecordCount count)
        {
            var records = new ShapeRecord[count.ToInt32()];
            var number  = RecordNumber.Initial;

            for (var index = 0; index < records.Length; index++)
            {
                ShapeContent content = null;
                switch (typeOfShape)
                {
                case ShapeType.Point:
                    content = new PointShapeContent(_fixture.Create <PointM>());
                    break;

                case ShapeType.PolyLineM:
                    content = new PolyLineMShapeContent(_fixture.Create <MultiLineString>());
                    break;

                //case ShapeType.NullShape:
                default:
                    content = NullShapeContent.Instance;
                    break;
                }

                records[index] = content.RecordAs(number);
                number         = number.Next();
            }

            return(records);
        }
예제 #2
0
        public static ShapeContent Read(BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var shapeType = reader.ReadInt32LittleEndian();

            if (!Enum.IsDefined(typeof(ShapeType), shapeType))
            {
                throw new ShapeRecordContentException("The Shape Type field does not contain a known type of shape.");
            }

            var content = NullShapeContent.Instance;

            switch ((ShapeType)shapeType)
            {
            case ShapeType.NullShape:
                break;

            case ShapeType.Point:
                content = PointShapeContent.ReadPointGeometry(reader);
                break;

            case ShapeType.PolyLineM:
                content = PolyLineMShapeContent.ReadPolyLineMGeometry(reader);
                break;

            default:
                throw new ShapeRecordContentException($"The Shape Type {shapeType} is currently not suppported.");
            }

            return(content);
        }
예제 #3
0
        public void ReadPolyLineMCanReadWrittenPolyLineMShape()
        {
            var shape = _fixture.Create <MultiLineString>();
            var sut   = new PolyLineMShapeContent(shape);

            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream, Encoding.ASCII, true))
                {
                    sut.Write(writer);
                    writer.Flush();
                }

                stream.Position = 0;

                using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
                {
                    var result = (PolyLineMShapeContent)PolyLineMShapeContent.ReadPolyLineM(reader);

                    Assert.Equal(sut.Shape, result.Shape);
                    Assert.Equal(sut.ShapeType, result.ShapeType);
                    Assert.Equal(sut.ContentLength, result.ContentLength);
                }
            }
        }
예제 #4
0
        internal static ShapeContent ReadFromRecord(BinaryReader reader, ShapeRecordHeader header)
        {
            var shapeType = reader.ReadInt32LittleEndian();

            if (!Enum.IsDefined(typeof(ShapeType), shapeType))
            {
                throw new ShapeRecordContentException("The Shape Type field does not contain a known type of shape.");
            }

            var content = NullShapeContent.Instance;

            switch ((ShapeType)shapeType)
            {
            case ShapeType.NullShape:
                break;

            case ShapeType.Point:
                content = PointShapeContent.ReadPointFromRecord(reader, header);
                break;

            case ShapeType.PolyLineM:
                content = PolyLineMShapeContent.ReadPolyLineMFromRecord(reader, header);
                break;

            default:
                throw new ShapeRecordContentException($"The Shape Type {shapeType} is currently not suppported.");
            }

            return(content);
        }
        private ShapeRecord GenerateOneRecord(ShapeType typeOfShape)
        {
            ShapeContent content = null;

            switch (typeOfShape)
            {
            case ShapeType.Point:
                content = new PointShapeContent(_fixture.Create <Point>());
                break;

            case ShapeType.PolyLineM:
                content = new PolyLineMShapeContent(_fixture.Create <PolyLineM>());
                break;

            case ShapeType.Polygon:
                content = new PolygonShapeContent(_fixture.Create <Polygon>());
                break;

            //case ShapeType.NullShape:
            default:
                content = NullShapeContent.Instance;
                break;
            }

            return(content.RecordAs(RecordNumber.Initial));
        }
예제 #6
0
        public void ShapeReturnsExpectedValue()
        {
            var shape = _fixture.Create <MultiLineString>();
            var sut   = new PolyLineMShapeContent(shape);

            Assert.Same(shape, sut.Shape);
        }
예제 #7
0
        private bool Equals(PolyLineMShapeContent left, PolyLineMShapeContent right)
        {
            var sameContentLength = left.ContentLength.Equals(right.ContentLength);
            var sameShapeType     = left.ShapeType.Equals(right.ShapeType);
            var sameShape         = left.Shape.Equals(right.Shape);

            return(sameContentLength && sameShapeType && sameShape);
        }
예제 #8
0
        public void FromBytesWithEncodingHasExpectedResult()
        {
            var sut = new PolyLineMShapeContent(_fixture.Create <MultiLineString>());

            var result = ShapeContent.FromBytes(sut.ToBytes(Encoding.UTF8), Encoding.UTF8);

            var actual = Assert.IsType <PolyLineMShapeContent>(result);

            Assert.Equal(sut.Shape, actual.Shape);
            Assert.Equal(sut.ShapeType, actual.ShapeType);
            Assert.Equal(sut.ContentLength, actual.ContentLength);
        }
예제 #9
0
        public ShapeRecordTests()
        {
            _fixture = new Fixture();
            _fixture.CustomizeRecordNumber();
            _fixture.CustomizeWordLength();
            _fixture.CustomizeWordOffset();
            _fixture.Customize <PointM>(customization =>
                                        customization.FromFactory(generator =>
                                                                  new PointM(
                                                                      _fixture.Create <double>(),
                                                                      _fixture.Create <double>(),
                                                                      _fixture.Create <double>(),
                                                                      _fixture.Create <double>()
                                                                      )
                                                                  ).OmitAutoProperties()
                                        );
            _fixture.Customize <ILineString>(customization =>
                                             customization.FromFactory(generator =>
                                                                       new LineString(
                                                                           new PointSequence(_fixture.CreateMany <PointM>()),
                                                                           GeometryConfiguration.GeometryFactory)
                                                                       ).OmitAutoProperties()
                                             );
            _fixture.Customize <MultiLineString>(customization =>
                                                 customization.FromFactory(generator =>
                                                                           new MultiLineString(_fixture.CreateMany <ILineString>(generator.Next(1, 10)).ToArray())
                                                                           ).OmitAutoProperties()
                                                 );
            _fixture.Customize <ShapeContent>(customization =>
                                              customization.FromFactory <int>(value =>
            {
                ShapeContent content = null;
                switch (value % 3)
                {
                case 0:
                    content = NullShapeContent.Instance;
                    break;

                case 1:
                    content = new PointShapeContent(_fixture.Create <PointM>());
                    break;

                case 2:
                    content = new PolyLineMShapeContent(_fixture.Create <MultiLineString>());
                    break;
                }

                return(content);
            }));
            _fixture.Register(() => new BinaryReader(new MemoryStream()));
            _fixture.Register(() => new BinaryWriter(new MemoryStream()));
        }
예제 #10
0
        public void ToBytesWithEncodingHasExpectedResult()
        {
            var sut = new PolyLineMShapeContent(_fixture.Create <MultiLineString>());

            var result = sut.ToBytes(Encoding.UTF8);

            using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream, Encoding.UTF8))
                {
                    sut.Write(writer);
                    writer.Flush();

                    Assert.Equal(stream.ToArray(), result);
                }
        }
예제 #11
0
        public void ContentLengthReturnsExpectedValue()
        {
            var shape          = _fixture.Create <MultiLineString>();
            var sut            = new PolyLineMShapeContent(shape);
            var numberOfParts  = shape.NumGeometries;
            var numberOfPoints = shape.NumPoints;
            var contentLength  = new WordLength(
                2 + 2 + 2                // shape type, number of parts, number of points,
                + 4 * 4                  // bounding box,
                + 2 * numberOfParts      // parts
                + 4 * 2 * numberOfPoints // points
                + 4 * 2                  // measure range
                + 4 * numberOfPoints     // measures
                );

            Assert.Equal(contentLength, sut.ContentLength);
        }
예제 #12
0
        public void AnonymousHasExpectedResult()
        {
            var sut = new PolyLineMShapeContent(_fixture.Create <MultiLineString>());

            var result = sut.Anonymous();

            using (var stream = new MemoryStream())
                using (var writer = new BinaryWriter(stream))
                {
                    sut.Write(writer);
                    writer.Flush();

                    Assert.Equal(sut.ShapeType, result.ShapeType);
                    Assert.Equal(sut.ContentLength, result.ContentLength);
                    Assert.Equal(
                        stream.ToArray(),
                        Assert.IsType <AnonymousShapeContent>(result).Content);
                }
        }
예제 #13
0
        public void ReadPolyLineMCanReadWrittenNullShape()
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream, Encoding.ASCII, true))
                {
                    NullShapeContent.Instance.Write(writer);
                    writer.Flush();
                }

                stream.Position = 0;

                using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
                {
                    var result = PolyLineMShapeContent.ReadPolyLineM(reader);

                    Assert.Equal(NullShapeContent.Instance, result);
                }
            }
        }
예제 #14
0
        public void ReadPolyLineMCanNotReadOtherShapeType(ShapeType other)
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream, Encoding.ASCII, true))
                {
                    writer.WriteInt32LittleEndian((int)other);

                    writer.Flush();
                }

                stream.Position = 0;

                using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
                {
                    Assert.Throws <ShapeRecordContentException>(
                        () => PolyLineMShapeContent.ReadPolyLineM(reader)
                        );
                }
            }
        }
        public ShapeRecordTests()
        {
            _fixture = new Fixture();
            _fixture.CustomizeRecordNumber();
            _fixture.CustomizeWordLength();
            _fixture.CustomizeWordOffset();
            _fixture.CustomizePoint();
            _fixture.CustomizePolygon();
            _fixture.CustomizePolyLineM();
            _fixture.Customize <ShapeContent>(customization =>
                                              customization.FromFactory <int>(value =>
            {
                ShapeContent content = null;
                switch (value % 4)
                {
                case 0:
                    content = NullShapeContent.Instance;
                    break;

                case 1:
                    content = new PointShapeContent(_fixture.Create <Point>());
                    break;

                case 2:
                    content = new PolyLineMShapeContent(_fixture.Create <PolyLineM>());
                    break;

                case 3:
                    content = new PolygonShapeContent(_fixture.Create <Polygon>());
                    break;
                }

                return(content);
            }));
            _fixture.Register(() => new BinaryReader(new MemoryStream()));
            _fixture.Register(() => new BinaryWriter(new MemoryStream()));
        }
예제 #16
0
 public void ReadPolyLineMReaderCanNotBeNull()
 {
     new GuardClauseAssertion(_fixture)
     .Verify(Methods.Select(() => PolyLineMShapeContent.ReadPolyLineM(null)));
 }
        public ShapeBinaryWriterTests()
        {
            _fixture = new Fixture();
            _fixture.CustomizeShapeRecordCount(100);
            _fixture.CustomizeRecordNumber();
            _fixture.CustomizeWordLength();
            _fixture.CustomizeWordOffset();
            _fixture.Customize <ShapeType>(customization =>
                                           customization.FromFactory(generator =>
            {
                var result = ShapeType.NullShape;
                switch (generator.Next() % 4)
                {
                //case 0:
                case 1:
                    result = ShapeType.Point;
                    break;

                case 2:
                    result = ShapeType.PolyLineM;
                    break;

                case 3:
                    result = ShapeType.Polygon;
                    break;
                }

                return(result);
            }
                                                                     ).OmitAutoProperties()
                                           );
            _fixture.CustomizePoint();
            _fixture.CustomizePolygon();
            _fixture.CustomizePolyLineM();
            _fixture.Customize <ShapeContent>(customization =>
                                              customization.FromFactory(generator =>
            {
                ShapeContent content = null;
                switch (generator.Next() % 4)
                {
                case 0:
                    content = NullShapeContent.Instance;
                    break;

                case 1:
                    content = new PointShapeContent(_fixture.Create <Point>());
                    break;

                case 2:
                    content = new PolyLineMShapeContent(_fixture.Create <PolyLineM>());
                    break;

                case 3:
                    content = new PolygonShapeContent(_fixture.Create <Polygon>());
                    break;
                }

                return(content);
            }));
            _fixture.Register <Stream>(() => new MemoryStream());
        }
예제 #18
0
        public void ShapeTypeReturnsExpectedValue()
        {
            var sut = new PolyLineMShapeContent(_fixture.Create <MultiLineString>());

            Assert.Equal(ShapeType.PolyLineM, sut.ShapeType);
        }