Example #1
0
        public void CanReadWrite()
        {
            var sut = new ShapeIndexRecord(
                _fixture.Create <WordOffset>(),
                _fixture.Create <WordLength>());

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

                    Assert.Equal(sut.Offset, result.Offset);
                    Assert.Equal(sut.ContentLength, result.ContentLength);
                }
            }
        }
Example #2
0
        public void WriteManyHasExpectedResult()
        {
            var shapeType    = _fixture.Create <ShapeType>();
            var recordCount  = _fixture.Create <ShapeRecordCount>();
            var shapeRecords = GenerateManyRecords(shapeType, recordCount);
            var length       = shapeRecords.Aggregate(ShapeFileHeader.Length,
                                                      (result, current) => result.Plus(current.Length));
            var boundingBox = shapeRecords.Aggregate(BoundingBox3D.Empty,
                                                     (result, current) =>
            {
                if (current.Content is PointShapeContent pointContent)
                {
                    return(result.ExpandWith(BoundingBox3D.FromGeometry(pointContent.Shape)));
                }
                if (current.Content is PolyLineMShapeContent lineContent)
                {
                    return(result.ExpandWith(BoundingBox3D.FromGeometry(lineContent.Shape)));
                }
                return(result);
            });
            var expectedHeader  = new ShapeFileHeader(length, shapeType, boundingBox);
            var expectedRecords = new ShapeIndexRecord[shapeRecords.Length];
            var offset          = ShapeIndexRecord.InitialOffset;

            for (var index = 0; index < shapeRecords.Length; index++)
            {
                var shapeRecord = shapeRecords[index];
                expectedRecords[index] = shapeRecord.IndexAt(offset);
                offset = offset.Plus(shapeRecord.Length);
            }

            using (var stream = new MemoryStream())
            {
                using (var sut =
                           new ShapeIndexBinaryWriter(expectedHeader, new BinaryWriter(stream, Encoding.ASCII, true)))
                {
                    //Act
                    sut.Write(expectedRecords);
                }

                // Assert
                stream.Position = 0;

                using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
                {
                    var actualHeader  = ShapeFileHeader.Read(reader);
                    var actualRecords = new List <ShapeIndexRecord>();
                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        actualRecords.Add(ShapeIndexRecord.Read(reader));
                    }

                    Assert.Equal(expectedHeader, actualHeader);
                    Assert.Equal(expectedRecords, actualRecords, new ShapeIndexRecordEqualityComparer());
                }
            }
        }
Example #3
0
        public void Write(ShapeIndexRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }

            record.Write(Writer);
        }
        public void Write(ShapeIndexRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException(nameof(record));
            }
            if (_disposed)
            {
                throw new ObjectDisposedException(nameof(DbaseBinaryWriter));
            }

            record.Write(Writer);
        }
        public void WriteOneHasExpectedResult()
        {
            var shapeType   = _fixture.Create <ShapeType>();
            var recordCount = _fixture.Create <ShapeRecordCount>();
            var shapeRecord = GenerateOneRecord(shapeType);
            var length      = ShapeFileHeader.Length.Plus(shapeRecord.Length);
            var boundingBox = BoundingBox3D.Empty;

            if (shapeRecord.Content is PointShapeContent pointContent)
            {
                boundingBox = BoundingBox3D.FromGeometry(pointContent.Shape);
            }
            if (shapeRecord.Content is PolyLineMShapeContent lineContent)
            {
                boundingBox = BoundingBox3D.FromGeometry(lineContent.Shape);
            }
            if (shapeRecord.Content is PolygonShapeContent polygonContent)
            {
                boundingBox = BoundingBox3D.FromGeometry(polygonContent.Shape);
            }
            var expectedHeader = new ShapeFileHeader(length, shapeType, boundingBox).ForIndex(recordCount);
            var expectedRecord = shapeRecord.IndexAt(ShapeIndexRecord.InitialOffset);

            using (var stream = new MemoryStream())
            {
                using (var sut =
                           new ShapeIndexBinaryWriter(expectedHeader, new BinaryWriter(stream, Encoding.ASCII, true)))
                {
                    //Act
                    sut.Write(expectedRecord);
                }

                // Assert
                stream.Position = 0;

                using (var reader = new BinaryReader(stream, Encoding.ASCII, true))
                {
                    var actualHeader = ShapeFileHeader.Read(reader);
                    var actualRecord = ShapeIndexRecord.Read(reader);

                    Assert.Equal(expectedHeader, actualHeader);
                    Assert.Equal(expectedRecord, actualRecord, new ShapeIndexRecordEqualityComparer());
                }
            }
        }
        public void WriteManyOnDisposedInstanceHasExpectedResult()
        {
            var shapeType    = _fixture.Create <ShapeType>();
            var recordCount  = _fixture.Create <ShapeRecordCount>();
            var shapeRecords = GenerateManyRecords(shapeType, recordCount);
            var length       = shapeRecords.Aggregate(ShapeFileHeader.Length,
                                                      (result, current) => result.Plus(current.Length));
            var boundingBox = shapeRecords.Aggregate(BoundingBox3D.Empty,
                                                     (result, current) =>
            {
                if (current.Content is PointShapeContent pointContent)
                {
                    return(result.ExpandWith(BoundingBox3D.FromGeometry(pointContent.Shape)));
                }
                if (current.Content is PolyLineMShapeContent lineContent)
                {
                    return(result.ExpandWith(BoundingBox3D.FromGeometry(lineContent.Shape)));
                }
                return(result);
            });
            var expectedHeader  = new ShapeFileHeader(length, shapeType, boundingBox);
            var expectedRecords = new ShapeIndexRecord[shapeRecords.Length];
            var offset          = ShapeIndexRecord.InitialOffset;

            for (var index = 0; index < shapeRecords.Length; index++)
            {
                var shapeRecord = shapeRecords[index];
                expectedRecords[index] = shapeRecord.IndexAt(offset);
                offset = offset.Plus(shapeRecord.Length);
            }

            using (var stream = new MemoryStream())
            {
                using (var sut =
                           new ShapeIndexBinaryWriter(expectedHeader, new BinaryWriter(stream, Encoding.ASCII, true)))
                {
                    sut.Dispose();
                    Assert.Throws <ObjectDisposedException>(() => sut.Write(expectedRecords));
                }
            }
        }
Example #7
0
 public void ReaderCanNotBeNull()
 {
     new GuardClauseAssertion(_fixture)
     .Verify(Methods.Select(() => ShapeIndexRecord.Read(null)));
 }