コード例 #1
0
        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));
                }
            }
        }
コード例 #2
0
        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));
                }
            }
        }
コード例 #3
0
        public void PropertiesReturnExpectedValues()
        {
            var header = _fixture.Create <ShapeFileHeader>();

            using (var writer = new BinaryWriter(new MemoryStream()))
                using (var sut = new ShapeBinaryWriter(header, writer))
                {
                    Assert.Same(header, sut.Header);
                    Assert.Same(writer, sut.Writer);
                }
        }
コード例 #4
0
        public void WriteManyHasExpectedResult()
        {
            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)));
                }
                if (current.Content is PolygonShapeContent polygonContent)
                {
                    return(result.ExpandWith(BoundingBox3D.FromGeometry(polygonContent.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)))
                {
                    //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 <ShapeRecord>();
                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        actualRecords.Add(ShapeRecord.Read(reader));
                    }

                    Assert.Equal(expectedHeader, actualHeader);
                    Assert.Equal(expectedRecords, actualRecords, new ShapeRecordEqualityComparer());
                }
            }
        }
コード例 #5
0
        public void WriteOneRecordCanNotBeNull()
        {
            var expectedHeader = new ShapeFileHeader(
                ShapeFileHeader.Length,
                _fixture.Create <ShapeType>(),
                BoundingBox3D.Empty
                );

            using (var stream = new MemoryStream())
            {
                using (var sut = new ShapeBinaryWriter(expectedHeader, new BinaryWriter(stream, Encoding.ASCII, true)))
                {
                    Assert.Throws <ArgumentNullException>(() => sut.Write((ShapeRecord)null));
                }
            }
        }
コード例 #6
0
        public void DisposeHasExpectedResult()
        {
            var expectedHeader = new ShapeFileHeader(
                ShapeFileHeader.Length,
                _fixture.Create <ShapeType>(),
                BoundingBox3D.Empty
                );

            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream, Encoding.ASCII, false))
                    using (var sut = new ShapeBinaryWriter(expectedHeader, writer))
                    {
                        sut.Dispose();
                        Assert.Throws <ObjectDisposedException>(() => writer.Write(_fixture.Create <byte>()));
                    }
            }
        }
コード例 #7
0
        public void WriteOneHasExpectedResult()
        {
            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);
            }
            if (expectedRecord.Content is PolygonShapeContent polygonContent)
            {
                boundingBox = BoundingBox3D.FromGeometry(polygonContent.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)))
                {
                    //Act
                    sut.Write(expectedRecord);
                }

                // Assert
                stream.Position = 0;

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

                    Assert.Equal(expectedHeader, actualHeader);
                    Assert.Equal(expectedRecord, actualRecord, new ShapeRecordEqualityComparer());
                }
            }
        }