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 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 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 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 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 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 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 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 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 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 ValidateWithRecordsThatHaveTheSameAttributeIdentifierReturnsExpectedResult() { var records = _fixture .CreateMany <NumberedRoadChangeDbaseRecord>(2) .Select(record => { record.GW_OIDN.Value = 1; return(record); }) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single( _entry.AtDbaseRecord(new RecordNumber(2)).IdentifierNotUnique( new AttributeId(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()); } } }