Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public void ShapeReturnsExpectedValue()
        {
            var shape = _fixture.Create <Point>();
            var sut   = new PointShapeContent(shape);

            Assert.Equal(shape, sut.Shape);
        }
        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));
        }
Ejemplo n.º 4
0
        public ShapeRecordEnumeratorWithShorterStreamTests()
        {
            var fixture = new Fixture();

            fixture.CustomizeShapeRecordCount();
            fixture.CustomizeWordLength();

            var content = new PointShapeContent(new PointM(1.0, 1.0));
            var number  = RecordNumber.Initial;

            _record = content.RecordAs(number);
            var header = new ShapeFileHeader(
                ShapeFileHeader.Length.Plus(_record.Length.Times(2)),
                ShapeType.Point,
                fixture.Create <BoundingBox3D>());
            var stream = new MemoryStream();

            using (var writer = new BinaryWriter(stream, Encoding.UTF8, true))
            {
                header.Write(writer);
                _record.Write(writer);
                writer.Write(fixture.CreateMany <byte>(_record.Length.ToByteLength().ToInt32() / 2).ToArray());
                writer.Flush();
            }

            stream.Position = 100;

            _reader = new DisposableBinaryReader(stream, Encoding.UTF8, false);
            _sut    = header.CreateShapeRecordEnumerator(_reader);
        }
Ejemplo n.º 5
0
        public ShapeRecordEnumeratorOverStreamWithExpectedBytesTests()
        {
            var fixture = new Fixture();

            fixture.CustomizeShapeRecordCount();
            fixture.CustomizeWordLength();

            var content = new PointShapeContent(new Point(1.0, 1.0));
            var number  = RecordNumber.Initial;

            _record1 = content.RecordAs(number);
            _record2 = content.RecordAs(number.Next());
            var header = new ShapeFileHeader(
                ShapeFileHeader.Length.Plus(_record1.Length).Plus(_record2.Length),
                ShapeType.Point,
                fixture.Create <BoundingBox3D>());
            var stream = new MemoryStream();

            using (var writer = new BinaryWriter(stream, Encoding.UTF8, true))
            {
                header.Write(writer);
                _record1.Write(writer);
                _record2.Write(writer);
                writer.Flush();
            }

            stream.Position = 100;

            _reader = new DisposableBinaryReader(stream, Encoding.UTF8, false);
            _sut    = header.CreateShapeRecordEnumerator(_reader);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        private bool Equals(PointShapeContent left, PointShapeContent 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);
        }
Ejemplo n.º 9
0
        public void FromBytesWithEncodingHasExpectedResult()
        {
            var sut = new PointShapeContent(_fixture.Create <PointM>());

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

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

            Assert.Equal(sut.Shape, actual.Shape);
            Assert.Equal(sut.ShapeType, actual.ShapeType);
            Assert.Equal(sut.ContentLength, actual.ContentLength);
        }
Ejemplo n.º 10
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()));
        }
Ejemplo n.º 11
0
        public void ToBytesHasExpectedResult()
        {
            var sut = new PointShapeContent(_fixture.Create <PointM>());

            var result = sut.ToBytes();

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

                    Assert.Equal(stream.ToArray(), result);
                }
        }
Ejemplo n.º 12
0
        public void AnonymousHasExpectedResult()
        {
            var sut = new PointShapeContent(_fixture.Create <PointM>());

            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);
                }
        }
Ejemplo n.º 13
0
        public void ReadPointCanReadWrittenNullShape()
        {
            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 = PointShapeContent.ReadPoint(reader);

                    Assert.Equal(NullShapeContent.Instance, result);
                }
            }
        }
Ejemplo n.º 14
0
        public void ReadPointCanNotReadOtherShapeType(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>(
                        () => PointShapeContent.ReadPoint(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()));
        }
Ejemplo n.º 16
0
        public void ReadPointCanReadWrittenPointShape()
        {
            var sut = new PointShapeContent(_fixture.Create <Point>());

            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 = (PointShapeContent)PointShapeContent.ReadPoint(reader);

                    Assert.Equal(sut.Shape, result.Shape);
                    Assert.Equal(sut.ShapeType, result.ShapeType);
                    Assert.Equal(sut.ContentLength, result.ContentLength);
                }
            }
        }
Ejemplo n.º 17
0
        public void ShapeTypeReturnsExpectedValue()
        {
            var sut = new PointShapeContent(_fixture.Create <Point>());

            Assert.Equal(ShapeType.Point, sut.ShapeType);
        }
        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());
        }
Ejemplo n.º 19
0
        public void ContentLengthReturnsExpectedValue()
        {
            var sut = new PointShapeContent(_fixture.Create <Point>());

            Assert.Equal(new WordLength(10), sut.ContentLength);
        }
Ejemplo n.º 20
0
 public void ReadPointReaderCanNotBeNull()
 {
     new GuardClauseAssertion(_fixture)
     .Verify(Methods.Select(() => PointShapeContent.ReadPoint(null)));
 }