public void ValidateWithRecordsThatHaveTheirRecordTypeMismatchReturnsExpectedResult() { var records = _fixture .CreateMany <GradeSeparatedJunctionChangeDbaseRecord>(2) .Select((record, index) => { record.OK_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 ValidateWithRecordThatIsMissingReasonReturnsExpectedResult() { var records = _fixture .CreateMany <TransactionZoneDbaseRecord>(1) .Select(record => { record.BESCHRIJV.Value = null; return(record); }) .ToDbaseRecordEnumerator(); var result = _sut.Validate(_entry, records); Assert.Equal( ZipArchiveProblems.Single(_entry.AtDbaseRecord(new RecordNumber(1)).RequiredFieldIsNull(TransactionZoneDbaseRecord.Schema.BESCHRIJV)), result); }
public ZipArchiveProblems Validate(ZipArchiveEntry entry, IDbaseRecordEnumerator <RoadSegmentChangeDbaseRecord> records) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } if (records == null) { throw new ArgumentNullException(nameof(records)); } var problems = ZipArchiveProblems.None; try { var identifiers = new Dictionary <RoadSegmentId, RecordNumber>(); var moved = records.MoveNext(); if (moved) { while (moved) { var recordContext = entry.AtDbaseRecord(records.CurrentRecordNumber); var record = records.Current; if (record != null) { if (!record.RECORDTYPE.HasValue) { problems += recordContext.RequiredFieldIsNull(record.RECORDTYPE.Field); } else { if (!RecordType.ByIdentifier.ContainsKey(record.RECORDTYPE.Value)) { problems += recordContext.RecordTypeMismatch(record.RECORDTYPE.Value); } } if (record.WS_OIDN.HasValue) { if (record.WS_OIDN.Value == 0) { problems += recordContext.IdentifierZero(); } else { var identifier = new RoadSegmentId(record.WS_OIDN.Value); if (identifiers.TryGetValue(identifier, out var takenByRecordNumber)) { problems += recordContext.IdentifierNotUnique( identifier, takenByRecordNumber ); } else { identifiers.Add(identifier, records.CurrentRecordNumber); } } } else { problems += recordContext.RequiredFieldIsNull(record.WS_OIDN.Field); } if (!record.TGBEP.HasValue) { problems += recordContext.RequiredFieldIsNull(record.TGBEP.Field); } else if (!RoadSegmentAccessRestriction.ByIdentifier.ContainsKey(record.TGBEP.Value)) { problems += recordContext.RoadSegmentAccessRestrictionMismatch(record.TGBEP.Value); } if (!record.STATUS.HasValue) { problems += recordContext.RequiredFieldIsNull(record.STATUS.Field); } else if (!RoadSegmentStatus.ByIdentifier.ContainsKey(record.STATUS.Value)) { problems += recordContext.RoadSegmentStatusMismatch(record.STATUS.Value); } if (!record.WEGCAT.HasValue) { problems += recordContext.RequiredFieldIsNull(record.WEGCAT.Field); } else if (!RoadSegmentCategory.ByIdentifier.ContainsKey(record.WEGCAT.Value)) { problems += recordContext.RoadSegmentCategoryMismatch(record.WEGCAT.Value); } if (!record.METHODE.HasValue) { problems += recordContext.RequiredFieldIsNull(record.METHODE.Field); } else if (!RoadSegmentGeometryDrawMethod.ByIdentifier.ContainsKey(record.METHODE.Value)) { problems += recordContext.RoadSegmentGeometryDrawMethodMismatch(record.METHODE.Value); } if (!record.MORFOLOGIE.HasValue) { problems += recordContext.RequiredFieldIsNull(record.MORFOLOGIE.Field); } else if (!RoadSegmentMorphology.ByIdentifier.ContainsKey(record.MORFOLOGIE.Value)) { problems += recordContext.RoadSegmentMorphologyMismatch(record.MORFOLOGIE.Value); } if (!record.B_WK_OIDN.HasValue) { problems += recordContext.RequiredFieldIsNull(record.B_WK_OIDN.Field); } else if (!RoadNodeId.Accepts(record.B_WK_OIDN.Value)) { problems += recordContext.BeginRoadNodeIdOutOfRange(record.B_WK_OIDN.Value); } if (!record.E_WK_OIDN.HasValue) { problems += recordContext.RequiredFieldIsNull(record.E_WK_OIDN.Field); } else if (!RoadNodeId.Accepts(record.E_WK_OIDN.Value)) { problems += recordContext.EndRoadNodeIdOutOfRange(record.E_WK_OIDN.Value); } if (!record.BEHEERDER.HasValue) { problems += recordContext.RequiredFieldIsNull(record.BEHEERDER.Field); } } moved = records.MoveNext(); } } else { problems += entry.HasNoDbaseRecords(false); } } catch (Exception exception) { problems += entry.AtDbaseRecord(records.CurrentRecordNumber).HasDbaseRecordFormatError(exception); } return(problems); }
public ZipArchiveProblems Validate(ZipArchiveEntry entry, IDbaseRecordEnumerator <NationalRoadChangeDbaseRecord> records) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } if (records == null) { throw new ArgumentNullException(nameof(records)); } var problems = ZipArchiveProblems.None; try { var identifiers = new Dictionary <AttributeId, RecordNumber>(); var moved = records.MoveNext(); if (moved) { while (moved) { var recordContext = entry.AtDbaseRecord(records.CurrentRecordNumber); var record = records.Current; if (record != null) { if (!record.RECORDTYPE.HasValue) { problems += recordContext.RequiredFieldIsNull(record.RECORDTYPE.Field); } else { if (!RecordType.ByIdentifier.ContainsKey(record.RECORDTYPE.Value)) { problems += recordContext.RecordTypeMismatch(record.RECORDTYPE.Value); } } if (record.NW_OIDN.HasValue) { if (record.NW_OIDN.Value == 0) { problems += recordContext.IdentifierZero(); } else { var identifier = new AttributeId(record.NW_OIDN.Value); if (identifiers.TryGetValue(identifier, out var takenByRecordNumber)) { problems += recordContext.IdentifierNotUnique( identifier, takenByRecordNumber ); } else { identifiers.Add(identifier, records.CurrentRecordNumber); } } } else { problems += recordContext.RequiredFieldIsNull(record.NW_OIDN.Field); } if (record.IDENT2.Value == null) { problems += recordContext.RequiredFieldIsNull(record.IDENT2.Field); } else if (!NationalRoadNumber.CanParse(record.IDENT2.Value)) { problems += recordContext.NotNationalRoadNumber(record.IDENT2.Value); } if (!record.WS_OIDN.HasValue) { problems += recordContext.RequiredFieldIsNull(record.WS_OIDN.Field); } else if (!RoadSegmentId.Accepts(record.WS_OIDN.Value)) { problems += recordContext.RoadSegmentIdOutOfRange(record.WS_OIDN.Value); } moved = records.MoveNext(); } } } else { problems += entry.HasNoDbaseRecords(true); } } catch (Exception exception) { problems += entry.AtDbaseRecord(records.CurrentRecordNumber).HasDbaseRecordFormatError(exception); } return(problems); }
public void ValidateWithRecordsThatHaveTheSameAttributeIdentifierReturnsExpectedResult() { var records = _fixture .CreateMany <EuropeanRoadChangeDbaseRecord>(2) .Select(record => { record.EU_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 ZipArchiveProblems Validate(ZipArchiveEntry entry, IDbaseRecordEnumerator <RoadSegmentLaneChangeDbaseRecord> records) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } if (records == null) { throw new ArgumentNullException(nameof(records)); } var problems = ZipArchiveProblems.None; try { var identifiers = new Dictionary <AttributeId, RecordNumber>(); var moved = records.MoveNext(); if (moved) { while (moved) { var recordContext = entry.AtDbaseRecord(records.CurrentRecordNumber); var record = records.Current; if (record != null) { if (!record.RECORDTYPE.HasValue) { problems += recordContext.RequiredFieldIsNull(record.RECORDTYPE.Field); } else { if (!RecordType.ByIdentifier.ContainsKey(record.RECORDTYPE.Value)) { problems += recordContext.RecordTypeMismatch(record.RECORDTYPE.Value); } } if (record.RS_OIDN.HasValue) { if (record.RS_OIDN.Value == 0) { problems += recordContext.IdentifierZero(); } else { var identifier = new AttributeId(record.RS_OIDN.Value); if (identifiers.TryGetValue(identifier, out var takenByRecordNumber)) { problems += recordContext.IdentifierNotUnique( identifier, takenByRecordNumber ); } else { identifiers.Add(identifier, records.CurrentRecordNumber); } } } else { problems += recordContext.RequiredFieldIsNull(record.RS_OIDN.Field); } if (!record.AANTAL.HasValue) { problems += recordContext.RequiredFieldIsNull(record.AANTAL.Field); } else if (!RoadSegmentLaneCount.Accepts(record.AANTAL.Value)) { problems += recordContext.LaneCountOutOfRange(record.AANTAL.Value); } if (!record.RICHTING.HasValue) { problems += recordContext.RequiredFieldIsNull(record.RICHTING.Field); } else if (!RoadSegmentLaneDirection.ByIdentifier.ContainsKey(record.RICHTING.Value)) { problems += recordContext.LaneDirectionMismatch(record.RICHTING.Value); } if (!record.VANPOSITIE.HasValue) { problems += recordContext.RequiredFieldIsNull(record.VANPOSITIE.Field); } else if (!RoadSegmentPosition.Accepts(record.VANPOSITIE.Value)) { problems += recordContext.FromPositionOutOfRange(record.VANPOSITIE.Value); } if (!record.TOTPOSITIE.HasValue) { problems += recordContext.RequiredFieldIsNull(record.TOTPOSITIE.Field); } else if (!RoadSegmentPosition.Accepts(record.TOTPOSITIE.Value)) { problems += recordContext.ToPositionOutOfRange(record.TOTPOSITIE.Value); } if (!record.WS_OIDN.HasValue) { problems += recordContext.RequiredFieldIsNull(record.WS_OIDN.Field); } else if (!RoadSegmentId.Accepts(record.WS_OIDN.Value)) { problems += recordContext.RoadSegmentIdOutOfRange(record.WS_OIDN.Value); } } moved = records.MoveNext(); } } else { problems += entry.HasNoDbaseRecords(false); } } catch (Exception exception) { problems += entry.AtDbaseRecord(records.CurrentRecordNumber).HasDbaseRecordFormatError(exception); } return(problems); }
public ZipArchiveProblems Validate(ZipArchiveEntry entry, IDbaseRecordEnumerator <TransactionZoneDbaseRecord> records) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } if (records == null) { throw new ArgumentNullException(nameof(records)); } var problems = ZipArchiveProblems.None; try { var count = 0; var moved = records.MoveNext(); if (moved) { while (moved) { var recordContext = entry.AtDbaseRecord(records.CurrentRecordNumber); var record = records.Current; if (record != null) { if (!record.BESCHRIJV.HasValue) { problems += recordContext.RequiredFieldIsNull(record.BESCHRIJV.Field); } if (!record.OPERATOR.HasValue) { problems += recordContext.RequiredFieldIsNull(record.OPERATOR.Field); } if (!record.ORG.HasValue) { problems += recordContext.RequiredFieldIsNull(record.ORG.Field); } else if (!OrganizationId.AcceptsValue(record.ORG.Value)) { problems += recordContext.OrganizationIdOutOfRange(record.ORG.Value); } count++; moved = records.MoveNext(); } } if (count != 1) { problems += entry.HasTooManyDbaseRecords(1, count); } } else { problems += entry.HasNoDbaseRecords(true); } } catch (Exception exception) { problems += entry.AtDbaseRecord(records.CurrentRecordNumber).HasDbaseRecordFormatError(exception); } return(problems); }