public void Exact_Offsets_Should_All_Match() { var offsets = GenerateUniqueRandonmOffsets(155, 500000); var root = new Container() { Sequence = new DicomDataset() }; root.CreateChildren(offsets, 5, 3, 3, 2); var allChildren = root.AllContainer.Skip(1).ToArray(); var sequence = new DicomSequence(DicomTag.DirectoryRecordSequence); root.Sequence.AddOrUpdate(sequence); var byteSource = new TestByteSource(); var observer = new DicomDirectoryReaderObserver(root.Sequence); observer.OnBeginSequence(byteSource, DicomTag.DirectoryRecordSequence, 0); foreach (var container in allChildren) { sequence.Items.Add(container.Sequence); byteSource.Position = container.Offset + 8; observer.OnBeginSequenceItem(byteSource, 0); observer.OnEndSequenceItem(); } observer.OnEndSequence(); var rootRecord = new DicomDirectoryRecord { LowerLevelDirectoryRecord = observer.BuildDirectoryRecords(), }; root.AssertRecord(rootRecord); }
public void Duplicate_Offsets_Should_Not_Throw() { var offsets = new List <uint>(GenerateUniqueRandonmOffsets(155, 100000).Select(o => o * 5)); for (int i = 0; i < offsets.Count - 2; i += 2) { offsets[i + 1] = offsets[i]; } var root = new Container() { Sequence = new DicomDataset() }; root.CreateChildren(offsets, 5, 3, 3, 2); var allChildren = root.AllContainer.Skip(1).ToArray(); var sequence = new DicomSequence(DicomTag.DirectoryRecordSequence); root.Sequence.AddOrUpdate(sequence); var byteSource = new TestByteSource(); var observer = new DicomDirectoryReaderObserver(root.Sequence); observer.OnBeginSequence(byteSource, DicomTag.DirectoryRecordSequence, 0); uint lastPosition = 0; foreach (var container in allChildren) { sequence.Items.Add(container.Sequence); var position = container.Offset + 8; if (position == lastPosition) { position += 1; } lastPosition = position; byteSource.Position = position; observer.OnBeginSequenceItem(byteSource, 0); observer.OnEndSequenceItem(); } observer.OnEndSequence(); var rootRecord = new DicomDirectoryRecord { LowerLevelDirectoryRecord = observer.BuildDirectoryRecords(), }; // Cannot assert all records when duplicate offsets exist. // root.AssertRecord(rootRecord); }