public void TryGetTest1() { //create a test dictionary which we will use var TestDictionary = new Dictionary<int, DummyObject>(); /* this saves you from declaring the out parameter which is rough with the syntax * if (!TestDictionary.TryGetValue(24, out...)) * { * * } */ //let's make sure we can't find an item since we have nothing in our dictionary right now Assert.Null(TestDictionary.TryGet(24)); //let's add an item TestDictionary.Add(24, new DummyObject(24, "24")); //make sure we have this item now Assert.Equal(24, TestDictionary.TryGet(24).Id); //make sure we can't find 25 Assert.Null(TestDictionary.TryGet(25)); //now add 25 TestDictionary.Add(25, new DummyObject(25, "25")); //make sure we can find 25 now Assert.Equal(25, TestDictionary.TryGet(25).Id); }
public void EqualityDictionary( Dictionary<Tuple<object>, object> sut ) { var item = new object(); var first = Tuple.Create( item ); var second = Tuple.Create( item ); sut.Add( first, item ); var found = sut.TryGet( second ); Assert.Same( item, found ); }