public void TestAddAll()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(2, 5);
            map.Add(2, 4);
            map.Add(2, 3);
            map.Add(1, 5);
            map.Add(1, 6);
            IMultiMap <int, int> map2 = HashMultiMap <int, int> .Create();

            map.Add(7, 5);
            map.Add(7, 4);
            map.Add(7, 3);
            map.Add(8, 5);
            map.Add(8, 6);
            map.AddAll(map2);
            foreach (int key in map2.Keys)
            {
                Assert.IsTrue(map.ContainsKey(key));
                foreach (int value in map2.Get(key))
                {
                    Assert.IsTrue(map.ContainsValue(value));
                }
            }
        }
        public void TestGet()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(2, 3);
            map.Add(2, 4);
            map.Add(2, 5);
            foreach (int item in map.Get(2))
            {
                Assert.IsTrue(item == 3 || item == 4 || item == 5);
            }
        }
        public void TestGetSet()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(2, 3);
            map.Add(2, 4);
            map.Add(2, 5);
            System.Collections.Generic.ISet <int> set = map.GetSet(2);
            Assert.IsTrue(set.Contains(3));
            Assert.IsTrue(set.Contains(4));
            Assert.IsTrue(set.Contains(5));
        }
        public void TestCountPair()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(1, 3);
            map.Add(2, 3);
            map.Add(3, 4);
            map.Add(4, 5);
            map.Add(5, 6);
            Assert.IsTrue(map.CountPairs == 5);
            map.Clear();
            Assert.IsTrue(map.CountPairs == 0);
        }
        public void TestRemoveAll()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(2, 3);
            map.Add(2, 4);
            map.Add(2, 5);
            map.RemoveAll(2);
            Assert.IsFalse(map.ContainsKey(2));
            Assert.IsFalse(map.ContainsValue(4));
            Assert.IsFalse(map.ContainsValue(5));
            Assert.IsFalse(map.ContainsValue(3));
        }
        public void TestRemove()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(2, 3);
            map.Add(2, 4);
            map.Add(2, 5);
            map.Remove(2, 5);
            Assert.IsFalse(map.ContainsKeyValuePair(new System.Collections.Generic.KeyValuePair <int, int>(2, 5)));
            map.Remove(2, 4);
            Assert.IsFalse(map.ContainsKeyValuePair(new System.Collections.Generic.KeyValuePair <int, int>(2, 4)));
            map.Remove(2, 3);
            Assert.IsFalse(map.ContainsKeyValuePair(new System.Collections.Generic.KeyValuePair <int, int>(2, 3)));
        }
        public void TestContainsKeyValuePair()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(100, 101);
            Assert.IsTrue(map.ContainsKeyValuePair(new System.Collections.Generic.KeyValuePair <int, int>(100, 101)));
        }
        public void TestContainsValue()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(4, 6);
            Assert.IsTrue(map.ContainsValue(6));
        }
        public void TestContainsKey()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(3, 2);
            Assert.IsTrue(map.ContainsKey(3));
            Assert.IsFalse(map.ContainsKey(45));
        }
        public void TestClear()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            Assert.IsTrue(map.CountPairs == 0);
            map.Add(1, 2);
            map.Clear();
            Assert.IsTrue(map.CountPairs == 0);
        }
Exemple #11
0
        /// <inheritdoc />
        public void Add(string key, string value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            contents.Add(key, value);
        }
Exemple #12
0
        /// <summary>
        /// This getting an object and extract all the methods marked with Subscribe attribute.
        /// </summary>
        /// <param name="subscriber">The object whose methods are desired to be event handlers</param>
        /// <returns>MultiMap between a key which is event type and a value which is the event handler contains a target object and methodInfo</returns>
        public IMultiMap <Type, EventHandler> FindAllHandlers(Object subscriber)
        {
            IMultiMap <Type, EventHandler> methodsInSubscriber = HashMultiMap <Type, EventHandler> .Create();

            foreach (MethodInfo method in GetMarkedMethods(subscriber))
            {
                ParameterInfo[] parmetersTypes = method.GetParameters();
                Type            eventType      = parmetersTypes[0].ParameterType;
                EventHandler    handler        = new EventHandler(subscriber, method);
                methodsInSubscriber.Add(eventType, handler);
            }
            return(methodsInSubscriber);
        }
        public void TestCountPairs()
        {
            IMultiMap <int, int> map = HashMultiMap <int, int> .Create();

            map.Add(2, 3);
            map.Add(2, 4);
            map.Add(2, 5);
            map.Add(7, 8);
            map.Add(7, 5);
            map.Add(1, 5);
            map.Add(29, 5);
            Assert.IsTrue(map.CountPairs == 7);
        }
Exemple #14
0
        /// <summary>
        /// This getting an object and extract all the methods marked with Subscribe attribute.
        /// </summary>
        /// <param name="subscriber">The object whose methods are desired to be event handlers</param>
        /// <returns>MultiMap between a key which is event type and a value which is the event handler contains a target object and methodInfo</returns>
        public IMultiMap <Type, EventHandler> FindAllHandlers(Object subscriber)
        {
            IMultiMap <Type, EventHandler> methodsInSubscriber = HashMultiMap <Type, EventHandler> .Create();

            foreach (MethodInfo method in GetMarkedMethods(subscriber))
            {
                Subscribe       attr           = (Subscribe)method.GetCustomAttribute(typeof(Subscribe));
                int             priority       = attr.GetPriority();
                ParameterInfo[] parmetersTypes = method.GetParameters();
                Type            eventType      = parmetersTypes[0].ParameterType;
                EventHandler    handler        = new EventHandler(subscriber, method, priority);
                methodsInSubscriber.Add(eventType, handler);
            }
            return(methodsInSubscriber);
        }
Exemple #15
0
        public static void ParseValue(IMultiMap <string, string> result, string value)
        {
            var clean = value.TrimStart('?');
            var parts = clean.Split('&');

            foreach (var part in parts)
            {
                var subParts = part.Split(new[] { '=' }, 2, StringSplitOptions.None);

                var key = Uri.UnescapeDataString(subParts[0]);

                if (string.IsNullOrWhiteSpace(key))
                {
                    continue;
                }

                result.Add(key, subParts.Length == 1 ? string.Empty : Uri.UnescapeDataString(subParts[1]));
            }
        }