public void NoDuplicateKeyedCollection() { // Uses an ObservableSortedArrayKeyList just for fun and // to challenge inheritance of DebuggerTypeProxy: the ObservableSortedArrayKeyList is not attributed // but it inherits the DebuggerTypeProxy of its SortedArrayKeyList base class. var a = new ObservableSortedArrayKeyList <int, string>(i => i.ToString()); a.AddRangeArray(3, 2, 1); bool exists; Assert.That(a.GetByKey("1", out exists) == 1 && exists); Assert.That(a.GetByKey("10", out exists) == 0 && !exists); Assert.That(a.GetByKey("2", out exists) == 2 && exists); Assert.That(a.Contains("2")); Assert.That(a.Contains("1")); Assert.That(!a.Contains("21")); object o; o = "2"; Assert.That(a.Contains(o), "Using the key."); o = 2; Assert.That(a.Contains(o), "Using the value itself."); Assert.That(!a.Add(3)); Assert.That(!a.Add(2)); Assert.That(!a.Add(1)); CheckList(a.GetAllByKey("2"), 2); }
public void NoDuplicateKeyedCollection() { // Uses an ObservableSortedArrayKeyList just for fun and // to challenge inheritance of DebuggerTypeProxy: the ObservableSortedArrayKeyList is not attributed // but it inherits the DebuggerTypeProxy of its SortedArrayKeyList base class. var a = new ObservableSortedArrayKeyList<int, string>( i => i.ToString() ); a.AddRangeArray( 3, 2, 1 ); bool exists; Assert.That( a.GetByKey( "1", out exists ) == 1 && exists ); Assert.That( a.GetByKey( "10", out exists ) == 0 && !exists ); Assert.That( a.GetByKey( "2", out exists ) == 2 && exists ); Assert.That( a.Contains( "2" ) ); Assert.That( a.Contains( "1" ) ); Assert.That( !a.Contains( "21" ) ); object o; o = "2"; Assert.That( a.Contains( o ), "Using the key." ); o = 2; Assert.That( a.Contains( o ), "Using the value itself." ); Assert.That( !a.Add( 3 ) ); Assert.That( !a.Add( 2 ) ); Assert.That( !a.Add( 1 ) ); CheckList( a.GetAllByKey( "2" ), 2 ); }