public ShapeFileHeader(WordLength fileWordLength, ShapeType shapeType, BoundingBox3D boundingBox)
 {
     FileLength  = fileWordLength;
     ShapeType   = shapeType;
     BoundingBox = boundingBox;
 }
        public void ExpandWithReturnsExpectedResult(BoundingBox3D sut, BoundingBox3D other, BoundingBox3D expected)
        {
            var result = sut.ExpandWith(other);

            Assert.Equal(expected, result);
        }
        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)));
                }
                if (current.Content is PolygonShapeContent polygonShapeContent)
                {
                    return(result.ExpandWith(BoundingBox3D.FromGeometry(polygonShapeContent.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());
                }
            }
        }