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 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 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);
        }
        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")));
        }
Esempio n. 7
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);
            }
        }
 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")));
 }