private void SortImagesAndValidate(
            PresentationImageCollection orderedCollection,
            PresentationImageCollection nonOrderedCollection,
            bool reverse,
            IComparer <IPresentationImage> comparer,
            TraceDelegate trace)
        {
            if (reverse)
            {
                PresentationImageCollection reversedCollection = new PresentationImageCollection();
                for (int i = orderedCollection.Count - 1; i >= 0; --i)
                {
                    reversedCollection.Add(orderedCollection[i]);
                }

                orderedCollection = reversedCollection;
            }

            Randomize(orderedCollection, nonOrderedCollection);

            Debug.WriteLine("NON-ORDERED COLLECTION (PRE-SORT)\n");
            trace(nonOrderedCollection);

            //Be certain it is currently *not* in order.
            Assert.IsFalse(VerifyOrdered(orderedCollection, nonOrderedCollection));

            //Sort it.
            nonOrderedCollection.Sort(comparer);

            Debug.WriteLine("NON-ORDERED COLLECTION (POST-SORT)");
            trace(nonOrderedCollection);

            //It should now be in the proper order.
            Assert.IsTrue(VerifyOrdered(orderedCollection, nonOrderedCollection));
        }
 private void AppendCollection(PresentationImageCollection collection, IEnumerable <PresentationImage> listImages)
 {
     foreach (PresentationImage image in listImages)
     {
         collection.Add(image);
     }
 }
        private void TestSortingDicomImagesByInstanceAndFrameNumber(bool reverse)
        {
            PresentationImageCollection orderedCollection    = new PresentationImageCollection();
            PresentationImageCollection nonOrderedCollection = new PresentationImageCollection();

            AppendCollection(orderedCollection, NewDicomSeries("123", "1", 1, 25));

            AppendCollection(orderedCollection, NewDicomSeries("123", "10", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("123", "111", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("123", "456", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("123", "789", 1, 25));

            //Note that the seriesUID are *not* in numerical order.  This is because
            //it is a string comparison that is being done.
            AppendCollection(orderedCollection, NewDicomSeries("a", "1", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("a", "11", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("a", "12", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("a", "6", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("a", "7", 1, 25));

            AppendCollection(orderedCollection, NewDicomSeries("b", "20", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("b", "21", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("b", "33", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("b", "34", 1, 25));
            AppendCollection(orderedCollection, NewDicomSeries("b", "40", 1, 25));

            //just put one of these at the end, it's enough.  We just want to see
            // that non-Dicom images get pushed to one end (depending on forward/reverse).
            orderedCollection.Add(new MockPresentationImage());

            SortImagesAndValidate(orderedCollection, nonOrderedCollection, reverse,
                                  new InstanceAndFrameNumberComparer(reverse), TraceInstanceAndFrameNumbers);

            foreach (PresentationImage image in nonOrderedCollection)
            {
                image.Dispose();
            }
            foreach (PresentationImage image in orderedCollection)
            {
                image.Dispose();
            }
        }
        private void TestSortingDicomImagesByAcquisitionTime(bool reverse)
        {
            PresentationImageCollection orderedCollection    = new PresentationImageCollection();
            PresentationImageCollection nonOrderedCollection = new PresentationImageCollection();

            foreach (IPresentationImage image in GetAcquisitionTimeTestImages())
            {
                orderedCollection.Add(image);
            }

            SortImagesAndValidate(orderedCollection, nonOrderedCollection, reverse,
                                  new SliceLocationComparer(reverse), TraceAcquisitionTime);

            foreach (PresentationImage image in nonOrderedCollection)
            {
                image.Dispose();
            }
            foreach (PresentationImage image in orderedCollection)
            {
                image.Dispose();
            }
        }