public void DelegateKeyCollection_Sort()
        {
            var col = new DelegateKeyedCollection <int, string>((s) => s == null ? 0 : s.Length);

            col.Add("string1");
            col.Add("string333");
            col.Add("string22");

            Assert.AreEqual("string1", col.ElementAt(0));
            Assert.AreEqual("string333", col.ElementAt(1));
            Assert.AreEqual("string22", col.ElementAt(2));

            col.Sort();
            Assert.AreEqual("string1", col.ElementAt(0));
            Assert.AreEqual("string22", col.ElementAt(1));
            Assert.AreEqual("string333", col.ElementAt(2));

            Assert.AreEqual("string22", col[8]);
        }
        public void DelegateKeyCollection_Sort_ItemComparer()
        {
            var col = new DelegateKeyedCollection <int, string>((s) => s == null ? 0 : s.Length);

            col.Add("string1");
            col.Add("string333");
            col.Add("string22");

            Assert.AreEqual("string1", col.ElementAt(0));
            Assert.AreEqual("string333", col.ElementAt(1));
            Assert.AreEqual("string22", col.ElementAt(2));

            // reverse list by item value (not key)
            col.Sort((x, y) => string.Compare(y, x, StringComparison.Ordinal));
            Assert.AreEqual("string333", col.ElementAt(0));
            Assert.AreEqual("string22", col.ElementAt(1));
            Assert.AreEqual("string1", col.ElementAt(2));

            Assert.AreEqual("string22", col[8]);
        }