Esempio n. 1
0
        public void ReadAnonymousCanReadWrittenPolyLineMShape()
        {
            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 = (AnonymousShapeContent)ShapeContent.ReadAnonymous(reader);

                    Assert.Equal(stream.ToArray(), result.Content);
                    Assert.Equal(sut.ShapeType, result.ShapeType);
                    Assert.Equal(sut.ContentLength, result.ContentLength);
                }
            }
        }
Esempio n. 2
0
        public void ReadCanReadWrittenPolygonShape()
        {
            var shape = _fixture.Create <Polygon>();
            var sut   = new PolygonShapeContent(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 = (PolygonShapeContent)ShapeContent.Read(reader);

                    Assert.Equal(sut.Shape, result.Shape);
                    Assert.Equal(sut.ShapeType, result.ShapeType);
                    Assert.Equal(sut.ContentLength, result.ContentLength);
                }
            }
        }
Esempio n. 3
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);
        }
        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));
        }
Esempio n. 5
0
        public void ReadCanReadWrittenAnonymousShape()
        {
            var sut = _fixture.Create <AnonymousShapeContent>();

            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 = ShapeContent.Read(reader);
                    Assert.Equal(sut.ShapeType, result.ShapeType);
                    Assert.Equal(sut.ContentLength, result.ContentLength);
                    switch (result)
                    {
                    case PointShapeContent instance:
                        Assert.Equal(sut.Content, instance.ToBytes(Encoding.ASCII));
                        break;

                    case PolyLineMShapeContent instance:
                        Assert.Equal(sut.Content, instance.ToBytes(Encoding.ASCII));
                        break;
                    }
                }
            }
        }
        public void FromBytesHasExpectedResult()
        {
            var content = NullShapeContent.Instance;

            var result = ShapeContent.FromBytes(content.ToBytes());

            Assert.Same(content, result);
        }
        public void FromBytesWithEncodingHasExpectedResult()
        {
            var content = NullShapeContent.Instance;

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

            Assert.Same(content, result);
        }
Esempio n. 8
0
        public static ShapeRecord Read(BinaryReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            var header  = ShapeRecordHeader.Read(reader);
            var content = ShapeContent.ReadFromRecord(reader, header);

            return(new ShapeRecord(header, content));
        }
Esempio n. 9
0
        public void FromBytesHasExpectedResult()
        {
            var sut = new PolyLineMShapeContent(_fixture.Create <MultiLineString>());

            var result = ShapeContent.FromBytes(sut.ToBytes());

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

            Assert.Equal(sut.Shape, actual.Shape);
            Assert.Equal(sut.ShapeType, actual.ShapeType);
            Assert.Equal(sut.ContentLength, actual.ContentLength);
        }
Esempio n. 10
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);
        }
Esempio n. 11
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()));
        }
        public void ReadCanNotReadOtherShapeType(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>(
                        () => ShapeContent.Read(reader)
                        );
                }
            }
        }
        public void ReadCanReadWriteNullShape()
        {
            var sut = NullShapeContent.Instance;

            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 = (NullShapeContent)ShapeContent.Read(reader);

                    Assert.Equal(sut.ShapeType, result.ShapeType);
                    Assert.Equal(sut.ContentLength, result.ContentLength);
                }
            }
        }
        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()));
        }
Esempio n. 15
0
 public ShapeRecord(ShapeRecordHeader header, ShapeContent content)
 {
     Header  = header ?? throw new ArgumentNullException(nameof(header));
     Content = content ?? throw new ArgumentNullException(nameof(content));
 }
        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());
        }
 public void ReadReaderCanNotBeNull()
 {
     new GuardClauseAssertion(_fixture)
     .Verify(Methods.Select(() => ShapeContent.Read(null)));
 }