public void WriteManyOnDisposedInstanceHasExpectedResult()
        {
            var shapeType       = _fixture.Create <ShapeType>();
            var recordCount     = _fixture.Create <ShapeRecordCount>();
            var expectedRecords = GenerateManyRecords(shapeType, recordCount);
            var length          = expectedRecords.Aggregate(ShapeFileHeader.Length,
                                                            (result, current) => result.Plus(current.Length));
            var boundingBox = expectedRecords.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);

            using (var stream = new MemoryStream())
            {
                using (var sut = new ShapeBinaryWriter(expectedHeader, new BinaryWriter(stream, Encoding.ASCII, true)))
                {
                    sut.Dispose();
                    Assert.Throws <ObjectDisposedException>(() => sut.Write(expectedRecords));
                }
            }
        }
        public void WriteOneOnDisposedInstanceHasExpectedResult()
        {
            var shapeType      = _fixture.Create <ShapeType>();
            var expectedRecord = GenerateOneRecord(shapeType);
            var length         = ShapeFileHeader.Length.Plus(expectedRecord.Length);
            var boundingBox    = BoundingBox3D.Empty;

            if (expectedRecord.Content is PointShapeContent pointContent)
            {
                boundingBox = BoundingBox3D.FromGeometry(pointContent.Shape);
            }
            if (expectedRecord.Content is PolyLineMShapeContent lineContent)
            {
                boundingBox = BoundingBox3D.FromGeometry(lineContent.Shape);
            }
            var expectedHeader = new ShapeFileHeader(length, shapeType, boundingBox);

            using (var stream = new MemoryStream())
            {
                using (var sut = new ShapeBinaryWriter(expectedHeader, new BinaryWriter(stream, Encoding.ASCII, true)))
                {
                    sut.Dispose();
                    Assert.Throws <ObjectDisposedException>(() => sut.Write(expectedRecord));
                }
            }
        }
Example #3
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());
                }
            }
        }
        public void FromPointGeometryReturnsExpectedResult()
        {
            var geometry = _fixture.Create <Point>();

            var result = BoundingBox3D.FromGeometry(geometry);

            Assert.Equal(new BoundingBox3D(
                             geometry.X,
                             geometry.Y,
                             geometry.X,
                             geometry.Y,
                             double.NaN,
                             double.NaN,
                             double.NaN,
                             double.NaN
                             ), result);
        }
        public void FromPolyLineMGeometryReturnsExpectedResult()
        {
            var geometry = _fixture.Create <PolyLineM>();

            var result = BoundingBox3D.FromGeometry(geometry);

            Assert.Equal(new BoundingBox3D(
                             geometry.Points.Min(point => point.X),
                             geometry.Points.Min(point => point.Y),
                             geometry.Points.Max(point => point.X),
                             geometry.Points.Max(point => point.Y),
                             double.NaN,
                             double.NaN,
                             geometry.MeasureRange.Min,
                             geometry.MeasureRange.Max
                             ), result);
        }
        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());
                }
            }
        }
Example #7
0
        public void FromGeometryReturnsExpectedResult(IGeometry geometry, BoundingBox3D expected)
        {
            var result = BoundingBox3D.FromGeometry(geometry);

            Assert.Equal(expected, result);
        }