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); }
public void ShapeReturnsExpectedValue() { var shape = _fixture.Create <Point>(); var sut = new PointShapeContent(shape); Assert.Equal(shape, sut.Shape); }
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)); }
public ShapeRecordEnumeratorWithShorterStreamTests() { var fixture = new Fixture(); fixture.CustomizeShapeRecordCount(); fixture.CustomizeWordLength(); var content = new PointShapeContent(new PointM(1.0, 1.0)); var number = RecordNumber.Initial; _record = content.RecordAs(number); var header = new ShapeFileHeader( ShapeFileHeader.Length.Plus(_record.Length.Times(2)), ShapeType.Point, fixture.Create <BoundingBox3D>()); var stream = new MemoryStream(); using (var writer = new BinaryWriter(stream, Encoding.UTF8, true)) { header.Write(writer); _record.Write(writer); writer.Write(fixture.CreateMany <byte>(_record.Length.ToByteLength().ToInt32() / 2).ToArray()); writer.Flush(); } stream.Position = 100; _reader = new DisposableBinaryReader(stream, Encoding.UTF8, false); _sut = header.CreateShapeRecordEnumerator(_reader); }
public ShapeRecordEnumeratorOverStreamWithExpectedBytesTests() { var fixture = new Fixture(); fixture.CustomizeShapeRecordCount(); fixture.CustomizeWordLength(); var content = new PointShapeContent(new Point(1.0, 1.0)); var number = RecordNumber.Initial; _record1 = content.RecordAs(number); _record2 = content.RecordAs(number.Next()); var header = new ShapeFileHeader( ShapeFileHeader.Length.Plus(_record1.Length).Plus(_record2.Length), ShapeType.Point, fixture.Create <BoundingBox3D>()); var stream = new MemoryStream(); using (var writer = new BinaryWriter(stream, Encoding.UTF8, true)) { header.Write(writer); _record1.Write(writer); _record2.Write(writer); writer.Flush(); } stream.Position = 100; _reader = new DisposableBinaryReader(stream, Encoding.UTF8, false); _sut = header.CreateShapeRecordEnumerator(_reader); }
public static ShapeContent Read(BinaryReader reader) { if (reader == null) { throw new ArgumentNullException(nameof(reader)); } var shapeType = reader.ReadInt32LittleEndian(); if (!Enum.IsDefined(typeof(ShapeType), shapeType)) { throw new ShapeRecordContentException("The Shape Type field does not contain a known type of shape."); } var content = NullShapeContent.Instance; switch ((ShapeType)shapeType) { case ShapeType.NullShape: break; case ShapeType.Point: content = PointShapeContent.ReadPointGeometry(reader); break; case ShapeType.PolyLineM: content = PolyLineMShapeContent.ReadPolyLineMGeometry(reader); break; default: throw new ShapeRecordContentException($"The Shape Type {shapeType} is currently not suppported."); } return(content); }
internal static ShapeContent ReadFromRecord(BinaryReader reader, ShapeRecordHeader header) { var shapeType = reader.ReadInt32LittleEndian(); if (!Enum.IsDefined(typeof(ShapeType), shapeType)) { throw new ShapeRecordContentException("The Shape Type field does not contain a known type of shape."); } var content = NullShapeContent.Instance; switch ((ShapeType)shapeType) { case ShapeType.NullShape: break; case ShapeType.Point: content = PointShapeContent.ReadPointFromRecord(reader, header); break; case ShapeType.PolyLineM: content = PolyLineMShapeContent.ReadPolyLineMFromRecord(reader, header); break; default: throw new ShapeRecordContentException($"The Shape Type {shapeType} is currently not suppported."); } return(content); }
private bool Equals(PointShapeContent left, PointShapeContent right) { var sameContentLength = left.ContentLength.Equals(right.ContentLength); var sameShapeType = left.ShapeType.Equals(right.ShapeType); var sameShape = left.Shape.Equals(right.Shape); return(sameContentLength && sameShapeType && sameShape); }
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); }
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 ToBytesHasExpectedResult() { var sut = new PointShapeContent(_fixture.Create <PointM>()); var result = sut.ToBytes(); using (var stream = new MemoryStream()) using (var writer = new BinaryWriter(stream)) { sut.Write(writer); writer.Flush(); Assert.Equal(stream.ToArray(), result); } }
public void AnonymousHasExpectedResult() { var sut = new PointShapeContent(_fixture.Create <PointM>()); var result = sut.Anonymous(); using (var stream = new MemoryStream()) using (var writer = new BinaryWriter(stream)) { sut.Write(writer); writer.Flush(); Assert.Equal(sut.ShapeType, result.ShapeType); Assert.Equal(sut.ContentLength, result.ContentLength); Assert.Equal( stream.ToArray(), Assert.IsType <AnonymousShapeContent>(result).Content); } }
public void ReadPointCanReadWrittenNullShape() { using (var stream = new MemoryStream()) { using (var writer = new BinaryWriter(stream, Encoding.ASCII, true)) { NullShapeContent.Instance.Write(writer); writer.Flush(); } stream.Position = 0; using (var reader = new BinaryReader(stream, Encoding.ASCII, true)) { var result = PointShapeContent.ReadPoint(reader); Assert.Equal(NullShapeContent.Instance, result); } } }
public void ReadPointCanNotReadOtherShapeType(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>( () => PointShapeContent.ReadPoint(reader) ); } } }
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())); }
public void ReadPointCanReadWrittenPointShape() { var sut = new PointShapeContent(_fixture.Create <Point>()); 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 = (PointShapeContent)PointShapeContent.ReadPoint(reader); Assert.Equal(sut.Shape, result.Shape); Assert.Equal(sut.ShapeType, result.ShapeType); Assert.Equal(sut.ContentLength, result.ContentLength); } } }
public void ShapeTypeReturnsExpectedValue() { var sut = new PointShapeContent(_fixture.Create <Point>()); Assert.Equal(ShapeType.Point, sut.ShapeType); }
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 ContentLengthReturnsExpectedValue() { var sut = new PointShapeContent(_fixture.Create <Point>()); Assert.Equal(new WordLength(10), sut.ContentLength); }
public void ReadPointReaderCanNotBeNull() { new GuardClauseAssertion(_fixture) .Verify(Methods.Select(() => PointShapeContent.ReadPoint(null))); }