public void PrioritizedEventListenerDictionaryTests_ValueCollections_Multiple_MultipleEntries()
        {
            EventListenerRegistrationComparer comparer = new EventListenerRegistrationComparer();
            var dictionary = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(comparer);

            var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), SurvivalKit.Events.Priority.NORMAL, null));

            dictionary.Add(GetType(), mockListener);

            for (var iterator = 5; iterator > 0; iterator--)
            {
                dictionary.Add(typeof(IEventHook), mockListener);
            }


            var collections = dictionary.ValueCollections;

            Assert.IsNotNull(collections);
            Assert.AreEqual(2, collections.Count);
            var indexer = 0;

            foreach (var item in collections)
            {
                if (indexer == 0)
                {
                    Assert.AreEqual(1, item.Count);
                }
                else
                {
                    Assert.AreEqual(5, item.Count);
                }

                indexer++;
            }
        }
        public void PrioritizedEventListenerDictionaryTests_Add_InsertTwo_Asc()
        {
            EventListenerRegistrationComparer comparer = new EventListenerRegistrationComparer();
            var dictionary   = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(comparer);
            var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), SurvivalKit.Events.Priority.HIGH, null));

            dictionary.Add(GetType(), mockListener);
            var mockListener1 = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), SurvivalKit.Events.Priority.NORMAL, null));

            dictionary.Add(GetType(), mockListener1);

            // count the keys int he dictionary
            Assert.AreEqual(1, dictionary.Count);
            var collection = dictionary.ValueCollections;
            var iterator   = 0;

            foreach (var item in collection)
            {
                foreach (var registration in item)
                {
                    if (iterator == 0)
                    {
                        Assert.AreEqual(SurvivalKit.Events.Priority.HIGH, registration.EventHook.HookPriority);
                    }
                    else
                    {
                        Assert.AreEqual(SurvivalKit.Events.Priority.NORMAL, registration.EventHook.HookPriority);
                    }
                    iterator++;
                }
            }
        }
        public void PrioritizedEventListenerDictionaryTests_Add_KeyNull()
        {
            EventListenerRegistrationComparer comparer = new EventListenerRegistrationComparer();
            var dictionary   = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(comparer);
            var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), (SurvivalKit.Events.Priority.HIGH), null));

            dictionary.Add(null, mockListener);
        }
Exemplo n.º 4
0
        public void EventHookPriorityComparerTests_RightNull()
        {
            var leftHook = new MockEventHook(GetType(), SurvivalKit.Events.Priority.NORMAL, null);
            var leftMock = new EventListenerRegistration(new MockEventListener(true, false), leftHook);

            var comparer = new EventListenerRegistrationComparer();

            comparer.Compare(leftMock, null);
        }
        public void PrioritizedEventListenerDictionaryTests_Add_InsertSingle()
        {
            EventListenerRegistrationComparer comparer = new EventListenerRegistrationComparer();
            var dictionary   = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(comparer);
            var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), SurvivalKit.Events.Priority.NORMAL, null));

            dictionary.Add(GetType(), mockListener);

            Assert.AreEqual(1, dictionary.Count);
        }
        public void PrioritizedEventListenerDictionaryTests_ContainsKey_Valid()
        {
            EventListenerRegistrationComparer comparer = new EventListenerRegistrationComparer();
            var dictionary   = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(comparer);
            var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), SurvivalKit.Events.Priority.LOW, null));

            dictionary.Add(GetType(), mockListener);

            Assert.IsTrue(dictionary.ContainsKey(GetType()));
        }
Exemplo n.º 7
0
        public void EventHookPriorityComparerTests_RightGreater()
        {
            var leftHook  = new MockEventHook(GetType(), SurvivalKit.Events.Priority.NORMAL, null);
            var leftMock  = new EventListenerRegistration(new MockEventListener(true, false), leftHook);
            var rightHook = new MockEventHook(GetType(), SurvivalKit.Events.Priority.HIGHEST, null);
            var rightMock = new EventListenerRegistration(new MockEventListener(true, false), rightHook);

            var comparer = new EventListenerRegistrationComparer();
            var result   = comparer.Compare(leftMock, rightMock);

            Assert.AreEqual(-1, result);
        }
        public void PrioritizedEventListenerDictionaryTests_TryGetValue_Valid()
        {
            EventListenerRegistrationComparer comparer = new EventListenerRegistrationComparer();
            var dictionary   = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(comparer);
            var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), SurvivalKit.Events.Priority.HIGH, null));

            dictionary.Add(typeof(PrioritizedEventListenerDictionaryTests), mockListener);
            List <EventListenerRegistration> list = null;
            var value = dictionary.TryGetValue(typeof(PrioritizedEventListenerDictionaryTests), out list);

            Assert.IsNotNull(list);
            Assert.AreEqual(1, list.Count);
            Assert.AreEqual(mockListener, list[0]);
        }
        public void PrioritizedEventListenerDictionaryTests_Keys_Filled()
        {
            EventListenerRegistrationComparer comparer = new EventListenerRegistrationComparer();
            var dictionary = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(comparer);

            var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), (SurvivalKit.Events.Priority.HIGH), null));

            dictionary.Add(GetType(), mockListener);

            var keys = new List <Type>(dictionary.Keys);

            Assert.IsNotNull(keys);
            Assert.AreEqual(1, keys.Count);
            Assert.AreEqual(GetType(), keys[0]);
        }
        public void PrioritizedEventListenerDictionaryTests_ValueCollections_Single()
        {
            EventListenerRegistrationComparer comparer = new EventListenerRegistrationComparer();
            var dictionary = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(comparer);

            var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), SurvivalKit.Events.Priority.NORMAL, null));

            dictionary.Add(GetType(), mockListener);

            var collections = dictionary.ValueCollections;

            Assert.IsNotNull(collections);
            Assert.AreEqual(1, collections.Count);
            foreach (var collection in collections)
            {
                Assert.AreEqual(GetType(), collection[0].EventHook.GetEventType());
            }
        }
        public void PrioritizedEventListenerDictionaryTests_Add_Random()
        {
            EventListenerRegistrationComparer comparer = new EventListenerRegistrationComparer();
            var dictionary = new PrioritizedEventListenerDictionary <Type, EventListenerRegistration>(comparer);

            for (var iterator = 0; iterator < 25; iterator++)
            {
                var prio         = numberGenerator.Next(1, 5);
                var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(GetType(), (SurvivalKit.Events.Priority)prio, null));
                dictionary.Add(GetType(), mockListener);
            }

            for (var iterator = 0; iterator < 25; iterator++)
            {
                var prio         = numberGenerator.Next(1, 5);
                var mockListener = new EventListenerRegistration(new MockEventListener(true, false), new MockEventHook(typeof(EventListenerRegistrationComparer), (SurvivalKit.Events.Priority)prio, null));
                dictionary.Add(typeof(EventListenerRegistrationComparer), mockListener);
            }

            // count the keys int he dictionary
            Assert.AreEqual(2, dictionary.Count);
            var collection = dictionary.ValueCollections;

            foreach (var item in collection)
            {
                var topPrio = 100;
                foreach (var evtListenerRegistration in item)
                {
                    if ((int)evtListenerRegistration.EventHook.HookPriority > topPrio)
                    {
                        Assert.Fail("Found an entry that has a higher priority than the previous item in the list");
                    }
                    else if ((int)evtListenerRegistration.EventHook.HookPriority < topPrio)
                    {
                        topPrio = (int)evtListenerRegistration.EventHook.HookPriority;
                    }
                }
            }
        }