public void CanCopyANonEmptyCollection()
        {
            UserDataCollection source = new UserDataCollection();

            source.SetValue(new Key <int>("key"), 42);

            UserDataCollection copy = source.Copy();

            Assert.AreEqual(42, copy.GetValue(new Key <int>("key")));

            copy.SetValue(new Key <int>("key"), 33);
            Assert.AreEqual(33, copy.GetValue(new Key <int>("key")));
            Assert.AreEqual(42, source.GetValue(new Key <int>("key")));
        }
 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 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 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 CanCopyANonEmptyCollection()
        {
            UserDataCollection source = new UserDataCollection();
            source.SetValue(new Key<int>("key"), 42);

            UserDataCollection copy = source.Copy();
            Assert.AreEqual(42, copy.GetValue(new Key<int>("key")));

            copy.SetValue(new Key<int>("key"), 33);
            Assert.AreEqual(33, copy.GetValue(new Key<int>("key")));
            Assert.AreEqual(42, source.GetValue(new Key<int>("key")));
        }
        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);
        }
Esempio n. 8
0
        internal static void AddConstraint(ISpecificationConstraint constraint)
        {
            UserDataCollection data = Context.CurrentContext.Data;

            lock (data)
            {
                List <ISpecificationConstraint> constraints = data.GetValue <List <ISpecificationConstraint> >(ConstraintsKey);
                if (constraints == null)
                {
                    constraints = new List <ISpecificationConstraint>();
                    data.SetValue(ConstraintsKey, constraints);
                }

                constraints.Add(constraint);
            }
        }