public void DelegateKeyCollection_PropertyCheck() { var col = new DelegateKeyedCollection <int, string>((s) => s == null ? 0 : s.Length); col.Add("string1"); col.Add("string333"); col.Add("string22"); Assert.AreEqual(3, col.Keys.Count); Assert.AreEqual(3, col.Values.Count); }
public void DelegateKeyCollection_SortByKeys_ComparrisonDelegate() { 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.SortByKeys((x, y) => y - x); Assert.AreEqual("string333", col.ElementAt(0)); Assert.AreEqual("string22", col.ElementAt(1)); Assert.AreEqual("string1", 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]); }