Beispiel #1
0
        public void Should_return_false_when_trygetvalue_could_not_find_key()
        {
            // Given
            var    input = new DynamicDictionary();
            object output;

            // When
            var result = input.TryGetValue("test", out output);

            // Then
            result.ShouldBeFalse();
        }
Beispiel #2
0
        public void Should_return_value_when_trygetvalue_could_find_key()
        {
            // Given
            var input = new DynamicDictionary();

            input["test"] = 10;
            dynamic output;

            // When
            input.TryGetValue("test", out output);

            // Then
            ((int)output).ShouldEqual(10);
        }
        public void TestTryGetValueKeyDoesNotExist()
        {
            var d = new DynamicDictionary();

            object value;

            Assert.IsFalse(
                d.TryGetValue("key", out value),
                "Expected false to trying to get a value for a non exisiting key.");

            Assert.IsNull(
                value,
                "Retrieved a Non null value for a key that doesn't exist.");
        }
        public void TestTryGetValueKeyExists()
        {
            var d = new DynamicDictionary();

            d.Add("key", "value");

            object value;

            Assert.IsTrue(
                d.TryGetValue("key", out value),
                "Expected true to trying to get a value for an existing key.");

            Assert.AreEqual("value", value);
        }
Beispiel #5
0
        private NameValueCollection GetQueryValues()
        {
            if (m_query == null)
            {
                m_query = new NameValueCollection();

                DynamicDictionary dynDict = m_request.Query;
                foreach (string itemKey in dynDict.Keys)
                {
                    dynamic newValue = null;
                    if (dynDict.TryGetValue(itemKey, out newValue))
                    {
                        m_query.Add(itemKey, newValue.Value.ToString());
                    }
                }
            }

            return(m_query);
        }
Beispiel #6
0
        protected override DynamicDictionary Sort(DynamicDictionary proxyDictionary)
        {
            var newProxyDictionary = new DynamicDictionary();
            var sortedList         = (from entry in SortKeys
                                      orderby entry.Value ascending
                                      select entry).ToDictionary(c => c.Key, t => t.Value);

            foreach (var item in sortedList.Keys)
            {
                var checkItem = proxyDictionary.TryGetValue(item, out var value);
                if (checkItem)
                {
                    newProxyDictionary.Add(item, value);
                    proxyDictionary.Remove(item);
                }
            }

            foreach (var item in proxyDictionary)
            {
                newProxyDictionary.Add(item.Key, item.Value);
            }

            return(newProxyDictionary);
        }
        public void Should_return_value_when_trygetvalue_could_find_key()
        {
            // Given
            var input = new DynamicDictionary();
            input["test"] = 10;
            dynamic output;

            // When
            input.TryGetValue("test", out output);

            // Then
            ((int)output).ShouldEqual(10);
        }
        public void Should_return_true_when_trygetvalue_could_find_key()
        {
            // Given
            var input = new DynamicDictionary();
            input["test"] = 10;
            object output;

            // When
            var result = input.TryGetValue("test", out output);

            // Then
            result.ShouldBeTrue();
        }
        public void TestTryGetValueKeyDoesNotExist()
        {
            var d = new DynamicDictionary();

            object value;

            Assert.IsFalse(
                d.TryGetValue("key", out value),
                "Expected false to trying to get a value for a non exisiting key.");

            Assert.IsNull(
                value, 
                "Retrieved a Non null value for a key that doesn't exist.");
        }
        public void TestTryGetValueKeyExists()
        {
            var d = new DynamicDictionary();

            d.Add("key", "value");

            object value;

            Assert.IsTrue(
                d.TryGetValue("key", out value), 
                "Expected true to trying to get a value for an existing key.");

            Assert.AreEqual("value", value);
        }