public void ValidateReturnsExpectedResultWhenEntryStreamIsEmpty() { var sut = new ZipArchiveDbaseEntryValidator <FakeDbaseRecord>( Encoding.Default, new FakeDbaseSchema(), new FakeDbaseRecordValidator()); using (var stream = new MemoryStream()) { using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true)) { archive.CreateEntry("entry"); } stream.Flush(); stream.Position = 0; using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, true)) { var entry = archive.GetEntry("entry"); var result = sut.Validate(entry); Assert.Equal( ZipArchiveProblems.Single(entry.HasDbaseHeaderFormatError( new EndOfStreamException("Unable to read beyond the end of the stream.")) ), result, new FileProblemComparer()); } } }
public void ValidateWithRecordsThatHaveTheirRecordTypeMismatchReturnsExpectedResult() { var records = _fixture .CreateMany <NumberedRoadChangeDbaseRecord>(2) .Select((record, index) => { record.GW_OIDN.Value = index + 1; record.RECORDTYPE.Value = -1; return(record); }) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Many( _entry .AtDbaseRecord(new RecordNumber(1)) .RecordTypeMismatch(-1), _entry .AtDbaseRecord(new RecordNumber(2)) .RecordTypeMismatch(-1) ), result); }
public void ValidateWithEmptyPolyLineMRecordsReturnsExpectedResult() { var records = Enumerable.Range(0, 2) .Select(index => new PolyLineMShapeContent( GeometryTranslator.FromGeometryMultiLineString( new MultiLineString( new[] { new LineString( new CoordinateArraySequence(new[] { NetTopologySuite.Geometries.Point.Empty.Coordinate, NetTopologySuite.Geometries.Point.Empty.Coordinate }), GeometryConfiguration.GeometryFactory) }))).RecordAs(new RecordNumber(index + 1))) .GetEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Many( _entry.AtShapeRecord(new RecordNumber(1)).ShapeRecordGeometryMismatch(), _entry.AtShapeRecord(new RecordNumber(2)).ShapeRecordGeometryMismatch() ), result); }
public void ValidateWithoutRecordsReturnsExpectedResult() { var result = _sut.Validate(_entry, _enumerator); Assert.Equal( ZipArchiveProblems.Single(_entry.HasNoShapeRecords()), result); }
public void ValidateWithMoreThanOneRecordReturnsExpectedResult() { var records = _fixture .CreateMany <TransactionZoneDbaseRecord>(2) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.HasTooManyDbaseRecords(1, 2)), result); }
public void ValidateWithRecordThatHasInvalidNumberedRoadNumberReturnsExpectedResult() { var record = _fixture.Create <NumberedRoadChangeDbaseRecord>(); record.IDENT8.Value = "-1"; var records = new [] { record }.ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(1)).NotNumberedRoadNumber("-1")), result); }
public void ValidateWithRecordThatHasInvalidTypeReturnsExpectedResult() { var record = _fixture.Create <RoadSegmentSurfaceChangeDbaseRecord>(); record.TYPE.Value = -1; var records = new [] { record }.ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(1)).SurfaceTypeMismatch(-1)), result); }
public void ValidateWithRecordThatHasInvalidNumberedRoadDirectionReturnsExpectedResult() { var record = _fixture.Create <NumberedRoadChangeDbaseRecord>(); record.RICHTING.Value = -1; var records = new [] { record }.ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(1)).NumberedRoadDirectionMismatch(-1)), result); }
public void ValidateWithRecordThatHasInvalidNumberedRoadOrdinalReturnsExpectedResult() { var record = _fixture.Create <NumberedRoadChangeDbaseRecord>(); record.VOLGNUMMER.Value = -1; var records = new [] { record }.ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(1)).NumberedRoadOrdinalOutOfRange(-1)), result); }
public void ValidateWithRecordThatHasInvalidCategoryReturnsExpectedResult() { var record = _fixture.Create <RoadSegmentChangeDbaseRecord>(); record.WEGCAT.Value = "-1"; var records = new [] { record }.ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(1)).RoadSegmentCategoryMismatch("-1")), result); }
public void ValidateWithRecordThatHasInvalidRoadSegmentIdReturnsExpectedResult() { var record = _fixture.Create <EuropeanRoadChangeDbaseRecord>(); record.WS_OIDN.Value = -1; var records = new [] { record }.ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(1)).RoadSegmentIdOutOfRange(-1)), result); }
public void ValidateReturnsExpectedResultFromEntryValidators() { using (var archive = CreateArchiveWithEmptyFiles()) { var sut = new ZipArchiveValidator(Encoding.UTF8); var result = sut.Validate(archive); Assert.Equal( ZipArchiveProblems.Many( archive.Entries.Select(entry => entry.Name.EndsWith(".SHP") ? entry.HasNoShapeRecords() : entry.HasNoDbaseRecords(false)) ), result); } }
public void ValidateWithProblematicRecordsReturnsExpectedResult() { var records = _fixture .CreateMany <RoadNodeChangeDbaseRecord>(2) .ToArray(); var exception = new Exception("problem"); var enumerator = new ProblematicDbaseRecordEnumerator <RoadNodeChangeDbaseRecord>(records, 1, exception); var result = _sut.Validate(_entry, enumerator); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(2)).HasDbaseRecordFormatError(exception)), result, new FileProblemComparer()); }
public void ValidateWithProblematicRecordsReturnsExpectedResult() { var records = _fixture .CreateMany <ShapeRecord>(new Random().Next(1, 5)) .Select((record, index) => record.Content.RecordAs(new RecordNumber(index + 1))) .ToArray(); var exception = new Exception("problem"); var enumerator = new ProblematicShapeRecordEnumerator(records, 1, exception); var result = _sut.Validate(_entry, enumerator); Assert.Equal( ZipArchiveProblems.Single(_entry.AtShapeRecord(new RecordNumber(2)).HasShapeRecordFormatError(exception)), result, new FileProblemComparer()); }
public void ValidateWithEmptyPointRecordsReturnsExpectedResult() { var records = Enumerable.Range(0, 2) .Select(index => new PointShapeContent(GeometryTranslator.FromGeometryPoint(NetTopologySuite.Geometries.Point.Empty)) .RecordAs(new RecordNumber(index + 1))) .GetEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Many( _entry.AtShapeRecord(new RecordNumber(1)).ShapeRecordGeometryMismatch(), _entry.AtShapeRecord(new RecordNumber(2)).ShapeRecordGeometryMismatch() ), result); }
public void ValidateWithRecordThatIsMissingOrganizationIdReturnsExpectedResult() { var records = _fixture .CreateMany <TransactionZoneDbaseRecord>(1) .Select(record => { record.ORG.Value = null; return(record); }) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(1)).RequiredFieldIsNull(TransactionZoneDbaseRecord.Schema.ORG)), result); }
public void ValidateWithRecordThatHasOrganizationIdOutOfRangeReturnsExpectedResult() { var value = string.Empty; var records = _fixture .CreateMany <TransactionZoneDbaseRecord>(1) .Select(record => { record.ORG.Value = value; return(record); }) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(1)).OrganizationIdOutOfRange(value)), result); }
public void ValidateWithTooLittleOrTooManyLinesPolyLineMRecordsReturnsExpectedResult() { var records = Enumerable.Range(0, 2) .Select(index => { if (index == 0) { return(new PolyLineMShapeContent( GeometryTranslator.FromGeometryMultiLineString(new MultiLineString(new LineString[0])) ).RecordAs(new RecordNumber(index + 1))); } return(new PolyLineMShapeContent( GeometryTranslator.FromGeometryMultiLineString( new MultiLineString(new[] { new LineString( new CoordinateArraySequence(new[] { new Coordinate(index * 2.0, index * 2.0), new Coordinate(index * 2.0 + 1.0, index * 2.0 + 1.0) }), GeometryConfiguration.GeometryFactory), new LineString( new CoordinateArraySequence(new[] { new Coordinate(index * 4.0, index * 4.0), new Coordinate(index * 4.0 + 1.0, index * 4.0 + 1.0) }), GeometryConfiguration.GeometryFactory) })) ).RecordAs(new RecordNumber(index + 1))); }) .GetEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Many( _entry.AtShapeRecord(new RecordNumber(1)).ShapeRecordGeometryLineCountMismatch(1, 0), _entry.AtShapeRecord(new RecordNumber(2)).ShapeRecordGeometryLineCountMismatch(1, 2) ), result); }
public void ValidateWithNullRecordsReturnsExpectedResult() { var records = _fixture .CreateMany <ShapeRecord>(new Random().Next(1, 5)) .Select((record, index) => index == 0 ? NullShapeContent.Instance.RecordAs(new RecordNumber(index + 1)) : record.Content.RecordAs(new RecordNumber(index + 1))) .GetEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single( _entry.AtShapeRecord(RecordNumber.Initial).ShapeRecordShapeTypeMismatch( ShapeType.PolyLineM, ShapeType.NullShape) ), result); }
public void ValidateReturnsExpectedResultWhenDbaseFileHeaderDoesNotMatch() { var sut = new ZipArchiveDbaseEntryValidator <FakeDbaseRecord>( Encoding.UTF8, new FakeDbaseSchema(), new FakeDbaseRecordValidator()); var date = DateTime.Today; var header = new DbaseFileHeader( date, DbaseCodePage.Western_European_ANSI, new DbaseRecordCount(0), new AnonymousDbaseSchema(new DbaseField[0])); using (var stream = new MemoryStream()) { using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true)) { var entry = archive.CreateEntry("entry"); using (var entryStream = entry.Open()) using (var writer = new BinaryWriter(entryStream, Encoding.UTF8)) { header.Write(writer); entryStream.Flush(); } } stream.Flush(); stream.Position = 0; using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, true)) { var entry = archive.GetEntry("entry"); var result = sut.Validate(entry); Assert.Equal( ZipArchiveProblems.Single(entry.HasDbaseSchemaMismatch( new FakeDbaseSchema(), new AnonymousDbaseSchema(new DbaseField[0])) ), result); } } }
public void ValidateWithSelfIntersectingRecordsReturnsExpectedResult() { var startPoint = new NetTopologySuite.Geometries.Point(new CoordinateM(0.0, 10.0, 0.0)) { SRID = SpatialReferenceSystemIdentifier.BelgeLambert1972.ToInt32() }; var middlePoint1 = new NetTopologySuite.Geometries.Point(new CoordinateM(10.0, 10.0, 10.0)) { SRID = SpatialReferenceSystemIdentifier.BelgeLambert1972.ToInt32() }; var middlePoint2 = new NetTopologySuite.Geometries.Point(new CoordinateM(5.0, 20.0, 21.1803)) { SRID = SpatialReferenceSystemIdentifier.BelgeLambert1972.ToInt32() }; var endPoint = new NetTopologySuite.Geometries.Point(new CoordinateM(5.0, 0.0, 41.1803)) { SRID = SpatialReferenceSystemIdentifier.BelgeLambert1972.ToInt32() }; var lineString = new LineString( new CoordinateArraySequence(new[] { startPoint.Coordinate, middlePoint1.Coordinate, middlePoint2.Coordinate, endPoint.Coordinate }), GeometryConfiguration.GeometryFactory ); var multiLineString = new MultiLineString( new [] { lineString }) { SRID = SpatialReferenceSystemIdentifier.BelgeLambert1972.ToInt32() }; var records = new List <ShapeRecord> { new PolyLineMShapeContent(GeometryTranslator.FromGeometryMultiLineString(multiLineString)).RecordAs(new RecordNumber(1)) } .GetEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtShapeRecord(new RecordNumber(1)).ShapeRecordGeometrySelfIntersects()), result); }
public void ValidateWithRecordsThatHaveZeroAsAttributeIdentifierReturnsExpectedResult() { var records = _fixture .CreateMany <NumberedRoadChangeDbaseRecord>(2) .Select(record => { record.GW_OIDN.Value = 0; return(record); }) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Many( _entry.AtDbaseRecord(new RecordNumber(1)).IdentifierZero(), _entry.AtDbaseRecord(new RecordNumber(2)).IdentifierZero() ), result); }
public void ValidateWithRecordsThatDoNotHaveEuropeanRoadNumbersReturnsExpectedResult(string number) { var records = _fixture .CreateMany <EuropeanRoadChangeDbaseRecord>(2) .Select((record, index) => { record.EU_OIDN.Value = index + 1; record.EUNUMMER.Value = number; return(record); }) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Many( _entry.AtDbaseRecord(new RecordNumber(1)).NotEuropeanRoadNumber(number), _entry.AtDbaseRecord(new RecordNumber(2)).NotEuropeanRoadNumber(number) ), result); }
public void ValidateWithRecordsThatHaveNullAsEuropeanRoadNumbersReturnsExpectedResult() { var records = _fixture .CreateMany <EuropeanRoadChangeDbaseRecord>(2) .Select((record, index) => { record.EU_OIDN.Value = index + 1; record.EUNUMMER.Value = null; return(record); }) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Many( _entry.AtDbaseRecord(new RecordNumber(1)).RequiredFieldIsNull(EuropeanRoadChangeDbaseRecord.Schema.EUNUMMER), _entry.AtDbaseRecord(new RecordNumber(2)).RequiredFieldIsNull(EuropeanRoadChangeDbaseRecord.Schema.EUNUMMER) ), result); }
public void ValidateWithRecordsThatHaveTheSameRoadNodeIdentifierReturnsExpectedResult() { var records = _fixture .CreateMany <RoadNodeChangeDbaseRecord>(2) .Select(record => { record.WEGKNOOPID.Value = 1; return(record); }) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single( _entry.AtDbaseRecord(new RecordNumber(2)).IdentifierNotUnique( new RoadNodeId(1), new RecordNumber(1)) ), result); }
public void ValidateReturnsExpectedResultWhenEntryStreamContainsMalformedShapeHeader() { var sut = new ZipArchiveShapeEntryValidator( Encoding.Default, new FakeShapeRecordValidator()); using (var stream = new MemoryStream()) { using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true)) { var entry = archive.CreateEntry("entry"); using (var entryStream = entry.Open()) { entryStream.WriteByte(0); entryStream.WriteByte(0); entryStream.WriteByte(0); entryStream.WriteByte(0); entryStream.Flush(); } } stream.Flush(); stream.Position = 0; using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, true)) { var entry = archive.GetEntry("entry"); var result = sut.Validate(entry); Assert.Equal( ZipArchiveProblems.Single(entry.HasShapeHeaderFormatError( new ShapeFileHeaderException("The File Code field does not match 9994.")) ), result, new FileProblemComparer()); } } }
public void ValidateReturnsExpectedResultWhenEntryStreamContainsMalformedDbaseHeader() { var sut = new ZipArchiveDbaseEntryValidator <FakeDbaseRecord>( Encoding.Default, new FakeDbaseSchema(), new FakeDbaseRecordValidator()); using (var stream = new MemoryStream()) { using (var archive = new ZipArchive(stream, ZipArchiveMode.Create, true)) { var entry = archive.CreateEntry("entry"); using (var entryStream = entry.Open()) { entryStream.WriteByte(0); entryStream.Flush(); } } stream.Flush(); stream.Position = 0; using (var archive = new ZipArchive(stream, ZipArchiveMode.Read, true)) { var entry = archive.GetEntry("entry"); var result = sut.Validate(entry); Assert.Equal( ZipArchiveProblems.Single(entry.HasDbaseHeaderFormatError( new DbaseFileHeaderException("The database file type must be 3 (dBase III).")) ), result, new FileProblemComparer()); } } }
public bool Equals(ZipArchiveProblems other) => other != null && _problems.SequenceEqual(other._problems);
public void ValidateReturnsExpectedResultWhenRequiredFileMissing(ZipArchive archive, ZipArchiveProblems expected) { using (archive) { var sut = new ZipArchiveValidator(Encoding.UTF8); var result = sut.Validate(archive); Assert.Equal(expected, result); } }