public void NonExistantValuesCannotBeRetrieved()
 {
     UserDataCollection collection = new UserDataCollection();
     Assert.IsFalse(collection.HasValue(new Key<int>("key")));
     int value;
     Assert.IsFalse(collection.TryGetValue(new Key<int>("key"), out value));
     Assert.AreEqual(0, value);
     Assert.Throws<KeyNotFoundException>(delegate { collection.GetValue(new Key<int>("key"));});
     Assert.AreEqual(42, collection.GetValueOrDefault(new Key<int>("key"), 42));
 }
 public void ExistingValuesCanBeRetrieved()
 {
     UserDataCollection collection = new UserDataCollection();
     collection.SetValue(new Key<int>("key"), 123);
     Assert.IsTrue(collection.HasValue(new Key<int>("key")));
     Assert.AreEqual(123, collection.GetValue(new Key<int>("key")));
     Assert.AreEqual(123, collection.GetValueOrDefault(new Key<int>("key"), 0));
     int value;
     Assert.IsTrue(collection.TryGetValue(new Key<int>("key"), out value));
     Assert.AreEqual(123, value);
 }
        public void CanCopyAnEmptyCollection()
        {
            UserDataCollection source = new UserDataCollection();

            UserDataCollection copy = source.Copy();
            Assert.IsFalse(copy.HasValue(new Key<int>("key")));

            copy.SetValue(new Key<int>("key"), 33);
            Assert.AreEqual(33, copy.GetValue(new Key<int>("key")));
            Assert.IsFalse(source.HasValue(new Key<int>("key")));
        }
 public void ExistingValuesCanBeRemoved()
 {
     UserDataCollection collection = new UserDataCollection();
     collection.SetValue(new Key<int>("key"), 123);
     Assert.IsTrue(collection.HasValue(new Key<int>("key")));
     collection.RemoveValue(new Key<int>("key"));
     Assert.IsFalse(collection.HasValue(new Key<int>("key")));
 }
 public void NonExistantValuesCanBeRemovedWithoutSideEffects()
 {
     UserDataCollection collection = new UserDataCollection();
     collection.RemoveValue(new Key<int>("key"));
     Assert.IsFalse(collection.HasValue(new Key<int>("key")));
 }